]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-3.0-3.17.4-201412040017.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.17.4-201412040017.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 764f599..c600e2f 100644
239 --- a/Documentation/kbuild/makefiles.txt
240 +++ b/Documentation/kbuild/makefiles.txt
241 @@ -23,10 +23,11 @@ This document describes the Linux kernel Makefiles.
242 === 4 Host Program support
243 --- 4.1 Simple Host Program
244 --- 4.2 Composite Host Programs
245 - --- 4.3 Using C++ for host programs
246 - --- 4.4 Controlling compiler options for host programs
247 - --- 4.5 When host programs are actually built
248 - --- 4.6 Using hostprogs-$(CONFIG_FOO)
249 + --- 4.3 Defining shared libraries
250 + --- 4.4 Using C++ for host programs
251 + --- 4.5 Controlling compiler options for host programs
252 + --- 4.6 When host programs are actually built
253 + --- 4.7 Using hostprogs-$(CONFIG_FOO)
254
255 === 5 Kbuild clean infrastructure
256
257 @@ -642,7 +643,29 @@ Both possibilities are described in the following.
258 Finally, the two .o files are linked to the executable, lxdialog.
259 Note: The syntax <executable>-y is not permitted for host-programs.
260
261 ---- 4.3 Using C++ for host programs
262 +--- 4.3 Defining shared libraries
263 +
264 + Objects with extension .so are considered shared libraries, and
265 + will be compiled as position independent objects.
266 + Kbuild provides support for shared libraries, but the usage
267 + shall be restricted.
268 + In the following example the libkconfig.so shared library is used
269 + to link the executable conf.
270 +
271 + Example:
272 + #scripts/kconfig/Makefile
273 + hostprogs-y := conf
274 + conf-objs := conf.o libkconfig.so
275 + libkconfig-objs := expr.o type.o
276 +
277 + Shared libraries always require a corresponding -objs line, and
278 + in the example above the shared library libkconfig is composed by
279 + the two objects expr.o and type.o.
280 + expr.o and type.o will be built as position independent code and
281 + linked as a shared library libkconfig.so. C++ is not supported for
282 + shared libraries.
283 +
284 +--- 4.4 Using C++ for host programs
285
286 kbuild offers support for host programs written in C++. This was
287 introduced solely to support kconfig, and is not recommended
288 @@ -665,7 +688,7 @@ Both possibilities are described in the following.
289 qconf-cxxobjs := qconf.o
290 qconf-objs := check.o
291
292 ---- 4.4 Controlling compiler options for host programs
293 +--- 4.5 Controlling compiler options for host programs
294
295 When compiling host programs, it is possible to set specific flags.
296 The programs will always be compiled utilising $(HOSTCC) passed
297 @@ -693,7 +716,7 @@ Both possibilities are described in the following.
298 When linking qconf, it will be passed the extra option
299 "-L$(QTDIR)/lib".
300
301 ---- 4.5 When host programs are actually built
302 +--- 4.6 When host programs are actually built
303
304 Kbuild will only build host-programs when they are referenced
305 as a prerequisite.
306 @@ -724,7 +747,7 @@ Both possibilities are described in the following.
307 This will tell kbuild to build lxdialog even if not referenced in
308 any rule.
309
310 ---- 4.6 Using hostprogs-$(CONFIG_FOO)
311 +--- 4.7 Using hostprogs-$(CONFIG_FOO)
312
313 A typical pattern in a Kbuild file looks like this:
314
315 diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
316 index 1edd5fd..107ff46 100644
317 --- a/Documentation/kernel-parameters.txt
318 +++ b/Documentation/kernel-parameters.txt
319 @@ -1155,6 +1155,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
320 Format: <unsigned int> such that (rxsize & ~0x1fffc0) == 0.
321 Default: 1024
322
323 + grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
324 + ignore grsecurity's /proc restrictions
325 +
326 +
327 hashdist= [KNL,NUMA] Large hashes allocated during boot
328 are distributed across NUMA nodes. Defaults on
329 for 64-bit NUMA, off otherwise.
330 @@ -2175,6 +2179,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
331 noexec=on: enable non-executable mappings (default)
332 noexec=off: disable non-executable mappings
333
334 + nopcid [X86-64]
335 + Disable PCID (Process-Context IDentifier) even if it
336 + is supported by the processor.
337 +
338 nosmap [X86]
339 Disable SMAP (Supervisor Mode Access Prevention)
340 even if it is supported by processor.
341 @@ -2467,6 +2475,30 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
342 the specified number of seconds. This is to be used if
343 your oopses keep scrolling off the screen.
344
345 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
346 + virtualization environments that don't cope well with the
347 + expand down segment used by UDEREF on X86-32 or the frequent
348 + page table updates on X86-64.
349 +
350 + pax_sanitize_slab=
351 + Format: { 0 | 1 | off | fast | full }
352 + Options '0' and '1' are only provided for backward
353 + compatibility, 'off' or 'fast' should be used instead.
354 + 0|off : disable slab object sanitization
355 + 1|fast: enable slab object sanitization excluding
356 + whitelisted slabs (default)
357 + full : sanitize all slabs, even the whitelisted ones
358 +
359 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
360 +
361 + pax_extra_latent_entropy
362 + Enable a very simple form of latent entropy extraction
363 + from the first 4GB of memory as the bootmem allocator
364 + passes the memory pages to the buddy allocator.
365 +
366 + pax_weakuderef [X86-64] enables the weaker but faster form of UDEREF
367 + when the processor supports PCID.
368 +
369 pcbit= [HW,ISDN]
370
371 pcd. [PARIDE]
372 diff --git a/Makefile b/Makefile
373 index b60b64d..33b7ec8 100644
374 --- a/Makefile
375 +++ b/Makefile
376 @@ -303,8 +303,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
377
378 HOSTCC = gcc
379 HOSTCXX = g++
380 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
381 -HOSTCXXFLAGS = -O2
382 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
383 +HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
384 +HOSTCXXFLAGS = -O2 -Wall -W -Wno-array-bounds
385
386 ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1)
387 HOSTCFLAGS += -Wno-unused-value -Wno-unused-parameter \
388 @@ -450,8 +451,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
389 # Rules shared between *config targets and build targets
390
391 # Basic helpers built in scripts/
392 -PHONY += scripts_basic
393 -scripts_basic:
394 +PHONY += scripts_basic gcc-plugins
395 +scripts_basic: gcc-plugins
396 $(Q)$(MAKE) $(build)=scripts/basic
397 $(Q)rm -f .tmp_quiet_recordmcount
398
399 @@ -625,6 +626,72 @@ endif
400 # Tell gcc to never replace conditional load with a non-conditional one
401 KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0)
402
403 +ifndef DISABLE_PAX_PLUGINS
404 +ifeq ($(call cc-ifversion, -ge, 0408, y), y)
405 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
406 +else
407 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
408 +endif
409 +ifneq ($(PLUGINCC),)
410 +ifdef CONFIG_PAX_CONSTIFY_PLUGIN
411 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
412 +endif
413 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
414 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
415 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
416 +endif
417 +ifdef CONFIG_KALLOCSTAT_PLUGIN
418 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
419 +endif
420 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
421 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
422 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
423 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
424 +endif
425 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT
426 +RANDSTRUCT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/randomize_layout_plugin.so -DRANDSTRUCT_PLUGIN
427 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT_PERFORMANCE
428 +RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-performance-mode
429 +endif
430 +endif
431 +ifdef CONFIG_CHECKER_PLUGIN
432 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
433 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
434 +endif
435 +endif
436 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
437 +ifdef CONFIG_PAX_SIZE_OVERFLOW
438 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
439 +endif
440 +ifdef CONFIG_PAX_LATENT_ENTROPY
441 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
442 +endif
443 +ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
444 +STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
445 +endif
446 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
447 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
448 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
449 +GCC_PLUGINS_CFLAGS += $(RANDSTRUCT_PLUGIN_CFLAGS)
450 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
451 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN LATENT_ENTROPY_PLUGIN_CFLAGS
452 +ifeq ($(KBUILD_EXTMOD),)
453 +gcc-plugins:
454 + $(Q)$(MAKE) $(build)=tools/gcc
455 +else
456 +gcc-plugins: ;
457 +endif
458 +else
459 +gcc-plugins:
460 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
461 + $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
462 +else
463 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
464 +endif
465 + $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
466 +endif
467 +endif
468 +
469 ifdef CONFIG_READABLE_ASM
470 # Disable optimizations that make assembler listings hard to read.
471 # reorder blocks reorders the control in the function
472 @@ -717,7 +784,7 @@ KBUILD_CFLAGS += $(call cc-option, -gsplit-dwarf, -g)
473 else
474 KBUILD_CFLAGS += -g
475 endif
476 -KBUILD_AFLAGS += -Wa,-gdwarf-2
477 +KBUILD_AFLAGS += -Wa,--gdwarf-2
478 endif
479 ifdef CONFIG_DEBUG_INFO_DWARF4
480 KBUILD_CFLAGS += $(call cc-option, -gdwarf-4,)
481 @@ -867,7 +934,7 @@ export mod_sign_cmd
482
483
484 ifeq ($(KBUILD_EXTMOD),)
485 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
486 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
487
488 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
489 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
490 @@ -916,6 +983,8 @@ endif
491
492 # The actual objects are generated when descending,
493 # make sure no implicit rule kicks in
494 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
495 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
496 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
497
498 # Handle descending into subdirectories listed in $(vmlinux-dirs)
499 @@ -925,7 +994,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
500 # Error messages still appears in the original language
501
502 PHONY += $(vmlinux-dirs)
503 -$(vmlinux-dirs): prepare scripts
504 +$(vmlinux-dirs): gcc-plugins prepare scripts
505 $(Q)$(MAKE) $(build)=$@
506
507 define filechk_kernel.release
508 @@ -968,10 +1037,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
509
510 archprepare: archheaders archscripts prepare1 scripts_basic
511
512 +prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
513 +prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
514 prepare0: archprepare FORCE
515 $(Q)$(MAKE) $(build)=.
516
517 # All the preparing..
518 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
519 prepare: prepare0
520
521 # Generate some files
522 @@ -1086,6 +1158,8 @@ all: modules
523 # using awk while concatenating to the final file.
524
525 PHONY += modules
526 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
527 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
528 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
529 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
530 @$(kecho) ' Building modules, stage 2.';
531 @@ -1101,7 +1175,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
532
533 # Target to prepare building external modules
534 PHONY += modules_prepare
535 -modules_prepare: prepare scripts
536 +modules_prepare: gcc-plugins prepare scripts
537
538 # Target to install modules
539 PHONY += modules_install
540 @@ -1167,7 +1241,10 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
541 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
542 signing_key.priv signing_key.x509 x509.genkey \
543 extra_certificates signing_key.x509.keyid \
544 - signing_key.x509.signer include/linux/version.h
545 + signing_key.x509.signer include/linux/version.h \
546 + tools/gcc/size_overflow_plugin/size_overflow_hash_aux.h \
547 + tools/gcc/size_overflow_plugin/size_overflow_hash.h \
548 + tools/gcc/randomize_layout_seed.h
549
550 # clean - Delete most, but leave enough to build external modules
551 #
552 @@ -1206,7 +1283,7 @@ distclean: mrproper
553 @find $(srctree) $(RCS_FIND_IGNORE) \
554 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
555 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
556 - -o -name '.*.rej' -o -name '*%' -o -name 'core' \) \
557 + -o -name '.*.rej' -o -name '*.so' -o -name '*%' -o -name 'core' \) \
558 -type f -print | xargs rm -f
559
560
561 @@ -1372,6 +1449,8 @@ PHONY += $(module-dirs) modules
562 $(module-dirs): crmodverdir $(objtree)/Module.symvers
563 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
564
565 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
566 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
567 modules: $(module-dirs)
568 @$(kecho) ' Building modules, stage 2.';
569 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
570 @@ -1512,17 +1591,21 @@ else
571 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
572 endif
573
574 -%.s: %.c prepare scripts FORCE
575 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
576 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
577 +%.s: %.c gcc-plugins prepare scripts FORCE
578 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
579 %.i: %.c prepare scripts FORCE
580 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
581 -%.o: %.c prepare scripts FORCE
582 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
583 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
584 +%.o: %.c gcc-plugins prepare scripts FORCE
585 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
586 %.lst: %.c prepare scripts FORCE
587 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
588 -%.s: %.S prepare scripts FORCE
589 +%.s: %.S gcc-plugins prepare scripts FORCE
590 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
591 -%.o: %.S prepare scripts FORCE
592 +%.o: %.S gcc-plugins prepare scripts FORCE
593 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
594 %.symtypes: %.c prepare scripts FORCE
595 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
596 @@ -1532,11 +1615,15 @@ endif
597 $(cmd_crmodverdir)
598 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
599 $(build)=$(build-dir)
600 -%/: prepare scripts FORCE
601 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
602 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
603 +%/: gcc-plugins prepare scripts FORCE
604 $(cmd_crmodverdir)
605 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
606 $(build)=$(build-dir)
607 -%.ko: prepare scripts FORCE
608 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
609 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
610 +%.ko: gcc-plugins prepare scripts FORCE
611 $(cmd_crmodverdir)
612 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
613 $(build)=$(build-dir) $(@:.ko=.o)
614 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
615 index ed60a1e..47f1a55 100644
616 --- a/arch/alpha/include/asm/atomic.h
617 +++ b/arch/alpha/include/asm/atomic.h
618 @@ -292,4 +292,14 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
619 #define atomic_dec(v) atomic_sub(1,(v))
620 #define atomic64_dec(v) atomic64_sub(1,(v))
621
622 +#define atomic64_read_unchecked(v) atomic64_read(v)
623 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
624 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
625 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
626 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
627 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
628 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
629 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
630 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
631 +
632 #endif /* _ALPHA_ATOMIC_H */
633 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
634 index ad368a9..fbe0f25 100644
635 --- a/arch/alpha/include/asm/cache.h
636 +++ b/arch/alpha/include/asm/cache.h
637 @@ -4,19 +4,19 @@
638 #ifndef __ARCH_ALPHA_CACHE_H
639 #define __ARCH_ALPHA_CACHE_H
640
641 +#include <linux/const.h>
642
643 /* Bytes per L1 (data) cache line. */
644 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
645 -# define L1_CACHE_BYTES 64
646 # define L1_CACHE_SHIFT 6
647 #else
648 /* Both EV4 and EV5 are write-through, read-allocate,
649 direct-mapped, physical.
650 */
651 -# define L1_CACHE_BYTES 32
652 # define L1_CACHE_SHIFT 5
653 #endif
654
655 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
656 #define SMP_CACHE_BYTES L1_CACHE_BYTES
657
658 #endif
659 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
660 index 968d999..d36b2df 100644
661 --- a/arch/alpha/include/asm/elf.h
662 +++ b/arch/alpha/include/asm/elf.h
663 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
664
665 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
666
667 +#ifdef CONFIG_PAX_ASLR
668 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
669 +
670 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
671 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
672 +#endif
673 +
674 /* $0 is set by ld.so to a pointer to a function which might be
675 registered using atexit. This provides a mean for the dynamic
676 linker to call DT_FINI functions for shared libraries that have
677 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
678 index aab14a0..b4fa3e7 100644
679 --- a/arch/alpha/include/asm/pgalloc.h
680 +++ b/arch/alpha/include/asm/pgalloc.h
681 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
682 pgd_set(pgd, pmd);
683 }
684
685 +static inline void
686 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
687 +{
688 + pgd_populate(mm, pgd, pmd);
689 +}
690 +
691 extern pgd_t *pgd_alloc(struct mm_struct *mm);
692
693 static inline void
694 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
695 index d8f9b7e..f6222fa 100644
696 --- a/arch/alpha/include/asm/pgtable.h
697 +++ b/arch/alpha/include/asm/pgtable.h
698 @@ -102,6 +102,17 @@ struct vm_area_struct;
699 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
700 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
701 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
702 +
703 +#ifdef CONFIG_PAX_PAGEEXEC
704 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
705 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
706 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
707 +#else
708 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
709 +# define PAGE_COPY_NOEXEC PAGE_COPY
710 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
711 +#endif
712 +
713 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
714
715 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
716 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
717 index 2fd00b7..cfd5069 100644
718 --- a/arch/alpha/kernel/module.c
719 +++ b/arch/alpha/kernel/module.c
720 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
721
722 /* The small sections were sorted to the end of the segment.
723 The following should definitely cover them. */
724 - gp = (u64)me->module_core + me->core_size - 0x8000;
725 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
726 got = sechdrs[me->arch.gotsecindex].sh_addr;
727
728 for (i = 0; i < n; i++) {
729 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
730 index 1402fcc..0b1abd2 100644
731 --- a/arch/alpha/kernel/osf_sys.c
732 +++ b/arch/alpha/kernel/osf_sys.c
733 @@ -1298,10 +1298,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
734 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
735
736 static unsigned long
737 -arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
738 - unsigned long limit)
739 +arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
740 + unsigned long limit, unsigned long flags)
741 {
742 struct vm_unmapped_area_info info;
743 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
744
745 info.flags = 0;
746 info.length = len;
747 @@ -1309,6 +1310,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
748 info.high_limit = limit;
749 info.align_mask = 0;
750 info.align_offset = 0;
751 + info.threadstack_offset = offset;
752 return vm_unmapped_area(&info);
753 }
754
755 @@ -1341,20 +1343,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
756 merely specific addresses, but regions of memory -- perhaps
757 this feature should be incorporated into all ports? */
758
759 +#ifdef CONFIG_PAX_RANDMMAP
760 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
761 +#endif
762 +
763 if (addr) {
764 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
765 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
766 if (addr != (unsigned long) -ENOMEM)
767 return addr;
768 }
769
770 /* Next, try allocating at TASK_UNMAPPED_BASE. */
771 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
772 - len, limit);
773 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
774 +
775 if (addr != (unsigned long) -ENOMEM)
776 return addr;
777
778 /* Finally, try allocating in low memory. */
779 - addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
780 + addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
781
782 return addr;
783 }
784 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
785 index 98838a0..b304fb4 100644
786 --- a/arch/alpha/mm/fault.c
787 +++ b/arch/alpha/mm/fault.c
788 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
789 __reload_thread(pcb);
790 }
791
792 +#ifdef CONFIG_PAX_PAGEEXEC
793 +/*
794 + * PaX: decide what to do with offenders (regs->pc = fault address)
795 + *
796 + * returns 1 when task should be killed
797 + * 2 when patched PLT trampoline was detected
798 + * 3 when unpatched PLT trampoline was detected
799 + */
800 +static int pax_handle_fetch_fault(struct pt_regs *regs)
801 +{
802 +
803 +#ifdef CONFIG_PAX_EMUPLT
804 + int err;
805 +
806 + do { /* PaX: patched PLT emulation #1 */
807 + unsigned int ldah, ldq, jmp;
808 +
809 + err = get_user(ldah, (unsigned int *)regs->pc);
810 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
811 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
812 +
813 + if (err)
814 + break;
815 +
816 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
817 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
818 + jmp == 0x6BFB0000U)
819 + {
820 + unsigned long r27, addr;
821 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
822 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
823 +
824 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
825 + err = get_user(r27, (unsigned long *)addr);
826 + if (err)
827 + break;
828 +
829 + regs->r27 = r27;
830 + regs->pc = r27;
831 + return 2;
832 + }
833 + } while (0);
834 +
835 + do { /* PaX: patched PLT emulation #2 */
836 + unsigned int ldah, lda, br;
837 +
838 + err = get_user(ldah, (unsigned int *)regs->pc);
839 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
840 + err |= get_user(br, (unsigned int *)(regs->pc+8));
841 +
842 + if (err)
843 + break;
844 +
845 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
846 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
847 + (br & 0xFFE00000U) == 0xC3E00000U)
848 + {
849 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
850 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
851 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
852 +
853 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
854 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
855 + return 2;
856 + }
857 + } while (0);
858 +
859 + do { /* PaX: unpatched PLT emulation */
860 + unsigned int br;
861 +
862 + err = get_user(br, (unsigned int *)regs->pc);
863 +
864 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
865 + unsigned int br2, ldq, nop, jmp;
866 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
867 +
868 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
869 + err = get_user(br2, (unsigned int *)addr);
870 + err |= get_user(ldq, (unsigned int *)(addr+4));
871 + err |= get_user(nop, (unsigned int *)(addr+8));
872 + err |= get_user(jmp, (unsigned int *)(addr+12));
873 + err |= get_user(resolver, (unsigned long *)(addr+16));
874 +
875 + if (err)
876 + break;
877 +
878 + if (br2 == 0xC3600000U &&
879 + ldq == 0xA77B000CU &&
880 + nop == 0x47FF041FU &&
881 + jmp == 0x6B7B0000U)
882 + {
883 + regs->r28 = regs->pc+4;
884 + regs->r27 = addr+16;
885 + regs->pc = resolver;
886 + return 3;
887 + }
888 + }
889 + } while (0);
890 +#endif
891 +
892 + return 1;
893 +}
894 +
895 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
896 +{
897 + unsigned long i;
898 +
899 + printk(KERN_ERR "PAX: bytes at PC: ");
900 + for (i = 0; i < 5; i++) {
901 + unsigned int c;
902 + if (get_user(c, (unsigned int *)pc+i))
903 + printk(KERN_CONT "???????? ");
904 + else
905 + printk(KERN_CONT "%08x ", c);
906 + }
907 + printk("\n");
908 +}
909 +#endif
910
911 /*
912 * This routine handles page faults. It determines the address,
913 @@ -133,8 +251,29 @@ retry:
914 good_area:
915 si_code = SEGV_ACCERR;
916 if (cause < 0) {
917 - if (!(vma->vm_flags & VM_EXEC))
918 + if (!(vma->vm_flags & VM_EXEC)) {
919 +
920 +#ifdef CONFIG_PAX_PAGEEXEC
921 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
922 + goto bad_area;
923 +
924 + up_read(&mm->mmap_sem);
925 + switch (pax_handle_fetch_fault(regs)) {
926 +
927 +#ifdef CONFIG_PAX_EMUPLT
928 + case 2:
929 + case 3:
930 + return;
931 +#endif
932 +
933 + }
934 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
935 + do_group_exit(SIGKILL);
936 +#else
937 goto bad_area;
938 +#endif
939 +
940 + }
941 } else if (!cause) {
942 /* Allow reads even for write-only mappings */
943 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
944 diff --git a/arch/arc/kernel/kgdb.c b/arch/arc/kernel/kgdb.c
945 index a2ff5c5..ecf6a78 100644
946 --- a/arch/arc/kernel/kgdb.c
947 +++ b/arch/arc/kernel/kgdb.c
948 @@ -158,11 +158,6 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
949 return -1;
950 }
951
952 -unsigned long kgdb_arch_pc(int exception, struct pt_regs *regs)
953 -{
954 - return instruction_pointer(regs);
955 -}
956 -
957 int kgdb_arch_init(void)
958 {
959 single_step_data.armed = 0;
960 diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
961 index 32cbbd5..c102df9 100644
962 --- a/arch/arm/Kconfig
963 +++ b/arch/arm/Kconfig
964 @@ -1719,7 +1719,7 @@ config ALIGNMENT_TRAP
965
966 config UACCESS_WITH_MEMCPY
967 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
968 - depends on MMU
969 + depends on MMU && !PAX_MEMORY_UDEREF
970 default y if CPU_FEROCEON
971 help
972 Implement faster copy_to_user and clear_user methods for CPU
973 @@ -1983,6 +1983,7 @@ config XIP_PHYS_ADDR
974 config KEXEC
975 bool "Kexec system call (EXPERIMENTAL)"
976 depends on (!SMP || PM_SLEEP_SMP)
977 + depends on !GRKERNSEC_KMEM
978 help
979 kexec is a system call that implements the ability to shutdown your
980 current kernel, and to start another kernel. It is like a reboot
981 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
982 index 3040359..a494fa3 100644
983 --- a/arch/arm/include/asm/atomic.h
984 +++ b/arch/arm/include/asm/atomic.h
985 @@ -18,17 +18,41 @@
986 #include <asm/barrier.h>
987 #include <asm/cmpxchg.h>
988
989 +#ifdef CONFIG_GENERIC_ATOMIC64
990 +#include <asm-generic/atomic64.h>
991 +#endif
992 +
993 #define ATOMIC_INIT(i) { (i) }
994
995 #ifdef __KERNEL__
996
997 +#ifdef CONFIG_THUMB2_KERNEL
998 +#define REFCOUNT_TRAP_INSN "bkpt 0xf1"
999 +#else
1000 +#define REFCOUNT_TRAP_INSN "bkpt 0xf103"
1001 +#endif
1002 +
1003 +#define _ASM_EXTABLE(from, to) \
1004 +" .pushsection __ex_table,\"a\"\n"\
1005 +" .align 3\n" \
1006 +" .long " #from ", " #to"\n" \
1007 +" .popsection"
1008 +
1009 /*
1010 * On ARM, ordinary assignment (str instruction) doesn't clear the local
1011 * strex/ldrex monitor on some implementations. The reason we can use it for
1012 * atomic_set() is the clrex or dummy strex done on every exception return.
1013 */
1014 #define atomic_read(v) (*(volatile int *)&(v)->counter)
1015 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
1016 +{
1017 + return v->counter;
1018 +}
1019 #define atomic_set(v,i) (((v)->counter) = (i))
1020 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
1021 +{
1022 + v->counter = i;
1023 +}
1024
1025 #if __LINUX_ARM_ARCH__ >= 6
1026
1027 @@ -44,6 +68,36 @@ static inline void atomic_add(int i, atomic_t *v)
1028
1029 prefetchw(&v->counter);
1030 __asm__ __volatile__("@ atomic_add\n"
1031 +"1: ldrex %1, [%3]\n"
1032 +" adds %0, %1, %4\n"
1033 +
1034 +#ifdef CONFIG_PAX_REFCOUNT
1035 +" bvc 3f\n"
1036 +"2: " REFCOUNT_TRAP_INSN "\n"
1037 +"3:\n"
1038 +#endif
1039 +
1040 +" strex %1, %0, [%3]\n"
1041 +" teq %1, #0\n"
1042 +" bne 1b"
1043 +
1044 +#ifdef CONFIG_PAX_REFCOUNT
1045 +"\n4:\n"
1046 + _ASM_EXTABLE(2b, 4b)
1047 +#endif
1048 +
1049 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1050 + : "r" (&v->counter), "Ir" (i)
1051 + : "cc");
1052 +}
1053 +
1054 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1055 +{
1056 + unsigned long tmp;
1057 + int result;
1058 +
1059 + prefetchw(&v->counter);
1060 + __asm__ __volatile__("@ atomic_add_unchecked\n"
1061 "1: ldrex %0, [%3]\n"
1062 " add %0, %0, %4\n"
1063 " strex %1, %0, [%3]\n"
1064 @@ -63,6 +117,43 @@ static inline int atomic_add_return(int i, atomic_t *v)
1065 prefetchw(&v->counter);
1066
1067 __asm__ __volatile__("@ atomic_add_return\n"
1068 +"1: ldrex %1, [%3]\n"
1069 +" adds %0, %1, %4\n"
1070 +
1071 +#ifdef CONFIG_PAX_REFCOUNT
1072 +" bvc 3f\n"
1073 +" mov %0, %1\n"
1074 +"2: " REFCOUNT_TRAP_INSN "\n"
1075 +"3:\n"
1076 +#endif
1077 +
1078 +" strex %1, %0, [%3]\n"
1079 +" teq %1, #0\n"
1080 +" bne 1b"
1081 +
1082 +#ifdef CONFIG_PAX_REFCOUNT
1083 +"\n4:\n"
1084 + _ASM_EXTABLE(2b, 4b)
1085 +#endif
1086 +
1087 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1088 + : "r" (&v->counter), "Ir" (i)
1089 + : "cc");
1090 +
1091 + smp_mb();
1092 +
1093 + return result;
1094 +}
1095 +
1096 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1097 +{
1098 + unsigned long tmp;
1099 + int result;
1100 +
1101 + smp_mb();
1102 + prefetchw(&v->counter);
1103 +
1104 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
1105 "1: ldrex %0, [%3]\n"
1106 " add %0, %0, %4\n"
1107 " strex %1, %0, [%3]\n"
1108 @@ -84,6 +175,36 @@ static inline void atomic_sub(int i, atomic_t *v)
1109
1110 prefetchw(&v->counter);
1111 __asm__ __volatile__("@ atomic_sub\n"
1112 +"1: ldrex %1, [%3]\n"
1113 +" subs %0, %1, %4\n"
1114 +
1115 +#ifdef CONFIG_PAX_REFCOUNT
1116 +" bvc 3f\n"
1117 +"2: " REFCOUNT_TRAP_INSN "\n"
1118 +"3:\n"
1119 +#endif
1120 +
1121 +" strex %1, %0, [%3]\n"
1122 +" teq %1, #0\n"
1123 +" bne 1b"
1124 +
1125 +#ifdef CONFIG_PAX_REFCOUNT
1126 +"\n4:\n"
1127 + _ASM_EXTABLE(2b, 4b)
1128 +#endif
1129 +
1130 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1131 + : "r" (&v->counter), "Ir" (i)
1132 + : "cc");
1133 +}
1134 +
1135 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1136 +{
1137 + unsigned long tmp;
1138 + int result;
1139 +
1140 + prefetchw(&v->counter);
1141 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
1142 "1: ldrex %0, [%3]\n"
1143 " sub %0, %0, %4\n"
1144 " strex %1, %0, [%3]\n"
1145 @@ -103,11 +224,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1146 prefetchw(&v->counter);
1147
1148 __asm__ __volatile__("@ atomic_sub_return\n"
1149 -"1: ldrex %0, [%3]\n"
1150 -" sub %0, %0, %4\n"
1151 +"1: ldrex %1, [%3]\n"
1152 +" subs %0, %1, %4\n"
1153 +
1154 +#ifdef CONFIG_PAX_REFCOUNT
1155 +" bvc 3f\n"
1156 +" mov %0, %1\n"
1157 +"2: " REFCOUNT_TRAP_INSN "\n"
1158 +"3:\n"
1159 +#endif
1160 +
1161 " strex %1, %0, [%3]\n"
1162 " teq %1, #0\n"
1163 " bne 1b"
1164 +
1165 +#ifdef CONFIG_PAX_REFCOUNT
1166 +"\n4:\n"
1167 + _ASM_EXTABLE(2b, 4b)
1168 +#endif
1169 +
1170 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1171 : "r" (&v->counter), "Ir" (i)
1172 : "cc");
1173 @@ -152,12 +287,24 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1174 __asm__ __volatile__ ("@ atomic_add_unless\n"
1175 "1: ldrex %0, [%4]\n"
1176 " teq %0, %5\n"
1177 -" beq 2f\n"
1178 -" add %1, %0, %6\n"
1179 +" beq 4f\n"
1180 +" adds %1, %0, %6\n"
1181 +
1182 +#ifdef CONFIG_PAX_REFCOUNT
1183 +" bvc 3f\n"
1184 +"2: " REFCOUNT_TRAP_INSN "\n"
1185 +"3:\n"
1186 +#endif
1187 +
1188 " strex %2, %1, [%4]\n"
1189 " teq %2, #0\n"
1190 " bne 1b\n"
1191 -"2:"
1192 +"4:"
1193 +
1194 +#ifdef CONFIG_PAX_REFCOUNT
1195 + _ASM_EXTABLE(2b, 4b)
1196 +#endif
1197 +
1198 : "=&r" (oldval), "=&r" (newval), "=&r" (tmp), "+Qo" (v->counter)
1199 : "r" (&v->counter), "r" (u), "r" (a)
1200 : "cc");
1201 @@ -168,6 +315,28 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1202 return oldval;
1203 }
1204
1205 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1206 +{
1207 + unsigned long oldval, res;
1208 +
1209 + smp_mb();
1210 +
1211 + do {
1212 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1213 + "ldrex %1, [%3]\n"
1214 + "mov %0, #0\n"
1215 + "teq %1, %4\n"
1216 + "strexeq %0, %5, [%3]\n"
1217 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1218 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
1219 + : "cc");
1220 + } while (res);
1221 +
1222 + smp_mb();
1223 +
1224 + return oldval;
1225 +}
1226 +
1227 #else /* ARM_ARCH_6 */
1228
1229 #ifdef CONFIG_SMP
1230 @@ -186,7 +355,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1231
1232 return val;
1233 }
1234 +
1235 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1236 +{
1237 + return atomic_add_return(i, v);
1238 +}
1239 +
1240 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1241 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1242 +{
1243 + (void) atomic_add_return(i, v);
1244 +}
1245
1246 static inline int atomic_sub_return(int i, atomic_t *v)
1247 {
1248 @@ -201,6 +380,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1249 return val;
1250 }
1251 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1252 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1253 +{
1254 + (void) atomic_sub_return(i, v);
1255 +}
1256
1257 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1258 {
1259 @@ -216,6 +399,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1260 return ret;
1261 }
1262
1263 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1264 +{
1265 + return atomic_cmpxchg(v, old, new);
1266 +}
1267 +
1268 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1269 {
1270 int c, old;
1271 @@ -229,13 +417,33 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1272 #endif /* __LINUX_ARM_ARCH__ */
1273
1274 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1275 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1276 +{
1277 + return xchg(&v->counter, new);
1278 +}
1279
1280 #define atomic_inc(v) atomic_add(1, v)
1281 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1282 +{
1283 + atomic_add_unchecked(1, v);
1284 +}
1285 #define atomic_dec(v) atomic_sub(1, v)
1286 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1287 +{
1288 + atomic_sub_unchecked(1, v);
1289 +}
1290
1291 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1292 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1293 +{
1294 + return atomic_add_return_unchecked(1, v) == 0;
1295 +}
1296 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1297 #define atomic_inc_return(v) (atomic_add_return(1, v))
1298 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1299 +{
1300 + return atomic_add_return_unchecked(1, v);
1301 +}
1302 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1303 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1304
1305 @@ -246,6 +454,14 @@ typedef struct {
1306 long long counter;
1307 } atomic64_t;
1308
1309 +#ifdef CONFIG_PAX_REFCOUNT
1310 +typedef struct {
1311 + long long counter;
1312 +} atomic64_unchecked_t;
1313 +#else
1314 +typedef atomic64_t atomic64_unchecked_t;
1315 +#endif
1316 +
1317 #define ATOMIC64_INIT(i) { (i) }
1318
1319 #ifdef CONFIG_ARM_LPAE
1320 @@ -262,6 +478,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1321 return result;
1322 }
1323
1324 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1325 +{
1326 + long long result;
1327 +
1328 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1329 +" ldrd %0, %H0, [%1]"
1330 + : "=&r" (result)
1331 + : "r" (&v->counter), "Qo" (v->counter)
1332 + );
1333 +
1334 + return result;
1335 +}
1336 +
1337 static inline void atomic64_set(atomic64_t *v, long long i)
1338 {
1339 __asm__ __volatile__("@ atomic64_set\n"
1340 @@ -270,6 +499,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1341 : "r" (&v->counter), "r" (i)
1342 );
1343 }
1344 +
1345 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1346 +{
1347 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1348 +" strd %2, %H2, [%1]"
1349 + : "=Qo" (v->counter)
1350 + : "r" (&v->counter), "r" (i)
1351 + );
1352 +}
1353 #else
1354 static inline long long atomic64_read(const atomic64_t *v)
1355 {
1356 @@ -284,6 +522,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1357 return result;
1358 }
1359
1360 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1361 +{
1362 + long long result;
1363 +
1364 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1365 +" ldrexd %0, %H0, [%1]"
1366 + : "=&r" (result)
1367 + : "r" (&v->counter), "Qo" (v->counter)
1368 + );
1369 +
1370 + return result;
1371 +}
1372 +
1373 static inline void atomic64_set(atomic64_t *v, long long i)
1374 {
1375 long long tmp;
1376 @@ -298,6 +549,21 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1377 : "r" (&v->counter), "r" (i)
1378 : "cc");
1379 }
1380 +
1381 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1382 +{
1383 + long long tmp;
1384 +
1385 + prefetchw(&v->counter);
1386 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1387 +"1: ldrexd %0, %H0, [%2]\n"
1388 +" strexd %0, %3, %H3, [%2]\n"
1389 +" teq %0, #0\n"
1390 +" bne 1b"
1391 + : "=&r" (tmp), "=Qo" (v->counter)
1392 + : "r" (&v->counter), "r" (i)
1393 + : "cc");
1394 +}
1395 #endif
1396
1397 static inline void atomic64_add(long long i, atomic64_t *v)
1398 @@ -309,6 +575,37 @@ static inline void atomic64_add(long long i, atomic64_t *v)
1399 __asm__ __volatile__("@ atomic64_add\n"
1400 "1: ldrexd %0, %H0, [%3]\n"
1401 " adds %Q0, %Q0, %Q4\n"
1402 +" adcs %R0, %R0, %R4\n"
1403 +
1404 +#ifdef CONFIG_PAX_REFCOUNT
1405 +" bvc 3f\n"
1406 +"2: " REFCOUNT_TRAP_INSN "\n"
1407 +"3:\n"
1408 +#endif
1409 +
1410 +" strexd %1, %0, %H0, [%3]\n"
1411 +" teq %1, #0\n"
1412 +" bne 1b"
1413 +
1414 +#ifdef CONFIG_PAX_REFCOUNT
1415 +"\n4:\n"
1416 + _ASM_EXTABLE(2b, 4b)
1417 +#endif
1418 +
1419 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1420 + : "r" (&v->counter), "r" (i)
1421 + : "cc");
1422 +}
1423 +
1424 +static inline void atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
1425 +{
1426 + long long result;
1427 + unsigned long tmp;
1428 +
1429 + prefetchw(&v->counter);
1430 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1431 +"1: ldrexd %0, %H0, [%3]\n"
1432 +" adds %Q0, %Q0, %Q4\n"
1433 " adc %R0, %R0, %R4\n"
1434 " strexd %1, %0, %H0, [%3]\n"
1435 " teq %1, #0\n"
1436 @@ -329,6 +626,44 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
1437 __asm__ __volatile__("@ atomic64_add_return\n"
1438 "1: ldrexd %0, %H0, [%3]\n"
1439 " adds %Q0, %Q0, %Q4\n"
1440 +" adcs %R0, %R0, %R4\n"
1441 +
1442 +#ifdef CONFIG_PAX_REFCOUNT
1443 +" bvc 3f\n"
1444 +" mov %0, %1\n"
1445 +" mov %H0, %H1\n"
1446 +"2: " REFCOUNT_TRAP_INSN "\n"
1447 +"3:\n"
1448 +#endif
1449 +
1450 +" strexd %1, %0, %H0, [%3]\n"
1451 +" teq %1, #0\n"
1452 +" bne 1b"
1453 +
1454 +#ifdef CONFIG_PAX_REFCOUNT
1455 +"\n4:\n"
1456 + _ASM_EXTABLE(2b, 4b)
1457 +#endif
1458 +
1459 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1460 + : "r" (&v->counter), "r" (i)
1461 + : "cc");
1462 +
1463 + smp_mb();
1464 +
1465 + return result;
1466 +}
1467 +
1468 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
1469 +{
1470 + long long result;
1471 + unsigned long tmp;
1472 +
1473 + smp_mb();
1474 +
1475 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1476 +"1: ldrexd %0, %H0, [%3]\n"
1477 +" adds %Q0, %Q0, %Q4\n"
1478 " adc %R0, %R0, %R4\n"
1479 " strexd %1, %0, %H0, [%3]\n"
1480 " teq %1, #0\n"
1481 @@ -351,6 +686,37 @@ static inline void atomic64_sub(long long i, atomic64_t *v)
1482 __asm__ __volatile__("@ atomic64_sub\n"
1483 "1: ldrexd %0, %H0, [%3]\n"
1484 " subs %Q0, %Q0, %Q4\n"
1485 +" sbcs %R0, %R0, %R4\n"
1486 +
1487 +#ifdef CONFIG_PAX_REFCOUNT
1488 +" bvc 3f\n"
1489 +"2: " REFCOUNT_TRAP_INSN "\n"
1490 +"3:\n"
1491 +#endif
1492 +
1493 +" strexd %1, %0, %H0, [%3]\n"
1494 +" teq %1, #0\n"
1495 +" bne 1b"
1496 +
1497 +#ifdef CONFIG_PAX_REFCOUNT
1498 +"\n4:\n"
1499 + _ASM_EXTABLE(2b, 4b)
1500 +#endif
1501 +
1502 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1503 + : "r" (&v->counter), "r" (i)
1504 + : "cc");
1505 +}
1506 +
1507 +static inline void atomic64_sub_unchecked(long long i, atomic64_unchecked_t *v)
1508 +{
1509 + long long result;
1510 + unsigned long tmp;
1511 +
1512 + prefetchw(&v->counter);
1513 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1514 +"1: ldrexd %0, %H0, [%3]\n"
1515 +" subs %Q0, %Q0, %Q4\n"
1516 " sbc %R0, %R0, %R4\n"
1517 " strexd %1, %0, %H0, [%3]\n"
1518 " teq %1, #0\n"
1519 @@ -371,10 +737,25 @@ static inline long long atomic64_sub_return(long long i, atomic64_t *v)
1520 __asm__ __volatile__("@ atomic64_sub_return\n"
1521 "1: ldrexd %0, %H0, [%3]\n"
1522 " subs %Q0, %Q0, %Q4\n"
1523 -" sbc %R0, %R0, %R4\n"
1524 +" sbcs %R0, %R0, %R4\n"
1525 +
1526 +#ifdef CONFIG_PAX_REFCOUNT
1527 +" bvc 3f\n"
1528 +" mov %0, %1\n"
1529 +" mov %H0, %H1\n"
1530 +"2: " REFCOUNT_TRAP_INSN "\n"
1531 +"3:\n"
1532 +#endif
1533 +
1534 " strexd %1, %0, %H0, [%3]\n"
1535 " teq %1, #0\n"
1536 " bne 1b"
1537 +
1538 +#ifdef CONFIG_PAX_REFCOUNT
1539 +"\n4:\n"
1540 + _ASM_EXTABLE(2b, 4b)
1541 +#endif
1542 +
1543 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1544 : "r" (&v->counter), "r" (i)
1545 : "cc");
1546 @@ -410,6 +791,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1547 return oldval;
1548 }
1549
1550 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1551 + long long new)
1552 +{
1553 + long long oldval;
1554 + unsigned long res;
1555 +
1556 + smp_mb();
1557 +
1558 + do {
1559 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1560 + "ldrexd %1, %H1, [%3]\n"
1561 + "mov %0, #0\n"
1562 + "teq %1, %4\n"
1563 + "teqeq %H1, %H4\n"
1564 + "strexdeq %0, %5, %H5, [%3]"
1565 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1566 + : "r" (&ptr->counter), "r" (old), "r" (new)
1567 + : "cc");
1568 + } while (res);
1569 +
1570 + smp_mb();
1571 +
1572 + return oldval;
1573 +}
1574 +
1575 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1576 {
1577 long long result;
1578 @@ -435,21 +841,35 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1579 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1580 {
1581 long long result;
1582 - unsigned long tmp;
1583 + u64 tmp;
1584
1585 smp_mb();
1586 prefetchw(&v->counter);
1587
1588 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1589 -"1: ldrexd %0, %H0, [%3]\n"
1590 -" subs %Q0, %Q0, #1\n"
1591 -" sbc %R0, %R0, #0\n"
1592 +"1: ldrexd %1, %H1, [%3]\n"
1593 +" subs %Q0, %Q1, #1\n"
1594 +" sbcs %R0, %R1, #0\n"
1595 +
1596 +#ifdef CONFIG_PAX_REFCOUNT
1597 +" bvc 3f\n"
1598 +" mov %Q0, %Q1\n"
1599 +" mov %R0, %R1\n"
1600 +"2: " REFCOUNT_TRAP_INSN "\n"
1601 +"3:\n"
1602 +#endif
1603 +
1604 " teq %R0, #0\n"
1605 -" bmi 2f\n"
1606 +" bmi 4f\n"
1607 " strexd %1, %0, %H0, [%3]\n"
1608 " teq %1, #0\n"
1609 " bne 1b\n"
1610 -"2:"
1611 +"4:\n"
1612 +
1613 +#ifdef CONFIG_PAX_REFCOUNT
1614 + _ASM_EXTABLE(2b, 4b)
1615 +#endif
1616 +
1617 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1618 : "r" (&v->counter)
1619 : "cc");
1620 @@ -473,13 +893,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1621 " teq %0, %5\n"
1622 " teqeq %H0, %H5\n"
1623 " moveq %1, #0\n"
1624 -" beq 2f\n"
1625 +" beq 4f\n"
1626 " adds %Q0, %Q0, %Q6\n"
1627 -" adc %R0, %R0, %R6\n"
1628 +" adcs %R0, %R0, %R6\n"
1629 +
1630 +#ifdef CONFIG_PAX_REFCOUNT
1631 +" bvc 3f\n"
1632 +"2: " REFCOUNT_TRAP_INSN "\n"
1633 +"3:\n"
1634 +#endif
1635 +
1636 " strexd %2, %0, %H0, [%4]\n"
1637 " teq %2, #0\n"
1638 " bne 1b\n"
1639 -"2:"
1640 +"4:\n"
1641 +
1642 +#ifdef CONFIG_PAX_REFCOUNT
1643 + _ASM_EXTABLE(2b, 4b)
1644 +#endif
1645 +
1646 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1647 : "r" (&v->counter), "r" (u), "r" (a)
1648 : "cc");
1649 @@ -492,10 +924,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1650
1651 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1652 #define atomic64_inc(v) atomic64_add(1LL, (v))
1653 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1654 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1655 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1656 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1657 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1658 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1659 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1660 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1661 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1662 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1663 diff --git a/arch/arm/include/asm/barrier.h b/arch/arm/include/asm/barrier.h
1664 index c6a3e73..35cca85 100644
1665 --- a/arch/arm/include/asm/barrier.h
1666 +++ b/arch/arm/include/asm/barrier.h
1667 @@ -63,7 +63,7 @@
1668 do { \
1669 compiletime_assert_atomic_type(*p); \
1670 smp_mb(); \
1671 - ACCESS_ONCE(*p) = (v); \
1672 + ACCESS_ONCE_RW(*p) = (v); \
1673 } while (0)
1674
1675 #define smp_load_acquire(p) \
1676 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1677 index 75fe66b..ba3dee4 100644
1678 --- a/arch/arm/include/asm/cache.h
1679 +++ b/arch/arm/include/asm/cache.h
1680 @@ -4,8 +4,10 @@
1681 #ifndef __ASMARM_CACHE_H
1682 #define __ASMARM_CACHE_H
1683
1684 +#include <linux/const.h>
1685 +
1686 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1687 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1688 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1689
1690 /*
1691 * Memory returned by kmalloc() may be used for DMA, so we must make
1692 @@ -24,5 +26,6 @@
1693 #endif
1694
1695 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1696 +#define __read_only __attribute__ ((__section__(".data..read_only")))
1697
1698 #endif
1699 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1700 index 10e78d0..dc8505d 100644
1701 --- a/arch/arm/include/asm/cacheflush.h
1702 +++ b/arch/arm/include/asm/cacheflush.h
1703 @@ -116,7 +116,7 @@ struct cpu_cache_fns {
1704 void (*dma_unmap_area)(const void *, size_t, int);
1705
1706 void (*dma_flush_range)(const void *, const void *);
1707 -};
1708 +} __no_const;
1709
1710 /*
1711 * Select the calling method
1712 diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1713 index 5233151..87a71fa 100644
1714 --- a/arch/arm/include/asm/checksum.h
1715 +++ b/arch/arm/include/asm/checksum.h
1716 @@ -37,7 +37,19 @@ __wsum
1717 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1718
1719 __wsum
1720 -csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1721 +__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1722 +
1723 +static inline __wsum
1724 +csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1725 +{
1726 + __wsum ret;
1727 + pax_open_userland();
1728 + ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1729 + pax_close_userland();
1730 + return ret;
1731 +}
1732 +
1733 +
1734
1735 /*
1736 * Fold a partial checksum without adding pseudo headers
1737 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1738 index abb2c37..96db950 100644
1739 --- a/arch/arm/include/asm/cmpxchg.h
1740 +++ b/arch/arm/include/asm/cmpxchg.h
1741 @@ -104,6 +104,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1742
1743 #define xchg(ptr,x) \
1744 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1745 +#define xchg_unchecked(ptr,x) \
1746 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1747
1748 #include <asm-generic/cmpxchg-local.h>
1749
1750 diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1751 index 6ddbe44..b5e38b1 100644
1752 --- a/arch/arm/include/asm/domain.h
1753 +++ b/arch/arm/include/asm/domain.h
1754 @@ -48,18 +48,37 @@
1755 * Domain types
1756 */
1757 #define DOMAIN_NOACCESS 0
1758 -#define DOMAIN_CLIENT 1
1759 #ifdef CONFIG_CPU_USE_DOMAINS
1760 +#define DOMAIN_USERCLIENT 1
1761 +#define DOMAIN_KERNELCLIENT 1
1762 #define DOMAIN_MANAGER 3
1763 +#define DOMAIN_VECTORS DOMAIN_USER
1764 #else
1765 +
1766 +#ifdef CONFIG_PAX_KERNEXEC
1767 #define DOMAIN_MANAGER 1
1768 +#define DOMAIN_KERNEXEC 3
1769 +#else
1770 +#define DOMAIN_MANAGER 1
1771 +#endif
1772 +
1773 +#ifdef CONFIG_PAX_MEMORY_UDEREF
1774 +#define DOMAIN_USERCLIENT 0
1775 +#define DOMAIN_UDEREF 1
1776 +#define DOMAIN_VECTORS DOMAIN_KERNEL
1777 +#else
1778 +#define DOMAIN_USERCLIENT 1
1779 +#define DOMAIN_VECTORS DOMAIN_USER
1780 +#endif
1781 +#define DOMAIN_KERNELCLIENT 1
1782 +
1783 #endif
1784
1785 #define domain_val(dom,type) ((type) << (2*(dom)))
1786
1787 #ifndef __ASSEMBLY__
1788
1789 -#ifdef CONFIG_CPU_USE_DOMAINS
1790 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1791 static inline void set_domain(unsigned val)
1792 {
1793 asm volatile(
1794 @@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1795 isb();
1796 }
1797
1798 -#define modify_domain(dom,type) \
1799 - do { \
1800 - struct thread_info *thread = current_thread_info(); \
1801 - unsigned int domain = thread->cpu_domain; \
1802 - domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1803 - thread->cpu_domain = domain | domain_val(dom, type); \
1804 - set_domain(thread->cpu_domain); \
1805 - } while (0)
1806 -
1807 +extern void modify_domain(unsigned int dom, unsigned int type);
1808 #else
1809 static inline void set_domain(unsigned val) { }
1810 static inline void modify_domain(unsigned dom, unsigned type) { }
1811 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1812 index afb9caf..9a0bac0 100644
1813 --- a/arch/arm/include/asm/elf.h
1814 +++ b/arch/arm/include/asm/elf.h
1815 @@ -115,7 +115,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1816 the loader. We need to make sure that it is out of the way of the program
1817 that it will "exec", and that there is sufficient room for the brk. */
1818
1819 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1820 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1821 +
1822 +#ifdef CONFIG_PAX_ASLR
1823 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1824 +
1825 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1826 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1827 +#endif
1828
1829 /* When the program starts, a1 contains a pointer to a function to be
1830 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1831 @@ -125,10 +132,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1832 extern void elf_set_personality(const struct elf32_hdr *);
1833 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1834
1835 -struct mm_struct;
1836 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1837 -#define arch_randomize_brk arch_randomize_brk
1838 -
1839 #ifdef CONFIG_MMU
1840 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1841 struct linux_binprm;
1842 diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1843 index de53547..52b9a28 100644
1844 --- a/arch/arm/include/asm/fncpy.h
1845 +++ b/arch/arm/include/asm/fncpy.h
1846 @@ -81,7 +81,9 @@
1847 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1848 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1849 \
1850 + pax_open_kernel(); \
1851 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1852 + pax_close_kernel(); \
1853 flush_icache_range((unsigned long)(dest_buf), \
1854 (unsigned long)(dest_buf) + (size)); \
1855 \
1856 diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1857 index 53e69da..3fdc896 100644
1858 --- a/arch/arm/include/asm/futex.h
1859 +++ b/arch/arm/include/asm/futex.h
1860 @@ -46,6 +46,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1861 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1862 return -EFAULT;
1863
1864 + pax_open_userland();
1865 +
1866 smp_mb();
1867 /* Prefetching cannot fault */
1868 prefetchw(uaddr);
1869 @@ -63,6 +65,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1870 : "cc", "memory");
1871 smp_mb();
1872
1873 + pax_close_userland();
1874 +
1875 *uval = val;
1876 return ret;
1877 }
1878 @@ -93,6 +97,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1879 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1880 return -EFAULT;
1881
1882 + pax_open_userland();
1883 +
1884 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1885 "1: " TUSER(ldr) " %1, [%4]\n"
1886 " teq %1, %2\n"
1887 @@ -103,6 +109,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1888 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1889 : "cc", "memory");
1890
1891 + pax_close_userland();
1892 +
1893 *uval = val;
1894 return ret;
1895 }
1896 @@ -125,6 +133,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1897 return -EFAULT;
1898
1899 pagefault_disable(); /* implies preempt_disable() */
1900 + pax_open_userland();
1901
1902 switch (op) {
1903 case FUTEX_OP_SET:
1904 @@ -146,6 +155,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1905 ret = -ENOSYS;
1906 }
1907
1908 + pax_close_userland();
1909 pagefault_enable(); /* subsumes preempt_enable() */
1910
1911 if (!ret) {
1912 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1913 index 83eb2f7..ed77159 100644
1914 --- a/arch/arm/include/asm/kmap_types.h
1915 +++ b/arch/arm/include/asm/kmap_types.h
1916 @@ -4,6 +4,6 @@
1917 /*
1918 * This is the "bare minimum". AIO seems to require this.
1919 */
1920 -#define KM_TYPE_NR 16
1921 +#define KM_TYPE_NR 17
1922
1923 #endif
1924 diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1925 index 9e614a1..3302cca 100644
1926 --- a/arch/arm/include/asm/mach/dma.h
1927 +++ b/arch/arm/include/asm/mach/dma.h
1928 @@ -22,7 +22,7 @@ struct dma_ops {
1929 int (*residue)(unsigned int, dma_t *); /* optional */
1930 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1931 const char *type;
1932 -};
1933 +} __do_const;
1934
1935 struct dma_struct {
1936 void *addr; /* single DMA address */
1937 diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1938 index f98c7f3..e5c626d 100644
1939 --- a/arch/arm/include/asm/mach/map.h
1940 +++ b/arch/arm/include/asm/mach/map.h
1941 @@ -23,17 +23,19 @@ struct map_desc {
1942
1943 /* types 0-3 are defined in asm/io.h */
1944 enum {
1945 - MT_UNCACHED = 4,
1946 - MT_CACHECLEAN,
1947 - MT_MINICLEAN,
1948 + MT_UNCACHED_RW = 4,
1949 + MT_CACHECLEAN_RO,
1950 + MT_MINICLEAN_RO,
1951 MT_LOW_VECTORS,
1952 MT_HIGH_VECTORS,
1953 - MT_MEMORY_RWX,
1954 + __MT_MEMORY_RWX,
1955 MT_MEMORY_RW,
1956 - MT_ROM,
1957 - MT_MEMORY_RWX_NONCACHED,
1958 + MT_MEMORY_RX,
1959 + MT_ROM_RX,
1960 + MT_MEMORY_RW_NONCACHED,
1961 + MT_MEMORY_RX_NONCACHED,
1962 MT_MEMORY_RW_DTCM,
1963 - MT_MEMORY_RWX_ITCM,
1964 + MT_MEMORY_RX_ITCM,
1965 MT_MEMORY_RW_SO,
1966 MT_MEMORY_DMA_READY,
1967 };
1968 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1969 index 891a56b..48f337e 100644
1970 --- a/arch/arm/include/asm/outercache.h
1971 +++ b/arch/arm/include/asm/outercache.h
1972 @@ -36,7 +36,7 @@ struct outer_cache_fns {
1973
1974 /* This is an ARM L2C thing */
1975 void (*write_sec)(unsigned long, unsigned);
1976 -};
1977 +} __no_const;
1978
1979 extern struct outer_cache_fns outer_cache;
1980
1981 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1982 index 4355f0e..cd9168e 100644
1983 --- a/arch/arm/include/asm/page.h
1984 +++ b/arch/arm/include/asm/page.h
1985 @@ -23,6 +23,7 @@
1986
1987 #else
1988
1989 +#include <linux/compiler.h>
1990 #include <asm/glue.h>
1991
1992 /*
1993 @@ -114,7 +115,7 @@ struct cpu_user_fns {
1994 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1995 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1996 unsigned long vaddr, struct vm_area_struct *vma);
1997 -};
1998 +} __no_const;
1999
2000 #ifdef MULTI_USER
2001 extern struct cpu_user_fns cpu_user;
2002 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
2003 index 78a7793..e3dc06c 100644
2004 --- a/arch/arm/include/asm/pgalloc.h
2005 +++ b/arch/arm/include/asm/pgalloc.h
2006 @@ -17,6 +17,7 @@
2007 #include <asm/processor.h>
2008 #include <asm/cacheflush.h>
2009 #include <asm/tlbflush.h>
2010 +#include <asm/system_info.h>
2011
2012 #define check_pgt_cache() do { } while (0)
2013
2014 @@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2015 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
2016 }
2017
2018 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2019 +{
2020 + pud_populate(mm, pud, pmd);
2021 +}
2022 +
2023 #else /* !CONFIG_ARM_LPAE */
2024
2025 /*
2026 @@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2027 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
2028 #define pmd_free(mm, pmd) do { } while (0)
2029 #define pud_populate(mm,pmd,pte) BUG()
2030 +#define pud_populate_kernel(mm,pmd,pte) BUG()
2031
2032 #endif /* CONFIG_ARM_LPAE */
2033
2034 @@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
2035 __free_page(pte);
2036 }
2037
2038 +static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
2039 +{
2040 +#ifdef CONFIG_ARM_LPAE
2041 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
2042 +#else
2043 + if (addr & SECTION_SIZE)
2044 + pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
2045 + else
2046 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
2047 +#endif
2048 + flush_pmd_entry(pmdp);
2049 +}
2050 +
2051 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
2052 pmdval_t prot)
2053 {
2054 @@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
2055 static inline void
2056 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
2057 {
2058 - __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
2059 + __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
2060 }
2061 #define pmd_pgtable(pmd) pmd_page(pmd)
2062
2063 diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
2064 index 5cfba15..f415e1a 100644
2065 --- a/arch/arm/include/asm/pgtable-2level-hwdef.h
2066 +++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
2067 @@ -20,12 +20,15 @@
2068 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
2069 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
2070 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
2071 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
2072 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
2073 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
2074 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
2075 +
2076 /*
2077 * - section
2078 */
2079 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
2080 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
2081 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
2082 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
2083 @@ -37,6 +40,7 @@
2084 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
2085 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
2086 #define PMD_SECT_AF (_AT(pmdval_t, 0))
2087 +#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
2088
2089 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
2090 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
2091 @@ -66,6 +70,7 @@
2092 * - extended small page/tiny page
2093 */
2094 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
2095 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
2096 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
2097 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
2098 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
2099 diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
2100 index 219ac88..73ec32a 100644
2101 --- a/arch/arm/include/asm/pgtable-2level.h
2102 +++ b/arch/arm/include/asm/pgtable-2level.h
2103 @@ -126,6 +126,9 @@
2104 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
2105 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
2106
2107 +/* Two-level page tables only have PXN in the PGD, not in the PTE. */
2108 +#define L_PTE_PXN (_AT(pteval_t, 0))
2109 +
2110 /*
2111 * These are the memory types, defined to be compatible with
2112 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
2113 diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
2114 index 9fd61c7..f8f1cff 100644
2115 --- a/arch/arm/include/asm/pgtable-3level-hwdef.h
2116 +++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
2117 @@ -76,6 +76,7 @@
2118 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
2119 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
2120 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
2121 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2122 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
2123
2124 /*
2125 diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
2126 index 06e0bc0..c65bca8 100644
2127 --- a/arch/arm/include/asm/pgtable-3level.h
2128 +++ b/arch/arm/include/asm/pgtable-3level.h
2129 @@ -81,6 +81,7 @@
2130 #define L_PTE_USER (_AT(pteval_t, 1) << 6) /* AP[1] */
2131 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
2132 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
2133 +#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2134 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
2135 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55)
2136 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56)
2137 @@ -92,10 +93,12 @@
2138 #define L_PMD_SECT_SPLITTING (_AT(pmdval_t, 1) << 56)
2139 #define L_PMD_SECT_NONE (_AT(pmdval_t, 1) << 57)
2140 #define L_PMD_SECT_RDONLY (_AT(pteval_t, 1) << 58)
2141 +#define PMD_SECT_RDONLY PMD_SECT_AP2
2142
2143 /*
2144 * To be used in assembly code with the upper page attributes.
2145 */
2146 +#define L_PTE_PXN_HIGH (1 << (53 - 32))
2147 #define L_PTE_XN_HIGH (1 << (54 - 32))
2148 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
2149
2150 diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
2151 index 01baef0..73c156e 100644
2152 --- a/arch/arm/include/asm/pgtable.h
2153 +++ b/arch/arm/include/asm/pgtable.h
2154 @@ -33,6 +33,9 @@
2155 #include <asm/pgtable-2level.h>
2156 #endif
2157
2158 +#define ktla_ktva(addr) (addr)
2159 +#define ktva_ktla(addr) (addr)
2160 +
2161 /*
2162 * Just any arbitrary offset to the start of the vmalloc VM area: the
2163 * current 8MB value just means that there will be a 8MB "hole" after the
2164 @@ -48,6 +51,9 @@
2165 #define LIBRARY_TEXT_START 0x0c000000
2166
2167 #ifndef __ASSEMBLY__
2168 +extern pteval_t __supported_pte_mask;
2169 +extern pmdval_t __supported_pmd_mask;
2170 +
2171 extern void __pte_error(const char *file, int line, pte_t);
2172 extern void __pmd_error(const char *file, int line, pmd_t);
2173 extern void __pgd_error(const char *file, int line, pgd_t);
2174 @@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2175 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2176 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2177
2178 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
2179 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2180 +
2181 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2182 +#include <asm/domain.h>
2183 +#include <linux/thread_info.h>
2184 +#include <linux/preempt.h>
2185 +
2186 +static inline int test_domain(int domain, int domaintype)
2187 +{
2188 + return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2189 +}
2190 +#endif
2191 +
2192 +#ifdef CONFIG_PAX_KERNEXEC
2193 +static inline unsigned long pax_open_kernel(void) {
2194 +#ifdef CONFIG_ARM_LPAE
2195 + /* TODO */
2196 +#else
2197 + preempt_disable();
2198 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2199 + modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2200 +#endif
2201 + return 0;
2202 +}
2203 +
2204 +static inline unsigned long pax_close_kernel(void) {
2205 +#ifdef CONFIG_ARM_LPAE
2206 + /* TODO */
2207 +#else
2208 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2209 + /* DOMAIN_MANAGER = "client" under KERNEXEC */
2210 + modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2211 + preempt_enable_no_resched();
2212 +#endif
2213 + return 0;
2214 +}
2215 +#else
2216 +static inline unsigned long pax_open_kernel(void) { return 0; }
2217 +static inline unsigned long pax_close_kernel(void) { return 0; }
2218 +#endif
2219 +
2220 /*
2221 * This is the lowest virtual address we can permit any user space
2222 * mapping to be mapped at. This is particularly important for
2223 @@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2224 /*
2225 * The pgprot_* and protection_map entries will be fixed up in runtime
2226 * to include the cachable and bufferable bits based on memory policy,
2227 - * as well as any architecture dependent bits like global/ASID and SMP
2228 - * shared mapping bits.
2229 + * as well as any architecture dependent bits like global/ASID, PXN,
2230 + * and SMP shared mapping bits.
2231 */
2232 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2233
2234 @@ -269,7 +317,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2235 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2236 {
2237 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2238 - L_PTE_NONE | L_PTE_VALID;
2239 + L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2240 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2241 return pte;
2242 }
2243 diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2244 index c25ef3e..735f14b 100644
2245 --- a/arch/arm/include/asm/psci.h
2246 +++ b/arch/arm/include/asm/psci.h
2247 @@ -32,7 +32,7 @@ struct psci_operations {
2248 int (*affinity_info)(unsigned long target_affinity,
2249 unsigned long lowest_affinity_level);
2250 int (*migrate_info_type)(void);
2251 -};
2252 +} __no_const;
2253
2254 extern struct psci_operations psci_ops;
2255 extern struct smp_operations psci_smp_ops;
2256 diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2257 index 2ec765c..beb1fe16 100644
2258 --- a/arch/arm/include/asm/smp.h
2259 +++ b/arch/arm/include/asm/smp.h
2260 @@ -113,7 +113,7 @@ struct smp_operations {
2261 int (*cpu_disable)(unsigned int cpu);
2262 #endif
2263 #endif
2264 -};
2265 +} __no_const;
2266
2267 struct of_cpu_method {
2268 const char *method;
2269 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2270 index fc44d37..acc63c4 100644
2271 --- a/arch/arm/include/asm/thread_info.h
2272 +++ b/arch/arm/include/asm/thread_info.h
2273 @@ -89,9 +89,9 @@ struct thread_info {
2274 .flags = 0, \
2275 .preempt_count = INIT_PREEMPT_COUNT, \
2276 .addr_limit = KERNEL_DS, \
2277 - .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2278 - domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2279 - domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2280 + .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2281 + domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2282 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2283 .restart_block = { \
2284 .fn = do_no_restart_syscall, \
2285 }, \
2286 @@ -165,7 +165,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2287 #define TIF_SYSCALL_AUDIT 9
2288 #define TIF_SYSCALL_TRACEPOINT 10
2289 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2290 -#define TIF_NOHZ 12 /* in adaptive nohz mode */
2291 +/* within 8 bits of TIF_SYSCALL_TRACE
2292 + * to meet flexible second operand requirements
2293 + */
2294 +#define TIF_GRSEC_SETXID 12
2295 +#define TIF_NOHZ 13 /* in adaptive nohz mode */
2296 #define TIF_USING_IWMMXT 17
2297 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2298 #define TIF_RESTORE_SIGMASK 20
2299 @@ -179,10 +183,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2300 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2301 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2302 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2303 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2304
2305 /* Checks for any syscall work in entry-common.S */
2306 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2307 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2308 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2309
2310 /*
2311 * Change these and you break ASM code in entry-common.S
2312 diff --git a/arch/arm/include/asm/tls.h b/arch/arm/include/asm/tls.h
2313 index 5f833f7..76e6644 100644
2314 --- a/arch/arm/include/asm/tls.h
2315 +++ b/arch/arm/include/asm/tls.h
2316 @@ -3,6 +3,7 @@
2317
2318 #include <linux/compiler.h>
2319 #include <asm/thread_info.h>
2320 +#include <asm/pgtable.h>
2321
2322 #ifdef __ASSEMBLY__
2323 #include <asm/asm-offsets.h>
2324 @@ -89,7 +90,9 @@ static inline void set_tls(unsigned long val)
2325 * at 0xffff0fe0 must be used instead. (see
2326 * entry-armv.S for details)
2327 */
2328 + pax_open_kernel();
2329 *((unsigned int *)0xffff0ff0) = val;
2330 + pax_close_kernel();
2331 #endif
2332 }
2333
2334 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2335 index 4767eb9..bf00668 100644
2336 --- a/arch/arm/include/asm/uaccess.h
2337 +++ b/arch/arm/include/asm/uaccess.h
2338 @@ -18,6 +18,7 @@
2339 #include <asm/domain.h>
2340 #include <asm/unified.h>
2341 #include <asm/compiler.h>
2342 +#include <asm/pgtable.h>
2343
2344 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2345 #include <asm-generic/uaccess-unaligned.h>
2346 @@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2347 static inline void set_fs(mm_segment_t fs)
2348 {
2349 current_thread_info()->addr_limit = fs;
2350 - modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2351 + modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2352 }
2353
2354 #define segment_eq(a,b) ((a) == (b))
2355
2356 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
2357 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2358 +
2359 +static inline void pax_open_userland(void)
2360 +{
2361 +
2362 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2363 + if (segment_eq(get_fs(), USER_DS)) {
2364 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2365 + modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2366 + }
2367 +#endif
2368 +
2369 +}
2370 +
2371 +static inline void pax_close_userland(void)
2372 +{
2373 +
2374 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2375 + if (segment_eq(get_fs(), USER_DS)) {
2376 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2377 + modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2378 + }
2379 +#endif
2380 +
2381 +}
2382 +
2383 #define __addr_ok(addr) ({ \
2384 unsigned long flag; \
2385 __asm__("cmp %2, %0; movlo %0, #0" \
2386 @@ -198,8 +226,12 @@ extern int __get_user_64t_4(void *);
2387
2388 #define get_user(x,p) \
2389 ({ \
2390 + int __e; \
2391 might_fault(); \
2392 - __get_user_check(x,p); \
2393 + pax_open_userland(); \
2394 + __e = __get_user_check(x,p); \
2395 + pax_close_userland(); \
2396 + __e; \
2397 })
2398
2399 extern int __put_user_1(void *, unsigned int);
2400 @@ -244,8 +276,12 @@ extern int __put_user_8(void *, unsigned long long);
2401
2402 #define put_user(x,p) \
2403 ({ \
2404 + int __e; \
2405 might_fault(); \
2406 - __put_user_check(x,p); \
2407 + pax_open_userland(); \
2408 + __e = __put_user_check(x,p); \
2409 + pax_close_userland(); \
2410 + __e; \
2411 })
2412
2413 #else /* CONFIG_MMU */
2414 @@ -269,6 +305,7 @@ static inline void set_fs(mm_segment_t fs)
2415
2416 #endif /* CONFIG_MMU */
2417
2418 +#define access_ok_noprefault(type,addr,size) access_ok((type),(addr),(size))
2419 #define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
2420
2421 #define user_addr_max() \
2422 @@ -286,13 +323,17 @@ static inline void set_fs(mm_segment_t fs)
2423 #define __get_user(x,ptr) \
2424 ({ \
2425 long __gu_err = 0; \
2426 + pax_open_userland(); \
2427 __get_user_err((x),(ptr),__gu_err); \
2428 + pax_close_userland(); \
2429 __gu_err; \
2430 })
2431
2432 #define __get_user_error(x,ptr,err) \
2433 ({ \
2434 + pax_open_userland(); \
2435 __get_user_err((x),(ptr),err); \
2436 + pax_close_userland(); \
2437 (void) 0; \
2438 })
2439
2440 @@ -368,13 +409,17 @@ do { \
2441 #define __put_user(x,ptr) \
2442 ({ \
2443 long __pu_err = 0; \
2444 + pax_open_userland(); \
2445 __put_user_err((x),(ptr),__pu_err); \
2446 + pax_close_userland(); \
2447 __pu_err; \
2448 })
2449
2450 #define __put_user_error(x,ptr,err) \
2451 ({ \
2452 + pax_open_userland(); \
2453 __put_user_err((x),(ptr),err); \
2454 + pax_close_userland(); \
2455 (void) 0; \
2456 })
2457
2458 @@ -474,11 +519,44 @@ do { \
2459
2460
2461 #ifdef CONFIG_MMU
2462 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2463 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2464 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2465 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2466 +
2467 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2468 +{
2469 + unsigned long ret;
2470 +
2471 + check_object_size(to, n, false);
2472 + pax_open_userland();
2473 + ret = ___copy_from_user(to, from, n);
2474 + pax_close_userland();
2475 + return ret;
2476 +}
2477 +
2478 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2479 +{
2480 + unsigned long ret;
2481 +
2482 + check_object_size(from, n, true);
2483 + pax_open_userland();
2484 + ret = ___copy_to_user(to, from, n);
2485 + pax_close_userland();
2486 + return ret;
2487 +}
2488 +
2489 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2490 -extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2491 +extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2492 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2493 +
2494 +static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2495 +{
2496 + unsigned long ret;
2497 + pax_open_userland();
2498 + ret = ___clear_user(addr, n);
2499 + pax_close_userland();
2500 + return ret;
2501 +}
2502 +
2503 #else
2504 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2505 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2506 @@ -487,6 +565,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2507
2508 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2509 {
2510 + if ((long)n < 0)
2511 + return n;
2512 +
2513 if (access_ok(VERIFY_READ, from, n))
2514 n = __copy_from_user(to, from, n);
2515 else /* security hole - plug it */
2516 @@ -496,6 +577,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2517
2518 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2519 {
2520 + if ((long)n < 0)
2521 + return n;
2522 +
2523 if (access_ok(VERIFY_WRITE, to, n))
2524 n = __copy_to_user(to, from, n);
2525 return n;
2526 diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2527 index 5af0ed1..cea83883 100644
2528 --- a/arch/arm/include/uapi/asm/ptrace.h
2529 +++ b/arch/arm/include/uapi/asm/ptrace.h
2530 @@ -92,7 +92,7 @@
2531 * ARMv7 groups of PSR bits
2532 */
2533 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2534 -#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2535 +#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2536 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2537 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2538
2539 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2540 index a88671c..1cc895e 100644
2541 --- a/arch/arm/kernel/armksyms.c
2542 +++ b/arch/arm/kernel/armksyms.c
2543 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2544
2545 /* networking */
2546 EXPORT_SYMBOL(csum_partial);
2547 -EXPORT_SYMBOL(csum_partial_copy_from_user);
2548 +EXPORT_SYMBOL(__csum_partial_copy_from_user);
2549 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2550 EXPORT_SYMBOL(__csum_ipv6_magic);
2551
2552 @@ -91,9 +91,9 @@ EXPORT_SYMBOL(__memzero);
2553 #ifdef CONFIG_MMU
2554 EXPORT_SYMBOL(copy_page);
2555
2556 -EXPORT_SYMBOL(__copy_from_user);
2557 -EXPORT_SYMBOL(__copy_to_user);
2558 -EXPORT_SYMBOL(__clear_user);
2559 +EXPORT_SYMBOL(___copy_from_user);
2560 +EXPORT_SYMBOL(___copy_to_user);
2561 +EXPORT_SYMBOL(___clear_user);
2562
2563 EXPORT_SYMBOL(__get_user_1);
2564 EXPORT_SYMBOL(__get_user_2);
2565 diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2566 index 36276cd..9d7b13b 100644
2567 --- a/arch/arm/kernel/entry-armv.S
2568 +++ b/arch/arm/kernel/entry-armv.S
2569 @@ -47,6 +47,87 @@
2570 9997:
2571 .endm
2572
2573 + .macro pax_enter_kernel
2574 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2575 + @ make aligned space for saved DACR
2576 + sub sp, sp, #8
2577 + @ save regs
2578 + stmdb sp!, {r1, r2}
2579 + @ read DACR from cpu_domain into r1
2580 + mov r2, sp
2581 + @ assume 8K pages, since we have to split the immediate in two
2582 + bic r2, r2, #(0x1fc0)
2583 + bic r2, r2, #(0x3f)
2584 + ldr r1, [r2, #TI_CPU_DOMAIN]
2585 + @ store old DACR on stack
2586 + str r1, [sp, #8]
2587 +#ifdef CONFIG_PAX_KERNEXEC
2588 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2589 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2590 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2591 +#endif
2592 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2593 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2594 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2595 +#endif
2596 + @ write r1 to current_thread_info()->cpu_domain
2597 + str r1, [r2, #TI_CPU_DOMAIN]
2598 + @ write r1 to DACR
2599 + mcr p15, 0, r1, c3, c0, 0
2600 + @ instruction sync
2601 + instr_sync
2602 + @ restore regs
2603 + ldmia sp!, {r1, r2}
2604 +#endif
2605 + .endm
2606 +
2607 + .macro pax_open_userland
2608 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2609 + @ save regs
2610 + stmdb sp!, {r0, r1}
2611 + @ read DACR from cpu_domain into r1
2612 + mov r0, sp
2613 + @ assume 8K pages, since we have to split the immediate in two
2614 + bic r0, r0, #(0x1fc0)
2615 + bic r0, r0, #(0x3f)
2616 + ldr r1, [r0, #TI_CPU_DOMAIN]
2617 + @ set current DOMAIN_USER to DOMAIN_CLIENT
2618 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2619 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2620 + @ write r1 to current_thread_info()->cpu_domain
2621 + str r1, [r0, #TI_CPU_DOMAIN]
2622 + @ write r1 to DACR
2623 + mcr p15, 0, r1, c3, c0, 0
2624 + @ instruction sync
2625 + instr_sync
2626 + @ restore regs
2627 + ldmia sp!, {r0, r1}
2628 +#endif
2629 + .endm
2630 +
2631 + .macro pax_close_userland
2632 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2633 + @ save regs
2634 + stmdb sp!, {r0, r1}
2635 + @ read DACR from cpu_domain into r1
2636 + mov r0, sp
2637 + @ assume 8K pages, since we have to split the immediate in two
2638 + bic r0, r0, #(0x1fc0)
2639 + bic r0, r0, #(0x3f)
2640 + ldr r1, [r0, #TI_CPU_DOMAIN]
2641 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2642 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2643 + @ write r1 to current_thread_info()->cpu_domain
2644 + str r1, [r0, #TI_CPU_DOMAIN]
2645 + @ write r1 to DACR
2646 + mcr p15, 0, r1, c3, c0, 0
2647 + @ instruction sync
2648 + instr_sync
2649 + @ restore regs
2650 + ldmia sp!, {r0, r1}
2651 +#endif
2652 + .endm
2653 +
2654 .macro pabt_helper
2655 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2656 #ifdef MULTI_PABORT
2657 @@ -89,11 +170,15 @@
2658 * Invalid mode handlers
2659 */
2660 .macro inv_entry, reason
2661 +
2662 + pax_enter_kernel
2663 +
2664 sub sp, sp, #S_FRAME_SIZE
2665 ARM( stmib sp, {r1 - lr} )
2666 THUMB( stmia sp, {r0 - r12} )
2667 THUMB( str sp, [sp, #S_SP] )
2668 THUMB( str lr, [sp, #S_LR] )
2669 +
2670 mov r1, #\reason
2671 .endm
2672
2673 @@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2674 .macro svc_entry, stack_hole=0
2675 UNWIND(.fnstart )
2676 UNWIND(.save {r0 - pc} )
2677 +
2678 + pax_enter_kernel
2679 +
2680 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2681 +
2682 #ifdef CONFIG_THUMB2_KERNEL
2683 SPFIX( str r0, [sp] ) @ temporarily saved
2684 SPFIX( mov r0, sp )
2685 @@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2686 ldmia r0, {r3 - r5}
2687 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2688 mov r6, #-1 @ "" "" "" ""
2689 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2690 + @ offset sp by 8 as done in pax_enter_kernel
2691 + add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2692 +#else
2693 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2694 +#endif
2695 SPFIX( addeq r2, r2, #4 )
2696 str r3, [sp, #-4]! @ save the "real" r0 copied
2697 @ from the exception stack
2698 @@ -317,6 +411,9 @@ ENDPROC(__pabt_svc)
2699 .macro usr_entry
2700 UNWIND(.fnstart )
2701 UNWIND(.cantunwind ) @ don't unwind the user space
2702 +
2703 + pax_enter_kernel_user
2704 +
2705 sub sp, sp, #S_FRAME_SIZE
2706 ARM( stmib sp, {r1 - r12} )
2707 THUMB( stmia sp, {r0 - r12} )
2708 @@ -421,7 +518,9 @@ __und_usr:
2709 tst r3, #PSR_T_BIT @ Thumb mode?
2710 bne __und_usr_thumb
2711 sub r4, r2, #4 @ ARM instr at LR - 4
2712 + pax_open_userland
2713 1: ldrt r0, [r4]
2714 + pax_close_userland
2715 ARM_BE8(rev r0, r0) @ little endian instruction
2716
2717 @ r0 = 32-bit ARM instruction which caused the exception
2718 @@ -455,11 +554,15 @@ __und_usr_thumb:
2719 */
2720 .arch armv6t2
2721 #endif
2722 + pax_open_userland
2723 2: ldrht r5, [r4]
2724 + pax_close_userland
2725 ARM_BE8(rev16 r5, r5) @ little endian instruction
2726 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2727 blo __und_usr_fault_16 @ 16bit undefined instruction
2728 + pax_open_userland
2729 3: ldrht r0, [r2]
2730 + pax_close_userland
2731 ARM_BE8(rev16 r0, r0) @ little endian instruction
2732 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2733 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2734 @@ -489,7 +592,8 @@ ENDPROC(__und_usr)
2735 */
2736 .pushsection .fixup, "ax"
2737 .align 2
2738 -4: str r4, [sp, #S_PC] @ retry current instruction
2739 +4: pax_close_userland
2740 + str r4, [sp, #S_PC] @ retry current instruction
2741 ret r9
2742 .popsection
2743 .pushsection __ex_table,"a"
2744 @@ -698,7 +802,7 @@ ENTRY(__switch_to)
2745 THUMB( str lr, [ip], #4 )
2746 ldr r4, [r2, #TI_TP_VALUE]
2747 ldr r5, [r2, #TI_TP_VALUE + 4]
2748 -#ifdef CONFIG_CPU_USE_DOMAINS
2749 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2750 ldr r6, [r2, #TI_CPU_DOMAIN]
2751 #endif
2752 switch_tls r1, r4, r5, r3, r7
2753 @@ -707,7 +811,7 @@ ENTRY(__switch_to)
2754 ldr r8, =__stack_chk_guard
2755 ldr r7, [r7, #TSK_STACK_CANARY]
2756 #endif
2757 -#ifdef CONFIG_CPU_USE_DOMAINS
2758 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2759 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2760 #endif
2761 mov r5, r0
2762 diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2763 index e52fe5a..1b0a924 100644
2764 --- a/arch/arm/kernel/entry-common.S
2765 +++ b/arch/arm/kernel/entry-common.S
2766 @@ -11,18 +11,46 @@
2767 #include <asm/assembler.h>
2768 #include <asm/unistd.h>
2769 #include <asm/ftrace.h>
2770 +#include <asm/domain.h>
2771 #include <asm/unwind.h>
2772
2773 +#include "entry-header.S"
2774 +
2775 #ifdef CONFIG_NEED_RET_TO_USER
2776 #include <mach/entry-macro.S>
2777 #else
2778 .macro arch_ret_to_user, tmp1, tmp2
2779 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2780 + @ save regs
2781 + stmdb sp!, {r1, r2}
2782 + @ read DACR from cpu_domain into r1
2783 + mov r2, sp
2784 + @ assume 8K pages, since we have to split the immediate in two
2785 + bic r2, r2, #(0x1fc0)
2786 + bic r2, r2, #(0x3f)
2787 + ldr r1, [r2, #TI_CPU_DOMAIN]
2788 +#ifdef CONFIG_PAX_KERNEXEC
2789 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2790 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2791 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2792 +#endif
2793 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2794 + @ set current DOMAIN_USER to DOMAIN_UDEREF
2795 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2796 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2797 +#endif
2798 + @ write r1 to current_thread_info()->cpu_domain
2799 + str r1, [r2, #TI_CPU_DOMAIN]
2800 + @ write r1 to DACR
2801 + mcr p15, 0, r1, c3, c0, 0
2802 + @ instruction sync
2803 + instr_sync
2804 + @ restore regs
2805 + ldmia sp!, {r1, r2}
2806 +#endif
2807 .endm
2808 #endif
2809
2810 -#include "entry-header.S"
2811 -
2812 -
2813 .align 5
2814 /*
2815 * This is the fast syscall return path. We do as little as
2816 @@ -406,6 +434,12 @@ ENTRY(vector_swi)
2817 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2818 #endif
2819
2820 + /*
2821 + * do this here to avoid a performance hit of wrapping the code above
2822 + * that directly dereferences userland to parse the SWI instruction
2823 + */
2824 + pax_enter_kernel_user
2825 +
2826 adr tbl, sys_call_table @ load syscall table pointer
2827
2828 #if defined(CONFIG_OABI_COMPAT)
2829 diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2830 index 2fdf867..6e909e4 100644
2831 --- a/arch/arm/kernel/entry-header.S
2832 +++ b/arch/arm/kernel/entry-header.S
2833 @@ -188,6 +188,60 @@
2834 msr cpsr_c, \rtemp @ switch back to the SVC mode
2835 .endm
2836
2837 + .macro pax_enter_kernel_user
2838 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2839 + @ save regs
2840 + stmdb sp!, {r0, r1}
2841 + @ read DACR from cpu_domain into r1
2842 + mov r0, sp
2843 + @ assume 8K pages, since we have to split the immediate in two
2844 + bic r0, r0, #(0x1fc0)
2845 + bic r0, r0, #(0x3f)
2846 + ldr r1, [r0, #TI_CPU_DOMAIN]
2847 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2848 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2849 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2850 +#endif
2851 +#ifdef CONFIG_PAX_KERNEXEC
2852 + @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2853 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2854 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2855 +#endif
2856 + @ write r1 to current_thread_info()->cpu_domain
2857 + str r1, [r0, #TI_CPU_DOMAIN]
2858 + @ write r1 to DACR
2859 + mcr p15, 0, r1, c3, c0, 0
2860 + @ instruction sync
2861 + instr_sync
2862 + @ restore regs
2863 + ldmia sp!, {r0, r1}
2864 +#endif
2865 + .endm
2866 +
2867 + .macro pax_exit_kernel
2868 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2869 + @ save regs
2870 + stmdb sp!, {r0, r1}
2871 + @ read old DACR from stack into r1
2872 + ldr r1, [sp, #(8 + S_SP)]
2873 + sub r1, r1, #8
2874 + ldr r1, [r1]
2875 +
2876 + @ write r1 to current_thread_info()->cpu_domain
2877 + mov r0, sp
2878 + @ assume 8K pages, since we have to split the immediate in two
2879 + bic r0, r0, #(0x1fc0)
2880 + bic r0, r0, #(0x3f)
2881 + str r1, [r0, #TI_CPU_DOMAIN]
2882 + @ write r1 to DACR
2883 + mcr p15, 0, r1, c3, c0, 0
2884 + @ instruction sync
2885 + instr_sync
2886 + @ restore regs
2887 + ldmia sp!, {r0, r1}
2888 +#endif
2889 + .endm
2890 +
2891 #ifndef CONFIG_THUMB2_KERNEL
2892 .macro svc_exit, rpsr, irq = 0
2893 .if \irq != 0
2894 @@ -207,6 +261,9 @@
2895 blne trace_hardirqs_off
2896 #endif
2897 .endif
2898 +
2899 + pax_exit_kernel
2900 +
2901 msr spsr_cxsf, \rpsr
2902 #if defined(CONFIG_CPU_V6) || defined(CONFIG_CPU_32v6K)
2903 @ We must avoid clrex due to Cortex-A15 erratum #830321
2904 @@ -254,6 +311,9 @@
2905 blne trace_hardirqs_off
2906 #endif
2907 .endif
2908 +
2909 + pax_exit_kernel
2910 +
2911 ldr lr, [sp, #S_SP] @ top of the stack
2912 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2913
2914 diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2915 index 918875d..cd5fa27 100644
2916 --- a/arch/arm/kernel/fiq.c
2917 +++ b/arch/arm/kernel/fiq.c
2918 @@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2919 void *base = vectors_page;
2920 unsigned offset = FIQ_OFFSET;
2921
2922 + pax_open_kernel();
2923 memcpy(base + offset, start, length);
2924 + pax_close_kernel();
2925 +
2926 if (!cache_is_vipt_nonaliasing())
2927 flush_icache_range((unsigned long)base + offset, offset +
2928 length);
2929 diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2930 index 664eee8..f470938 100644
2931 --- a/arch/arm/kernel/head.S
2932 +++ b/arch/arm/kernel/head.S
2933 @@ -437,7 +437,7 @@ __enable_mmu:
2934 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2935 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2936 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2937 - domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2938 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2939 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2940 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2941 #endif
2942 diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2943 index 6a4dffe..4a86a70 100644
2944 --- a/arch/arm/kernel/module.c
2945 +++ b/arch/arm/kernel/module.c
2946 @@ -38,12 +38,39 @@
2947 #endif
2948
2949 #ifdef CONFIG_MMU
2950 -void *module_alloc(unsigned long size)
2951 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2952 {
2953 + if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2954 + return NULL;
2955 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2956 - GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
2957 + GFP_KERNEL, prot, NUMA_NO_NODE,
2958 __builtin_return_address(0));
2959 }
2960 +
2961 +void *module_alloc(unsigned long size)
2962 +{
2963 +
2964 +#ifdef CONFIG_PAX_KERNEXEC
2965 + return __module_alloc(size, PAGE_KERNEL);
2966 +#else
2967 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2968 +#endif
2969 +
2970 +}
2971 +
2972 +#ifdef CONFIG_PAX_KERNEXEC
2973 +void module_free_exec(struct module *mod, void *module_region)
2974 +{
2975 + module_free(mod, module_region);
2976 +}
2977 +EXPORT_SYMBOL(module_free_exec);
2978 +
2979 +void *module_alloc_exec(unsigned long size)
2980 +{
2981 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2982 +}
2983 +EXPORT_SYMBOL(module_alloc_exec);
2984 +#endif
2985 #endif
2986
2987 int
2988 diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2989 index 07314af..c46655c 100644
2990 --- a/arch/arm/kernel/patch.c
2991 +++ b/arch/arm/kernel/patch.c
2992 @@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2993 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2994 int size;
2995
2996 + pax_open_kernel();
2997 if (thumb2 && __opcode_is_thumb16(insn)) {
2998 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2999 size = sizeof(u16);
3000 @@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
3001 *(u32 *)addr = insn;
3002 size = sizeof(u32);
3003 }
3004 + pax_close_kernel();
3005
3006 flush_icache_range((uintptr_t)(addr),
3007 (uintptr_t)(addr) + size);
3008 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
3009 index a35f6eb..7af43a0 100644
3010 --- a/arch/arm/kernel/process.c
3011 +++ b/arch/arm/kernel/process.c
3012 @@ -212,6 +212,7 @@ void machine_power_off(void)
3013
3014 if (pm_power_off)
3015 pm_power_off();
3016 + BUG();
3017 }
3018
3019 /*
3020 @@ -225,7 +226,7 @@ void machine_power_off(void)
3021 * executing pre-reset code, and using RAM that the primary CPU's code wishes
3022 * to use. Implementing such co-ordination would be essentially impossible.
3023 */
3024 -void machine_restart(char *cmd)
3025 +__noreturn void machine_restart(char *cmd)
3026 {
3027 local_irq_disable();
3028 smp_send_stop();
3029 @@ -248,8 +249,8 @@ void __show_regs(struct pt_regs *regs)
3030
3031 show_regs_print_info(KERN_DEFAULT);
3032
3033 - print_symbol("PC is at %s\n", instruction_pointer(regs));
3034 - print_symbol("LR is at %s\n", regs->ARM_lr);
3035 + printk("PC is at %pA\n", (void *)instruction_pointer(regs));
3036 + printk("LR is at %pA\n", (void *)regs->ARM_lr);
3037 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
3038 "sp : %08lx ip : %08lx fp : %08lx\n",
3039 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
3040 @@ -427,12 +428,6 @@ unsigned long get_wchan(struct task_struct *p)
3041 return 0;
3042 }
3043
3044 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3045 -{
3046 - unsigned long range_end = mm->brk + 0x02000000;
3047 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
3048 -}
3049 -
3050 #ifdef CONFIG_MMU
3051 #ifdef CONFIG_KUSER_HELPERS
3052 /*
3053 @@ -448,7 +443,7 @@ static struct vm_area_struct gate_vma = {
3054
3055 static int __init gate_vma_init(void)
3056 {
3057 - gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
3058 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
3059 return 0;
3060 }
3061 arch_initcall(gate_vma_init);
3062 @@ -474,41 +469,16 @@ int in_gate_area_no_mm(unsigned long addr)
3063
3064 const char *arch_vma_name(struct vm_area_struct *vma)
3065 {
3066 - return is_gate_vma(vma) ? "[vectors]" :
3067 - (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
3068 - "[sigpage]" : NULL;
3069 + return is_gate_vma(vma) ? "[vectors]" : NULL;
3070 }
3071
3072 -static struct page *signal_page;
3073 -extern struct page *get_signal_page(void);
3074 -
3075 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
3076 {
3077 struct mm_struct *mm = current->mm;
3078 - unsigned long addr;
3079 - int ret;
3080 -
3081 - if (!signal_page)
3082 - signal_page = get_signal_page();
3083 - if (!signal_page)
3084 - return -ENOMEM;
3085
3086 down_write(&mm->mmap_sem);
3087 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
3088 - if (IS_ERR_VALUE(addr)) {
3089 - ret = addr;
3090 - goto up_fail;
3091 - }
3092 -
3093 - ret = install_special_mapping(mm, addr, PAGE_SIZE,
3094 - VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
3095 - &signal_page);
3096 -
3097 - if (ret == 0)
3098 - mm->context.sigpage = addr;
3099 -
3100 - up_fail:
3101 + mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
3102 up_write(&mm->mmap_sem);
3103 - return ret;
3104 + return 0;
3105 }
3106 #endif
3107 diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
3108 index f73891b..cf3004e 100644
3109 --- a/arch/arm/kernel/psci.c
3110 +++ b/arch/arm/kernel/psci.c
3111 @@ -28,7 +28,7 @@
3112 #include <asm/psci.h>
3113 #include <asm/system_misc.h>
3114
3115 -struct psci_operations psci_ops;
3116 +struct psci_operations psci_ops __read_only;
3117
3118 static int (*invoke_psci_fn)(u32, u32, u32, u32);
3119 typedef int (*psci_initcall_t)(const struct device_node *);
3120 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
3121 index 0c27ed6..b67388e 100644
3122 --- a/arch/arm/kernel/ptrace.c
3123 +++ b/arch/arm/kernel/ptrace.c
3124 @@ -928,10 +928,19 @@ static void tracehook_report_syscall(struct pt_regs *regs,
3125 regs->ARM_ip = ip;
3126 }
3127
3128 +#ifdef CONFIG_GRKERNSEC_SETXID
3129 +extern void gr_delayed_cred_worker(void);
3130 +#endif
3131 +
3132 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
3133 {
3134 current_thread_info()->syscall = scno;
3135
3136 +#ifdef CONFIG_GRKERNSEC_SETXID
3137 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3138 + gr_delayed_cred_worker();
3139 +#endif
3140 +
3141 /* Do the secure computing check first; failures should be fast. */
3142 if (secure_computing(scno) == -1)
3143 return -1;
3144 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
3145 index 84db893d..bd8213a 100644
3146 --- a/arch/arm/kernel/setup.c
3147 +++ b/arch/arm/kernel/setup.c
3148 @@ -104,21 +104,23 @@ EXPORT_SYMBOL(elf_hwcap);
3149 unsigned int elf_hwcap2 __read_mostly;
3150 EXPORT_SYMBOL(elf_hwcap2);
3151
3152 +pteval_t __supported_pte_mask __read_only;
3153 +pmdval_t __supported_pmd_mask __read_only;
3154
3155 #ifdef MULTI_CPU
3156 -struct processor processor __read_mostly;
3157 +struct processor processor __read_only;
3158 #endif
3159 #ifdef MULTI_TLB
3160 -struct cpu_tlb_fns cpu_tlb __read_mostly;
3161 +struct cpu_tlb_fns cpu_tlb __read_only;
3162 #endif
3163 #ifdef MULTI_USER
3164 -struct cpu_user_fns cpu_user __read_mostly;
3165 +struct cpu_user_fns cpu_user __read_only;
3166 #endif
3167 #ifdef MULTI_CACHE
3168 -struct cpu_cache_fns cpu_cache __read_mostly;
3169 +struct cpu_cache_fns cpu_cache __read_only;
3170 #endif
3171 #ifdef CONFIG_OUTER_CACHE
3172 -struct outer_cache_fns outer_cache __read_mostly;
3173 +struct outer_cache_fns outer_cache __read_only;
3174 EXPORT_SYMBOL(outer_cache);
3175 #endif
3176
3177 @@ -251,9 +253,13 @@ static int __get_cpu_architecture(void)
3178 asm("mrc p15, 0, %0, c0, c1, 4"
3179 : "=r" (mmfr0));
3180 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3181 - (mmfr0 & 0x000000f0) >= 0x00000030)
3182 + (mmfr0 & 0x000000f0) >= 0x00000030) {
3183 cpu_arch = CPU_ARCH_ARMv7;
3184 - else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3185 + if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3186 + __supported_pte_mask |= L_PTE_PXN;
3187 + __supported_pmd_mask |= PMD_PXNTABLE;
3188 + }
3189 + } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3190 (mmfr0 & 0x000000f0) == 0x00000020)
3191 cpu_arch = CPU_ARCH_ARMv6;
3192 else
3193 diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3194 index bd19834..e4d8c66 100644
3195 --- a/arch/arm/kernel/signal.c
3196 +++ b/arch/arm/kernel/signal.c
3197 @@ -24,8 +24,6 @@
3198
3199 extern const unsigned long sigreturn_codes[7];
3200
3201 -static unsigned long signal_return_offset;
3202 -
3203 #ifdef CONFIG_CRUNCH
3204 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3205 {
3206 @@ -396,8 +394,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3207 * except when the MPU has protected the vectors
3208 * page from PL0
3209 */
3210 - retcode = mm->context.sigpage + signal_return_offset +
3211 - (idx << 2) + thumb;
3212 + retcode = mm->context.sigpage + (idx << 2) + thumb;
3213 } else
3214 #endif
3215 {
3216 @@ -604,33 +601,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3217 } while (thread_flags & _TIF_WORK_MASK);
3218 return 0;
3219 }
3220 -
3221 -struct page *get_signal_page(void)
3222 -{
3223 - unsigned long ptr;
3224 - unsigned offset;
3225 - struct page *page;
3226 - void *addr;
3227 -
3228 - page = alloc_pages(GFP_KERNEL, 0);
3229 -
3230 - if (!page)
3231 - return NULL;
3232 -
3233 - addr = page_address(page);
3234 -
3235 - /* Give the signal return code some randomness */
3236 - offset = 0x200 + (get_random_int() & 0x7fc);
3237 - signal_return_offset = offset;
3238 -
3239 - /*
3240 - * Copy signal return handlers into the vector page, and
3241 - * set sigreturn to be a pointer to these.
3242 - */
3243 - memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3244 -
3245 - ptr = (unsigned long)addr + offset;
3246 - flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3247 -
3248 - return page;
3249 -}
3250 diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3251 index bbe22fc..d7737f5 100644
3252 --- a/arch/arm/kernel/smp.c
3253 +++ b/arch/arm/kernel/smp.c
3254 @@ -76,7 +76,7 @@ enum ipi_msg_type {
3255
3256 static DECLARE_COMPLETION(cpu_running);
3257
3258 -static struct smp_operations smp_ops;
3259 +static struct smp_operations smp_ops __read_only;
3260
3261 void __init smp_set_ops(struct smp_operations *ops)
3262 {
3263 diff --git a/arch/arm/kernel/tcm.c b/arch/arm/kernel/tcm.c
3264 index 7a3be1d..b00c7de 100644
3265 --- a/arch/arm/kernel/tcm.c
3266 +++ b/arch/arm/kernel/tcm.c
3267 @@ -61,7 +61,7 @@ static struct map_desc itcm_iomap[] __initdata = {
3268 .virtual = ITCM_OFFSET,
3269 .pfn = __phys_to_pfn(ITCM_OFFSET),
3270 .length = 0,
3271 - .type = MT_MEMORY_RWX_ITCM,
3272 + .type = MT_MEMORY_RX_ITCM,
3273 }
3274 };
3275
3276 @@ -267,7 +267,9 @@ no_dtcm:
3277 start = &__sitcm_text;
3278 end = &__eitcm_text;
3279 ram = &__itcm_start;
3280 + pax_open_kernel();
3281 memcpy(start, ram, itcm_code_sz);
3282 + pax_close_kernel();
3283 pr_debug("CPU ITCM: copied code from %p - %p\n",
3284 start, end);
3285 itcm_present = true;
3286 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3287 index a964c9f..cf2a5b1 100644
3288 --- a/arch/arm/kernel/traps.c
3289 +++ b/arch/arm/kernel/traps.c
3290 @@ -64,7 +64,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3291 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3292 {
3293 #ifdef CONFIG_KALLSYMS
3294 - printk("[<%08lx>] (%ps) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3295 + printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3296 #else
3297 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3298 #endif
3299 @@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3300 static int die_owner = -1;
3301 static unsigned int die_nest_count;
3302
3303 +extern void gr_handle_kernel_exploit(void);
3304 +
3305 static unsigned long oops_begin(void)
3306 {
3307 int cpu;
3308 @@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3309 panic("Fatal exception in interrupt");
3310 if (panic_on_oops)
3311 panic("Fatal exception");
3312 +
3313 + gr_handle_kernel_exploit();
3314 +
3315 if (signr)
3316 do_exit(signr);
3317 }
3318 @@ -887,7 +892,11 @@ void __init early_trap_init(void *vectors_base)
3319 kuser_init(vectors_base);
3320
3321 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3322 - modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3323 +
3324 +#ifndef CONFIG_PAX_MEMORY_UDEREF
3325 + modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3326 +#endif
3327 +
3328 #else /* ifndef CONFIG_CPU_V7M */
3329 /*
3330 * on V7-M there is no need to copy the vector table to a dedicated
3331 diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3332 index 6f57cb9..645f8c4 100644
3333 --- a/arch/arm/kernel/vmlinux.lds.S
3334 +++ b/arch/arm/kernel/vmlinux.lds.S
3335 @@ -8,7 +8,11 @@
3336 #include <asm/thread_info.h>
3337 #include <asm/memory.h>
3338 #include <asm/page.h>
3339 -
3340 +
3341 +#ifdef CONFIG_PAX_KERNEXEC
3342 +#include <asm/pgtable.h>
3343 +#endif
3344 +
3345 #define PROC_INFO \
3346 . = ALIGN(4); \
3347 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3348 @@ -34,7 +38,7 @@
3349 #endif
3350
3351 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3352 - defined(CONFIG_GENERIC_BUG)
3353 + defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3354 #define ARM_EXIT_KEEP(x) x
3355 #define ARM_EXIT_DISCARD(x)
3356 #else
3357 @@ -90,6 +94,11 @@ SECTIONS
3358 _text = .;
3359 HEAD_TEXT
3360 }
3361 +
3362 +#ifdef CONFIG_PAX_KERNEXEC
3363 + . = ALIGN(1<<SECTION_SHIFT);
3364 +#endif
3365 +
3366 .text : { /* Real text segment */
3367 _stext = .; /* Text and read-only data */
3368 __exception_text_start = .;
3369 @@ -112,6 +121,8 @@ SECTIONS
3370 ARM_CPU_KEEP(PROC_INFO)
3371 }
3372
3373 + _etext = .; /* End of text section */
3374 +
3375 RO_DATA(PAGE_SIZE)
3376
3377 . = ALIGN(4);
3378 @@ -142,7 +153,9 @@ SECTIONS
3379
3380 NOTES
3381
3382 - _etext = .; /* End of text and rodata section */
3383 +#ifdef CONFIG_PAX_KERNEXEC
3384 + . = ALIGN(1<<SECTION_SHIFT);
3385 +#endif
3386
3387 #ifndef CONFIG_XIP_KERNEL
3388 . = ALIGN(PAGE_SIZE);
3389 @@ -220,6 +233,11 @@ SECTIONS
3390 . = PAGE_OFFSET + TEXT_OFFSET;
3391 #else
3392 __init_end = .;
3393 +
3394 +#ifdef CONFIG_PAX_KERNEXEC
3395 + . = ALIGN(1<<SECTION_SHIFT);
3396 +#endif
3397 +
3398 . = ALIGN(THREAD_SIZE);
3399 __data_loc = .;
3400 #endif
3401 diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3402 index a99e0cd..ab56421d 100644
3403 --- a/arch/arm/kvm/arm.c
3404 +++ b/arch/arm/kvm/arm.c
3405 @@ -57,7 +57,7 @@ static unsigned long hyp_default_vectors;
3406 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3407
3408 /* The VMID used in the VTTBR */
3409 -static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3410 +static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3411 static u8 kvm_next_vmid;
3412 static DEFINE_SPINLOCK(kvm_vmid_lock);
3413
3414 @@ -372,7 +372,7 @@ void force_vm_exit(const cpumask_t *mask)
3415 */
3416 static bool need_new_vmid_gen(struct kvm *kvm)
3417 {
3418 - return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3419 + return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3420 }
3421
3422 /**
3423 @@ -405,7 +405,7 @@ static void update_vttbr(struct kvm *kvm)
3424
3425 /* First user of a new VMID generation? */
3426 if (unlikely(kvm_next_vmid == 0)) {
3427 - atomic64_inc(&kvm_vmid_gen);
3428 + atomic64_inc_unchecked(&kvm_vmid_gen);
3429 kvm_next_vmid = 1;
3430
3431 /*
3432 @@ -422,7 +422,7 @@ static void update_vttbr(struct kvm *kvm)
3433 kvm_call_hyp(__kvm_flush_vm_context);
3434 }
3435
3436 - kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3437 + kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3438 kvm->arch.vmid = kvm_next_vmid;
3439 kvm_next_vmid++;
3440
3441 @@ -997,7 +997,7 @@ static void check_kvm_target_cpu(void *ret)
3442 /**
3443 * Initialize Hyp-mode and memory mappings on all CPUs.
3444 */
3445 -int kvm_arch_init(void *opaque)
3446 +int kvm_arch_init(const void *opaque)
3447 {
3448 int err;
3449 int ret, cpu;
3450 diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3451 index 14a0d98..7771a7d 100644
3452 --- a/arch/arm/lib/clear_user.S
3453 +++ b/arch/arm/lib/clear_user.S
3454 @@ -12,14 +12,14 @@
3455
3456 .text
3457
3458 -/* Prototype: int __clear_user(void *addr, size_t sz)
3459 +/* Prototype: int ___clear_user(void *addr, size_t sz)
3460 * Purpose : clear some user memory
3461 * Params : addr - user memory address to clear
3462 * : sz - number of bytes to clear
3463 * Returns : number of bytes NOT cleared
3464 */
3465 ENTRY(__clear_user_std)
3466 -WEAK(__clear_user)
3467 +WEAK(___clear_user)
3468 stmfd sp!, {r1, lr}
3469 mov r2, #0
3470 cmp r1, #4
3471 @@ -44,7 +44,7 @@ WEAK(__clear_user)
3472 USER( strnebt r2, [r0])
3473 mov r0, #0
3474 ldmfd sp!, {r1, pc}
3475 -ENDPROC(__clear_user)
3476 +ENDPROC(___clear_user)
3477 ENDPROC(__clear_user_std)
3478
3479 .pushsection .fixup,"ax"
3480 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3481 index 66a477a..bee61d3 100644
3482 --- a/arch/arm/lib/copy_from_user.S
3483 +++ b/arch/arm/lib/copy_from_user.S
3484 @@ -16,7 +16,7 @@
3485 /*
3486 * Prototype:
3487 *
3488 - * size_t __copy_from_user(void *to, const void *from, size_t n)
3489 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
3490 *
3491 * Purpose:
3492 *
3493 @@ -84,11 +84,11 @@
3494
3495 .text
3496
3497 -ENTRY(__copy_from_user)
3498 +ENTRY(___copy_from_user)
3499
3500 #include "copy_template.S"
3501
3502 -ENDPROC(__copy_from_user)
3503 +ENDPROC(___copy_from_user)
3504
3505 .pushsection .fixup,"ax"
3506 .align 0
3507 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3508 index 6ee2f67..d1cce76 100644
3509 --- a/arch/arm/lib/copy_page.S
3510 +++ b/arch/arm/lib/copy_page.S
3511 @@ -10,6 +10,7 @@
3512 * ASM optimised string functions
3513 */
3514 #include <linux/linkage.h>
3515 +#include <linux/const.h>
3516 #include <asm/assembler.h>
3517 #include <asm/asm-offsets.h>
3518 #include <asm/cache.h>
3519 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3520 index d066df6..df28194 100644
3521 --- a/arch/arm/lib/copy_to_user.S
3522 +++ b/arch/arm/lib/copy_to_user.S
3523 @@ -16,7 +16,7 @@
3524 /*
3525 * Prototype:
3526 *
3527 - * size_t __copy_to_user(void *to, const void *from, size_t n)
3528 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
3529 *
3530 * Purpose:
3531 *
3532 @@ -88,11 +88,11 @@
3533 .text
3534
3535 ENTRY(__copy_to_user_std)
3536 -WEAK(__copy_to_user)
3537 +WEAK(___copy_to_user)
3538
3539 #include "copy_template.S"
3540
3541 -ENDPROC(__copy_to_user)
3542 +ENDPROC(___copy_to_user)
3543 ENDPROC(__copy_to_user_std)
3544
3545 .pushsection .fixup,"ax"
3546 diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3547 index 7d08b43..f7ca7ea 100644
3548 --- a/arch/arm/lib/csumpartialcopyuser.S
3549 +++ b/arch/arm/lib/csumpartialcopyuser.S
3550 @@ -57,8 +57,8 @@
3551 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3552 */
3553
3554 -#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3555 -#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3556 +#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3557 +#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3558
3559 #include "csumpartialcopygeneric.S"
3560
3561 diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3562 index 312d43e..21d2322 100644
3563 --- a/arch/arm/lib/delay.c
3564 +++ b/arch/arm/lib/delay.c
3565 @@ -29,7 +29,7 @@
3566 /*
3567 * Default to the loop-based delay implementation.
3568 */
3569 -struct arm_delay_ops arm_delay_ops = {
3570 +struct arm_delay_ops arm_delay_ops __read_only = {
3571 .delay = __loop_delay,
3572 .const_udelay = __loop_const_udelay,
3573 .udelay = __loop_udelay,
3574 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3575 index 3e58d71..029817c 100644
3576 --- a/arch/arm/lib/uaccess_with_memcpy.c
3577 +++ b/arch/arm/lib/uaccess_with_memcpy.c
3578 @@ -136,7 +136,7 @@ out:
3579 }
3580
3581 unsigned long
3582 -__copy_to_user(void __user *to, const void *from, unsigned long n)
3583 +___copy_to_user(void __user *to, const void *from, unsigned long n)
3584 {
3585 /*
3586 * This test is stubbed out of the main function above to keep
3587 @@ -190,7 +190,7 @@ out:
3588 return n;
3589 }
3590
3591 -unsigned long __clear_user(void __user *addr, unsigned long n)
3592 +unsigned long ___clear_user(void __user *addr, unsigned long n)
3593 {
3594 /* See rational for this in __copy_to_user() above. */
3595 if (n < 64)
3596 diff --git a/arch/arm/mach-at91/setup.c b/arch/arm/mach-at91/setup.c
3597 index f7a07a5..258e1f7 100644
3598 --- a/arch/arm/mach-at91/setup.c
3599 +++ b/arch/arm/mach-at91/setup.c
3600 @@ -81,7 +81,7 @@ void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
3601
3602 desc->pfn = __phys_to_pfn(base);
3603 desc->length = length;
3604 - desc->type = MT_MEMORY_RWX_NONCACHED;
3605 + desc->type = MT_MEMORY_RW_NONCACHED;
3606
3607 pr_info("AT91: sram at 0x%lx of 0x%x mapped at 0x%lx\n",
3608 base, length, desc->virtual);
3609 diff --git a/arch/arm/mach-keystone/keystone.c b/arch/arm/mach-keystone/keystone.c
3610 index 7f352de..6dc0929 100644
3611 --- a/arch/arm/mach-keystone/keystone.c
3612 +++ b/arch/arm/mach-keystone/keystone.c
3613 @@ -27,7 +27,7 @@
3614
3615 #include "keystone.h"
3616
3617 -static struct notifier_block platform_nb;
3618 +static notifier_block_no_const platform_nb;
3619 static unsigned long keystone_dma_pfn_offset __read_mostly;
3620
3621 static int keystone_platform_notifier(struct notifier_block *nb,
3622 diff --git a/arch/arm/mach-mvebu/coherency.c b/arch/arm/mach-mvebu/coherency.c
3623 index 2bdc323..cf1c607 100644
3624 --- a/arch/arm/mach-mvebu/coherency.c
3625 +++ b/arch/arm/mach-mvebu/coherency.c
3626 @@ -316,7 +316,7 @@ static void __init armada_370_coherency_init(struct device_node *np)
3627
3628 /*
3629 * This ioremap hook is used on Armada 375/38x to ensure that PCIe
3630 - * memory areas are mapped as MT_UNCACHED instead of MT_DEVICE. This
3631 + * memory areas are mapped as MT_UNCACHED_RW instead of MT_DEVICE. This
3632 * is needed as a workaround for a deadlock issue between the PCIe
3633 * interface and the cache controller.
3634 */
3635 @@ -329,7 +329,7 @@ armada_pcie_wa_ioremap_caller(phys_addr_t phys_addr, size_t size,
3636 mvebu_mbus_get_pcie_mem_aperture(&pcie_mem);
3637
3638 if (pcie_mem.start <= phys_addr && (phys_addr + size) <= pcie_mem.end)
3639 - mtype = MT_UNCACHED;
3640 + mtype = MT_UNCACHED_RW;
3641
3642 return __arm_ioremap_caller(phys_addr, size, mtype, caller);
3643 }
3644 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3645 index aead77a..a2253fa 100644
3646 --- a/arch/arm/mach-omap2/board-n8x0.c
3647 +++ b/arch/arm/mach-omap2/board-n8x0.c
3648 @@ -568,7 +568,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3649 }
3650 #endif
3651
3652 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3653 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3654 .late_init = n8x0_menelaus_late_init,
3655 };
3656
3657 diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3658 index 2f97228..6ce10e1 100644
3659 --- a/arch/arm/mach-omap2/gpmc.c
3660 +++ b/arch/arm/mach-omap2/gpmc.c
3661 @@ -151,7 +151,6 @@ struct omap3_gpmc_regs {
3662 };
3663
3664 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3665 -static struct irq_chip gpmc_irq_chip;
3666 static int gpmc_irq_start;
3667
3668 static struct resource gpmc_mem_root;
3669 @@ -736,6 +735,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3670
3671 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3672
3673 +static struct irq_chip gpmc_irq_chip = {
3674 + .name = "gpmc",
3675 + .irq_startup = gpmc_irq_noop_ret,
3676 + .irq_enable = gpmc_irq_enable,
3677 + .irq_disable = gpmc_irq_disable,
3678 + .irq_shutdown = gpmc_irq_noop,
3679 + .irq_ack = gpmc_irq_noop,
3680 + .irq_mask = gpmc_irq_noop,
3681 + .irq_unmask = gpmc_irq_noop,
3682 +
3683 +};
3684 +
3685 static int gpmc_setup_irq(void)
3686 {
3687 int i;
3688 @@ -750,15 +761,6 @@ static int gpmc_setup_irq(void)
3689 return gpmc_irq_start;
3690 }
3691
3692 - gpmc_irq_chip.name = "gpmc";
3693 - gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3694 - gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3695 - gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3696 - gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3697 - gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3698 - gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3699 - gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3700 -
3701 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3702 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3703
3704 diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3705 index 4001325..b14e2a0 100644
3706 --- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3707 +++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3708 @@ -84,7 +84,7 @@ struct cpu_pm_ops {
3709 int (*finish_suspend)(unsigned long cpu_state);
3710 void (*resume)(void);
3711 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3712 -};
3713 +} __no_const;
3714
3715 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3716 static struct powerdomain *mpuss_pd;
3717 @@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3718 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3719 {}
3720
3721 -struct cpu_pm_ops omap_pm_ops = {
3722 +static struct cpu_pm_ops omap_pm_ops __read_only = {
3723 .finish_suspend = default_finish_suspend,
3724 .resume = dummy_cpu_resume,
3725 .scu_prepare = dummy_scu_prepare,
3726 diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3727 index 37843a7..a98df13 100644
3728 --- a/arch/arm/mach-omap2/omap-wakeupgen.c
3729 +++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3730 @@ -343,7 +343,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3731 return NOTIFY_OK;
3732 }
3733
3734 -static struct notifier_block __refdata irq_hotplug_notifier = {
3735 +static struct notifier_block irq_hotplug_notifier = {
3736 .notifier_call = irq_cpu_hotplug_notify,
3737 };
3738
3739 diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3740 index d22c30d..23697a1 100644
3741 --- a/arch/arm/mach-omap2/omap_device.c
3742 +++ b/arch/arm/mach-omap2/omap_device.c
3743 @@ -510,7 +510,7 @@ void omap_device_delete(struct omap_device *od)
3744 struct platform_device __init *omap_device_build(const char *pdev_name,
3745 int pdev_id,
3746 struct omap_hwmod *oh,
3747 - void *pdata, int pdata_len)
3748 + const void *pdata, int pdata_len)
3749 {
3750 struct omap_hwmod *ohs[] = { oh };
3751
3752 @@ -538,7 +538,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3753 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3754 int pdev_id,
3755 struct omap_hwmod **ohs,
3756 - int oh_cnt, void *pdata,
3757 + int oh_cnt, const void *pdata,
3758 int pdata_len)
3759 {
3760 int ret = -ENOMEM;
3761 diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3762 index 78c02b3..c94109a 100644
3763 --- a/arch/arm/mach-omap2/omap_device.h
3764 +++ b/arch/arm/mach-omap2/omap_device.h
3765 @@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3766 /* Core code interface */
3767
3768 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3769 - struct omap_hwmod *oh, void *pdata,
3770 + struct omap_hwmod *oh, const void *pdata,
3771 int pdata_len);
3772
3773 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3774 struct omap_hwmod **oh, int oh_cnt,
3775 - void *pdata, int pdata_len);
3776 + const void *pdata, int pdata_len);
3777
3778 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3779 struct omap_hwmod **ohs, int oh_cnt);
3780 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3781 index 9e91a4e..357ed0d 100644
3782 --- a/arch/arm/mach-omap2/omap_hwmod.c
3783 +++ b/arch/arm/mach-omap2/omap_hwmod.c
3784 @@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3785 int (*init_clkdm)(struct omap_hwmod *oh);
3786 void (*update_context_lost)(struct omap_hwmod *oh);
3787 int (*get_context_lost)(struct omap_hwmod *oh);
3788 -};
3789 +} __no_const;
3790
3791 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3792 -static struct omap_hwmod_soc_ops soc_ops;
3793 +static struct omap_hwmod_soc_ops soc_ops __read_only;
3794
3795 /* omap_hwmod_list contains all registered struct omap_hwmods */
3796 static LIST_HEAD(omap_hwmod_list);
3797 diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
3798 index 95fee54..cfa9cf1 100644
3799 --- a/arch/arm/mach-omap2/powerdomains43xx_data.c
3800 +++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
3801 @@ -10,6 +10,7 @@
3802
3803 #include <linux/kernel.h>
3804 #include <linux/init.h>
3805 +#include <asm/pgtable.h>
3806
3807 #include "powerdomain.h"
3808
3809 @@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
3810
3811 void __init am43xx_powerdomains_init(void)
3812 {
3813 - omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3814 + pax_open_kernel();
3815 + *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3816 + pax_close_kernel();
3817 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
3818 pwrdm_register_pwrdms(powerdomains_am43xx);
3819 pwrdm_complete_init();
3820 diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3821 index 97d6607..8429d14 100644
3822 --- a/arch/arm/mach-omap2/wd_timer.c
3823 +++ b/arch/arm/mach-omap2/wd_timer.c
3824 @@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3825 struct omap_hwmod *oh;
3826 char *oh_name = "wd_timer2";
3827 char *dev_name = "omap_wdt";
3828 - struct omap_wd_timer_platform_data pdata;
3829 + static struct omap_wd_timer_platform_data pdata = {
3830 + .read_reset_sources = prm_read_reset_sources
3831 + };
3832
3833 if (!cpu_class_is_omap2() || of_have_populated_dt())
3834 return 0;
3835 @@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3836 return -EINVAL;
3837 }
3838
3839 - pdata.read_reset_sources = prm_read_reset_sources;
3840 -
3841 pdev = omap_device_build(dev_name, id, oh, &pdata,
3842 sizeof(struct omap_wd_timer_platform_data));
3843 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3844 diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3845 index b30bf5c..d0825bf 100644
3846 --- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3847 +++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3848 @@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3849 bool entered_lp2 = false;
3850
3851 if (tegra_pending_sgi())
3852 - ACCESS_ONCE(abort_flag) = true;
3853 + ACCESS_ONCE_RW(abort_flag) = true;
3854
3855 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3856
3857 diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3858 index 2dea8b5..6499da2 100644
3859 --- a/arch/arm/mach-ux500/setup.h
3860 +++ b/arch/arm/mach-ux500/setup.h
3861 @@ -33,13 +33,6 @@ extern void ux500_timer_init(void);
3862 .type = MT_DEVICE, \
3863 }
3864
3865 -#define __MEM_DEV_DESC(x, sz) { \
3866 - .virtual = IO_ADDRESS(x), \
3867 - .pfn = __phys_to_pfn(x), \
3868 - .length = sz, \
3869 - .type = MT_MEMORY_RWX, \
3870 -}
3871 -
3872 extern struct smp_operations ux500_smp_ops;
3873 extern void ux500_cpu_die(unsigned int cpu);
3874
3875 diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3876 index 7eb94e6..799ad3e 100644
3877 --- a/arch/arm/mm/Kconfig
3878 +++ b/arch/arm/mm/Kconfig
3879 @@ -446,6 +446,7 @@ config CPU_32v5
3880
3881 config CPU_32v6
3882 bool
3883 + select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3884 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3885
3886 config CPU_32v6K
3887 @@ -600,6 +601,7 @@ config CPU_CP15_MPU
3888
3889 config CPU_USE_DOMAINS
3890 bool
3891 + depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3892 help
3893 This option enables or disables the use of domain switching
3894 via the set_fs() function.
3895 @@ -798,7 +800,7 @@ config NEED_KUSER_HELPERS
3896
3897 config KUSER_HELPERS
3898 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3899 - depends on MMU
3900 + depends on MMU && (!(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND)
3901 default y
3902 help
3903 Warning: disabling this option may break user programs.
3904 @@ -812,7 +814,7 @@ config KUSER_HELPERS
3905 See Documentation/arm/kernel_user_helpers.txt for details.
3906
3907 However, the fixed address nature of these helpers can be used
3908 - by ROP (return orientated programming) authors when creating
3909 + by ROP (Return Oriented Programming) authors when creating
3910 exploits.
3911
3912 If all of the binaries and libraries which run on your platform
3913 diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3914 index 83792f4..c25d36b 100644
3915 --- a/arch/arm/mm/alignment.c
3916 +++ b/arch/arm/mm/alignment.c
3917 @@ -216,10 +216,12 @@ union offset_union {
3918 #define __get16_unaligned_check(ins,val,addr) \
3919 do { \
3920 unsigned int err = 0, v, a = addr; \
3921 + pax_open_userland(); \
3922 __get8_unaligned_check(ins,v,a,err); \
3923 val = v << ((BE) ? 8 : 0); \
3924 __get8_unaligned_check(ins,v,a,err); \
3925 val |= v << ((BE) ? 0 : 8); \
3926 + pax_close_userland(); \
3927 if (err) \
3928 goto fault; \
3929 } while (0)
3930 @@ -233,6 +235,7 @@ union offset_union {
3931 #define __get32_unaligned_check(ins,val,addr) \
3932 do { \
3933 unsigned int err = 0, v, a = addr; \
3934 + pax_open_userland(); \
3935 __get8_unaligned_check(ins,v,a,err); \
3936 val = v << ((BE) ? 24 : 0); \
3937 __get8_unaligned_check(ins,v,a,err); \
3938 @@ -241,6 +244,7 @@ union offset_union {
3939 val |= v << ((BE) ? 8 : 16); \
3940 __get8_unaligned_check(ins,v,a,err); \
3941 val |= v << ((BE) ? 0 : 24); \
3942 + pax_close_userland(); \
3943 if (err) \
3944 goto fault; \
3945 } while (0)
3946 @@ -254,6 +258,7 @@ union offset_union {
3947 #define __put16_unaligned_check(ins,val,addr) \
3948 do { \
3949 unsigned int err = 0, v = val, a = addr; \
3950 + pax_open_userland(); \
3951 __asm__( FIRST_BYTE_16 \
3952 ARM( "1: "ins" %1, [%2], #1\n" ) \
3953 THUMB( "1: "ins" %1, [%2]\n" ) \
3954 @@ -273,6 +278,7 @@ union offset_union {
3955 " .popsection\n" \
3956 : "=r" (err), "=&r" (v), "=&r" (a) \
3957 : "0" (err), "1" (v), "2" (a)); \
3958 + pax_close_userland(); \
3959 if (err) \
3960 goto fault; \
3961 } while (0)
3962 @@ -286,6 +292,7 @@ union offset_union {
3963 #define __put32_unaligned_check(ins,val,addr) \
3964 do { \
3965 unsigned int err = 0, v = val, a = addr; \
3966 + pax_open_userland(); \
3967 __asm__( FIRST_BYTE_32 \
3968 ARM( "1: "ins" %1, [%2], #1\n" ) \
3969 THUMB( "1: "ins" %1, [%2]\n" ) \
3970 @@ -315,6 +322,7 @@ union offset_union {
3971 " .popsection\n" \
3972 : "=r" (err), "=&r" (v), "=&r" (a) \
3973 : "0" (err), "1" (v), "2" (a)); \
3974 + pax_close_userland(); \
3975 if (err) \
3976 goto fault; \
3977 } while (0)
3978 diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3979 index 5f2c988..221412d 100644
3980 --- a/arch/arm/mm/cache-l2x0.c
3981 +++ b/arch/arm/mm/cache-l2x0.c
3982 @@ -41,7 +41,7 @@ struct l2c_init_data {
3983 void (*fixup)(void __iomem *, u32, struct outer_cache_fns *);
3984 void (*save)(void __iomem *);
3985 struct outer_cache_fns outer_cache;
3986 -};
3987 +} __do_const;
3988
3989 #define CACHE_LINE_SIZE 32
3990
3991 diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3992 index 6eb97b3..ac509f6 100644
3993 --- a/arch/arm/mm/context.c
3994 +++ b/arch/arm/mm/context.c
3995 @@ -43,7 +43,7 @@
3996 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3997
3998 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3999 -static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
4000 +static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
4001 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
4002
4003 static DEFINE_PER_CPU(atomic64_t, active_asids);
4004 @@ -182,7 +182,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
4005 {
4006 static u32 cur_idx = 1;
4007 u64 asid = atomic64_read(&mm->context.id);
4008 - u64 generation = atomic64_read(&asid_generation);
4009 + u64 generation = atomic64_read_unchecked(&asid_generation);
4010
4011 if (asid != 0 && is_reserved_asid(asid)) {
4012 /*
4013 @@ -203,7 +203,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
4014 */
4015 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, cur_idx);
4016 if (asid == NUM_USER_ASIDS) {
4017 - generation = atomic64_add_return(ASID_FIRST_VERSION,
4018 + generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
4019 &asid_generation);
4020 flush_context(cpu);
4021 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
4022 @@ -234,14 +234,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
4023 cpu_set_reserved_ttbr0();
4024
4025 asid = atomic64_read(&mm->context.id);
4026 - if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
4027 + if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
4028 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
4029 goto switch_mm_fastpath;
4030
4031 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
4032 /* Check that our ASID belongs to the current generation. */
4033 asid = atomic64_read(&mm->context.id);
4034 - if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
4035 + if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
4036 asid = new_context(mm, cpu);
4037 atomic64_set(&mm->context.id, asid);
4038 }
4039 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
4040 index eb8830a..e8ff52e 100644
4041 --- a/arch/arm/mm/fault.c
4042 +++ b/arch/arm/mm/fault.c
4043 @@ -25,6 +25,7 @@
4044 #include <asm/system_misc.h>
4045 #include <asm/system_info.h>
4046 #include <asm/tlbflush.h>
4047 +#include <asm/sections.h>
4048
4049 #include "fault.h"
4050
4051 @@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
4052 if (fixup_exception(regs))
4053 return;
4054
4055 +#ifdef CONFIG_PAX_MEMORY_UDEREF
4056 + if (addr < TASK_SIZE) {
4057 + if (current->signal->curr_ip)
4058 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
4059 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4060 + else
4061 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
4062 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4063 + }
4064 +#endif
4065 +
4066 +#ifdef CONFIG_PAX_KERNEXEC
4067 + if ((fsr & FSR_WRITE) &&
4068 + (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
4069 + (MODULES_VADDR <= addr && addr < MODULES_END)))
4070 + {
4071 + if (current->signal->curr_ip)
4072 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
4073 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
4074 + else
4075 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
4076 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
4077 + }
4078 +#endif
4079 +
4080 /*
4081 * No handler, we'll have to terminate things with extreme prejudice.
4082 */
4083 @@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
4084 }
4085 #endif
4086
4087 +#ifdef CONFIG_PAX_PAGEEXEC
4088 + if (fsr & FSR_LNX_PF) {
4089 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
4090 + do_group_exit(SIGKILL);
4091 + }
4092 +#endif
4093 +
4094 tsk->thread.address = addr;
4095 tsk->thread.error_code = fsr;
4096 tsk->thread.trap_no = 14;
4097 @@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4098 }
4099 #endif /* CONFIG_MMU */
4100
4101 +#ifdef CONFIG_PAX_PAGEEXEC
4102 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4103 +{
4104 + long i;
4105 +
4106 + printk(KERN_ERR "PAX: bytes at PC: ");
4107 + for (i = 0; i < 20; i++) {
4108 + unsigned char c;
4109 + if (get_user(c, (__force unsigned char __user *)pc+i))
4110 + printk(KERN_CONT "?? ");
4111 + else
4112 + printk(KERN_CONT "%02x ", c);
4113 + }
4114 + printk("\n");
4115 +
4116 + printk(KERN_ERR "PAX: bytes at SP-4: ");
4117 + for (i = -1; i < 20; i++) {
4118 + unsigned long c;
4119 + if (get_user(c, (__force unsigned long __user *)sp+i))
4120 + printk(KERN_CONT "???????? ");
4121 + else
4122 + printk(KERN_CONT "%08lx ", c);
4123 + }
4124 + printk("\n");
4125 +}
4126 +#endif
4127 +
4128 /*
4129 * First Level Translation Fault Handler
4130 *
4131 @@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4132 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
4133 struct siginfo info;
4134
4135 +#ifdef CONFIG_PAX_MEMORY_UDEREF
4136 + if (addr < TASK_SIZE && is_domain_fault(fsr)) {
4137 + if (current->signal->curr_ip)
4138 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
4139 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4140 + else
4141 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
4142 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4143 + goto die;
4144 + }
4145 +#endif
4146 +
4147 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
4148 return;
4149
4150 +die:
4151 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
4152 inf->name, fsr, addr);
4153
4154 @@ -574,15 +647,104 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
4155 ifsr_info[nr].name = name;
4156 }
4157
4158 +asmlinkage int sys_sigreturn(struct pt_regs *regs);
4159 +asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
4160 +
4161 asmlinkage void __exception
4162 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
4163 {
4164 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
4165 struct siginfo info;
4166 + unsigned long pc = instruction_pointer(regs);
4167 +
4168 + if (user_mode(regs)) {
4169 + unsigned long sigpage = current->mm->context.sigpage;
4170 +
4171 + if (sigpage <= pc && pc < sigpage + 7*4) {
4172 + if (pc < sigpage + 3*4)
4173 + sys_sigreturn(regs);
4174 + else
4175 + sys_rt_sigreturn(regs);
4176 + return;
4177 + }
4178 + if (pc == 0xffff0f60UL) {
4179 + /*
4180 + * PaX: __kuser_cmpxchg64 emulation
4181 + */
4182 + // TODO
4183 + //regs->ARM_pc = regs->ARM_lr;
4184 + //return;
4185 + }
4186 + if (pc == 0xffff0fa0UL) {
4187 + /*
4188 + * PaX: __kuser_memory_barrier emulation
4189 + */
4190 + // dmb(); implied by the exception
4191 + regs->ARM_pc = regs->ARM_lr;
4192 + return;
4193 + }
4194 + if (pc == 0xffff0fc0UL) {
4195 + /*
4196 + * PaX: __kuser_cmpxchg emulation
4197 + */
4198 + // TODO
4199 + //long new;
4200 + //int op;
4201 +
4202 + //op = FUTEX_OP_SET << 28;
4203 + //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4204 + //regs->ARM_r0 = old != new;
4205 + //regs->ARM_pc = regs->ARM_lr;
4206 + //return;
4207 + }
4208 + if (pc == 0xffff0fe0UL) {
4209 + /*
4210 + * PaX: __kuser_get_tls emulation
4211 + */
4212 + regs->ARM_r0 = current_thread_info()->tp_value[0];
4213 + regs->ARM_pc = regs->ARM_lr;
4214 + return;
4215 + }
4216 + }
4217 +
4218 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4219 + else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4220 + if (current->signal->curr_ip)
4221 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
4222 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4223 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4224 + else
4225 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4226 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4227 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4228 + goto die;
4229 + }
4230 +#endif
4231 +
4232 +#ifdef CONFIG_PAX_REFCOUNT
4233 + if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4234 +#ifdef CONFIG_THUMB2_KERNEL
4235 + unsigned short bkpt;
4236 +
4237 + if (!probe_kernel_address(pc, bkpt) && cpu_to_le16(bkpt) == 0xbef1) {
4238 +#else
4239 + unsigned int bkpt;
4240 +
4241 + if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4242 +#endif
4243 + current->thread.error_code = ifsr;
4244 + current->thread.trap_no = 0;
4245 + pax_report_refcount_overflow(regs);
4246 + fixup_exception(regs);
4247 + return;
4248 + }
4249 + }
4250 +#endif
4251
4252 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4253 return;
4254
4255 +die:
4256 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4257 inf->name, ifsr, addr);
4258
4259 diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4260 index cf08bdf..772656c 100644
4261 --- a/arch/arm/mm/fault.h
4262 +++ b/arch/arm/mm/fault.h
4263 @@ -3,6 +3,7 @@
4264
4265 /*
4266 * Fault status register encodings. We steal bit 31 for our own purposes.
4267 + * Set when the FSR value is from an instruction fault.
4268 */
4269 #define FSR_LNX_PF (1 << 31)
4270 #define FSR_WRITE (1 << 11)
4271 @@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4272 }
4273 #endif
4274
4275 +/* valid for LPAE and !LPAE */
4276 +static inline int is_xn_fault(unsigned int fsr)
4277 +{
4278 + return ((fsr_fs(fsr) & 0x3c) == 0xc);
4279 +}
4280 +
4281 +static inline int is_domain_fault(unsigned int fsr)
4282 +{
4283 + return ((fsr_fs(fsr) & 0xD) == 0x9);
4284 +}
4285 +
4286 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4287 unsigned long search_exception_table(unsigned long addr);
4288
4289 diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4290 index 659c75d..6f8c029 100644
4291 --- a/arch/arm/mm/init.c
4292 +++ b/arch/arm/mm/init.c
4293 @@ -31,6 +31,8 @@
4294 #include <asm/setup.h>
4295 #include <asm/tlb.h>
4296 #include <asm/fixmap.h>
4297 +#include <asm/system_info.h>
4298 +#include <asm/cp15.h>
4299
4300 #include <asm/mach/arch.h>
4301 #include <asm/mach/map.h>
4302 @@ -619,7 +621,46 @@ void free_initmem(void)
4303 {
4304 #ifdef CONFIG_HAVE_TCM
4305 extern char __tcm_start, __tcm_end;
4306 +#endif
4307
4308 +#ifdef CONFIG_PAX_KERNEXEC
4309 + unsigned long addr;
4310 + pgd_t *pgd;
4311 + pud_t *pud;
4312 + pmd_t *pmd;
4313 + int cpu_arch = cpu_architecture();
4314 + unsigned int cr = get_cr();
4315 +
4316 + if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4317 + /* make pages tables, etc before .text NX */
4318 + for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4319 + pgd = pgd_offset_k(addr);
4320 + pud = pud_offset(pgd, addr);
4321 + pmd = pmd_offset(pud, addr);
4322 + __section_update(pmd, addr, PMD_SECT_XN);
4323 + }
4324 + /* make init NX */
4325 + for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4326 + pgd = pgd_offset_k(addr);
4327 + pud = pud_offset(pgd, addr);
4328 + pmd = pmd_offset(pud, addr);
4329 + __section_update(pmd, addr, PMD_SECT_XN);
4330 + }
4331 + /* make kernel code/rodata RX */
4332 + for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4333 + pgd = pgd_offset_k(addr);
4334 + pud = pud_offset(pgd, addr);
4335 + pmd = pmd_offset(pud, addr);
4336 +#ifdef CONFIG_ARM_LPAE
4337 + __section_update(pmd, addr, PMD_SECT_RDONLY);
4338 +#else
4339 + __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4340 +#endif
4341 + }
4342 + }
4343 +#endif
4344 +
4345 +#ifdef CONFIG_HAVE_TCM
4346 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4347 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4348 #endif
4349 diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4350 index d1e5ad7..84dcbf2 100644
4351 --- a/arch/arm/mm/ioremap.c
4352 +++ b/arch/arm/mm/ioremap.c
4353 @@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4354 unsigned int mtype;
4355
4356 if (cached)
4357 - mtype = MT_MEMORY_RWX;
4358 + mtype = MT_MEMORY_RX;
4359 else
4360 - mtype = MT_MEMORY_RWX_NONCACHED;
4361 + mtype = MT_MEMORY_RX_NONCACHED;
4362
4363 return __arm_ioremap_caller(phys_addr, size, mtype,
4364 __builtin_return_address(0));
4365 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4366 index 5e85ed3..b10a7ed 100644
4367 --- a/arch/arm/mm/mmap.c
4368 +++ b/arch/arm/mm/mmap.c
4369 @@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4370 struct vm_area_struct *vma;
4371 int do_align = 0;
4372 int aliasing = cache_is_vipt_aliasing();
4373 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4374 struct vm_unmapped_area_info info;
4375
4376 /*
4377 @@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4378 if (len > TASK_SIZE)
4379 return -ENOMEM;
4380
4381 +#ifdef CONFIG_PAX_RANDMMAP
4382 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4383 +#endif
4384 +
4385 if (addr) {
4386 if (do_align)
4387 addr = COLOUR_ALIGN(addr, pgoff);
4388 @@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4389 addr = PAGE_ALIGN(addr);
4390
4391 vma = find_vma(mm, addr);
4392 - if (TASK_SIZE - len >= addr &&
4393 - (!vma || addr + len <= vma->vm_start))
4394 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4395 return addr;
4396 }
4397
4398 @@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4399 info.high_limit = TASK_SIZE;
4400 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4401 info.align_offset = pgoff << PAGE_SHIFT;
4402 + info.threadstack_offset = offset;
4403 return vm_unmapped_area(&info);
4404 }
4405
4406 @@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4407 unsigned long addr = addr0;
4408 int do_align = 0;
4409 int aliasing = cache_is_vipt_aliasing();
4410 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4411 struct vm_unmapped_area_info info;
4412
4413 /*
4414 @@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4415 return addr;
4416 }
4417
4418 +#ifdef CONFIG_PAX_RANDMMAP
4419 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4420 +#endif
4421 +
4422 /* requesting a specific address */
4423 if (addr) {
4424 if (do_align)
4425 @@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4426 else
4427 addr = PAGE_ALIGN(addr);
4428 vma = find_vma(mm, addr);
4429 - if (TASK_SIZE - len >= addr &&
4430 - (!vma || addr + len <= vma->vm_start))
4431 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4432 return addr;
4433 }
4434
4435 @@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4436 info.high_limit = mm->mmap_base;
4437 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4438 info.align_offset = pgoff << PAGE_SHIFT;
4439 + info.threadstack_offset = offset;
4440 addr = vm_unmapped_area(&info);
4441
4442 /*
4443 @@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4444 {
4445 unsigned long random_factor = 0UL;
4446
4447 +#ifdef CONFIG_PAX_RANDMMAP
4448 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4449 +#endif
4450 +
4451 /* 8 bits of randomness in 20 address space bits */
4452 if ((current->flags & PF_RANDOMIZE) &&
4453 !(current->personality & ADDR_NO_RANDOMIZE))
4454 @@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4455
4456 if (mmap_is_legacy()) {
4457 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4458 +
4459 +#ifdef CONFIG_PAX_RANDMMAP
4460 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4461 + mm->mmap_base += mm->delta_mmap;
4462 +#endif
4463 +
4464 mm->get_unmapped_area = arch_get_unmapped_area;
4465 } else {
4466 mm->mmap_base = mmap_base(random_factor);
4467 +
4468 +#ifdef CONFIG_PAX_RANDMMAP
4469 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4470 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4471 +#endif
4472 +
4473 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4474 }
4475 }
4476 diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4477 index 8348ed6..b73a807 100644
4478 --- a/arch/arm/mm/mmu.c
4479 +++ b/arch/arm/mm/mmu.c
4480 @@ -40,6 +40,22 @@
4481 #include "mm.h"
4482 #include "tcm.h"
4483
4484 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4485 +void modify_domain(unsigned int dom, unsigned int type)
4486 +{
4487 + struct thread_info *thread = current_thread_info();
4488 + unsigned int domain = thread->cpu_domain;
4489 + /*
4490 + * DOMAIN_MANAGER might be defined to some other value,
4491 + * use the arch-defined constant
4492 + */
4493 + domain &= ~domain_val(dom, 3);
4494 + thread->cpu_domain = domain | domain_val(dom, type);
4495 + set_domain(thread->cpu_domain);
4496 +}
4497 +EXPORT_SYMBOL(modify_domain);
4498 +#endif
4499 +
4500 /*
4501 * empty_zero_page is a special page that is used for
4502 * zero-initialized data and COW.
4503 @@ -239,7 +255,15 @@ __setup("noalign", noalign_setup);
4504 #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
4505 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4506
4507 -static struct mem_type mem_types[] = {
4508 +#ifdef CONFIG_PAX_KERNEXEC
4509 +#define L_PTE_KERNEXEC L_PTE_RDONLY
4510 +#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4511 +#else
4512 +#define L_PTE_KERNEXEC L_PTE_DIRTY
4513 +#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4514 +#endif
4515 +
4516 +static struct mem_type mem_types[] __read_only = {
4517 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4518 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4519 L_PTE_SHARED,
4520 @@ -268,19 +292,19 @@ static struct mem_type mem_types[] = {
4521 .prot_sect = PROT_SECT_DEVICE,
4522 .domain = DOMAIN_IO,
4523 },
4524 - [MT_UNCACHED] = {
4525 + [MT_UNCACHED_RW] = {
4526 .prot_pte = PROT_PTE_DEVICE,
4527 .prot_l1 = PMD_TYPE_TABLE,
4528 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4529 .domain = DOMAIN_IO,
4530 },
4531 - [MT_CACHECLEAN] = {
4532 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4533 + [MT_CACHECLEAN_RO] = {
4534 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_RDONLY,
4535 .domain = DOMAIN_KERNEL,
4536 },
4537 #ifndef CONFIG_ARM_LPAE
4538 - [MT_MINICLEAN] = {
4539 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4540 + [MT_MINICLEAN_RO] = {
4541 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_XN | PMD_SECT_RDONLY,
4542 .domain = DOMAIN_KERNEL,
4543 },
4544 #endif
4545 @@ -288,15 +312,15 @@ static struct mem_type mem_types[] = {
4546 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4547 L_PTE_RDONLY,
4548 .prot_l1 = PMD_TYPE_TABLE,
4549 - .domain = DOMAIN_USER,
4550 + .domain = DOMAIN_VECTORS,
4551 },
4552 [MT_HIGH_VECTORS] = {
4553 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4554 L_PTE_USER | L_PTE_RDONLY,
4555 .prot_l1 = PMD_TYPE_TABLE,
4556 - .domain = DOMAIN_USER,
4557 + .domain = DOMAIN_VECTORS,
4558 },
4559 - [MT_MEMORY_RWX] = {
4560 + [__MT_MEMORY_RWX] = {
4561 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4562 .prot_l1 = PMD_TYPE_TABLE,
4563 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4564 @@ -309,17 +333,30 @@ static struct mem_type mem_types[] = {
4565 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4566 .domain = DOMAIN_KERNEL,
4567 },
4568 - [MT_ROM] = {
4569 - .prot_sect = PMD_TYPE_SECT,
4570 + [MT_MEMORY_RX] = {
4571 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4572 + .prot_l1 = PMD_TYPE_TABLE,
4573 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4574 + .domain = DOMAIN_KERNEL,
4575 + },
4576 + [MT_ROM_RX] = {
4577 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4578 .domain = DOMAIN_KERNEL,
4579 },
4580 - [MT_MEMORY_RWX_NONCACHED] = {
4581 + [MT_MEMORY_RW_NONCACHED] = {
4582 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4583 L_PTE_MT_BUFFERABLE,
4584 .prot_l1 = PMD_TYPE_TABLE,
4585 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4586 .domain = DOMAIN_KERNEL,
4587 },
4588 + [MT_MEMORY_RX_NONCACHED] = {
4589 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4590 + L_PTE_MT_BUFFERABLE,
4591 + .prot_l1 = PMD_TYPE_TABLE,
4592 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4593 + .domain = DOMAIN_KERNEL,
4594 + },
4595 [MT_MEMORY_RW_DTCM] = {
4596 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4597 L_PTE_XN,
4598 @@ -327,9 +364,10 @@ static struct mem_type mem_types[] = {
4599 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4600 .domain = DOMAIN_KERNEL,
4601 },
4602 - [MT_MEMORY_RWX_ITCM] = {
4603 - .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4604 + [MT_MEMORY_RX_ITCM] = {
4605 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4606 .prot_l1 = PMD_TYPE_TABLE,
4607 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4608 .domain = DOMAIN_KERNEL,
4609 },
4610 [MT_MEMORY_RW_SO] = {
4611 @@ -547,9 +585,14 @@ static void __init build_mem_type_table(void)
4612 * Mark cache clean areas and XIP ROM read only
4613 * from SVC mode and no access from userspace.
4614 */
4615 - mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4616 - mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4617 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4618 + mem_types[MT_ROM_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4619 +#ifdef CONFIG_PAX_KERNEXEC
4620 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4621 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4622 + mem_types[MT_MEMORY_RX_ITCM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4623 +#endif
4624 + mem_types[MT_MINICLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4625 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4626 #endif
4627
4628 /*
4629 @@ -566,13 +609,17 @@ static void __init build_mem_type_table(void)
4630 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4631 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4632 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4633 - mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4634 - mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4635 + mem_types[__MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4636 + mem_types[__MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4637 mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4638 mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4639 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4640 + mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4641 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4642 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_S;
4643 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_pte |= L_PTE_SHARED;
4644 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_S;
4645 + mem_types[MT_MEMORY_RW_NONCACHED].prot_pte |= L_PTE_SHARED;
4646 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_S;
4647 + mem_types[MT_MEMORY_RX_NONCACHED].prot_pte |= L_PTE_SHARED;
4648 }
4649 }
4650
4651 @@ -583,15 +630,20 @@ static void __init build_mem_type_table(void)
4652 if (cpu_arch >= CPU_ARCH_ARMv6) {
4653 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4654 /* Non-cacheable Normal is XCB = 001 */
4655 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4656 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4657 + PMD_SECT_BUFFERED;
4658 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4659 PMD_SECT_BUFFERED;
4660 } else {
4661 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4662 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4663 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4664 + PMD_SECT_TEX(1);
4665 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4666 PMD_SECT_TEX(1);
4667 }
4668 } else {
4669 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4670 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4671 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4672 }
4673
4674 #ifdef CONFIG_ARM_LPAE
4675 @@ -607,6 +659,8 @@ static void __init build_mem_type_table(void)
4676 vecs_pgprot |= PTE_EXT_AF;
4677 #endif
4678
4679 + user_pgprot |= __supported_pte_mask;
4680 +
4681 for (i = 0; i < 16; i++) {
4682 pteval_t v = pgprot_val(protection_map[i]);
4683 protection_map[i] = __pgprot(v | user_pgprot);
4684 @@ -624,21 +678,24 @@ static void __init build_mem_type_table(void)
4685
4686 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4687 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4688 - mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4689 - mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4690 + mem_types[__MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4691 + mem_types[__MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4692 mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4693 mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4694 + mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4695 + mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4696 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4697 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= ecc_mask;
4698 - mem_types[MT_ROM].prot_sect |= cp->pmd;
4699 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= ecc_mask;
4700 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= ecc_mask;
4701 + mem_types[MT_ROM_RX].prot_sect |= cp->pmd;
4702
4703 switch (cp->pmd) {
4704 case PMD_SECT_WT:
4705 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
4706 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WT;
4707 break;
4708 case PMD_SECT_WB:
4709 case PMD_SECT_WBWA:
4710 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
4711 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WB;
4712 break;
4713 }
4714 pr_info("Memory policy: %sData cache %s\n",
4715 @@ -856,7 +913,7 @@ static void __init create_mapping(struct map_desc *md)
4716 return;
4717 }
4718
4719 - if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
4720 + if ((md->type == MT_DEVICE || md->type == MT_ROM_RX) &&
4721 md->virtual >= PAGE_OFFSET &&
4722 (md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) {
4723 printk(KERN_WARNING "BUG: mapping for 0x%08llx"
4724 @@ -1224,18 +1281,15 @@ void __init arm_mm_memblock_reserve(void)
4725 * called function. This means you can't use any function or debugging
4726 * method which may touch any device, otherwise the kernel _will_ crash.
4727 */
4728 +
4729 +static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4730 +
4731 static void __init devicemaps_init(const struct machine_desc *mdesc)
4732 {
4733 struct map_desc map;
4734 unsigned long addr;
4735 - void *vectors;
4736
4737 - /*
4738 - * Allocate the vector page early.
4739 - */
4740 - vectors = early_alloc(PAGE_SIZE * 2);
4741 -
4742 - early_trap_init(vectors);
4743 + early_trap_init(&vectors);
4744
4745 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4746 pmd_clear(pmd_off_k(addr));
4747 @@ -1248,7 +1302,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4748 map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
4749 map.virtual = MODULES_VADDR;
4750 map.length = ((unsigned long)_etext - map.virtual + ~SECTION_MASK) & SECTION_MASK;
4751 - map.type = MT_ROM;
4752 + map.type = MT_ROM_RX;
4753 create_mapping(&map);
4754 #endif
4755
4756 @@ -1259,14 +1313,14 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4757 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS);
4758 map.virtual = FLUSH_BASE;
4759 map.length = SZ_1M;
4760 - map.type = MT_CACHECLEAN;
4761 + map.type = MT_CACHECLEAN_RO;
4762 create_mapping(&map);
4763 #endif
4764 #ifdef FLUSH_BASE_MINICACHE
4765 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS + SZ_1M);
4766 map.virtual = FLUSH_BASE_MINICACHE;
4767 map.length = SZ_1M;
4768 - map.type = MT_MINICLEAN;
4769 + map.type = MT_MINICLEAN_RO;
4770 create_mapping(&map);
4771 #endif
4772
4773 @@ -1275,7 +1329,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4774 * location (0xffff0000). If we aren't using high-vectors, also
4775 * create a mapping at the low-vectors virtual address.
4776 */
4777 - map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4778 + map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4779 map.virtual = 0xffff0000;
4780 map.length = PAGE_SIZE;
4781 #ifdef CONFIG_KUSER_HELPERS
4782 @@ -1335,8 +1389,10 @@ static void __init kmap_init(void)
4783 static void __init map_lowmem(void)
4784 {
4785 struct memblock_region *reg;
4786 +#ifndef CONFIG_PAX_KERNEXEC
4787 unsigned long kernel_x_start = round_down(__pa(_stext), SECTION_SIZE);
4788 unsigned long kernel_x_end = round_up(__pa(__init_end), SECTION_SIZE);
4789 +#endif
4790
4791 /* Map all the lowmem memory banks. */
4792 for_each_memblock(memory, reg) {
4793 @@ -1349,11 +1405,48 @@ static void __init map_lowmem(void)
4794 if (start >= end)
4795 break;
4796
4797 +#ifdef CONFIG_PAX_KERNEXEC
4798 + map.pfn = __phys_to_pfn(start);
4799 + map.virtual = __phys_to_virt(start);
4800 + map.length = end - start;
4801 +
4802 + if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4803 + struct map_desc kernel;
4804 + struct map_desc initmap;
4805 +
4806 + /* when freeing initmem we will make this RW */
4807 + initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4808 + initmap.virtual = (unsigned long)__init_begin;
4809 + initmap.length = _sdata - __init_begin;
4810 + initmap.type = __MT_MEMORY_RWX;
4811 + create_mapping(&initmap);
4812 +
4813 + /* when freeing initmem we will make this RX */
4814 + kernel.pfn = __phys_to_pfn(__pa(_stext));
4815 + kernel.virtual = (unsigned long)_stext;
4816 + kernel.length = __init_begin - _stext;
4817 + kernel.type = __MT_MEMORY_RWX;
4818 + create_mapping(&kernel);
4819 +
4820 + if (map.virtual < (unsigned long)_stext) {
4821 + map.length = (unsigned long)_stext - map.virtual;
4822 + map.type = __MT_MEMORY_RWX;
4823 + create_mapping(&map);
4824 + }
4825 +
4826 + map.pfn = __phys_to_pfn(__pa(_sdata));
4827 + map.virtual = (unsigned long)_sdata;
4828 + map.length = end - __pa(_sdata);
4829 + }
4830 +
4831 + map.type = MT_MEMORY_RW;
4832 + create_mapping(&map);
4833 +#else
4834 if (end < kernel_x_start || start >= kernel_x_end) {
4835 map.pfn = __phys_to_pfn(start);
4836 map.virtual = __phys_to_virt(start);
4837 map.length = end - start;
4838 - map.type = MT_MEMORY_RWX;
4839 + map.type = __MT_MEMORY_RWX;
4840
4841 create_mapping(&map);
4842 } else {
4843 @@ -1370,7 +1463,7 @@ static void __init map_lowmem(void)
4844 map.pfn = __phys_to_pfn(kernel_x_start);
4845 map.virtual = __phys_to_virt(kernel_x_start);
4846 map.length = kernel_x_end - kernel_x_start;
4847 - map.type = MT_MEMORY_RWX;
4848 + map.type = __MT_MEMORY_RWX;
4849
4850 create_mapping(&map);
4851
4852 @@ -1383,6 +1476,7 @@ static void __init map_lowmem(void)
4853 create_mapping(&map);
4854 }
4855 }
4856 +#endif
4857 }
4858 }
4859
4860 diff --git a/arch/arm/net/bpf_jit_32.c b/arch/arm/net/bpf_jit_32.c
4861 index a37b989..5c9ae75 100644
4862 --- a/arch/arm/net/bpf_jit_32.c
4863 +++ b/arch/arm/net/bpf_jit_32.c
4864 @@ -71,7 +71,11 @@ struct jit_ctx {
4865 #endif
4866 };
4867
4868 +#ifdef CONFIG_GRKERNSEC_BPF_HARDEN
4869 +int bpf_jit_enable __read_only;
4870 +#else
4871 int bpf_jit_enable __read_mostly;
4872 +#endif
4873
4874 static u64 jit_get_skb_b(struct sk_buff *skb, unsigned offset)
4875 {
4876 @@ -930,5 +934,6 @@ void bpf_jit_free(struct bpf_prog *fp)
4877 {
4878 if (fp->jited)
4879 module_free(NULL, fp->bpf_func);
4880 - kfree(fp);
4881 +
4882 + bpf_prog_unlock_free(fp);
4883 }
4884 diff --git a/arch/arm/plat-iop/setup.c b/arch/arm/plat-iop/setup.c
4885 index 5b217f4..c23f40e 100644
4886 --- a/arch/arm/plat-iop/setup.c
4887 +++ b/arch/arm/plat-iop/setup.c
4888 @@ -24,7 +24,7 @@ static struct map_desc iop3xx_std_desc[] __initdata = {
4889 .virtual = IOP3XX_PERIPHERAL_VIRT_BASE,
4890 .pfn = __phys_to_pfn(IOP3XX_PERIPHERAL_PHYS_BASE),
4891 .length = IOP3XX_PERIPHERAL_SIZE,
4892 - .type = MT_UNCACHED,
4893 + .type = MT_UNCACHED_RW,
4894 },
4895 };
4896
4897 diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4898 index a5bc92d..0bb4730 100644
4899 --- a/arch/arm/plat-omap/sram.c
4900 +++ b/arch/arm/plat-omap/sram.c
4901 @@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4902 * Looks like we need to preserve some bootloader code at the
4903 * beginning of SRAM for jumping to flash for reboot to work...
4904 */
4905 + pax_open_kernel();
4906 memset_io(omap_sram_base + omap_sram_skip, 0,
4907 omap_sram_size - omap_sram_skip);
4908 + pax_close_kernel();
4909 }
4910 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4911 index ce6d763..cfea917 100644
4912 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4913 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4914 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
4915 int (*started)(unsigned ch);
4916 int (*flush)(unsigned ch);
4917 int (*stop)(unsigned ch);
4918 -};
4919 +} __no_const;
4920
4921 extern void *samsung_dmadev_get_ops(void);
4922 extern void *s3c_dma_get_ops(void);
4923 diff --git a/arch/arm64/include/asm/barrier.h b/arch/arm64/include/asm/barrier.h
4924 index 6389d60..b5d3bdd 100644
4925 --- a/arch/arm64/include/asm/barrier.h
4926 +++ b/arch/arm64/include/asm/barrier.h
4927 @@ -41,7 +41,7 @@
4928 do { \
4929 compiletime_assert_atomic_type(*p); \
4930 barrier(); \
4931 - ACCESS_ONCE(*p) = (v); \
4932 + ACCESS_ONCE_RW(*p) = (v); \
4933 } while (0)
4934
4935 #define smp_load_acquire(p) \
4936 diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
4937 index 3bf8f4e..5dd5491 100644
4938 --- a/arch/arm64/include/asm/uaccess.h
4939 +++ b/arch/arm64/include/asm/uaccess.h
4940 @@ -99,6 +99,7 @@ static inline void set_fs(mm_segment_t fs)
4941 flag; \
4942 })
4943
4944 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
4945 #define access_ok(type, addr, size) __range_ok(addr, size)
4946 #define user_addr_max get_fs
4947
4948 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4949 index c3a58a1..78fbf54 100644
4950 --- a/arch/avr32/include/asm/cache.h
4951 +++ b/arch/avr32/include/asm/cache.h
4952 @@ -1,8 +1,10 @@
4953 #ifndef __ASM_AVR32_CACHE_H
4954 #define __ASM_AVR32_CACHE_H
4955
4956 +#include <linux/const.h>
4957 +
4958 #define L1_CACHE_SHIFT 5
4959 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4960 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4961
4962 /*
4963 * Memory returned by kmalloc() may be used for DMA, so we must make
4964 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4965 index d232888..87c8df1 100644
4966 --- a/arch/avr32/include/asm/elf.h
4967 +++ b/arch/avr32/include/asm/elf.h
4968 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4969 the loader. We need to make sure that it is out of the way of the program
4970 that it will "exec", and that there is sufficient room for the brk. */
4971
4972 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4973 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4974
4975 +#ifdef CONFIG_PAX_ASLR
4976 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4977 +
4978 +#define PAX_DELTA_MMAP_LEN 15
4979 +#define PAX_DELTA_STACK_LEN 15
4980 +#endif
4981
4982 /* This yields a mask that user programs can use to figure out what
4983 instruction set this CPU supports. This could be done in user space,
4984 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4985 index 479330b..53717a8 100644
4986 --- a/arch/avr32/include/asm/kmap_types.h
4987 +++ b/arch/avr32/include/asm/kmap_types.h
4988 @@ -2,9 +2,9 @@
4989 #define __ASM_AVR32_KMAP_TYPES_H
4990
4991 #ifdef CONFIG_DEBUG_HIGHMEM
4992 -# define KM_TYPE_NR 29
4993 +# define KM_TYPE_NR 30
4994 #else
4995 -# define KM_TYPE_NR 14
4996 +# define KM_TYPE_NR 15
4997 #endif
4998
4999 #endif /* __ASM_AVR32_KMAP_TYPES_H */
5000 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
5001 index 0eca933..eb78c7b 100644
5002 --- a/arch/avr32/mm/fault.c
5003 +++ b/arch/avr32/mm/fault.c
5004 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
5005
5006 int exception_trace = 1;
5007
5008 +#ifdef CONFIG_PAX_PAGEEXEC
5009 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5010 +{
5011 + unsigned long i;
5012 +
5013 + printk(KERN_ERR "PAX: bytes at PC: ");
5014 + for (i = 0; i < 20; i++) {
5015 + unsigned char c;
5016 + if (get_user(c, (unsigned char *)pc+i))
5017 + printk(KERN_CONT "???????? ");
5018 + else
5019 + printk(KERN_CONT "%02x ", c);
5020 + }
5021 + printk("\n");
5022 +}
5023 +#endif
5024 +
5025 /*
5026 * This routine handles page faults. It determines the address and the
5027 * problem, and then passes it off to one of the appropriate routines.
5028 @@ -176,6 +193,16 @@ bad_area:
5029 up_read(&mm->mmap_sem);
5030
5031 if (user_mode(regs)) {
5032 +
5033 +#ifdef CONFIG_PAX_PAGEEXEC
5034 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
5035 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
5036 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
5037 + do_group_exit(SIGKILL);
5038 + }
5039 + }
5040 +#endif
5041 +
5042 if (exception_trace && printk_ratelimit())
5043 printk("%s%s[%d]: segfault at %08lx pc %08lx "
5044 "sp %08lx ecr %lu\n",
5045 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
5046 index 568885a..f8008df 100644
5047 --- a/arch/blackfin/include/asm/cache.h
5048 +++ b/arch/blackfin/include/asm/cache.h
5049 @@ -7,6 +7,7 @@
5050 #ifndef __ARCH_BLACKFIN_CACHE_H
5051 #define __ARCH_BLACKFIN_CACHE_H
5052
5053 +#include <linux/const.h>
5054 #include <linux/linkage.h> /* for asmlinkage */
5055
5056 /*
5057 @@ -14,7 +15,7 @@
5058 * Blackfin loads 32 bytes for cache
5059 */
5060 #define L1_CACHE_SHIFT 5
5061 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5062 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5063 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5064
5065 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5066 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
5067 index aea2718..3639a60 100644
5068 --- a/arch/cris/include/arch-v10/arch/cache.h
5069 +++ b/arch/cris/include/arch-v10/arch/cache.h
5070 @@ -1,8 +1,9 @@
5071 #ifndef _ASM_ARCH_CACHE_H
5072 #define _ASM_ARCH_CACHE_H
5073
5074 +#include <linux/const.h>
5075 /* Etrax 100LX have 32-byte cache-lines. */
5076 -#define L1_CACHE_BYTES 32
5077 #define L1_CACHE_SHIFT 5
5078 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5079
5080 #endif /* _ASM_ARCH_CACHE_H */
5081 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
5082 index 7caf25d..ee65ac5 100644
5083 --- a/arch/cris/include/arch-v32/arch/cache.h
5084 +++ b/arch/cris/include/arch-v32/arch/cache.h
5085 @@ -1,11 +1,12 @@
5086 #ifndef _ASM_CRIS_ARCH_CACHE_H
5087 #define _ASM_CRIS_ARCH_CACHE_H
5088
5089 +#include <linux/const.h>
5090 #include <arch/hwregs/dma.h>
5091
5092 /* A cache-line is 32 bytes. */
5093 -#define L1_CACHE_BYTES 32
5094 #define L1_CACHE_SHIFT 5
5095 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5096
5097 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5098
5099 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
5100 index f6c3a16..cd422a4 100644
5101 --- a/arch/frv/include/asm/atomic.h
5102 +++ b/arch/frv/include/asm/atomic.h
5103 @@ -181,6 +181,16 @@ static inline void atomic64_dec(atomic64_t *v)
5104 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
5105 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
5106
5107 +#define atomic64_read_unchecked(v) atomic64_read(v)
5108 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5109 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5110 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5111 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5112 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5113 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5114 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5115 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5116 +
5117 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5118 {
5119 int c, old;
5120 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
5121 index 2797163..c2a401df9 100644
5122 --- a/arch/frv/include/asm/cache.h
5123 +++ b/arch/frv/include/asm/cache.h
5124 @@ -12,10 +12,11 @@
5125 #ifndef __ASM_CACHE_H
5126 #define __ASM_CACHE_H
5127
5128 +#include <linux/const.h>
5129
5130 /* bytes per L1 cache line */
5131 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
5132 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5133 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5134
5135 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
5136 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
5137 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
5138 index 43901f2..0d8b865 100644
5139 --- a/arch/frv/include/asm/kmap_types.h
5140 +++ b/arch/frv/include/asm/kmap_types.h
5141 @@ -2,6 +2,6 @@
5142 #ifndef _ASM_KMAP_TYPES_H
5143 #define _ASM_KMAP_TYPES_H
5144
5145 -#define KM_TYPE_NR 17
5146 +#define KM_TYPE_NR 18
5147
5148 #endif
5149 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
5150 index 836f147..4cf23f5 100644
5151 --- a/arch/frv/mm/elf-fdpic.c
5152 +++ b/arch/frv/mm/elf-fdpic.c
5153 @@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5154 {
5155 struct vm_area_struct *vma;
5156 struct vm_unmapped_area_info info;
5157 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5158
5159 if (len > TASK_SIZE)
5160 return -ENOMEM;
5161 @@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5162 if (addr) {
5163 addr = PAGE_ALIGN(addr);
5164 vma = find_vma(current->mm, addr);
5165 - if (TASK_SIZE - len >= addr &&
5166 - (!vma || addr + len <= vma->vm_start))
5167 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
5168 goto success;
5169 }
5170
5171 @@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5172 info.high_limit = (current->mm->start_stack - 0x00200000);
5173 info.align_mask = 0;
5174 info.align_offset = 0;
5175 + info.threadstack_offset = offset;
5176 addr = vm_unmapped_area(&info);
5177 if (!(addr & ~PAGE_MASK))
5178 goto success;
5179 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
5180 index 2635117..fa223cb 100644
5181 --- a/arch/hexagon/include/asm/cache.h
5182 +++ b/arch/hexagon/include/asm/cache.h
5183 @@ -21,9 +21,11 @@
5184 #ifndef __ASM_CACHE_H
5185 #define __ASM_CACHE_H
5186
5187 +#include <linux/const.h>
5188 +
5189 /* Bytes per L1 cache line */
5190 -#define L1_CACHE_SHIFT (5)
5191 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5192 +#define L1_CACHE_SHIFT 5
5193 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5194
5195 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
5196 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
5197 diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
5198 index c84c88b..2a6e1ba 100644
5199 --- a/arch/ia64/Kconfig
5200 +++ b/arch/ia64/Kconfig
5201 @@ -549,6 +549,7 @@ source "drivers/sn/Kconfig"
5202 config KEXEC
5203 bool "kexec system call"
5204 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
5205 + depends on !GRKERNSEC_KMEM
5206 help
5207 kexec is a system call that implements the ability to shutdown your
5208 current kernel, and to start another kernel. It is like a reboot
5209 diff --git a/arch/ia64/Makefile b/arch/ia64/Makefile
5210 index 5441b14..039a446 100644
5211 --- a/arch/ia64/Makefile
5212 +++ b/arch/ia64/Makefile
5213 @@ -99,5 +99,6 @@ endef
5214 archprepare: make_nr_irqs_h FORCE
5215 PHONY += make_nr_irqs_h FORCE
5216
5217 +make_nr_irqs_h: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
5218 make_nr_irqs_h: FORCE
5219 $(Q)$(MAKE) $(build)=arch/ia64/kernel include/generated/nr-irqs.h
5220 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
5221 index 0f8bf48..40ea950 100644
5222 --- a/arch/ia64/include/asm/atomic.h
5223 +++ b/arch/ia64/include/asm/atomic.h
5224 @@ -209,4 +209,14 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
5225 #define atomic64_inc(v) atomic64_add(1, (v))
5226 #define atomic64_dec(v) atomic64_sub(1, (v))
5227
5228 +#define atomic64_read_unchecked(v) atomic64_read(v)
5229 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5230 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5231 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5232 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5233 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5234 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5235 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5236 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5237 +
5238 #endif /* _ASM_IA64_ATOMIC_H */
5239 diff --git a/arch/ia64/include/asm/barrier.h b/arch/ia64/include/asm/barrier.h
5240 index a48957c..e097b56 100644
5241 --- a/arch/ia64/include/asm/barrier.h
5242 +++ b/arch/ia64/include/asm/barrier.h
5243 @@ -67,7 +67,7 @@
5244 do { \
5245 compiletime_assert_atomic_type(*p); \
5246 barrier(); \
5247 - ACCESS_ONCE(*p) = (v); \
5248 + ACCESS_ONCE_RW(*p) = (v); \
5249 } while (0)
5250
5251 #define smp_load_acquire(p) \
5252 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
5253 index 988254a..e1ee885 100644
5254 --- a/arch/ia64/include/asm/cache.h
5255 +++ b/arch/ia64/include/asm/cache.h
5256 @@ -1,6 +1,7 @@
5257 #ifndef _ASM_IA64_CACHE_H
5258 #define _ASM_IA64_CACHE_H
5259
5260 +#include <linux/const.h>
5261
5262 /*
5263 * Copyright (C) 1998-2000 Hewlett-Packard Co
5264 @@ -9,7 +10,7 @@
5265
5266 /* Bytes per L1 (data) cache line. */
5267 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
5268 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5269 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5270
5271 #ifdef CONFIG_SMP
5272 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5273 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
5274 index 5a83c5c..4d7f553 100644
5275 --- a/arch/ia64/include/asm/elf.h
5276 +++ b/arch/ia64/include/asm/elf.h
5277 @@ -42,6 +42,13 @@
5278 */
5279 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
5280
5281 +#ifdef CONFIG_PAX_ASLR
5282 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
5283 +
5284 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5285 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5286 +#endif
5287 +
5288 #define PT_IA_64_UNWIND 0x70000001
5289
5290 /* IA-64 relocations: */
5291 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
5292 index 5767cdf..7462574 100644
5293 --- a/arch/ia64/include/asm/pgalloc.h
5294 +++ b/arch/ia64/include/asm/pgalloc.h
5295 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5296 pgd_val(*pgd_entry) = __pa(pud);
5297 }
5298
5299 +static inline void
5300 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5301 +{
5302 + pgd_populate(mm, pgd_entry, pud);
5303 +}
5304 +
5305 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
5306 {
5307 return quicklist_alloc(0, GFP_KERNEL, NULL);
5308 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5309 pud_val(*pud_entry) = __pa(pmd);
5310 }
5311
5312 +static inline void
5313 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5314 +{
5315 + pud_populate(mm, pud_entry, pmd);
5316 +}
5317 +
5318 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5319 {
5320 return quicklist_alloc(0, GFP_KERNEL, NULL);
5321 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5322 index 7935115..c0eca6a 100644
5323 --- a/arch/ia64/include/asm/pgtable.h
5324 +++ b/arch/ia64/include/asm/pgtable.h
5325 @@ -12,7 +12,7 @@
5326 * David Mosberger-Tang <davidm@hpl.hp.com>
5327 */
5328
5329 -
5330 +#include <linux/const.h>
5331 #include <asm/mman.h>
5332 #include <asm/page.h>
5333 #include <asm/processor.h>
5334 @@ -142,6 +142,17 @@
5335 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5336 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5337 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5338 +
5339 +#ifdef CONFIG_PAX_PAGEEXEC
5340 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5341 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5342 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5343 +#else
5344 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
5345 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
5346 +# define PAGE_COPY_NOEXEC PAGE_COPY
5347 +#endif
5348 +
5349 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5350 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5351 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5352 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5353 index 45698cd..e8e2dbc 100644
5354 --- a/arch/ia64/include/asm/spinlock.h
5355 +++ b/arch/ia64/include/asm/spinlock.h
5356 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5357 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5358
5359 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5360 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5361 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5362 }
5363
5364 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5365 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5366 index 449c8c0..3d4b1e9 100644
5367 --- a/arch/ia64/include/asm/uaccess.h
5368 +++ b/arch/ia64/include/asm/uaccess.h
5369 @@ -70,6 +70,7 @@
5370 && ((segment).seg == KERNEL_DS.seg \
5371 || likely(REGION_OFFSET((unsigned long) (addr)) < RGN_MAP_LIMIT))); \
5372 })
5373 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5374 #define access_ok(type, addr, size) __access_ok((addr), (size), get_fs())
5375
5376 /*
5377 @@ -240,12 +241,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5378 static inline unsigned long
5379 __copy_to_user (void __user *to, const void *from, unsigned long count)
5380 {
5381 + if (count > INT_MAX)
5382 + return count;
5383 +
5384 + if (!__builtin_constant_p(count))
5385 + check_object_size(from, count, true);
5386 +
5387 return __copy_user(to, (__force void __user *) from, count);
5388 }
5389
5390 static inline unsigned long
5391 __copy_from_user (void *to, const void __user *from, unsigned long count)
5392 {
5393 + if (count > INT_MAX)
5394 + return count;
5395 +
5396 + if (!__builtin_constant_p(count))
5397 + check_object_size(to, count, false);
5398 +
5399 return __copy_user((__force void __user *) to, from, count);
5400 }
5401
5402 @@ -255,10 +268,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5403 ({ \
5404 void __user *__cu_to = (to); \
5405 const void *__cu_from = (from); \
5406 - long __cu_len = (n); \
5407 + unsigned long __cu_len = (n); \
5408 \
5409 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
5410 + if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5411 + if (!__builtin_constant_p(n)) \
5412 + check_object_size(__cu_from, __cu_len, true); \
5413 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5414 + } \
5415 __cu_len; \
5416 })
5417
5418 @@ -266,11 +282,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5419 ({ \
5420 void *__cu_to = (to); \
5421 const void __user *__cu_from = (from); \
5422 - long __cu_len = (n); \
5423 + unsigned long __cu_len = (n); \
5424 \
5425 __chk_user_ptr(__cu_from); \
5426 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
5427 + if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5428 + if (!__builtin_constant_p(n)) \
5429 + check_object_size(__cu_to, __cu_len, false); \
5430 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5431 + } \
5432 __cu_len; \
5433 })
5434
5435 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5436 index 24603be..948052d 100644
5437 --- a/arch/ia64/kernel/module.c
5438 +++ b/arch/ia64/kernel/module.c
5439 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5440 void
5441 module_free (struct module *mod, void *module_region)
5442 {
5443 - if (mod && mod->arch.init_unw_table &&
5444 - module_region == mod->module_init) {
5445 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5446 unw_remove_unwind_table(mod->arch.init_unw_table);
5447 mod->arch.init_unw_table = NULL;
5448 }
5449 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5450 }
5451
5452 static inline int
5453 +in_init_rx (const struct module *mod, uint64_t addr)
5454 +{
5455 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5456 +}
5457 +
5458 +static inline int
5459 +in_init_rw (const struct module *mod, uint64_t addr)
5460 +{
5461 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5462 +}
5463 +
5464 +static inline int
5465 in_init (const struct module *mod, uint64_t addr)
5466 {
5467 - return addr - (uint64_t) mod->module_init < mod->init_size;
5468 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5469 +}
5470 +
5471 +static inline int
5472 +in_core_rx (const struct module *mod, uint64_t addr)
5473 +{
5474 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5475 +}
5476 +
5477 +static inline int
5478 +in_core_rw (const struct module *mod, uint64_t addr)
5479 +{
5480 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5481 }
5482
5483 static inline int
5484 in_core (const struct module *mod, uint64_t addr)
5485 {
5486 - return addr - (uint64_t) mod->module_core < mod->core_size;
5487 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5488 }
5489
5490 static inline int
5491 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5492 break;
5493
5494 case RV_BDREL:
5495 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5496 + if (in_init_rx(mod, val))
5497 + val -= (uint64_t) mod->module_init_rx;
5498 + else if (in_init_rw(mod, val))
5499 + val -= (uint64_t) mod->module_init_rw;
5500 + else if (in_core_rx(mod, val))
5501 + val -= (uint64_t) mod->module_core_rx;
5502 + else if (in_core_rw(mod, val))
5503 + val -= (uint64_t) mod->module_core_rw;
5504 break;
5505
5506 case RV_LTV:
5507 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5508 * addresses have been selected...
5509 */
5510 uint64_t gp;
5511 - if (mod->core_size > MAX_LTOFF)
5512 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5513 /*
5514 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5515 * at the end of the module.
5516 */
5517 - gp = mod->core_size - MAX_LTOFF / 2;
5518 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5519 else
5520 - gp = mod->core_size / 2;
5521 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5522 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5523 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5524 mod->arch.gp = gp;
5525 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5526 }
5527 diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5528 index c39c3cd..3c77738 100644
5529 --- a/arch/ia64/kernel/palinfo.c
5530 +++ b/arch/ia64/kernel/palinfo.c
5531 @@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5532 return NOTIFY_OK;
5533 }
5534
5535 -static struct notifier_block __refdata palinfo_cpu_notifier =
5536 +static struct notifier_block palinfo_cpu_notifier =
5537 {
5538 .notifier_call = palinfo_cpu_callback,
5539 .priority = 0,
5540 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5541 index 41e33f8..65180b2a 100644
5542 --- a/arch/ia64/kernel/sys_ia64.c
5543 +++ b/arch/ia64/kernel/sys_ia64.c
5544 @@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5545 unsigned long align_mask = 0;
5546 struct mm_struct *mm = current->mm;
5547 struct vm_unmapped_area_info info;
5548 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5549
5550 if (len > RGN_MAP_LIMIT)
5551 return -ENOMEM;
5552 @@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5553 if (REGION_NUMBER(addr) == RGN_HPAGE)
5554 addr = 0;
5555 #endif
5556 +
5557 +#ifdef CONFIG_PAX_RANDMMAP
5558 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5559 + addr = mm->free_area_cache;
5560 + else
5561 +#endif
5562 +
5563 if (!addr)
5564 addr = TASK_UNMAPPED_BASE;
5565
5566 @@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5567 info.high_limit = TASK_SIZE;
5568 info.align_mask = align_mask;
5569 info.align_offset = 0;
5570 + info.threadstack_offset = offset;
5571 return vm_unmapped_area(&info);
5572 }
5573
5574 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5575 index 84f8a52..7c76178 100644
5576 --- a/arch/ia64/kernel/vmlinux.lds.S
5577 +++ b/arch/ia64/kernel/vmlinux.lds.S
5578 @@ -192,7 +192,7 @@ SECTIONS {
5579 /* Per-cpu data: */
5580 . = ALIGN(PERCPU_PAGE_SIZE);
5581 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5582 - __phys_per_cpu_start = __per_cpu_load;
5583 + __phys_per_cpu_start = per_cpu_load;
5584 /*
5585 * ensure percpu data fits
5586 * into percpu page size
5587 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5588 index 7225dad..2a7c8256 100644
5589 --- a/arch/ia64/mm/fault.c
5590 +++ b/arch/ia64/mm/fault.c
5591 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5592 return pte_present(pte);
5593 }
5594
5595 +#ifdef CONFIG_PAX_PAGEEXEC
5596 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5597 +{
5598 + unsigned long i;
5599 +
5600 + printk(KERN_ERR "PAX: bytes at PC: ");
5601 + for (i = 0; i < 8; i++) {
5602 + unsigned int c;
5603 + if (get_user(c, (unsigned int *)pc+i))
5604 + printk(KERN_CONT "???????? ");
5605 + else
5606 + printk(KERN_CONT "%08x ", c);
5607 + }
5608 + printk("\n");
5609 +}
5610 +#endif
5611 +
5612 # define VM_READ_BIT 0
5613 # define VM_WRITE_BIT 1
5614 # define VM_EXEC_BIT 2
5615 @@ -151,8 +168,21 @@ retry:
5616 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5617 goto bad_area;
5618
5619 - if ((vma->vm_flags & mask) != mask)
5620 + if ((vma->vm_flags & mask) != mask) {
5621 +
5622 +#ifdef CONFIG_PAX_PAGEEXEC
5623 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5624 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5625 + goto bad_area;
5626 +
5627 + up_read(&mm->mmap_sem);
5628 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5629 + do_group_exit(SIGKILL);
5630 + }
5631 +#endif
5632 +
5633 goto bad_area;
5634 + }
5635
5636 /*
5637 * If for any reason at all we couldn't handle the fault, make
5638 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5639 index 76069c1..c2aa816 100644
5640 --- a/arch/ia64/mm/hugetlbpage.c
5641 +++ b/arch/ia64/mm/hugetlbpage.c
5642 @@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5643 unsigned long pgoff, unsigned long flags)
5644 {
5645 struct vm_unmapped_area_info info;
5646 + unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5647
5648 if (len > RGN_MAP_LIMIT)
5649 return -ENOMEM;
5650 @@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5651 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5652 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5653 info.align_offset = 0;
5654 + info.threadstack_offset = offset;
5655 return vm_unmapped_area(&info);
5656 }
5657
5658 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5659 index 6b33457..88b5124 100644
5660 --- a/arch/ia64/mm/init.c
5661 +++ b/arch/ia64/mm/init.c
5662 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5663 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5664 vma->vm_end = vma->vm_start + PAGE_SIZE;
5665 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5666 +
5667 +#ifdef CONFIG_PAX_PAGEEXEC
5668 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5669 + vma->vm_flags &= ~VM_EXEC;
5670 +
5671 +#ifdef CONFIG_PAX_MPROTECT
5672 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
5673 + vma->vm_flags &= ~VM_MAYEXEC;
5674 +#endif
5675 +
5676 + }
5677 +#endif
5678 +
5679 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5680 down_write(&current->mm->mmap_sem);
5681 if (insert_vm_struct(current->mm, vma)) {
5682 @@ -286,7 +299,7 @@ static int __init gate_vma_init(void)
5683 gate_vma.vm_start = FIXADDR_USER_START;
5684 gate_vma.vm_end = FIXADDR_USER_END;
5685 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
5686 - gate_vma.vm_page_prot = __P101;
5687 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
5688
5689 return 0;
5690 }
5691 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5692 index 40b3ee9..8c2c112 100644
5693 --- a/arch/m32r/include/asm/cache.h
5694 +++ b/arch/m32r/include/asm/cache.h
5695 @@ -1,8 +1,10 @@
5696 #ifndef _ASM_M32R_CACHE_H
5697 #define _ASM_M32R_CACHE_H
5698
5699 +#include <linux/const.h>
5700 +
5701 /* L1 cache line size */
5702 #define L1_CACHE_SHIFT 4
5703 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5704 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5705
5706 #endif /* _ASM_M32R_CACHE_H */
5707 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5708 index 82abd15..d95ae5d 100644
5709 --- a/arch/m32r/lib/usercopy.c
5710 +++ b/arch/m32r/lib/usercopy.c
5711 @@ -14,6 +14,9 @@
5712 unsigned long
5713 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5714 {
5715 + if ((long)n < 0)
5716 + return n;
5717 +
5718 prefetch(from);
5719 if (access_ok(VERIFY_WRITE, to, n))
5720 __copy_user(to,from,n);
5721 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5722 unsigned long
5723 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5724 {
5725 + if ((long)n < 0)
5726 + return n;
5727 +
5728 prefetchw(to);
5729 if (access_ok(VERIFY_READ, from, n))
5730 __copy_user_zeroing(to,from,n);
5731 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5732 index 0395c51..5f26031 100644
5733 --- a/arch/m68k/include/asm/cache.h
5734 +++ b/arch/m68k/include/asm/cache.h
5735 @@ -4,9 +4,11 @@
5736 #ifndef __ARCH_M68K_CACHE_H
5737 #define __ARCH_M68K_CACHE_H
5738
5739 +#include <linux/const.h>
5740 +
5741 /* bytes per L1 cache line */
5742 #define L1_CACHE_SHIFT 4
5743 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5744 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5745
5746 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5747
5748 diff --git a/arch/metag/include/asm/barrier.h b/arch/metag/include/asm/barrier.h
5749 index c7591e8..ecef036 100644
5750 --- a/arch/metag/include/asm/barrier.h
5751 +++ b/arch/metag/include/asm/barrier.h
5752 @@ -89,7 +89,7 @@ static inline void fence(void)
5753 do { \
5754 compiletime_assert_atomic_type(*p); \
5755 smp_mb(); \
5756 - ACCESS_ONCE(*p) = (v); \
5757 + ACCESS_ONCE_RW(*p) = (v); \
5758 } while (0)
5759
5760 #define smp_load_acquire(p) \
5761 diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5762 index 3c32075..ae0ae75 100644
5763 --- a/arch/metag/mm/hugetlbpage.c
5764 +++ b/arch/metag/mm/hugetlbpage.c
5765 @@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5766 info.high_limit = TASK_SIZE;
5767 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5768 info.align_offset = 0;
5769 + info.threadstack_offset = 0;
5770 return vm_unmapped_area(&info);
5771 }
5772
5773 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5774 index 4efe96a..60e8699 100644
5775 --- a/arch/microblaze/include/asm/cache.h
5776 +++ b/arch/microblaze/include/asm/cache.h
5777 @@ -13,11 +13,12 @@
5778 #ifndef _ASM_MICROBLAZE_CACHE_H
5779 #define _ASM_MICROBLAZE_CACHE_H
5780
5781 +#include <linux/const.h>
5782 #include <asm/registers.h>
5783
5784 #define L1_CACHE_SHIFT 5
5785 /* word-granular cache in microblaze */
5786 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5787 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5788
5789 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5790
5791 diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5792 index 574c430..470200d 100644
5793 --- a/arch/mips/Kconfig
5794 +++ b/arch/mips/Kconfig
5795 @@ -2399,6 +2399,7 @@ source "kernel/Kconfig.preempt"
5796
5797 config KEXEC
5798 bool "Kexec system call"
5799 + depends on !GRKERNSEC_KMEM
5800 help
5801 kexec is a system call that implements the ability to shutdown your
5802 current kernel, and to start another kernel. It is like a reboot
5803 diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
5804 index 02f2444..506969c 100644
5805 --- a/arch/mips/cavium-octeon/dma-octeon.c
5806 +++ b/arch/mips/cavium-octeon/dma-octeon.c
5807 @@ -199,7 +199,7 @@ static void octeon_dma_free_coherent(struct device *dev, size_t size,
5808 if (dma_release_from_coherent(dev, order, vaddr))
5809 return;
5810
5811 - swiotlb_free_coherent(dev, size, vaddr, dma_handle);
5812 + swiotlb_free_coherent(dev, size, vaddr, dma_handle, attrs);
5813 }
5814
5815 static dma_addr_t octeon_unity_phys_to_dma(struct device *dev, phys_addr_t paddr)
5816 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5817 index 37b2bef..02122b8 100644
5818 --- a/arch/mips/include/asm/atomic.h
5819 +++ b/arch/mips/include/asm/atomic.h
5820 @@ -21,15 +21,39 @@
5821 #include <asm/cmpxchg.h>
5822 #include <asm/war.h>
5823
5824 +#ifdef CONFIG_GENERIC_ATOMIC64
5825 +#include <asm-generic/atomic64.h>
5826 +#endif
5827 +
5828 #define ATOMIC_INIT(i) { (i) }
5829
5830 +#ifdef CONFIG_64BIT
5831 +#define _ASM_EXTABLE(from, to) \
5832 +" .section __ex_table,\"a\"\n" \
5833 +" .dword " #from ", " #to"\n" \
5834 +" .previous\n"
5835 +#else
5836 +#define _ASM_EXTABLE(from, to) \
5837 +" .section __ex_table,\"a\"\n" \
5838 +" .word " #from ", " #to"\n" \
5839 +" .previous\n"
5840 +#endif
5841 +
5842 /*
5843 * atomic_read - read atomic variable
5844 * @v: pointer of type atomic_t
5845 *
5846 * Atomically reads the value of @v.
5847 */
5848 -#define atomic_read(v) (*(volatile int *)&(v)->counter)
5849 +static inline int atomic_read(const atomic_t *v)
5850 +{
5851 + return (*(volatile const int *) &v->counter);
5852 +}
5853 +
5854 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5855 +{
5856 + return (*(volatile const int *) &v->counter);
5857 +}
5858
5859 /*
5860 * atomic_set - set atomic variable
5861 @@ -38,7 +62,15 @@
5862 *
5863 * Atomically sets the value of @v to @i.
5864 */
5865 -#define atomic_set(v, i) ((v)->counter = (i))
5866 +static inline void atomic_set(atomic_t *v, int i)
5867 +{
5868 + v->counter = i;
5869 +}
5870 +
5871 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5872 +{
5873 + v->counter = i;
5874 +}
5875
5876 /*
5877 * atomic_add - add integer to atomic variable
5878 @@ -47,7 +79,67 @@
5879 *
5880 * Atomically adds @i to @v.
5881 */
5882 -static __inline__ void atomic_add(int i, atomic_t * v)
5883 +static __inline__ void atomic_add(int i, atomic_t *v)
5884 +{
5885 + int temp;
5886 +
5887 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5888 + __asm__ __volatile__(
5889 + " .set mips3 \n"
5890 + "1: ll %0, %1 # atomic_add \n"
5891 +#ifdef CONFIG_PAX_REFCOUNT
5892 + /* Exception on overflow. */
5893 + "2: add %0, %2 \n"
5894 +#else
5895 + " addu %0, %2 \n"
5896 +#endif
5897 + " sc %0, %1 \n"
5898 + " beqzl %0, 1b \n"
5899 +#ifdef CONFIG_PAX_REFCOUNT
5900 + "3: \n"
5901 + _ASM_EXTABLE(2b, 3b)
5902 +#endif
5903 + " .set mips0 \n"
5904 + : "=&r" (temp), "+m" (v->counter)
5905 + : "Ir" (i));
5906 + } else if (kernel_uses_llsc) {
5907 + __asm__ __volatile__(
5908 + " .set mips3 \n"
5909 + "1: ll %0, %1 # atomic_add \n"
5910 +#ifdef CONFIG_PAX_REFCOUNT
5911 + /* Exception on overflow. */
5912 + "2: add %0, %2 \n"
5913 +#else
5914 + " addu %0, %2 \n"
5915 +#endif
5916 + " sc %0, %1 \n"
5917 + " beqz %0, 1b \n"
5918 +#ifdef CONFIG_PAX_REFCOUNT
5919 + "3: \n"
5920 + _ASM_EXTABLE(2b, 3b)
5921 +#endif
5922 + " .set mips0 \n"
5923 + : "=&r" (temp), "+m" (v->counter)
5924 + : "Ir" (i));
5925 + } else {
5926 + unsigned long flags;
5927 +
5928 + raw_local_irq_save(flags);
5929 + __asm__ __volatile__(
5930 +#ifdef CONFIG_PAX_REFCOUNT
5931 + /* Exception on overflow. */
5932 + "1: add %0, %1 \n"
5933 + "2: \n"
5934 + _ASM_EXTABLE(1b, 2b)
5935 +#else
5936 + " addu %0, %1 \n"
5937 +#endif
5938 + : "+r" (v->counter) : "Ir" (i));
5939 + raw_local_irq_restore(flags);
5940 + }
5941 +}
5942 +
5943 +static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5944 {
5945 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5946 int temp;
5947 @@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5948 *
5949 * Atomically subtracts @i from @v.
5950 */
5951 -static __inline__ void atomic_sub(int i, atomic_t * v)
5952 +static __inline__ void atomic_sub(int i, atomic_t *v)
5953 +{
5954 + int temp;
5955 +
5956 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5957 + __asm__ __volatile__(
5958 + " .set mips3 \n"
5959 + "1: ll %0, %1 # atomic64_sub \n"
5960 +#ifdef CONFIG_PAX_REFCOUNT
5961 + /* Exception on overflow. */
5962 + "2: sub %0, %2 \n"
5963 +#else
5964 + " subu %0, %2 \n"
5965 +#endif
5966 + " sc %0, %1 \n"
5967 + " beqzl %0, 1b \n"
5968 +#ifdef CONFIG_PAX_REFCOUNT
5969 + "3: \n"
5970 + _ASM_EXTABLE(2b, 3b)
5971 +#endif
5972 + " .set mips0 \n"
5973 + : "=&r" (temp), "+m" (v->counter)
5974 + : "Ir" (i));
5975 + } else if (kernel_uses_llsc) {
5976 + __asm__ __volatile__(
5977 + " .set mips3 \n"
5978 + "1: ll %0, %1 # atomic64_sub \n"
5979 +#ifdef CONFIG_PAX_REFCOUNT
5980 + /* Exception on overflow. */
5981 + "2: sub %0, %2 \n"
5982 +#else
5983 + " subu %0, %2 \n"
5984 +#endif
5985 + " sc %0, %1 \n"
5986 + " beqz %0, 1b \n"
5987 +#ifdef CONFIG_PAX_REFCOUNT
5988 + "3: \n"
5989 + _ASM_EXTABLE(2b, 3b)
5990 +#endif
5991 + " .set mips0 \n"
5992 + : "=&r" (temp), "+m" (v->counter)
5993 + : "Ir" (i));
5994 + } else {
5995 + unsigned long flags;
5996 +
5997 + raw_local_irq_save(flags);
5998 + __asm__ __volatile__(
5999 +#ifdef CONFIG_PAX_REFCOUNT
6000 + /* Exception on overflow. */
6001 + "1: sub %0, %1 \n"
6002 + "2: \n"
6003 + _ASM_EXTABLE(1b, 2b)
6004 +#else
6005 + " subu %0, %1 \n"
6006 +#endif
6007 + : "+r" (v->counter) : "Ir" (i));
6008 + raw_local_irq_restore(flags);
6009 + }
6010 +}
6011 +
6012 +static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
6013 {
6014 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6015 int temp;
6016 @@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
6017 /*
6018 * Same as above, but return the result value
6019 */
6020 -static __inline__ int atomic_add_return(int i, atomic_t * v)
6021 +static __inline__ int atomic_add_return(int i, atomic_t *v)
6022 +{
6023 + int result;
6024 + int temp;
6025 +
6026 + smp_mb__before_llsc();
6027 +
6028 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6029 + __asm__ __volatile__(
6030 + " .set mips3 \n"
6031 + "1: ll %1, %2 # atomic_add_return \n"
6032 +#ifdef CONFIG_PAX_REFCOUNT
6033 + "2: add %0, %1, %3 \n"
6034 +#else
6035 + " addu %0, %1, %3 \n"
6036 +#endif
6037 + " sc %0, %2 \n"
6038 + " beqzl %0, 1b \n"
6039 +#ifdef CONFIG_PAX_REFCOUNT
6040 + " b 4f \n"
6041 + " .set noreorder \n"
6042 + "3: b 5f \n"
6043 + " move %0, %1 \n"
6044 + " .set reorder \n"
6045 + _ASM_EXTABLE(2b, 3b)
6046 +#endif
6047 + "4: addu %0, %1, %3 \n"
6048 +#ifdef CONFIG_PAX_REFCOUNT
6049 + "5: \n"
6050 +#endif
6051 + " .set mips0 \n"
6052 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6053 + : "Ir" (i));
6054 + } else if (kernel_uses_llsc) {
6055 + __asm__ __volatile__(
6056 + " .set mips3 \n"
6057 + "1: ll %1, %2 # atomic_add_return \n"
6058 +#ifdef CONFIG_PAX_REFCOUNT
6059 + "2: add %0, %1, %3 \n"
6060 +#else
6061 + " addu %0, %1, %3 \n"
6062 +#endif
6063 + " sc %0, %2 \n"
6064 + " bnez %0, 4f \n"
6065 + " b 1b \n"
6066 +#ifdef CONFIG_PAX_REFCOUNT
6067 + " .set noreorder \n"
6068 + "3: b 5f \n"
6069 + " move %0, %1 \n"
6070 + " .set reorder \n"
6071 + _ASM_EXTABLE(2b, 3b)
6072 +#endif
6073 + "4: addu %0, %1, %3 \n"
6074 +#ifdef CONFIG_PAX_REFCOUNT
6075 + "5: \n"
6076 +#endif
6077 + " .set mips0 \n"
6078 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6079 + : "Ir" (i));
6080 + } else {
6081 + unsigned long flags;
6082 +
6083 + raw_local_irq_save(flags);
6084 + __asm__ __volatile__(
6085 + " lw %0, %1 \n"
6086 +#ifdef CONFIG_PAX_REFCOUNT
6087 + /* Exception on overflow. */
6088 + "1: add %0, %2 \n"
6089 +#else
6090 + " addu %0, %2 \n"
6091 +#endif
6092 + " sw %0, %1 \n"
6093 +#ifdef CONFIG_PAX_REFCOUNT
6094 + /* Note: Dest reg is not modified on overflow */
6095 + "2: \n"
6096 + _ASM_EXTABLE(1b, 2b)
6097 +#endif
6098 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6099 + raw_local_irq_restore(flags);
6100 + }
6101 +
6102 + smp_llsc_mb();
6103 +
6104 + return result;
6105 +}
6106 +
6107 +static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
6108 {
6109 int result;
6110
6111 @@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
6112 return result;
6113 }
6114
6115 -static __inline__ int atomic_sub_return(int i, atomic_t * v)
6116 +static __inline__ int atomic_sub_return(int i, atomic_t *v)
6117 +{
6118 + int result;
6119 + int temp;
6120 +
6121 + smp_mb__before_llsc();
6122 +
6123 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6124 + __asm__ __volatile__(
6125 + " .set mips3 \n"
6126 + "1: ll %1, %2 # atomic_sub_return \n"
6127 +#ifdef CONFIG_PAX_REFCOUNT
6128 + "2: sub %0, %1, %3 \n"
6129 +#else
6130 + " subu %0, %1, %3 \n"
6131 +#endif
6132 + " sc %0, %2 \n"
6133 + " beqzl %0, 1b \n"
6134 +#ifdef CONFIG_PAX_REFCOUNT
6135 + " b 4f \n"
6136 + " .set noreorder \n"
6137 + "3: b 5f \n"
6138 + " move %0, %1 \n"
6139 + " .set reorder \n"
6140 + _ASM_EXTABLE(2b, 3b)
6141 +#endif
6142 + "4: subu %0, %1, %3 \n"
6143 +#ifdef CONFIG_PAX_REFCOUNT
6144 + "5: \n"
6145 +#endif
6146 + " .set mips0 \n"
6147 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6148 + : "Ir" (i), "m" (v->counter)
6149 + : "memory");
6150 + } else if (kernel_uses_llsc) {
6151 + __asm__ __volatile__(
6152 + " .set mips3 \n"
6153 + "1: ll %1, %2 # atomic_sub_return \n"
6154 +#ifdef CONFIG_PAX_REFCOUNT
6155 + "2: sub %0, %1, %3 \n"
6156 +#else
6157 + " subu %0, %1, %3 \n"
6158 +#endif
6159 + " sc %0, %2 \n"
6160 + " bnez %0, 4f \n"
6161 + " b 1b \n"
6162 +#ifdef CONFIG_PAX_REFCOUNT
6163 + " .set noreorder \n"
6164 + "3: b 5f \n"
6165 + " move %0, %1 \n"
6166 + " .set reorder \n"
6167 + _ASM_EXTABLE(2b, 3b)
6168 +#endif
6169 + "4: subu %0, %1, %3 \n"
6170 +#ifdef CONFIG_PAX_REFCOUNT
6171 + "5: \n"
6172 +#endif
6173 + " .set mips0 \n"
6174 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6175 + : "Ir" (i));
6176 + } else {
6177 + unsigned long flags;
6178 +
6179 + raw_local_irq_save(flags);
6180 + __asm__ __volatile__(
6181 + " lw %0, %1 \n"
6182 +#ifdef CONFIG_PAX_REFCOUNT
6183 + /* Exception on overflow. */
6184 + "1: sub %0, %2 \n"
6185 +#else
6186 + " subu %0, %2 \n"
6187 +#endif
6188 + " sw %0, %1 \n"
6189 +#ifdef CONFIG_PAX_REFCOUNT
6190 + /* Note: Dest reg is not modified on overflow */
6191 + "2: \n"
6192 + _ASM_EXTABLE(1b, 2b)
6193 +#endif
6194 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6195 + raw_local_irq_restore(flags);
6196 + }
6197 +
6198 + smp_llsc_mb();
6199 +
6200 + return result;
6201 +}
6202 +static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
6203 {
6204 int result;
6205
6206 @@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
6207 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6208 * The function returns the old value of @v minus @i.
6209 */
6210 -static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
6211 +static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
6212 {
6213 int result;
6214
6215 @@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
6216 return result;
6217 }
6218
6219 -#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
6220 -#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
6221 +static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
6222 +{
6223 + return cmpxchg(&v->counter, old, new);
6224 +}
6225 +
6226 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
6227 + int new)
6228 +{
6229 + return cmpxchg(&(v->counter), old, new);
6230 +}
6231 +
6232 +static inline int atomic_xchg(atomic_t *v, int new)
6233 +{
6234 + return xchg(&v->counter, new);
6235 +}
6236 +
6237 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
6238 +{
6239 + return xchg(&(v->counter), new);
6240 +}
6241
6242 /**
6243 * __atomic_add_unless - add unless the number is a given value
6244 @@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6245
6246 #define atomic_dec_return(v) atomic_sub_return(1, (v))
6247 #define atomic_inc_return(v) atomic_add_return(1, (v))
6248 +static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
6249 +{
6250 + return atomic_add_return_unchecked(1, v);
6251 +}
6252
6253 /*
6254 * atomic_sub_and_test - subtract value from variable and test result
6255 @@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6256 * other cases.
6257 */
6258 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
6259 +static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
6260 +{
6261 + return atomic_add_return_unchecked(1, v) == 0;
6262 +}
6263
6264 /*
6265 * atomic_dec_and_test - decrement by 1 and test
6266 @@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6267 * Atomically increments @v by 1.
6268 */
6269 #define atomic_inc(v) atomic_add(1, (v))
6270 +static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
6271 +{
6272 + atomic_add_unchecked(1, v);
6273 +}
6274
6275 /*
6276 * atomic_dec - decrement and test
6277 @@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6278 * Atomically decrements @v by 1.
6279 */
6280 #define atomic_dec(v) atomic_sub(1, (v))
6281 +static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
6282 +{
6283 + atomic_sub_unchecked(1, v);
6284 +}
6285
6286 /*
6287 * atomic_add_negative - add and test if negative
6288 @@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6289 * @v: pointer of type atomic64_t
6290 *
6291 */
6292 -#define atomic64_read(v) (*(volatile long *)&(v)->counter)
6293 +static inline long atomic64_read(const atomic64_t *v)
6294 +{
6295 + return (*(volatile const long *) &v->counter);
6296 +}
6297 +
6298 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6299 +{
6300 + return (*(volatile const long *) &v->counter);
6301 +}
6302
6303 /*
6304 * atomic64_set - set atomic variable
6305 * @v: pointer of type atomic64_t
6306 * @i: required value
6307 */
6308 -#define atomic64_set(v, i) ((v)->counter = (i))
6309 +static inline void atomic64_set(atomic64_t *v, long i)
6310 +{
6311 + v->counter = i;
6312 +}
6313 +
6314 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6315 +{
6316 + v->counter = i;
6317 +}
6318
6319 /*
6320 * atomic64_add - add integer to atomic variable
6321 @@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6322 *
6323 * Atomically adds @i to @v.
6324 */
6325 -static __inline__ void atomic64_add(long i, atomic64_t * v)
6326 +static __inline__ void atomic64_add(long i, atomic64_t *v)
6327 +{
6328 + long temp;
6329 +
6330 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6331 + __asm__ __volatile__(
6332 + " .set mips3 \n"
6333 + "1: lld %0, %1 # atomic64_add \n"
6334 +#ifdef CONFIG_PAX_REFCOUNT
6335 + /* Exception on overflow. */
6336 + "2: dadd %0, %2 \n"
6337 +#else
6338 + " daddu %0, %2 \n"
6339 +#endif
6340 + " scd %0, %1 \n"
6341 + " beqzl %0, 1b \n"
6342 +#ifdef CONFIG_PAX_REFCOUNT
6343 + "3: \n"
6344 + _ASM_EXTABLE(2b, 3b)
6345 +#endif
6346 + " .set mips0 \n"
6347 + : "=&r" (temp), "+m" (v->counter)
6348 + : "Ir" (i));
6349 + } else if (kernel_uses_llsc) {
6350 + __asm__ __volatile__(
6351 + " .set mips3 \n"
6352 + "1: lld %0, %1 # atomic64_add \n"
6353 +#ifdef CONFIG_PAX_REFCOUNT
6354 + /* Exception on overflow. */
6355 + "2: dadd %0, %2 \n"
6356 +#else
6357 + " daddu %0, %2 \n"
6358 +#endif
6359 + " scd %0, %1 \n"
6360 + " beqz %0, 1b \n"
6361 +#ifdef CONFIG_PAX_REFCOUNT
6362 + "3: \n"
6363 + _ASM_EXTABLE(2b, 3b)
6364 +#endif
6365 + " .set mips0 \n"
6366 + : "=&r" (temp), "+m" (v->counter)
6367 + : "Ir" (i));
6368 + } else {
6369 + unsigned long flags;
6370 +
6371 + raw_local_irq_save(flags);
6372 + __asm__ __volatile__(
6373 +#ifdef CONFIG_PAX_REFCOUNT
6374 + /* Exception on overflow. */
6375 + "1: dadd %0, %1 \n"
6376 + "2: \n"
6377 + _ASM_EXTABLE(1b, 2b)
6378 +#else
6379 + " daddu %0, %1 \n"
6380 +#endif
6381 + : "+r" (v->counter) : "Ir" (i));
6382 + raw_local_irq_restore(flags);
6383 + }
6384 +}
6385 +static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
6386 {
6387 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6388 long temp;
6389 @@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
6390 *
6391 * Atomically subtracts @i from @v.
6392 */
6393 -static __inline__ void atomic64_sub(long i, atomic64_t * v)
6394 +static __inline__ void atomic64_sub(long i, atomic64_t *v)
6395 +{
6396 + long temp;
6397 +
6398 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6399 + __asm__ __volatile__(
6400 + " .set mips3 \n"
6401 + "1: lld %0, %1 # atomic64_sub \n"
6402 +#ifdef CONFIG_PAX_REFCOUNT
6403 + /* Exception on overflow. */
6404 + "2: dsub %0, %2 \n"
6405 +#else
6406 + " dsubu %0, %2 \n"
6407 +#endif
6408 + " scd %0, %1 \n"
6409 + " beqzl %0, 1b \n"
6410 +#ifdef CONFIG_PAX_REFCOUNT
6411 + "3: \n"
6412 + _ASM_EXTABLE(2b, 3b)
6413 +#endif
6414 + " .set mips0 \n"
6415 + : "=&r" (temp), "+m" (v->counter)
6416 + : "Ir" (i));
6417 + } else if (kernel_uses_llsc) {
6418 + __asm__ __volatile__(
6419 + " .set mips3 \n"
6420 + "1: lld %0, %1 # atomic64_sub \n"
6421 +#ifdef CONFIG_PAX_REFCOUNT
6422 + /* Exception on overflow. */
6423 + "2: dsub %0, %2 \n"
6424 +#else
6425 + " dsubu %0, %2 \n"
6426 +#endif
6427 + " scd %0, %1 \n"
6428 + " beqz %0, 1b \n"
6429 +#ifdef CONFIG_PAX_REFCOUNT
6430 + "3: \n"
6431 + _ASM_EXTABLE(2b, 3b)
6432 +#endif
6433 + " .set mips0 \n"
6434 + : "=&r" (temp), "+m" (v->counter)
6435 + : "Ir" (i));
6436 + } else {
6437 + unsigned long flags;
6438 +
6439 + raw_local_irq_save(flags);
6440 + __asm__ __volatile__(
6441 +#ifdef CONFIG_PAX_REFCOUNT
6442 + /* Exception on overflow. */
6443 + "1: dsub %0, %1 \n"
6444 + "2: \n"
6445 + _ASM_EXTABLE(1b, 2b)
6446 +#else
6447 + " dsubu %0, %1 \n"
6448 +#endif
6449 + : "+r" (v->counter) : "Ir" (i));
6450 + raw_local_irq_restore(flags);
6451 + }
6452 +}
6453 +
6454 +static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6455 {
6456 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6457 long temp;
6458 @@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6459 /*
6460 * Same as above, but return the result value
6461 */
6462 -static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6463 +static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6464 +{
6465 + long result;
6466 + long temp;
6467 +
6468 + smp_mb__before_llsc();
6469 +
6470 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6471 + __asm__ __volatile__(
6472 + " .set mips3 \n"
6473 + "1: lld %1, %2 # atomic64_add_return \n"
6474 +#ifdef CONFIG_PAX_REFCOUNT
6475 + "2: dadd %0, %1, %3 \n"
6476 +#else
6477 + " daddu %0, %1, %3 \n"
6478 +#endif
6479 + " scd %0, %2 \n"
6480 + " beqzl %0, 1b \n"
6481 +#ifdef CONFIG_PAX_REFCOUNT
6482 + " b 4f \n"
6483 + " .set noreorder \n"
6484 + "3: b 5f \n"
6485 + " move %0, %1 \n"
6486 + " .set reorder \n"
6487 + _ASM_EXTABLE(2b, 3b)
6488 +#endif
6489 + "4: daddu %0, %1, %3 \n"
6490 +#ifdef CONFIG_PAX_REFCOUNT
6491 + "5: \n"
6492 +#endif
6493 + " .set mips0 \n"
6494 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6495 + : "Ir" (i));
6496 + } else if (kernel_uses_llsc) {
6497 + __asm__ __volatile__(
6498 + " .set mips3 \n"
6499 + "1: lld %1, %2 # atomic64_add_return \n"
6500 +#ifdef CONFIG_PAX_REFCOUNT
6501 + "2: dadd %0, %1, %3 \n"
6502 +#else
6503 + " daddu %0, %1, %3 \n"
6504 +#endif
6505 + " scd %0, %2 \n"
6506 + " bnez %0, 4f \n"
6507 + " b 1b \n"
6508 +#ifdef CONFIG_PAX_REFCOUNT
6509 + " .set noreorder \n"
6510 + "3: b 5f \n"
6511 + " move %0, %1 \n"
6512 + " .set reorder \n"
6513 + _ASM_EXTABLE(2b, 3b)
6514 +#endif
6515 + "4: daddu %0, %1, %3 \n"
6516 +#ifdef CONFIG_PAX_REFCOUNT
6517 + "5: \n"
6518 +#endif
6519 + " .set mips0 \n"
6520 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6521 + : "Ir" (i), "m" (v->counter)
6522 + : "memory");
6523 + } else {
6524 + unsigned long flags;
6525 +
6526 + raw_local_irq_save(flags);
6527 + __asm__ __volatile__(
6528 + " ld %0, %1 \n"
6529 +#ifdef CONFIG_PAX_REFCOUNT
6530 + /* Exception on overflow. */
6531 + "1: dadd %0, %2 \n"
6532 +#else
6533 + " daddu %0, %2 \n"
6534 +#endif
6535 + " sd %0, %1 \n"
6536 +#ifdef CONFIG_PAX_REFCOUNT
6537 + /* Note: Dest reg is not modified on overflow */
6538 + "2: \n"
6539 + _ASM_EXTABLE(1b, 2b)
6540 +#endif
6541 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6542 + raw_local_irq_restore(flags);
6543 + }
6544 +
6545 + smp_llsc_mb();
6546 +
6547 + return result;
6548 +}
6549 +static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6550 {
6551 long result;
6552
6553 @@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6554 return result;
6555 }
6556
6557 -static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6558 +static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6559 +{
6560 + long result;
6561 + long temp;
6562 +
6563 + smp_mb__before_llsc();
6564 +
6565 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6566 + long temp;
6567 +
6568 + __asm__ __volatile__(
6569 + " .set mips3 \n"
6570 + "1: lld %1, %2 # atomic64_sub_return \n"
6571 +#ifdef CONFIG_PAX_REFCOUNT
6572 + "2: dsub %0, %1, %3 \n"
6573 +#else
6574 + " dsubu %0, %1, %3 \n"
6575 +#endif
6576 + " scd %0, %2 \n"
6577 + " beqzl %0, 1b \n"
6578 +#ifdef CONFIG_PAX_REFCOUNT
6579 + " b 4f \n"
6580 + " .set noreorder \n"
6581 + "3: b 5f \n"
6582 + " move %0, %1 \n"
6583 + " .set reorder \n"
6584 + _ASM_EXTABLE(2b, 3b)
6585 +#endif
6586 + "4: dsubu %0, %1, %3 \n"
6587 +#ifdef CONFIG_PAX_REFCOUNT
6588 + "5: \n"
6589 +#endif
6590 + " .set mips0 \n"
6591 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6592 + : "Ir" (i), "m" (v->counter)
6593 + : "memory");
6594 + } else if (kernel_uses_llsc) {
6595 + __asm__ __volatile__(
6596 + " .set mips3 \n"
6597 + "1: lld %1, %2 # atomic64_sub_return \n"
6598 +#ifdef CONFIG_PAX_REFCOUNT
6599 + "2: dsub %0, %1, %3 \n"
6600 +#else
6601 + " dsubu %0, %1, %3 \n"
6602 +#endif
6603 + " scd %0, %2 \n"
6604 + " bnez %0, 4f \n"
6605 + " b 1b \n"
6606 +#ifdef CONFIG_PAX_REFCOUNT
6607 + " .set noreorder \n"
6608 + "3: b 5f \n"
6609 + " move %0, %1 \n"
6610 + " .set reorder \n"
6611 + _ASM_EXTABLE(2b, 3b)
6612 +#endif
6613 + "4: dsubu %0, %1, %3 \n"
6614 +#ifdef CONFIG_PAX_REFCOUNT
6615 + "5: \n"
6616 +#endif
6617 + " .set mips0 \n"
6618 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6619 + : "Ir" (i), "m" (v->counter)
6620 + : "memory");
6621 + } else {
6622 + unsigned long flags;
6623 +
6624 + raw_local_irq_save(flags);
6625 + __asm__ __volatile__(
6626 + " ld %0, %1 \n"
6627 +#ifdef CONFIG_PAX_REFCOUNT
6628 + /* Exception on overflow. */
6629 + "1: dsub %0, %2 \n"
6630 +#else
6631 + " dsubu %0, %2 \n"
6632 +#endif
6633 + " sd %0, %1 \n"
6634 +#ifdef CONFIG_PAX_REFCOUNT
6635 + /* Note: Dest reg is not modified on overflow */
6636 + "2: \n"
6637 + _ASM_EXTABLE(1b, 2b)
6638 +#endif
6639 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6640 + raw_local_irq_restore(flags);
6641 + }
6642 +
6643 + smp_llsc_mb();
6644 +
6645 + return result;
6646 +}
6647 +
6648 +static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6649 {
6650 long result;
6651
6652 @@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6653 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6654 * The function returns the old value of @v minus @i.
6655 */
6656 -static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6657 +static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6658 {
6659 long result;
6660
6661 @@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6662 return result;
6663 }
6664
6665 -#define atomic64_cmpxchg(v, o, n) \
6666 - ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6667 -#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6668 +static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6669 +{
6670 + return cmpxchg(&v->counter, old, new);
6671 +}
6672 +
6673 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6674 + long new)
6675 +{
6676 + return cmpxchg(&(v->counter), old, new);
6677 +}
6678 +
6679 +static inline long atomic64_xchg(atomic64_t *v, long new)
6680 +{
6681 + return xchg(&v->counter, new);
6682 +}
6683 +
6684 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6685 +{
6686 + return xchg(&(v->counter), new);
6687 +}
6688
6689 /**
6690 * atomic64_add_unless - add unless the number is a given value
6691 @@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6692
6693 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6694 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6695 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6696
6697 /*
6698 * atomic64_sub_and_test - subtract value from variable and test result
6699 @@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6700 * other cases.
6701 */
6702 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6703 +#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6704
6705 /*
6706 * atomic64_dec_and_test - decrement by 1 and test
6707 @@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6708 * Atomically increments @v by 1.
6709 */
6710 #define atomic64_inc(v) atomic64_add(1, (v))
6711 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6712
6713 /*
6714 * atomic64_dec - decrement and test
6715 @@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6716 * Atomically decrements @v by 1.
6717 */
6718 #define atomic64_dec(v) atomic64_sub(1, (v))
6719 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6720
6721 /*
6722 * atomic64_add_negative - add and test if negative
6723 diff --git a/arch/mips/include/asm/barrier.h b/arch/mips/include/asm/barrier.h
6724 index d0101dd..266982c 100644
6725 --- a/arch/mips/include/asm/barrier.h
6726 +++ b/arch/mips/include/asm/barrier.h
6727 @@ -184,7 +184,7 @@
6728 do { \
6729 compiletime_assert_atomic_type(*p); \
6730 smp_mb(); \
6731 - ACCESS_ONCE(*p) = (v); \
6732 + ACCESS_ONCE_RW(*p) = (v); \
6733 } while (0)
6734
6735 #define smp_load_acquire(p) \
6736 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6737 index b4db69f..8f3b093 100644
6738 --- a/arch/mips/include/asm/cache.h
6739 +++ b/arch/mips/include/asm/cache.h
6740 @@ -9,10 +9,11 @@
6741 #ifndef _ASM_CACHE_H
6742 #define _ASM_CACHE_H
6743
6744 +#include <linux/const.h>
6745 #include <kmalloc.h>
6746
6747 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6748 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6749 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6750
6751 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6752 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6753 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6754 index 1d38fe0..9beabc9 100644
6755 --- a/arch/mips/include/asm/elf.h
6756 +++ b/arch/mips/include/asm/elf.h
6757 @@ -381,13 +381,16 @@ extern const char *__elf_platform;
6758 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6759 #endif
6760
6761 +#ifdef CONFIG_PAX_ASLR
6762 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6763 +
6764 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6765 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6766 +#endif
6767 +
6768 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6769 struct linux_binprm;
6770 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6771 int uses_interp);
6772
6773 -struct mm_struct;
6774 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6775 -#define arch_randomize_brk arch_randomize_brk
6776 -
6777 #endif /* _ASM_ELF_H */
6778 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6779 index c1f6afa..38cc6e9 100644
6780 --- a/arch/mips/include/asm/exec.h
6781 +++ b/arch/mips/include/asm/exec.h
6782 @@ -12,6 +12,6 @@
6783 #ifndef _ASM_EXEC_H
6784 #define _ASM_EXEC_H
6785
6786 -extern unsigned long arch_align_stack(unsigned long sp);
6787 +#define arch_align_stack(x) ((x) & ~0xfUL)
6788
6789 #endif /* _ASM_EXEC_H */
6790 diff --git a/arch/mips/include/asm/hw_irq.h b/arch/mips/include/asm/hw_irq.h
6791 index 9e8ef59..1139d6b 100644
6792 --- a/arch/mips/include/asm/hw_irq.h
6793 +++ b/arch/mips/include/asm/hw_irq.h
6794 @@ -10,7 +10,7 @@
6795
6796 #include <linux/atomic.h>
6797
6798 -extern atomic_t irq_err_count;
6799 +extern atomic_unchecked_t irq_err_count;
6800
6801 /*
6802 * interrupt-retrigger: NOP for now. This may not be appropriate for all
6803 diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6804 index 46dfc3c..a16b13a 100644
6805 --- a/arch/mips/include/asm/local.h
6806 +++ b/arch/mips/include/asm/local.h
6807 @@ -12,15 +12,25 @@ typedef struct
6808 atomic_long_t a;
6809 } local_t;
6810
6811 +typedef struct {
6812 + atomic_long_unchecked_t a;
6813 +} local_unchecked_t;
6814 +
6815 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6816
6817 #define local_read(l) atomic_long_read(&(l)->a)
6818 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6819 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6820 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6821
6822 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6823 +#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6824 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6825 +#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6826 #define local_inc(l) atomic_long_inc(&(l)->a)
6827 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6828 #define local_dec(l) atomic_long_dec(&(l)->a)
6829 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6830
6831 /*
6832 * Same as above, but return the result value
6833 @@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6834 return result;
6835 }
6836
6837 +static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6838 +{
6839 + unsigned long result;
6840 +
6841 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6842 + unsigned long temp;
6843 +
6844 + __asm__ __volatile__(
6845 + " .set mips3 \n"
6846 + "1:" __LL "%1, %2 # local_add_return \n"
6847 + " addu %0, %1, %3 \n"
6848 + __SC "%0, %2 \n"
6849 + " beqzl %0, 1b \n"
6850 + " addu %0, %1, %3 \n"
6851 + " .set mips0 \n"
6852 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6853 + : "Ir" (i), "m" (l->a.counter)
6854 + : "memory");
6855 + } else if (kernel_uses_llsc) {
6856 + unsigned long temp;
6857 +
6858 + __asm__ __volatile__(
6859 + " .set mips3 \n"
6860 + "1:" __LL "%1, %2 # local_add_return \n"
6861 + " addu %0, %1, %3 \n"
6862 + __SC "%0, %2 \n"
6863 + " beqz %0, 1b \n"
6864 + " addu %0, %1, %3 \n"
6865 + " .set mips0 \n"
6866 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6867 + : "Ir" (i), "m" (l->a.counter)
6868 + : "memory");
6869 + } else {
6870 + unsigned long flags;
6871 +
6872 + local_irq_save(flags);
6873 + result = l->a.counter;
6874 + result += i;
6875 + l->a.counter = result;
6876 + local_irq_restore(flags);
6877 + }
6878 +
6879 + return result;
6880 +}
6881 +
6882 static __inline__ long local_sub_return(long i, local_t * l)
6883 {
6884 unsigned long result;
6885 @@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6886
6887 #define local_cmpxchg(l, o, n) \
6888 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6889 +#define local_cmpxchg_unchecked(l, o, n) \
6890 + ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6891 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6892
6893 /**
6894 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6895 index 3be8180..c4798d5 100644
6896 --- a/arch/mips/include/asm/page.h
6897 +++ b/arch/mips/include/asm/page.h
6898 @@ -120,7 +120,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6899 #ifdef CONFIG_CPU_MIPS32
6900 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6901 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6902 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6903 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6904 #else
6905 typedef struct { unsigned long long pte; } pte_t;
6906 #define pte_val(x) ((x).pte)
6907 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6908 index b336037..5b874cc 100644
6909 --- a/arch/mips/include/asm/pgalloc.h
6910 +++ b/arch/mips/include/asm/pgalloc.h
6911 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6912 {
6913 set_pud(pud, __pud((unsigned long)pmd));
6914 }
6915 +
6916 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6917 +{
6918 + pud_populate(mm, pud, pmd);
6919 +}
6920 #endif
6921
6922 /*
6923 diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
6924 index df49a30..c0d3dd6 100644
6925 --- a/arch/mips/include/asm/pgtable.h
6926 +++ b/arch/mips/include/asm/pgtable.h
6927 @@ -20,6 +20,9 @@
6928 #include <asm/io.h>
6929 #include <asm/pgtable-bits.h>
6930
6931 +#define ktla_ktva(addr) (addr)
6932 +#define ktva_ktla(addr) (addr)
6933 +
6934 struct mm_struct;
6935 struct vm_area_struct;
6936
6937 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6938 index 7de8658..c109224 100644
6939 --- a/arch/mips/include/asm/thread_info.h
6940 +++ b/arch/mips/include/asm/thread_info.h
6941 @@ -105,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
6942 #define TIF_SECCOMP 4 /* secure computing */
6943 #define TIF_NOTIFY_RESUME 5 /* callback before returning to user */
6944 #define TIF_RESTORE_SIGMASK 9 /* restore signal mask in do_signal() */
6945 +/* li takes a 32bit immediate */
6946 +#define TIF_GRSEC_SETXID 10 /* update credentials on syscall entry/exit */
6947 +
6948 #define TIF_USEDFPU 16 /* FPU was used by this task this quantum (SMP) */
6949 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
6950 #define TIF_NOHZ 19 /* in adaptive nohz mode */
6951 @@ -138,14 +141,16 @@ static inline struct thread_info *current_thread_info(void)
6952 #define _TIF_USEDMSA (1<<TIF_USEDMSA)
6953 #define _TIF_MSA_CTX_LIVE (1<<TIF_MSA_CTX_LIVE)
6954 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6955 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6956
6957 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6958 _TIF_SYSCALL_AUDIT | \
6959 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
6960 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \
6961 + _TIF_GRSEC_SETXID)
6962
6963 /* work to do in syscall_trace_leave() */
6964 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6965 - _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6966 + _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6967
6968 /* work to do on interrupt/exception return */
6969 #define _TIF_WORK_MASK \
6970 @@ -153,7 +158,7 @@ static inline struct thread_info *current_thread_info(void)
6971 /* work to do on any return to u-space */
6972 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6973 _TIF_WORK_SYSCALL_EXIT | \
6974 - _TIF_SYSCALL_TRACEPOINT)
6975 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6976
6977 /*
6978 * We stash processor id into a COP0 register to retrieve it fast
6979 diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
6980 index a109510..0a764f7 100644
6981 --- a/arch/mips/include/asm/uaccess.h
6982 +++ b/arch/mips/include/asm/uaccess.h
6983 @@ -130,6 +130,7 @@ extern u64 __ua_limit;
6984 __ok == 0; \
6985 })
6986
6987 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
6988 #define access_ok(type, addr, size) \
6989 likely(__access_ok((addr), (size), __access_mask))
6990
6991 @@ -301,7 +302,8 @@ do { \
6992 __get_kernel_common((x), size, __gu_ptr); \
6993 else \
6994 __get_user_common((x), size, __gu_ptr); \
6995 - } \
6996 + } else \
6997 + (x) = 0; \
6998 \
6999 __gu_err; \
7000 })
7001 @@ -316,6 +318,7 @@ do { \
7002 " .insn \n" \
7003 " .section .fixup,\"ax\" \n" \
7004 "3: li %0, %4 \n" \
7005 + " move %1, $0 \n" \
7006 " j 2b \n" \
7007 " .previous \n" \
7008 " .section __ex_table,\"a\" \n" \
7009 @@ -630,6 +633,7 @@ do { \
7010 " .insn \n" \
7011 " .section .fixup,\"ax\" \n" \
7012 "3: li %0, %4 \n" \
7013 + " move %1, $0 \n" \
7014 " j 2b \n" \
7015 " .previous \n" \
7016 " .section __ex_table,\"a\" \n" \
7017 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
7018 index 1188e00..41cf144 100644
7019 --- a/arch/mips/kernel/binfmt_elfn32.c
7020 +++ b/arch/mips/kernel/binfmt_elfn32.c
7021 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
7022 #undef ELF_ET_DYN_BASE
7023 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
7024
7025 +#ifdef CONFIG_PAX_ASLR
7026 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
7027 +
7028 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7029 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7030 +#endif
7031 +
7032 #include <asm/processor.h>
7033 #include <linux/module.h>
7034 #include <linux/elfcore.h>
7035 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
7036 index 9287678..f870e47 100644
7037 --- a/arch/mips/kernel/binfmt_elfo32.c
7038 +++ b/arch/mips/kernel/binfmt_elfo32.c
7039 @@ -70,6 +70,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
7040 #undef ELF_ET_DYN_BASE
7041 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
7042
7043 +#ifdef CONFIG_PAX_ASLR
7044 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
7045 +
7046 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7047 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7048 +#endif
7049 +
7050 #include <asm/processor.h>
7051
7052 #include <linux/module.h>
7053 diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
7054 index 50b3648..c2f3cec 100644
7055 --- a/arch/mips/kernel/i8259.c
7056 +++ b/arch/mips/kernel/i8259.c
7057 @@ -201,7 +201,7 @@ spurious_8259A_irq:
7058 printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
7059 spurious_irq_mask |= irqmask;
7060 }
7061 - atomic_inc(&irq_err_count);
7062 + atomic_inc_unchecked(&irq_err_count);
7063 /*
7064 * Theoretically we do not have to handle this IRQ,
7065 * but in Linux this does not cause problems and is
7066 diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
7067 index 44a1f79..2bd6aa3 100644
7068 --- a/arch/mips/kernel/irq-gt641xx.c
7069 +++ b/arch/mips/kernel/irq-gt641xx.c
7070 @@ -110,7 +110,7 @@ void gt641xx_irq_dispatch(void)
7071 }
7072 }
7073
7074 - atomic_inc(&irq_err_count);
7075 + atomic_inc_unchecked(&irq_err_count);
7076 }
7077
7078 void __init gt641xx_irq_init(void)
7079 diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
7080 index d2bfbc2..a8eacd2 100644
7081 --- a/arch/mips/kernel/irq.c
7082 +++ b/arch/mips/kernel/irq.c
7083 @@ -76,17 +76,17 @@ void ack_bad_irq(unsigned int irq)
7084 printk("unexpected IRQ # %d\n", irq);
7085 }
7086
7087 -atomic_t irq_err_count;
7088 +atomic_unchecked_t irq_err_count;
7089
7090 int arch_show_interrupts(struct seq_file *p, int prec)
7091 {
7092 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
7093 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
7094 return 0;
7095 }
7096
7097 asmlinkage void spurious_interrupt(void)
7098 {
7099 - atomic_inc(&irq_err_count);
7100 + atomic_inc_unchecked(&irq_err_count);
7101 }
7102
7103 void __init init_IRQ(void)
7104 @@ -109,7 +109,10 @@ void __init init_IRQ(void)
7105 #endif
7106 }
7107
7108 +
7109 #ifdef DEBUG_STACKOVERFLOW
7110 +extern void gr_handle_kernel_exploit(void);
7111 +
7112 static inline void check_stack_overflow(void)
7113 {
7114 unsigned long sp;
7115 @@ -125,6 +128,7 @@ static inline void check_stack_overflow(void)
7116 printk("do_IRQ: stack overflow: %ld\n",
7117 sp - sizeof(struct thread_info));
7118 dump_stack();
7119 + gr_handle_kernel_exploit();
7120 }
7121 }
7122 #else
7123 diff --git a/arch/mips/kernel/pm-cps.c b/arch/mips/kernel/pm-cps.c
7124 index 0614717..002fa43 100644
7125 --- a/arch/mips/kernel/pm-cps.c
7126 +++ b/arch/mips/kernel/pm-cps.c
7127 @@ -172,7 +172,7 @@ int cps_pm_enter_state(enum cps_pm_state state)
7128 nc_core_ready_count = nc_addr;
7129
7130 /* Ensure ready_count is zero-initialised before the assembly runs */
7131 - ACCESS_ONCE(*nc_core_ready_count) = 0;
7132 + ACCESS_ONCE_RW(*nc_core_ready_count) = 0;
7133 coupled_barrier(&per_cpu(pm_barrier, core), online);
7134
7135 /* Run the generated entry code */
7136 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
7137 index 636b074..8fbb91f 100644
7138 --- a/arch/mips/kernel/process.c
7139 +++ b/arch/mips/kernel/process.c
7140 @@ -520,15 +520,3 @@ unsigned long get_wchan(struct task_struct *task)
7141 out:
7142 return pc;
7143 }
7144 -
7145 -/*
7146 - * Don't forget that the stack pointer must be aligned on a 8 bytes
7147 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
7148 - */
7149 -unsigned long arch_align_stack(unsigned long sp)
7150 -{
7151 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7152 - sp -= get_random_int() & ~PAGE_MASK;
7153 -
7154 - return sp & ALMASK;
7155 -}
7156 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
7157 index 645b3c4..909c75a 100644
7158 --- a/arch/mips/kernel/ptrace.c
7159 +++ b/arch/mips/kernel/ptrace.c
7160 @@ -761,6 +761,10 @@ long arch_ptrace(struct task_struct *child, long request,
7161 return ret;
7162 }
7163
7164 +#ifdef CONFIG_GRKERNSEC_SETXID
7165 +extern void gr_delayed_cred_worker(void);
7166 +#endif
7167 +
7168 /*
7169 * Notification of system call entry/exit
7170 * - triggered by current->work.syscall_trace
7171 @@ -777,6 +781,11 @@ asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall)
7172 tracehook_report_syscall_entry(regs))
7173 ret = -1;
7174
7175 +#ifdef CONFIG_GRKERNSEC_SETXID
7176 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
7177 + gr_delayed_cred_worker();
7178 +#endif
7179 +
7180 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
7181 trace_sys_enter(regs, regs->regs[2]);
7182
7183 diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
7184 index 07fc524..b9d7f28 100644
7185 --- a/arch/mips/kernel/reset.c
7186 +++ b/arch/mips/kernel/reset.c
7187 @@ -13,6 +13,7 @@
7188 #include <linux/reboot.h>
7189
7190 #include <asm/reboot.h>
7191 +#include <asm/bug.h>
7192
7193 /*
7194 * Urgs ... Too many MIPS machines to handle this in a generic way.
7195 @@ -29,16 +30,19 @@ void machine_restart(char *command)
7196 {
7197 if (_machine_restart)
7198 _machine_restart(command);
7199 + BUG();
7200 }
7201
7202 void machine_halt(void)
7203 {
7204 if (_machine_halt)
7205 _machine_halt();
7206 + BUG();
7207 }
7208
7209 void machine_power_off(void)
7210 {
7211 if (pm_power_off)
7212 pm_power_off();
7213 + BUG();
7214 }
7215 diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
7216 index 2242bdd..b284048 100644
7217 --- a/arch/mips/kernel/sync-r4k.c
7218 +++ b/arch/mips/kernel/sync-r4k.c
7219 @@ -18,8 +18,8 @@
7220 #include <asm/mipsregs.h>
7221
7222 static atomic_t count_start_flag = ATOMIC_INIT(0);
7223 -static atomic_t count_count_start = ATOMIC_INIT(0);
7224 -static atomic_t count_count_stop = ATOMIC_INIT(0);
7225 +static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
7226 +static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
7227 static atomic_t count_reference = ATOMIC_INIT(0);
7228
7229 #define COUNTON 100
7230 @@ -58,13 +58,13 @@ void synchronise_count_master(int cpu)
7231
7232 for (i = 0; i < NR_LOOPS; i++) {
7233 /* slaves loop on '!= 2' */
7234 - while (atomic_read(&count_count_start) != 1)
7235 + while (atomic_read_unchecked(&count_count_start) != 1)
7236 mb();
7237 - atomic_set(&count_count_stop, 0);
7238 + atomic_set_unchecked(&count_count_stop, 0);
7239 smp_wmb();
7240
7241 /* this lets the slaves write their count register */
7242 - atomic_inc(&count_count_start);
7243 + atomic_inc_unchecked(&count_count_start);
7244
7245 /*
7246 * Everyone initialises count in the last loop:
7247 @@ -75,11 +75,11 @@ void synchronise_count_master(int cpu)
7248 /*
7249 * Wait for all slaves to leave the synchronization point:
7250 */
7251 - while (atomic_read(&count_count_stop) != 1)
7252 + while (atomic_read_unchecked(&count_count_stop) != 1)
7253 mb();
7254 - atomic_set(&count_count_start, 0);
7255 + atomic_set_unchecked(&count_count_start, 0);
7256 smp_wmb();
7257 - atomic_inc(&count_count_stop);
7258 + atomic_inc_unchecked(&count_count_stop);
7259 }
7260 /* Arrange for an interrupt in a short while */
7261 write_c0_compare(read_c0_count() + COUNTON);
7262 @@ -112,8 +112,8 @@ void synchronise_count_slave(int cpu)
7263 initcount = atomic_read(&count_reference);
7264
7265 for (i = 0; i < NR_LOOPS; i++) {
7266 - atomic_inc(&count_count_start);
7267 - while (atomic_read(&count_count_start) != 2)
7268 + atomic_inc_unchecked(&count_count_start);
7269 + while (atomic_read_unchecked(&count_count_start) != 2)
7270 mb();
7271
7272 /*
7273 @@ -122,8 +122,8 @@ void synchronise_count_slave(int cpu)
7274 if (i == NR_LOOPS-1)
7275 write_c0_count(initcount);
7276
7277 - atomic_inc(&count_count_stop);
7278 - while (atomic_read(&count_count_stop) != 2)
7279 + atomic_inc_unchecked(&count_count_stop);
7280 + while (atomic_read_unchecked(&count_count_stop) != 2)
7281 mb();
7282 }
7283 /* Arrange for an interrupt in a short while */
7284 diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
7285 index 22b19c2..c5cc8c4 100644
7286 --- a/arch/mips/kernel/traps.c
7287 +++ b/arch/mips/kernel/traps.c
7288 @@ -688,7 +688,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
7289 siginfo_t info;
7290
7291 prev_state = exception_enter();
7292 - die_if_kernel("Integer overflow", regs);
7293 + if (unlikely(!user_mode(regs))) {
7294 +
7295 +#ifdef CONFIG_PAX_REFCOUNT
7296 + if (fixup_exception(regs)) {
7297 + pax_report_refcount_overflow(regs);
7298 + exception_exit(prev_state);
7299 + return;
7300 + }
7301 +#endif
7302 +
7303 + die("Integer overflow", regs);
7304 + }
7305
7306 info.si_code = FPE_INTOVF;
7307 info.si_signo = SIGFPE;
7308 diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c
7309 index cd71141..e02c4df 100644
7310 --- a/arch/mips/kvm/mips.c
7311 +++ b/arch/mips/kvm/mips.c
7312 @@ -839,7 +839,7 @@ long kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
7313 return r;
7314 }
7315
7316 -int kvm_arch_init(void *opaque)
7317 +int kvm_arch_init(const void *opaque)
7318 {
7319 if (kvm_mips_callbacks) {
7320 kvm_err("kvm: module already exists\n");
7321 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
7322 index becc42b..9e43d4b 100644
7323 --- a/arch/mips/mm/fault.c
7324 +++ b/arch/mips/mm/fault.c
7325 @@ -28,6 +28,23 @@
7326 #include <asm/highmem.h> /* For VMALLOC_END */
7327 #include <linux/kdebug.h>
7328
7329 +#ifdef CONFIG_PAX_PAGEEXEC
7330 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7331 +{
7332 + unsigned long i;
7333 +
7334 + printk(KERN_ERR "PAX: bytes at PC: ");
7335 + for (i = 0; i < 5; i++) {
7336 + unsigned int c;
7337 + if (get_user(c, (unsigned int *)pc+i))
7338 + printk(KERN_CONT "???????? ");
7339 + else
7340 + printk(KERN_CONT "%08x ", c);
7341 + }
7342 + printk("\n");
7343 +}
7344 +#endif
7345 +
7346 /*
7347 * This routine handles page faults. It determines the address,
7348 * and the problem, and then passes it off to one of the appropriate
7349 @@ -199,6 +216,14 @@ bad_area:
7350 bad_area_nosemaphore:
7351 /* User mode accesses just cause a SIGSEGV */
7352 if (user_mode(regs)) {
7353 +
7354 +#ifdef CONFIG_PAX_PAGEEXEC
7355 + if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
7356 + pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
7357 + do_group_exit(SIGKILL);
7358 + }
7359 +#endif
7360 +
7361 tsk->thread.cp0_badvaddr = address;
7362 tsk->thread.error_code = write;
7363 #if 0
7364 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
7365 index f1baadd..5472dca 100644
7366 --- a/arch/mips/mm/mmap.c
7367 +++ b/arch/mips/mm/mmap.c
7368 @@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7369 struct vm_area_struct *vma;
7370 unsigned long addr = addr0;
7371 int do_color_align;
7372 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7373 struct vm_unmapped_area_info info;
7374
7375 if (unlikely(len > TASK_SIZE))
7376 @@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7377 do_color_align = 1;
7378
7379 /* requesting a specific address */
7380 +
7381 +#ifdef CONFIG_PAX_RANDMMAP
7382 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
7383 +#endif
7384 +
7385 if (addr) {
7386 if (do_color_align)
7387 addr = COLOUR_ALIGN(addr, pgoff);
7388 @@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7389 addr = PAGE_ALIGN(addr);
7390
7391 vma = find_vma(mm, addr);
7392 - if (TASK_SIZE - len >= addr &&
7393 - (!vma || addr + len <= vma->vm_start))
7394 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7395 return addr;
7396 }
7397
7398 info.length = len;
7399 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
7400 info.align_offset = pgoff << PAGE_SHIFT;
7401 + info.threadstack_offset = offset;
7402
7403 if (dir == DOWN) {
7404 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
7405 @@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7406 {
7407 unsigned long random_factor = 0UL;
7408
7409 +#ifdef CONFIG_PAX_RANDMMAP
7410 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7411 +#endif
7412 +
7413 if (current->flags & PF_RANDOMIZE) {
7414 random_factor = get_random_int();
7415 random_factor = random_factor << PAGE_SHIFT;
7416 @@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7417
7418 if (mmap_is_legacy()) {
7419 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7420 +
7421 +#ifdef CONFIG_PAX_RANDMMAP
7422 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7423 + mm->mmap_base += mm->delta_mmap;
7424 +#endif
7425 +
7426 mm->get_unmapped_area = arch_get_unmapped_area;
7427 } else {
7428 mm->mmap_base = mmap_base(random_factor);
7429 +
7430 +#ifdef CONFIG_PAX_RANDMMAP
7431 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7432 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7433 +#endif
7434 +
7435 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7436 }
7437 }
7438
7439 -static inline unsigned long brk_rnd(void)
7440 -{
7441 - unsigned long rnd = get_random_int();
7442 -
7443 - rnd = rnd << PAGE_SHIFT;
7444 - /* 8MB for 32bit, 256MB for 64bit */
7445 - if (TASK_IS_32BIT_ADDR)
7446 - rnd = rnd & 0x7ffffful;
7447 - else
7448 - rnd = rnd & 0xffffffful;
7449 -
7450 - return rnd;
7451 -}
7452 -
7453 -unsigned long arch_randomize_brk(struct mm_struct *mm)
7454 -{
7455 - unsigned long base = mm->brk;
7456 - unsigned long ret;
7457 -
7458 - ret = PAGE_ALIGN(base + brk_rnd());
7459 -
7460 - if (ret < mm->brk)
7461 - return mm->brk;
7462 -
7463 - return ret;
7464 -}
7465 -
7466 int __virt_addr_valid(const volatile void *kaddr)
7467 {
7468 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
7469 diff --git a/arch/mips/net/bpf_jit.c b/arch/mips/net/bpf_jit.c
7470 index 9f7ecbd..6e370fc 100644
7471 --- a/arch/mips/net/bpf_jit.c
7472 +++ b/arch/mips/net/bpf_jit.c
7473 @@ -1428,5 +1428,6 @@ void bpf_jit_free(struct bpf_prog *fp)
7474 {
7475 if (fp->jited)
7476 module_free(NULL, fp->bpf_func);
7477 - kfree(fp);
7478 +
7479 + bpf_prog_unlock_free(fp);
7480 }
7481 diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
7482 index 59cccd9..f39ac2f 100644
7483 --- a/arch/mips/pci/pci-octeon.c
7484 +++ b/arch/mips/pci/pci-octeon.c
7485 @@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
7486
7487
7488 static struct pci_ops octeon_pci_ops = {
7489 - octeon_read_config,
7490 - octeon_write_config,
7491 + .read = octeon_read_config,
7492 + .write = octeon_write_config,
7493 };
7494
7495 static struct resource octeon_pci_mem_resource = {
7496 diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
7497 index 5e36c33..eb4a17b 100644
7498 --- a/arch/mips/pci/pcie-octeon.c
7499 +++ b/arch/mips/pci/pcie-octeon.c
7500 @@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
7501 }
7502
7503 static struct pci_ops octeon_pcie0_ops = {
7504 - octeon_pcie0_read_config,
7505 - octeon_pcie0_write_config,
7506 + .read = octeon_pcie0_read_config,
7507 + .write = octeon_pcie0_write_config,
7508 };
7509
7510 static struct resource octeon_pcie0_mem_resource = {
7511 @@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
7512 };
7513
7514 static struct pci_ops octeon_pcie1_ops = {
7515 - octeon_pcie1_read_config,
7516 - octeon_pcie1_write_config,
7517 + .read = octeon_pcie1_read_config,
7518 + .write = octeon_pcie1_write_config,
7519 };
7520
7521 static struct resource octeon_pcie1_mem_resource = {
7522 @@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
7523 };
7524
7525 static struct pci_ops octeon_dummy_ops = {
7526 - octeon_dummy_read_config,
7527 - octeon_dummy_write_config,
7528 + .read = octeon_dummy_read_config,
7529 + .write = octeon_dummy_write_config,
7530 };
7531
7532 static struct resource octeon_dummy_mem_resource = {
7533 diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
7534 index a2358b4..7cead4f 100644
7535 --- a/arch/mips/sgi-ip27/ip27-nmi.c
7536 +++ b/arch/mips/sgi-ip27/ip27-nmi.c
7537 @@ -187,9 +187,9 @@ void
7538 cont_nmi_dump(void)
7539 {
7540 #ifndef REAL_NMI_SIGNAL
7541 - static atomic_t nmied_cpus = ATOMIC_INIT(0);
7542 + static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
7543
7544 - atomic_inc(&nmied_cpus);
7545 + atomic_inc_unchecked(&nmied_cpus);
7546 #endif
7547 /*
7548 * Only allow 1 cpu to proceed
7549 @@ -233,7 +233,7 @@ cont_nmi_dump(void)
7550 udelay(10000);
7551 }
7552 #else
7553 - while (atomic_read(&nmied_cpus) != num_online_cpus());
7554 + while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7555 #endif
7556
7557 /*
7558 diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
7559 index a046b30..6799527 100644
7560 --- a/arch/mips/sni/rm200.c
7561 +++ b/arch/mips/sni/rm200.c
7562 @@ -270,7 +270,7 @@ spurious_8259A_irq:
7563 "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
7564 spurious_irq_mask |= irqmask;
7565 }
7566 - atomic_inc(&irq_err_count);
7567 + atomic_inc_unchecked(&irq_err_count);
7568 /*
7569 * Theoretically we do not have to handle this IRQ,
7570 * but in Linux this does not cause problems and is
7571 diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
7572 index 41e873b..34d33a7 100644
7573 --- a/arch/mips/vr41xx/common/icu.c
7574 +++ b/arch/mips/vr41xx/common/icu.c
7575 @@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
7576
7577 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
7578
7579 - atomic_inc(&irq_err_count);
7580 + atomic_inc_unchecked(&irq_err_count);
7581
7582 return -1;
7583 }
7584 diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
7585 index ae0e4ee..e8f0692 100644
7586 --- a/arch/mips/vr41xx/common/irq.c
7587 +++ b/arch/mips/vr41xx/common/irq.c
7588 @@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
7589 irq_cascade_t *cascade;
7590
7591 if (irq >= NR_IRQS) {
7592 - atomic_inc(&irq_err_count);
7593 + atomic_inc_unchecked(&irq_err_count);
7594 return;
7595 }
7596
7597 @@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
7598 ret = cascade->get_irq(irq);
7599 irq = ret;
7600 if (ret < 0)
7601 - atomic_inc(&irq_err_count);
7602 + atomic_inc_unchecked(&irq_err_count);
7603 else
7604 irq_dispatch(irq);
7605 if (!irqd_irq_disabled(idata) && chip->irq_unmask)
7606 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7607 index 967d144..db12197 100644
7608 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7609 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7610 @@ -11,12 +11,14 @@
7611 #ifndef _ASM_PROC_CACHE_H
7612 #define _ASM_PROC_CACHE_H
7613
7614 +#include <linux/const.h>
7615 +
7616 /* L1 cache */
7617
7618 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7619 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7620 -#define L1_CACHE_BYTES 16 /* bytes per entry */
7621 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7622 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7623 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7624
7625 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7626 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7627 index bcb5df2..84fabd2 100644
7628 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7629 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7630 @@ -16,13 +16,15 @@
7631 #ifndef _ASM_PROC_CACHE_H
7632 #define _ASM_PROC_CACHE_H
7633
7634 +#include <linux/const.h>
7635 +
7636 /*
7637 * L1 cache
7638 */
7639 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7640 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7641 -#define L1_CACHE_BYTES 32 /* bytes per entry */
7642 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7643 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7644 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7645
7646 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7647 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7648 index 4ce7a01..449202a 100644
7649 --- a/arch/openrisc/include/asm/cache.h
7650 +++ b/arch/openrisc/include/asm/cache.h
7651 @@ -19,11 +19,13 @@
7652 #ifndef __ASM_OPENRISC_CACHE_H
7653 #define __ASM_OPENRISC_CACHE_H
7654
7655 +#include <linux/const.h>
7656 +
7657 /* FIXME: How can we replace these with values from the CPU...
7658 * they shouldn't be hard-coded!
7659 */
7660
7661 -#define L1_CACHE_BYTES 16
7662 #define L1_CACHE_SHIFT 4
7663 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7664
7665 #endif /* __ASM_OPENRISC_CACHE_H */
7666 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7667 index 0be2db2..1b0f26d 100644
7668 --- a/arch/parisc/include/asm/atomic.h
7669 +++ b/arch/parisc/include/asm/atomic.h
7670 @@ -248,6 +248,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7671 return dec;
7672 }
7673
7674 +#define atomic64_read_unchecked(v) atomic64_read(v)
7675 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7676 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7677 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7678 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7679 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7680 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7681 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7682 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7683 +
7684 #endif /* !CONFIG_64BIT */
7685
7686
7687 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7688 index 47f11c7..3420df2 100644
7689 --- a/arch/parisc/include/asm/cache.h
7690 +++ b/arch/parisc/include/asm/cache.h
7691 @@ -5,6 +5,7 @@
7692 #ifndef __ARCH_PARISC_CACHE_H
7693 #define __ARCH_PARISC_CACHE_H
7694
7695 +#include <linux/const.h>
7696
7697 /*
7698 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7699 @@ -15,13 +16,13 @@
7700 * just ruin performance.
7701 */
7702 #ifdef CONFIG_PA20
7703 -#define L1_CACHE_BYTES 64
7704 #define L1_CACHE_SHIFT 6
7705 #else
7706 -#define L1_CACHE_BYTES 32
7707 #define L1_CACHE_SHIFT 5
7708 #endif
7709
7710 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7711 +
7712 #ifndef __ASSEMBLY__
7713
7714 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7715 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7716 index 3391d06..c23a2cc 100644
7717 --- a/arch/parisc/include/asm/elf.h
7718 +++ b/arch/parisc/include/asm/elf.h
7719 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7720
7721 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7722
7723 +#ifdef CONFIG_PAX_ASLR
7724 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
7725 +
7726 +#define PAX_DELTA_MMAP_LEN 16
7727 +#define PAX_DELTA_STACK_LEN 16
7728 +#endif
7729 +
7730 /* This yields a mask that user programs can use to figure out what
7731 instruction set this CPU supports. This could be done in user space,
7732 but it's not easy, and we've already done it here. */
7733 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7734 index f213f5b..0af3e8e 100644
7735 --- a/arch/parisc/include/asm/pgalloc.h
7736 +++ b/arch/parisc/include/asm/pgalloc.h
7737 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7738 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7739 }
7740
7741 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7742 +{
7743 + pgd_populate(mm, pgd, pmd);
7744 +}
7745 +
7746 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7747 {
7748 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7749 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7750 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7751 #define pmd_free(mm, x) do { } while (0)
7752 #define pgd_populate(mm, pmd, pte) BUG()
7753 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
7754
7755 #endif
7756
7757 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7758 index 22b89d1..ce34230 100644
7759 --- a/arch/parisc/include/asm/pgtable.h
7760 +++ b/arch/parisc/include/asm/pgtable.h
7761 @@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7762 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7763 #define PAGE_COPY PAGE_EXECREAD
7764 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7765 +
7766 +#ifdef CONFIG_PAX_PAGEEXEC
7767 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7768 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7769 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7770 +#else
7771 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
7772 +# define PAGE_COPY_NOEXEC PAGE_COPY
7773 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
7774 +#endif
7775 +
7776 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7777 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7778 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7779 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7780 index 4006964..fcb3cc2 100644
7781 --- a/arch/parisc/include/asm/uaccess.h
7782 +++ b/arch/parisc/include/asm/uaccess.h
7783 @@ -246,10 +246,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7784 const void __user *from,
7785 unsigned long n)
7786 {
7787 - int sz = __compiletime_object_size(to);
7788 + size_t sz = __compiletime_object_size(to);
7789 int ret = -EFAULT;
7790
7791 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7792 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7793 ret = __copy_from_user(to, from, n);
7794 else
7795 copy_from_user_overflow();
7796 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7797 index 50dfafc..b9fc230 100644
7798 --- a/arch/parisc/kernel/module.c
7799 +++ b/arch/parisc/kernel/module.c
7800 @@ -98,16 +98,38 @@
7801
7802 /* three functions to determine where in the module core
7803 * or init pieces the location is */
7804 +static inline int in_init_rx(struct module *me, void *loc)
7805 +{
7806 + return (loc >= me->module_init_rx &&
7807 + loc < (me->module_init_rx + me->init_size_rx));
7808 +}
7809 +
7810 +static inline int in_init_rw(struct module *me, void *loc)
7811 +{
7812 + return (loc >= me->module_init_rw &&
7813 + loc < (me->module_init_rw + me->init_size_rw));
7814 +}
7815 +
7816 static inline int in_init(struct module *me, void *loc)
7817 {
7818 - return (loc >= me->module_init &&
7819 - loc <= (me->module_init + me->init_size));
7820 + return in_init_rx(me, loc) || in_init_rw(me, loc);
7821 +}
7822 +
7823 +static inline int in_core_rx(struct module *me, void *loc)
7824 +{
7825 + return (loc >= me->module_core_rx &&
7826 + loc < (me->module_core_rx + me->core_size_rx));
7827 +}
7828 +
7829 +static inline int in_core_rw(struct module *me, void *loc)
7830 +{
7831 + return (loc >= me->module_core_rw &&
7832 + loc < (me->module_core_rw + me->core_size_rw));
7833 }
7834
7835 static inline int in_core(struct module *me, void *loc)
7836 {
7837 - return (loc >= me->module_core &&
7838 - loc <= (me->module_core + me->core_size));
7839 + return in_core_rx(me, loc) || in_core_rw(me, loc);
7840 }
7841
7842 static inline int in_local(struct module *me, void *loc)
7843 @@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7844 }
7845
7846 /* align things a bit */
7847 - me->core_size = ALIGN(me->core_size, 16);
7848 - me->arch.got_offset = me->core_size;
7849 - me->core_size += gots * sizeof(struct got_entry);
7850 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7851 + me->arch.got_offset = me->core_size_rw;
7852 + me->core_size_rw += gots * sizeof(struct got_entry);
7853
7854 - me->core_size = ALIGN(me->core_size, 16);
7855 - me->arch.fdesc_offset = me->core_size;
7856 - me->core_size += fdescs * sizeof(Elf_Fdesc);
7857 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7858 + me->arch.fdesc_offset = me->core_size_rw;
7859 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7860
7861 me->arch.got_max = gots;
7862 me->arch.fdesc_max = fdescs;
7863 @@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7864
7865 BUG_ON(value == 0);
7866
7867 - got = me->module_core + me->arch.got_offset;
7868 + got = me->module_core_rw + me->arch.got_offset;
7869 for (i = 0; got[i].addr; i++)
7870 if (got[i].addr == value)
7871 goto out;
7872 @@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7873 #ifdef CONFIG_64BIT
7874 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7875 {
7876 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7877 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7878
7879 if (!value) {
7880 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7881 @@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7882
7883 /* Create new one */
7884 fdesc->addr = value;
7885 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7886 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7887 return (Elf_Addr)fdesc;
7888 }
7889 #endif /* CONFIG_64BIT */
7890 @@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7891
7892 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7893 end = table + sechdrs[me->arch.unwind_section].sh_size;
7894 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7895 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7896
7897 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7898 me->arch.unwind_section, table, end, gp);
7899 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7900 index e1ffea2..46ed66e 100644
7901 --- a/arch/parisc/kernel/sys_parisc.c
7902 +++ b/arch/parisc/kernel/sys_parisc.c
7903 @@ -89,6 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7904 unsigned long task_size = TASK_SIZE;
7905 int do_color_align, last_mmap;
7906 struct vm_unmapped_area_info info;
7907 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7908
7909 if (len > task_size)
7910 return -ENOMEM;
7911 @@ -106,6 +107,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7912 goto found_addr;
7913 }
7914
7915 +#ifdef CONFIG_PAX_RANDMMAP
7916 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7917 +#endif
7918 +
7919 if (addr) {
7920 if (do_color_align && last_mmap)
7921 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7922 @@ -124,6 +129,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7923 info.high_limit = mmap_upper_limit();
7924 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7925 info.align_offset = shared_align_offset(last_mmap, pgoff);
7926 + info.threadstack_offset = offset;
7927 addr = vm_unmapped_area(&info);
7928
7929 found_addr:
7930 @@ -143,6 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7931 unsigned long addr = addr0;
7932 int do_color_align, last_mmap;
7933 struct vm_unmapped_area_info info;
7934 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7935
7936 #ifdef CONFIG_64BIT
7937 /* This should only ever run for 32-bit processes. */
7938 @@ -167,6 +174,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7939 }
7940
7941 /* requesting a specific address */
7942 +#ifdef CONFIG_PAX_RANDMMAP
7943 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7944 +#endif
7945 +
7946 if (addr) {
7947 if (do_color_align && last_mmap)
7948 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7949 @@ -184,6 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7950 info.high_limit = mm->mmap_base;
7951 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7952 info.align_offset = shared_align_offset(last_mmap, pgoff);
7953 + info.threadstack_offset = offset;
7954 addr = vm_unmapped_area(&info);
7955 if (!(addr & ~PAGE_MASK))
7956 goto found_addr;
7957 @@ -249,6 +261,13 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7958 mm->mmap_legacy_base = mmap_legacy_base();
7959 mm->mmap_base = mmap_upper_limit();
7960
7961 +#ifdef CONFIG_PAX_RANDMMAP
7962 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
7963 + mm->mmap_legacy_base += mm->delta_mmap;
7964 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7965 + }
7966 +#endif
7967 +
7968 if (mmap_is_legacy()) {
7969 mm->mmap_base = mm->mmap_legacy_base;
7970 mm->get_unmapped_area = arch_get_unmapped_area;
7971 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7972 index 47ee620..1107387 100644
7973 --- a/arch/parisc/kernel/traps.c
7974 +++ b/arch/parisc/kernel/traps.c
7975 @@ -726,9 +726,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7976
7977 down_read(&current->mm->mmap_sem);
7978 vma = find_vma(current->mm,regs->iaoq[0]);
7979 - if (vma && (regs->iaoq[0] >= vma->vm_start)
7980 - && (vma->vm_flags & VM_EXEC)) {
7981 -
7982 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7983 fault_address = regs->iaoq[0];
7984 fault_space = regs->iasq[0];
7985
7986 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7987 index 3ca9c11..d163ef7 100644
7988 --- a/arch/parisc/mm/fault.c
7989 +++ b/arch/parisc/mm/fault.c
7990 @@ -15,6 +15,7 @@
7991 #include <linux/sched.h>
7992 #include <linux/interrupt.h>
7993 #include <linux/module.h>
7994 +#include <linux/unistd.h>
7995
7996 #include <asm/uaccess.h>
7997 #include <asm/traps.h>
7998 @@ -50,7 +51,7 @@ int show_unhandled_signals = 1;
7999 static unsigned long
8000 parisc_acctyp(unsigned long code, unsigned int inst)
8001 {
8002 - if (code == 6 || code == 16)
8003 + if (code == 6 || code == 7 || code == 16)
8004 return VM_EXEC;
8005
8006 switch (inst & 0xf0000000) {
8007 @@ -136,6 +137,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
8008 }
8009 #endif
8010
8011 +#ifdef CONFIG_PAX_PAGEEXEC
8012 +/*
8013 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
8014 + *
8015 + * returns 1 when task should be killed
8016 + * 2 when rt_sigreturn trampoline was detected
8017 + * 3 when unpatched PLT trampoline was detected
8018 + */
8019 +static int pax_handle_fetch_fault(struct pt_regs *regs)
8020 +{
8021 +
8022 +#ifdef CONFIG_PAX_EMUPLT
8023 + int err;
8024 +
8025 + do { /* PaX: unpatched PLT emulation */
8026 + unsigned int bl, depwi;
8027 +
8028 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
8029 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
8030 +
8031 + if (err)
8032 + break;
8033 +
8034 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
8035 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
8036 +
8037 + err = get_user(ldw, (unsigned int *)addr);
8038 + err |= get_user(bv, (unsigned int *)(addr+4));
8039 + err |= get_user(ldw2, (unsigned int *)(addr+8));
8040 +
8041 + if (err)
8042 + break;
8043 +
8044 + if (ldw == 0x0E801096U &&
8045 + bv == 0xEAC0C000U &&
8046 + ldw2 == 0x0E881095U)
8047 + {
8048 + unsigned int resolver, map;
8049 +
8050 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
8051 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
8052 + if (err)
8053 + break;
8054 +
8055 + regs->gr[20] = instruction_pointer(regs)+8;
8056 + regs->gr[21] = map;
8057 + regs->gr[22] = resolver;
8058 + regs->iaoq[0] = resolver | 3UL;
8059 + regs->iaoq[1] = regs->iaoq[0] + 4;
8060 + return 3;
8061 + }
8062 + }
8063 + } while (0);
8064 +#endif
8065 +
8066 +#ifdef CONFIG_PAX_EMUTRAMP
8067 +
8068 +#ifndef CONFIG_PAX_EMUSIGRT
8069 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
8070 + return 1;
8071 +#endif
8072 +
8073 + do { /* PaX: rt_sigreturn emulation */
8074 + unsigned int ldi1, ldi2, bel, nop;
8075 +
8076 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
8077 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
8078 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
8079 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
8080 +
8081 + if (err)
8082 + break;
8083 +
8084 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
8085 + ldi2 == 0x3414015AU &&
8086 + bel == 0xE4008200U &&
8087 + nop == 0x08000240U)
8088 + {
8089 + regs->gr[25] = (ldi1 & 2) >> 1;
8090 + regs->gr[20] = __NR_rt_sigreturn;
8091 + regs->gr[31] = regs->iaoq[1] + 16;
8092 + regs->sr[0] = regs->iasq[1];
8093 + regs->iaoq[0] = 0x100UL;
8094 + regs->iaoq[1] = regs->iaoq[0] + 4;
8095 + regs->iasq[0] = regs->sr[2];
8096 + regs->iasq[1] = regs->sr[2];
8097 + return 2;
8098 + }
8099 + } while (0);
8100 +#endif
8101 +
8102 + return 1;
8103 +}
8104 +
8105 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8106 +{
8107 + unsigned long i;
8108 +
8109 + printk(KERN_ERR "PAX: bytes at PC: ");
8110 + for (i = 0; i < 5; i++) {
8111 + unsigned int c;
8112 + if (get_user(c, (unsigned int *)pc+i))
8113 + printk(KERN_CONT "???????? ");
8114 + else
8115 + printk(KERN_CONT "%08x ", c);
8116 + }
8117 + printk("\n");
8118 +}
8119 +#endif
8120 +
8121 int fixup_exception(struct pt_regs *regs)
8122 {
8123 const struct exception_table_entry *fix;
8124 @@ -234,8 +345,33 @@ retry:
8125
8126 good_area:
8127
8128 - if ((vma->vm_flags & acc_type) != acc_type)
8129 + if ((vma->vm_flags & acc_type) != acc_type) {
8130 +
8131 +#ifdef CONFIG_PAX_PAGEEXEC
8132 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
8133 + (address & ~3UL) == instruction_pointer(regs))
8134 + {
8135 + up_read(&mm->mmap_sem);
8136 + switch (pax_handle_fetch_fault(regs)) {
8137 +
8138 +#ifdef CONFIG_PAX_EMUPLT
8139 + case 3:
8140 + return;
8141 +#endif
8142 +
8143 +#ifdef CONFIG_PAX_EMUTRAMP
8144 + case 2:
8145 + return;
8146 +#endif
8147 +
8148 + }
8149 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
8150 + do_group_exit(SIGKILL);
8151 + }
8152 +#endif
8153 +
8154 goto bad_area;
8155 + }
8156
8157 /*
8158 * If for any reason at all we couldn't handle the fault, make
8159 diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
8160 index 4bc7b62..107e0b2 100644
8161 --- a/arch/powerpc/Kconfig
8162 +++ b/arch/powerpc/Kconfig
8163 @@ -399,6 +399,7 @@ config PPC64_SUPPORTS_MEMORY_FAILURE
8164 config KEXEC
8165 bool "kexec system call"
8166 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
8167 + depends on !GRKERNSEC_KMEM
8168 help
8169 kexec is a system call that implements the ability to shutdown your
8170 current kernel, and to start another kernel. It is like a reboot
8171 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
8172 index 28992d0..434c881 100644
8173 --- a/arch/powerpc/include/asm/atomic.h
8174 +++ b/arch/powerpc/include/asm/atomic.h
8175 @@ -12,6 +12,11 @@
8176
8177 #define ATOMIC_INIT(i) { (i) }
8178
8179 +#define _ASM_EXTABLE(from, to) \
8180 +" .section __ex_table,\"a\"\n" \
8181 + PPC_LONG" " #from ", " #to"\n" \
8182 +" .previous\n"
8183 +
8184 static __inline__ int atomic_read(const atomic_t *v)
8185 {
8186 int t;
8187 @@ -21,16 +26,61 @@ static __inline__ int atomic_read(const atomic_t *v)
8188 return t;
8189 }
8190
8191 +static __inline__ int atomic_read_unchecked(const atomic_unchecked_t *v)
8192 +{
8193 + int t;
8194 +
8195 + __asm__ __volatile__("lwz%U1%X1 %0,%1" : "=r"(t) : "m"(v->counter));
8196 +
8197 + return t;
8198 +}
8199 +
8200 static __inline__ void atomic_set(atomic_t *v, int i)
8201 {
8202 __asm__ __volatile__("stw%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
8203 }
8204
8205 +static __inline__ void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8206 +{
8207 + __asm__ __volatile__("stw%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
8208 +}
8209 +
8210 static __inline__ void atomic_add(int a, atomic_t *v)
8211 {
8212 int t;
8213
8214 __asm__ __volatile__(
8215 +"1: lwarx %0,0,%3 # atomic_add\n"
8216 +
8217 +#ifdef CONFIG_PAX_REFCOUNT
8218 +" mcrxr cr0\n"
8219 +" addo. %0,%2,%0\n"
8220 +" bf 4*cr0+so, 3f\n"
8221 +"2:.long " "0x00c00b00""\n"
8222 +#else
8223 +" add %0,%2,%0\n"
8224 +#endif
8225 +
8226 +"3:\n"
8227 + PPC405_ERR77(0,%3)
8228 +" stwcx. %0,0,%3 \n\
8229 + bne- 1b"
8230 +
8231 +#ifdef CONFIG_PAX_REFCOUNT
8232 +"\n4:\n"
8233 + _ASM_EXTABLE(2b, 4b)
8234 +#endif
8235 +
8236 + : "=&r" (t), "+m" (v->counter)
8237 + : "r" (a), "r" (&v->counter)
8238 + : "cc");
8239 +}
8240 +
8241 +static __inline__ void atomic_add_unchecked(int a, atomic_unchecked_t *v)
8242 +{
8243 + int t;
8244 +
8245 + __asm__ __volatile__(
8246 "1: lwarx %0,0,%3 # atomic_add\n\
8247 add %0,%2,%0\n"
8248 PPC405_ERR77(0,%3)
8249 @@ -41,12 +91,49 @@ static __inline__ void atomic_add(int a, atomic_t *v)
8250 : "cc");
8251 }
8252
8253 +/* Same as atomic_add but return the value */
8254 static __inline__ int atomic_add_return(int a, atomic_t *v)
8255 {
8256 int t;
8257
8258 __asm__ __volatile__(
8259 PPC_ATOMIC_ENTRY_BARRIER
8260 +"1: lwarx %0,0,%2 # atomic_add_return\n"
8261 +
8262 +#ifdef CONFIG_PAX_REFCOUNT
8263 +" mcrxr cr0\n"
8264 +" addo. %0,%1,%0\n"
8265 +" bf 4*cr0+so, 3f\n"
8266 +"2:.long " "0x00c00b00""\n"
8267 +#else
8268 +" add %0,%1,%0\n"
8269 +#endif
8270 +
8271 +"3:\n"
8272 + PPC405_ERR77(0,%2)
8273 +" stwcx. %0,0,%2 \n\
8274 + bne- 1b\n"
8275 +"4:"
8276 +
8277 +#ifdef CONFIG_PAX_REFCOUNT
8278 + _ASM_EXTABLE(2b, 4b)
8279 +#endif
8280 +
8281 + PPC_ATOMIC_EXIT_BARRIER
8282 + : "=&r" (t)
8283 + : "r" (a), "r" (&v->counter)
8284 + : "cc", "memory");
8285 +
8286 + return t;
8287 +}
8288 +
8289 +/* Same as atomic_add_unchecked but return the value */
8290 +static __inline__ int atomic_add_return_unchecked(int a, atomic_unchecked_t *v)
8291 +{
8292 + int t;
8293 +
8294 + __asm__ __volatile__(
8295 + PPC_ATOMIC_ENTRY_BARRIER
8296 "1: lwarx %0,0,%2 # atomic_add_return\n\
8297 add %0,%1,%0\n"
8298 PPC405_ERR77(0,%2)
8299 @@ -67,6 +154,37 @@ static __inline__ void atomic_sub(int a, atomic_t *v)
8300 int t;
8301
8302 __asm__ __volatile__(
8303 +"1: lwarx %0,0,%3 # atomic_sub\n"
8304 +
8305 +#ifdef CONFIG_PAX_REFCOUNT
8306 +" mcrxr cr0\n"
8307 +" subfo. %0,%2,%0\n"
8308 +" bf 4*cr0+so, 3f\n"
8309 +"2:.long " "0x00c00b00""\n"
8310 +#else
8311 +" subf %0,%2,%0\n"
8312 +#endif
8313 +
8314 +"3:\n"
8315 + PPC405_ERR77(0,%3)
8316 +" stwcx. %0,0,%3 \n\
8317 + bne- 1b\n"
8318 +"4:"
8319 +
8320 +#ifdef CONFIG_PAX_REFCOUNT
8321 + _ASM_EXTABLE(2b, 4b)
8322 +#endif
8323 +
8324 + : "=&r" (t), "+m" (v->counter)
8325 + : "r" (a), "r" (&v->counter)
8326 + : "cc");
8327 +}
8328 +
8329 +static __inline__ void atomic_sub_unchecked(int a, atomic_unchecked_t *v)
8330 +{
8331 + int t;
8332 +
8333 + __asm__ __volatile__(
8334 "1: lwarx %0,0,%3 # atomic_sub\n\
8335 subf %0,%2,%0\n"
8336 PPC405_ERR77(0,%3)
8337 @@ -77,12 +195,49 @@ static __inline__ void atomic_sub(int a, atomic_t *v)
8338 : "cc");
8339 }
8340
8341 +/* Same as atomic_sub but return the value */
8342 static __inline__ int atomic_sub_return(int a, atomic_t *v)
8343 {
8344 int t;
8345
8346 __asm__ __volatile__(
8347 PPC_ATOMIC_ENTRY_BARRIER
8348 +"1: lwarx %0,0,%2 # atomic_sub_return\n"
8349 +
8350 +#ifdef CONFIG_PAX_REFCOUNT
8351 +" mcrxr cr0\n"
8352 +" subfo. %0,%1,%0\n"
8353 +" bf 4*cr0+so, 3f\n"
8354 +"2:.long " "0x00c00b00""\n"
8355 +#else
8356 +" subf %0,%1,%0\n"
8357 +#endif
8358 +
8359 +"3:\n"
8360 + PPC405_ERR77(0,%2)
8361 +" stwcx. %0,0,%2 \n\
8362 + bne- 1b\n"
8363 + PPC_ATOMIC_EXIT_BARRIER
8364 +"4:"
8365 +
8366 +#ifdef CONFIG_PAX_REFCOUNT
8367 + _ASM_EXTABLE(2b, 4b)
8368 +#endif
8369 +
8370 + : "=&r" (t)
8371 + : "r" (a), "r" (&v->counter)
8372 + : "cc", "memory");
8373 +
8374 + return t;
8375 +}
8376 +
8377 +/* Same as atomic_sub_unchecked but return the value */
8378 +static __inline__ int atomic_sub_return_unchecked(int a, atomic_unchecked_t *v)
8379 +{
8380 + int t;
8381 +
8382 + __asm__ __volatile__(
8383 + PPC_ATOMIC_ENTRY_BARRIER
8384 "1: lwarx %0,0,%2 # atomic_sub_return\n\
8385 subf %0,%1,%0\n"
8386 PPC405_ERR77(0,%2)
8387 @@ -96,38 +251,23 @@ static __inline__ int atomic_sub_return(int a, atomic_t *v)
8388 return t;
8389 }
8390
8391 -static __inline__ void atomic_inc(atomic_t *v)
8392 -{
8393 - int t;
8394 +/*
8395 + * atomic_inc - increment atomic variable
8396 + * @v: pointer of type atomic_t
8397 + *
8398 + * Automatically increments @v by 1
8399 + */
8400 +#define atomic_inc(v) atomic_add(1, (v))
8401 +#define atomic_inc_return(v) atomic_add_return(1, (v))
8402
8403 - __asm__ __volatile__(
8404 -"1: lwarx %0,0,%2 # atomic_inc\n\
8405 - addic %0,%0,1\n"
8406 - PPC405_ERR77(0,%2)
8407 -" stwcx. %0,0,%2 \n\
8408 - bne- 1b"
8409 - : "=&r" (t), "+m" (v->counter)
8410 - : "r" (&v->counter)
8411 - : "cc", "xer");
8412 +static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
8413 +{
8414 + atomic_add_unchecked(1, v);
8415 }
8416
8417 -static __inline__ int atomic_inc_return(atomic_t *v)
8418 +static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
8419 {
8420 - int t;
8421 -
8422 - __asm__ __volatile__(
8423 - PPC_ATOMIC_ENTRY_BARRIER
8424 -"1: lwarx %0,0,%1 # atomic_inc_return\n\
8425 - addic %0,%0,1\n"
8426 - PPC405_ERR77(0,%1)
8427 -" stwcx. %0,0,%1 \n\
8428 - bne- 1b"
8429 - PPC_ATOMIC_EXIT_BARRIER
8430 - : "=&r" (t)
8431 - : "r" (&v->counter)
8432 - : "cc", "xer", "memory");
8433 -
8434 - return t;
8435 + return atomic_add_return_unchecked(1, v);
8436 }
8437
8438 /*
8439 @@ -140,43 +280,38 @@ static __inline__ int atomic_inc_return(atomic_t *v)
8440 */
8441 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
8442
8443 -static __inline__ void atomic_dec(atomic_t *v)
8444 +static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
8445 {
8446 - int t;
8447 -
8448 - __asm__ __volatile__(
8449 -"1: lwarx %0,0,%2 # atomic_dec\n\
8450 - addic %0,%0,-1\n"
8451 - PPC405_ERR77(0,%2)\
8452 -" stwcx. %0,0,%2\n\
8453 - bne- 1b"
8454 - : "=&r" (t), "+m" (v->counter)
8455 - : "r" (&v->counter)
8456 - : "cc", "xer");
8457 + return atomic_add_return_unchecked(1, v) == 0;
8458 }
8459
8460 -static __inline__ int atomic_dec_return(atomic_t *v)
8461 +/*
8462 + * atomic_dec - decrement atomic variable
8463 + * @v: pointer of type atomic_t
8464 + *
8465 + * Atomically decrements @v by 1
8466 + */
8467 +#define atomic_dec(v) atomic_sub(1, (v))
8468 +#define atomic_dec_return(v) atomic_sub_return(1, (v))
8469 +
8470 +static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
8471 {
8472 - int t;
8473 -
8474 - __asm__ __volatile__(
8475 - PPC_ATOMIC_ENTRY_BARRIER
8476 -"1: lwarx %0,0,%1 # atomic_dec_return\n\
8477 - addic %0,%0,-1\n"
8478 - PPC405_ERR77(0,%1)
8479 -" stwcx. %0,0,%1\n\
8480 - bne- 1b"
8481 - PPC_ATOMIC_EXIT_BARRIER
8482 - : "=&r" (t)
8483 - : "r" (&v->counter)
8484 - : "cc", "xer", "memory");
8485 -
8486 - return t;
8487 + atomic_sub_unchecked(1, v);
8488 }
8489
8490 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
8491 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
8492
8493 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
8494 +{
8495 + return cmpxchg(&(v->counter), old, new);
8496 +}
8497 +
8498 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
8499 +{
8500 + return xchg(&(v->counter), new);
8501 +}
8502 +
8503 /**
8504 * __atomic_add_unless - add unless the number is a given value
8505 * @v: pointer of type atomic_t
8506 @@ -271,6 +406,11 @@ static __inline__ int atomic_dec_if_positive(atomic_t *v)
8507 }
8508 #define atomic_dec_if_positive atomic_dec_if_positive
8509
8510 +#define smp_mb__before_atomic_dec() smp_mb()
8511 +#define smp_mb__after_atomic_dec() smp_mb()
8512 +#define smp_mb__before_atomic_inc() smp_mb()
8513 +#define smp_mb__after_atomic_inc() smp_mb()
8514 +
8515 #ifdef __powerpc64__
8516
8517 #define ATOMIC64_INIT(i) { (i) }
8518 @@ -284,11 +424,25 @@ static __inline__ long atomic64_read(const atomic64_t *v)
8519 return t;
8520 }
8521
8522 +static __inline__ long atomic64_read_unchecked(const atomic64_unchecked_t *v)
8523 +{
8524 + long t;
8525 +
8526 + __asm__ __volatile__("ld%U1%X1 %0,%1" : "=r"(t) : "m"(v->counter));
8527 +
8528 + return t;
8529 +}
8530 +
8531 static __inline__ void atomic64_set(atomic64_t *v, long i)
8532 {
8533 __asm__ __volatile__("std%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
8534 }
8535
8536 +static __inline__ void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
8537 +{
8538 + __asm__ __volatile__("std%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
8539 +}
8540 +
8541 static __inline__ void atomic64_add(long a, atomic64_t *v)
8542 {
8543 long t;
8544 @@ -303,12 +457,76 @@ static __inline__ void atomic64_add(long a, atomic64_t *v)
8545 : "cc");
8546 }
8547
8548 +static __inline__ void atomic64_add_unchecked(long a, atomic64_unchecked_t *v)
8549 +{
8550 + long t;
8551 +
8552 + __asm__ __volatile__(
8553 +"1: ldarx %0,0,%3 # atomic64_add\n"
8554 +
8555 +#ifdef CONFIG_PAX_REFCOUNT
8556 +" mcrxr cr0\n"
8557 +" addo. %0,%2,%0\n"
8558 +" bf 4*cr0+so, 3f\n"
8559 +"2:.long " "0x00c00b00""\n"
8560 +#else
8561 +" add %0,%2,%0\n"
8562 +#endif
8563 +
8564 +"3:\n"
8565 +" stdcx. %0,0,%3 \n\
8566 + bne- 1b\n"
8567 +"4:"
8568 +
8569 +#ifdef CONFIG_PAX_REFCOUNT
8570 + _ASM_EXTABLE(2b, 4b)
8571 +#endif
8572 +
8573 + : "=&r" (t), "+m" (v->counter)
8574 + : "r" (a), "r" (&v->counter)
8575 + : "cc");
8576 +}
8577 +
8578 static __inline__ long atomic64_add_return(long a, atomic64_t *v)
8579 {
8580 long t;
8581
8582 __asm__ __volatile__(
8583 PPC_ATOMIC_ENTRY_BARRIER
8584 +"1: ldarx %0,0,%2 # atomic64_add_return\n"
8585 +
8586 +#ifdef CONFIG_PAX_REFCOUNT
8587 +" mcrxr cr0\n"
8588 +" addo. %0,%1,%0\n"
8589 +" bf 4*cr0+so, 3f\n"
8590 +"2:.long " "0x00c00b00""\n"
8591 +#else
8592 +" add %0,%1,%0\n"
8593 +#endif
8594 +
8595 +"3:\n"
8596 +" stdcx. %0,0,%2 \n\
8597 + bne- 1b\n"
8598 + PPC_ATOMIC_EXIT_BARRIER
8599 +"4:"
8600 +
8601 +#ifdef CONFIG_PAX_REFCOUNT
8602 + _ASM_EXTABLE(2b, 4b)
8603 +#endif
8604 +
8605 + : "=&r" (t)
8606 + : "r" (a), "r" (&v->counter)
8607 + : "cc", "memory");
8608 +
8609 + return t;
8610 +}
8611 +
8612 +static __inline__ long atomic64_add_return_unchecked(long a, atomic64_unchecked_t *v)
8613 +{
8614 + long t;
8615 +
8616 + __asm__ __volatile__(
8617 + PPC_ATOMIC_ENTRY_BARRIER
8618 "1: ldarx %0,0,%2 # atomic64_add_return\n\
8619 add %0,%1,%0\n\
8620 stdcx. %0,0,%2 \n\
8621 @@ -328,6 +546,36 @@ static __inline__ void atomic64_sub(long a, atomic64_t *v)
8622 long t;
8623
8624 __asm__ __volatile__(
8625 +"1: ldarx %0,0,%3 # atomic64_sub\n"
8626 +
8627 +#ifdef CONFIG_PAX_REFCOUNT
8628 +" mcrxr cr0\n"
8629 +" subfo. %0,%2,%0\n"
8630 +" bf 4*cr0+so, 3f\n"
8631 +"2:.long " "0x00c00b00""\n"
8632 +#else
8633 +" subf %0,%2,%0\n"
8634 +#endif
8635 +
8636 +"3:\n"
8637 +" stdcx. %0,0,%3 \n\
8638 + bne- 1b"
8639 +"4:"
8640 +
8641 +#ifdef CONFIG_PAX_REFCOUNT
8642 + _ASM_EXTABLE(2b, 4b)
8643 +#endif
8644 +
8645 + : "=&r" (t), "+m" (v->counter)
8646 + : "r" (a), "r" (&v->counter)
8647 + : "cc");
8648 +}
8649 +
8650 +static __inline__ void atomic64_sub_unchecked(long a, atomic64_unchecked_t *v)
8651 +{
8652 + long t;
8653 +
8654 + __asm__ __volatile__(
8655 "1: ldarx %0,0,%3 # atomic64_sub\n\
8656 subf %0,%2,%0\n\
8657 stdcx. %0,0,%3 \n\
8658 @@ -343,6 +591,40 @@ static __inline__ long atomic64_sub_return(long a, atomic64_t *v)
8659
8660 __asm__ __volatile__(
8661 PPC_ATOMIC_ENTRY_BARRIER
8662 +"1: ldarx %0,0,%2 # atomic64_sub_return\n"
8663 +
8664 +#ifdef CONFIG_PAX_REFCOUNT
8665 +" mcrxr cr0\n"
8666 +" subfo. %0,%1,%0\n"
8667 +" bf 4*cr0+so, 3f\n"
8668 +"2:.long " "0x00c00b00""\n"
8669 +#else
8670 +" subf %0,%1,%0\n"
8671 +#endif
8672 +
8673 +"3:\n"
8674 +" stdcx. %0,0,%2 \n\
8675 + bne- 1b\n"
8676 + PPC_ATOMIC_EXIT_BARRIER
8677 +"4:"
8678 +
8679 +#ifdef CONFIG_PAX_REFCOUNT
8680 + _ASM_EXTABLE(2b, 4b)
8681 +#endif
8682 +
8683 + : "=&r" (t)
8684 + : "r" (a), "r" (&v->counter)
8685 + : "cc", "memory");
8686 +
8687 + return t;
8688 +}
8689 +
8690 +static __inline__ long atomic64_sub_return_unchecked(long a, atomic64_unchecked_t *v)
8691 +{
8692 + long t;
8693 +
8694 + __asm__ __volatile__(
8695 + PPC_ATOMIC_ENTRY_BARRIER
8696 "1: ldarx %0,0,%2 # atomic64_sub_return\n\
8697 subf %0,%1,%0\n\
8698 stdcx. %0,0,%2 \n\
8699 @@ -355,36 +637,23 @@ static __inline__ long atomic64_sub_return(long a, atomic64_t *v)
8700 return t;
8701 }
8702
8703 -static __inline__ void atomic64_inc(atomic64_t *v)
8704 -{
8705 - long t;
8706 +/*
8707 + * atomic64_inc - increment atomic variable
8708 + * @v: pointer of type atomic64_t
8709 + *
8710 + * Automatically increments @v by 1
8711 + */
8712 +#define atomic64_inc(v) atomic64_add(1, (v))
8713 +#define atomic64_inc_return(v) atomic64_add_return(1, (v))
8714
8715 - __asm__ __volatile__(
8716 -"1: ldarx %0,0,%2 # atomic64_inc\n\
8717 - addic %0,%0,1\n\
8718 - stdcx. %0,0,%2 \n\
8719 - bne- 1b"
8720 - : "=&r" (t), "+m" (v->counter)
8721 - : "r" (&v->counter)
8722 - : "cc", "xer");
8723 +static __inline__ void atomic64_inc_unchecked(atomic64_unchecked_t *v)
8724 +{
8725 + atomic64_add_unchecked(1, v);
8726 }
8727
8728 -static __inline__ long atomic64_inc_return(atomic64_t *v)
8729 +static __inline__ int atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8730 {
8731 - long t;
8732 -
8733 - __asm__ __volatile__(
8734 - PPC_ATOMIC_ENTRY_BARRIER
8735 -"1: ldarx %0,0,%1 # atomic64_inc_return\n\
8736 - addic %0,%0,1\n\
8737 - stdcx. %0,0,%1 \n\
8738 - bne- 1b"
8739 - PPC_ATOMIC_EXIT_BARRIER
8740 - : "=&r" (t)
8741 - : "r" (&v->counter)
8742 - : "cc", "xer", "memory");
8743 -
8744 - return t;
8745 + return atomic64_add_return_unchecked(1, v);
8746 }
8747
8748 /*
8749 @@ -397,36 +666,18 @@ static __inline__ long atomic64_inc_return(atomic64_t *v)
8750 */
8751 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
8752
8753 -static __inline__ void atomic64_dec(atomic64_t *v)
8754 +/*
8755 + * atomic64_dec - decrement atomic variable
8756 + * @v: pointer of type atomic64_t
8757 + *
8758 + * Atomically decrements @v by 1
8759 + */
8760 +#define atomic64_dec(v) atomic64_sub(1, (v))
8761 +#define atomic64_dec_return(v) atomic64_sub_return(1, (v))
8762 +
8763 +static __inline__ void atomic64_dec_unchecked(atomic64_unchecked_t *v)
8764 {
8765 - long t;
8766 -
8767 - __asm__ __volatile__(
8768 -"1: ldarx %0,0,%2 # atomic64_dec\n\
8769 - addic %0,%0,-1\n\
8770 - stdcx. %0,0,%2\n\
8771 - bne- 1b"
8772 - : "=&r" (t), "+m" (v->counter)
8773 - : "r" (&v->counter)
8774 - : "cc", "xer");
8775 -}
8776 -
8777 -static __inline__ long atomic64_dec_return(atomic64_t *v)
8778 -{
8779 - long t;
8780 -
8781 - __asm__ __volatile__(
8782 - PPC_ATOMIC_ENTRY_BARRIER
8783 -"1: ldarx %0,0,%1 # atomic64_dec_return\n\
8784 - addic %0,%0,-1\n\
8785 - stdcx. %0,0,%1\n\
8786 - bne- 1b"
8787 - PPC_ATOMIC_EXIT_BARRIER
8788 - : "=&r" (t)
8789 - : "r" (&v->counter)
8790 - : "cc", "xer", "memory");
8791 -
8792 - return t;
8793 + atomic64_sub_unchecked(1, v);
8794 }
8795
8796 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
8797 @@ -459,6 +710,16 @@ static __inline__ long atomic64_dec_if_positive(atomic64_t *v)
8798 #define atomic64_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
8799 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
8800
8801 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
8802 +{
8803 + return cmpxchg(&(v->counter), old, new);
8804 +}
8805 +
8806 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
8807 +{
8808 + return xchg(&(v->counter), new);
8809 +}
8810 +
8811 /**
8812 * atomic64_add_unless - add unless the number is a given value
8813 * @v: pointer of type atomic64_t
8814 diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
8815 index bab79a1..4a3eabc 100644
8816 --- a/arch/powerpc/include/asm/barrier.h
8817 +++ b/arch/powerpc/include/asm/barrier.h
8818 @@ -73,7 +73,7 @@
8819 do { \
8820 compiletime_assert_atomic_type(*p); \
8821 __lwsync(); \
8822 - ACCESS_ONCE(*p) = (v); \
8823 + ACCESS_ONCE_RW(*p) = (v); \
8824 } while (0)
8825
8826 #define smp_load_acquire(p) \
8827 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
8828 index 34a05a1..a1f2c67 100644
8829 --- a/arch/powerpc/include/asm/cache.h
8830 +++ b/arch/powerpc/include/asm/cache.h
8831 @@ -4,6 +4,7 @@
8832 #ifdef __KERNEL__
8833
8834 #include <asm/reg.h>
8835 +#include <linux/const.h>
8836
8837 /* bytes per L1 cache line */
8838 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
8839 @@ -23,7 +24,7 @@
8840 #define L1_CACHE_SHIFT 7
8841 #endif
8842
8843 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8844 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8845
8846 #define SMP_CACHE_BYTES L1_CACHE_BYTES
8847
8848 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
8849 index 888d8f3..66f581c 100644
8850 --- a/arch/powerpc/include/asm/elf.h
8851 +++ b/arch/powerpc/include/asm/elf.h
8852 @@ -28,8 +28,19 @@
8853 the loader. We need to make sure that it is out of the way of the program
8854 that it will "exec", and that there is sufficient room for the brk. */
8855
8856 -extern unsigned long randomize_et_dyn(unsigned long base);
8857 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
8858 +#define ELF_ET_DYN_BASE (0x20000000)
8859 +
8860 +#ifdef CONFIG_PAX_ASLR
8861 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
8862 +
8863 +#ifdef __powerpc64__
8864 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
8865 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
8866 +#else
8867 +#define PAX_DELTA_MMAP_LEN 15
8868 +#define PAX_DELTA_STACK_LEN 15
8869 +#endif
8870 +#endif
8871
8872 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
8873
8874 @@ -129,10 +140,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
8875 (0x7ff >> (PAGE_SHIFT - 12)) : \
8876 (0x3ffff >> (PAGE_SHIFT - 12)))
8877
8878 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8879 -#define arch_randomize_brk arch_randomize_brk
8880 -
8881 -
8882 #ifdef CONFIG_SPU_BASE
8883 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
8884 #define NT_SPU 1
8885 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
8886 index 8196e9c..d83a9f3 100644
8887 --- a/arch/powerpc/include/asm/exec.h
8888 +++ b/arch/powerpc/include/asm/exec.h
8889 @@ -4,6 +4,6 @@
8890 #ifndef _ASM_POWERPC_EXEC_H
8891 #define _ASM_POWERPC_EXEC_H
8892
8893 -extern unsigned long arch_align_stack(unsigned long sp);
8894 +#define arch_align_stack(x) ((x) & ~0xfUL)
8895
8896 #endif /* _ASM_POWERPC_EXEC_H */
8897 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
8898 index 5acabbd..7ea14fa 100644
8899 --- a/arch/powerpc/include/asm/kmap_types.h
8900 +++ b/arch/powerpc/include/asm/kmap_types.h
8901 @@ -10,7 +10,7 @@
8902 * 2 of the License, or (at your option) any later version.
8903 */
8904
8905 -#define KM_TYPE_NR 16
8906 +#define KM_TYPE_NR 17
8907
8908 #endif /* __KERNEL__ */
8909 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
8910 diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
8911 index b8da913..c02b593 100644
8912 --- a/arch/powerpc/include/asm/local.h
8913 +++ b/arch/powerpc/include/asm/local.h
8914 @@ -9,21 +9,65 @@ typedef struct
8915 atomic_long_t a;
8916 } local_t;
8917
8918 +typedef struct
8919 +{
8920 + atomic_long_unchecked_t a;
8921 +} local_unchecked_t;
8922 +
8923 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
8924
8925 #define local_read(l) atomic_long_read(&(l)->a)
8926 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
8927 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
8928 +#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
8929
8930 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
8931 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
8932 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
8933 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
8934 #define local_inc(l) atomic_long_inc(&(l)->a)
8935 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
8936 #define local_dec(l) atomic_long_dec(&(l)->a)
8937 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
8938
8939 static __inline__ long local_add_return(long a, local_t *l)
8940 {
8941 long t;
8942
8943 __asm__ __volatile__(
8944 +"1:" PPC_LLARX(%0,0,%2,0) " # local_add_return\n"
8945 +
8946 +#ifdef CONFIG_PAX_REFCOUNT
8947 +" mcrxr cr0\n"
8948 +" addo. %0,%1,%0\n"
8949 +" bf 4*cr0+so, 3f\n"
8950 +"2:.long " "0x00c00b00""\n"
8951 +#else
8952 +" add %0,%1,%0\n"
8953 +#endif
8954 +
8955 +"3:\n"
8956 + PPC405_ERR77(0,%2)
8957 + PPC_STLCX "%0,0,%2 \n\
8958 + bne- 1b"
8959 +
8960 +#ifdef CONFIG_PAX_REFCOUNT
8961 +"\n4:\n"
8962 + _ASM_EXTABLE(2b, 4b)
8963 +#endif
8964 +
8965 + : "=&r" (t)
8966 + : "r" (a), "r" (&(l->a.counter))
8967 + : "cc", "memory");
8968 +
8969 + return t;
8970 +}
8971 +
8972 +static __inline__ long local_add_return_unchecked(long a, local_unchecked_t *l)
8973 +{
8974 + long t;
8975 +
8976 + __asm__ __volatile__(
8977 "1:" PPC_LLARX(%0,0,%2,0) " # local_add_return\n\
8978 add %0,%1,%0\n"
8979 PPC405_ERR77(0,%2)
8980 @@ -101,6 +145,8 @@ static __inline__ long local_dec_return(local_t *l)
8981
8982 #define local_cmpxchg(l, o, n) \
8983 (cmpxchg_local(&((l)->a.counter), (o), (n)))
8984 +#define local_cmpxchg_unchecked(l, o, n) \
8985 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
8986 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
8987
8988 /**
8989 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
8990 index 8565c25..2865190 100644
8991 --- a/arch/powerpc/include/asm/mman.h
8992 +++ b/arch/powerpc/include/asm/mman.h
8993 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
8994 }
8995 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
8996
8997 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
8998 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
8999 {
9000 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
9001 }
9002 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
9003 index 26fe1ae..987ffc5 100644
9004 --- a/arch/powerpc/include/asm/page.h
9005 +++ b/arch/powerpc/include/asm/page.h
9006 @@ -227,8 +227,9 @@ extern long long virt_phys_offset;
9007 * and needs to be executable. This means the whole heap ends
9008 * up being executable.
9009 */
9010 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
9011 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
9012 +#define VM_DATA_DEFAULT_FLAGS32 \
9013 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
9014 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
9015
9016 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
9017 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
9018 @@ -256,6 +257,9 @@ extern long long virt_phys_offset;
9019 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
9020 #endif
9021
9022 +#define ktla_ktva(addr) (addr)
9023 +#define ktva_ktla(addr) (addr)
9024 +
9025 #ifndef CONFIG_PPC_BOOK3S_64
9026 /*
9027 * Use the top bit of the higher-level page table entries to indicate whether
9028 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
9029 index 88693ce..ac6f9ab 100644
9030 --- a/arch/powerpc/include/asm/page_64.h
9031 +++ b/arch/powerpc/include/asm/page_64.h
9032 @@ -153,15 +153,18 @@ do { \
9033 * stack by default, so in the absence of a PT_GNU_STACK program header
9034 * we turn execute permission off.
9035 */
9036 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
9037 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
9038 +#define VM_STACK_DEFAULT_FLAGS32 \
9039 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
9040 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
9041
9042 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
9043 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
9044
9045 +#ifndef CONFIG_PAX_PAGEEXEC
9046 #define VM_STACK_DEFAULT_FLAGS \
9047 (is_32bit_task() ? \
9048 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
9049 +#endif
9050
9051 #include <asm-generic/getorder.h>
9052
9053 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
9054 index 4b0be20..c15a27d 100644
9055 --- a/arch/powerpc/include/asm/pgalloc-64.h
9056 +++ b/arch/powerpc/include/asm/pgalloc-64.h
9057 @@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9058 #ifndef CONFIG_PPC_64K_PAGES
9059
9060 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
9061 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
9062
9063 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
9064 {
9065 @@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
9066 pud_set(pud, (unsigned long)pmd);
9067 }
9068
9069 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
9070 +{
9071 + pud_populate(mm, pud, pmd);
9072 +}
9073 +
9074 #define pmd_populate(mm, pmd, pte_page) \
9075 pmd_populate_kernel(mm, pmd, page_address(pte_page))
9076 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
9077 @@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
9078 #endif
9079
9080 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
9081 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
9082
9083 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
9084 pte_t *pte)
9085 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
9086 index d98c1ec..9f61569 100644
9087 --- a/arch/powerpc/include/asm/pgtable.h
9088 +++ b/arch/powerpc/include/asm/pgtable.h
9089 @@ -2,6 +2,7 @@
9090 #define _ASM_POWERPC_PGTABLE_H
9091 #ifdef __KERNEL__
9092
9093 +#include <linux/const.h>
9094 #ifndef __ASSEMBLY__
9095 #include <linux/mmdebug.h>
9096 #include <asm/processor.h> /* For TASK_SIZE */
9097 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
9098 index 4aad413..85d86bf 100644
9099 --- a/arch/powerpc/include/asm/pte-hash32.h
9100 +++ b/arch/powerpc/include/asm/pte-hash32.h
9101 @@ -21,6 +21,7 @@
9102 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
9103 #define _PAGE_USER 0x004 /* usermode access allowed */
9104 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
9105 +#define _PAGE_EXEC _PAGE_GUARDED
9106 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
9107 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
9108 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
9109 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
9110 index 0c05059..7e056e4 100644
9111 --- a/arch/powerpc/include/asm/reg.h
9112 +++ b/arch/powerpc/include/asm/reg.h
9113 @@ -251,6 +251,7 @@
9114 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
9115 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
9116 #define DSISR_NOHPTE 0x40000000 /* no translation found */
9117 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
9118 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
9119 #define DSISR_ISSTORE 0x02000000 /* access was a store */
9120 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
9121 diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
9122 index 5a6614a..d89995d1 100644
9123 --- a/arch/powerpc/include/asm/smp.h
9124 +++ b/arch/powerpc/include/asm/smp.h
9125 @@ -51,7 +51,7 @@ struct smp_ops_t {
9126 int (*cpu_disable)(void);
9127 void (*cpu_die)(unsigned int nr);
9128 int (*cpu_bootable)(unsigned int nr);
9129 -};
9130 +} __no_const;
9131
9132 extern void smp_send_debugger_break(void);
9133 extern void start_secondary_resume(void);
9134 diff --git a/arch/powerpc/include/asm/spinlock.h b/arch/powerpc/include/asm/spinlock.h
9135 index 4dbe072..b803275 100644
9136 --- a/arch/powerpc/include/asm/spinlock.h
9137 +++ b/arch/powerpc/include/asm/spinlock.h
9138 @@ -204,13 +204,29 @@ static inline long __arch_read_trylock(arch_rwlock_t *rw)
9139 __asm__ __volatile__(
9140 "1: " PPC_LWARX(%0,0,%1,1) "\n"
9141 __DO_SIGN_EXTEND
9142 -" addic. %0,%0,1\n\
9143 - ble- 2f\n"
9144 +
9145 +#ifdef CONFIG_PAX_REFCOUNT
9146 +" mcrxr cr0\n"
9147 +" addico. %0,%0,1\n"
9148 +" bf 4*cr0+so, 3f\n"
9149 +"2:.long " "0x00c00b00""\n"
9150 +#else
9151 +" addic. %0,%0,1\n"
9152 +#endif
9153 +
9154 +"3:\n"
9155 + "ble- 4f\n"
9156 PPC405_ERR77(0,%1)
9157 " stwcx. %0,0,%1\n\
9158 bne- 1b\n"
9159 PPC_ACQUIRE_BARRIER
9160 -"2:" : "=&r" (tmp)
9161 +"4:"
9162 +
9163 +#ifdef CONFIG_PAX_REFCOUNT
9164 + _ASM_EXTABLE(2b,4b)
9165 +#endif
9166 +
9167 + : "=&r" (tmp)
9168 : "r" (&rw->lock)
9169 : "cr0", "xer", "memory");
9170
9171 @@ -286,11 +302,27 @@ static inline void arch_read_unlock(arch_rwlock_t *rw)
9172 __asm__ __volatile__(
9173 "# read_unlock\n\t"
9174 PPC_RELEASE_BARRIER
9175 -"1: lwarx %0,0,%1\n\
9176 - addic %0,%0,-1\n"
9177 +"1: lwarx %0,0,%1\n"
9178 +
9179 +#ifdef CONFIG_PAX_REFCOUNT
9180 +" mcrxr cr0\n"
9181 +" addico. %0,%0,-1\n"
9182 +" bf 4*cr0+so, 3f\n"
9183 +"2:.long " "0x00c00b00""\n"
9184 +#else
9185 +" addic. %0,%0,-1\n"
9186 +#endif
9187 +
9188 +"3:\n"
9189 PPC405_ERR77(0,%1)
9190 " stwcx. %0,0,%1\n\
9191 bne- 1b"
9192 +
9193 +#ifdef CONFIG_PAX_REFCOUNT
9194 +"\n4:\n"
9195 + _ASM_EXTABLE(2b, 4b)
9196 +#endif
9197 +
9198 : "=&r"(tmp)
9199 : "r"(&rw->lock)
9200 : "cr0", "xer", "memory");
9201 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
9202 index b034ecd..af7e31f 100644
9203 --- a/arch/powerpc/include/asm/thread_info.h
9204 +++ b/arch/powerpc/include/asm/thread_info.h
9205 @@ -107,6 +107,8 @@ static inline struct thread_info *current_thread_info(void)
9206 #if defined(CONFIG_PPC64)
9207 #define TIF_ELF2ABI 18 /* function descriptors must die! */
9208 #endif
9209 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
9210 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
9211
9212 /* as above, but as bit values */
9213 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
9214 @@ -125,9 +127,10 @@ static inline struct thread_info *current_thread_info(void)
9215 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
9216 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
9217 #define _TIF_NOHZ (1<<TIF_NOHZ)
9218 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
9219 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
9220 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
9221 - _TIF_NOHZ)
9222 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
9223
9224 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
9225 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
9226 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
9227 index 9485b43..3bd3c16 100644
9228 --- a/arch/powerpc/include/asm/uaccess.h
9229 +++ b/arch/powerpc/include/asm/uaccess.h
9230 @@ -58,6 +58,7 @@
9231
9232 #endif
9233
9234 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9235 #define access_ok(type, addr, size) \
9236 (__chk_user_ptr(addr), \
9237 __access_ok((__force unsigned long)(addr), (size), get_fs()))
9238 @@ -318,52 +319,6 @@ do { \
9239 extern unsigned long __copy_tofrom_user(void __user *to,
9240 const void __user *from, unsigned long size);
9241
9242 -#ifndef __powerpc64__
9243 -
9244 -static inline unsigned long copy_from_user(void *to,
9245 - const void __user *from, unsigned long n)
9246 -{
9247 - unsigned long over;
9248 -
9249 - if (access_ok(VERIFY_READ, from, n))
9250 - return __copy_tofrom_user((__force void __user *)to, from, n);
9251 - if ((unsigned long)from < TASK_SIZE) {
9252 - over = (unsigned long)from + n - TASK_SIZE;
9253 - return __copy_tofrom_user((__force void __user *)to, from,
9254 - n - over) + over;
9255 - }
9256 - return n;
9257 -}
9258 -
9259 -static inline unsigned long copy_to_user(void __user *to,
9260 - const void *from, unsigned long n)
9261 -{
9262 - unsigned long over;
9263 -
9264 - if (access_ok(VERIFY_WRITE, to, n))
9265 - return __copy_tofrom_user(to, (__force void __user *)from, n);
9266 - if ((unsigned long)to < TASK_SIZE) {
9267 - over = (unsigned long)to + n - TASK_SIZE;
9268 - return __copy_tofrom_user(to, (__force void __user *)from,
9269 - n - over) + over;
9270 - }
9271 - return n;
9272 -}
9273 -
9274 -#else /* __powerpc64__ */
9275 -
9276 -#define __copy_in_user(to, from, size) \
9277 - __copy_tofrom_user((to), (from), (size))
9278 -
9279 -extern unsigned long copy_from_user(void *to, const void __user *from,
9280 - unsigned long n);
9281 -extern unsigned long copy_to_user(void __user *to, const void *from,
9282 - unsigned long n);
9283 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
9284 - unsigned long n);
9285 -
9286 -#endif /* __powerpc64__ */
9287 -
9288 static inline unsigned long __copy_from_user_inatomic(void *to,
9289 const void __user *from, unsigned long n)
9290 {
9291 @@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
9292 if (ret == 0)
9293 return 0;
9294 }
9295 +
9296 + if (!__builtin_constant_p(n))
9297 + check_object_size(to, n, false);
9298 +
9299 return __copy_tofrom_user((__force void __user *)to, from, n);
9300 }
9301
9302 @@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
9303 if (ret == 0)
9304 return 0;
9305 }
9306 +
9307 + if (!__builtin_constant_p(n))
9308 + check_object_size(from, n, true);
9309 +
9310 return __copy_tofrom_user(to, (__force const void __user *)from, n);
9311 }
9312
9313 @@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
9314 return __copy_to_user_inatomic(to, from, size);
9315 }
9316
9317 +#ifndef __powerpc64__
9318 +
9319 +static inline unsigned long __must_check copy_from_user(void *to,
9320 + const void __user *from, unsigned long n)
9321 +{
9322 + unsigned long over;
9323 +
9324 + if ((long)n < 0)
9325 + return n;
9326 +
9327 + if (access_ok(VERIFY_READ, from, n)) {
9328 + if (!__builtin_constant_p(n))
9329 + check_object_size(to, n, false);
9330 + return __copy_tofrom_user((__force void __user *)to, from, n);
9331 + }
9332 + if ((unsigned long)from < TASK_SIZE) {
9333 + over = (unsigned long)from + n - TASK_SIZE;
9334 + if (!__builtin_constant_p(n - over))
9335 + check_object_size(to, n - over, false);
9336 + return __copy_tofrom_user((__force void __user *)to, from,
9337 + n - over) + over;
9338 + }
9339 + return n;
9340 +}
9341 +
9342 +static inline unsigned long __must_check copy_to_user(void __user *to,
9343 + const void *from, unsigned long n)
9344 +{
9345 + unsigned long over;
9346 +
9347 + if ((long)n < 0)
9348 + return n;
9349 +
9350 + if (access_ok(VERIFY_WRITE, to, n)) {
9351 + if (!__builtin_constant_p(n))
9352 + check_object_size(from, n, true);
9353 + return __copy_tofrom_user(to, (__force void __user *)from, n);
9354 + }
9355 + if ((unsigned long)to < TASK_SIZE) {
9356 + over = (unsigned long)to + n - TASK_SIZE;
9357 + if (!__builtin_constant_p(n))
9358 + check_object_size(from, n - over, true);
9359 + return __copy_tofrom_user(to, (__force void __user *)from,
9360 + n - over) + over;
9361 + }
9362 + return n;
9363 +}
9364 +
9365 +#else /* __powerpc64__ */
9366 +
9367 +#define __copy_in_user(to, from, size) \
9368 + __copy_tofrom_user((to), (from), (size))
9369 +
9370 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
9371 +{
9372 + if ((long)n < 0 || n > INT_MAX)
9373 + return n;
9374 +
9375 + if (!__builtin_constant_p(n))
9376 + check_object_size(to, n, false);
9377 +
9378 + if (likely(access_ok(VERIFY_READ, from, n)))
9379 + n = __copy_from_user(to, from, n);
9380 + else
9381 + memset(to, 0, n);
9382 + return n;
9383 +}
9384 +
9385 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
9386 +{
9387 + if ((long)n < 0 || n > INT_MAX)
9388 + return n;
9389 +
9390 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
9391 + if (!__builtin_constant_p(n))
9392 + check_object_size(from, n, true);
9393 + n = __copy_to_user(to, from, n);
9394 + }
9395 + return n;
9396 +}
9397 +
9398 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
9399 + unsigned long n);
9400 +
9401 +#endif /* __powerpc64__ */
9402 +
9403 extern unsigned long __clear_user(void __user *addr, unsigned long size);
9404
9405 static inline unsigned long clear_user(void __user *addr, unsigned long size)
9406 diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
9407 index 670c312..60c2b52 100644
9408 --- a/arch/powerpc/kernel/Makefile
9409 +++ b/arch/powerpc/kernel/Makefile
9410 @@ -27,6 +27,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
9411 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
9412 endif
9413
9414 +CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
9415 +
9416 obj-y := cputable.o ptrace.o syscalls.o \
9417 irq.o align.o signal_32.o pmc.o vdso.o \
9418 process.o systbl.o idle.o \
9419 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
9420 index bb9cac6..5181202 100644
9421 --- a/arch/powerpc/kernel/exceptions-64e.S
9422 +++ b/arch/powerpc/kernel/exceptions-64e.S
9423 @@ -1010,6 +1010,7 @@ storage_fault_common:
9424 std r14,_DAR(r1)
9425 std r15,_DSISR(r1)
9426 addi r3,r1,STACK_FRAME_OVERHEAD
9427 + bl save_nvgprs
9428 mr r4,r14
9429 mr r5,r15
9430 ld r14,PACA_EXGEN+EX_R14(r13)
9431 @@ -1018,8 +1019,7 @@ storage_fault_common:
9432 cmpdi r3,0
9433 bne- 1f
9434 b ret_from_except_lite
9435 -1: bl save_nvgprs
9436 - mr r5,r3
9437 +1: mr r5,r3
9438 addi r3,r1,STACK_FRAME_OVERHEAD
9439 ld r4,_DAR(r1)
9440 bl bad_page_fault
9441 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
9442 index 050f79a..f385bfe 100644
9443 --- a/arch/powerpc/kernel/exceptions-64s.S
9444 +++ b/arch/powerpc/kernel/exceptions-64s.S
9445 @@ -1593,10 +1593,10 @@ handle_page_fault:
9446 11: ld r4,_DAR(r1)
9447 ld r5,_DSISR(r1)
9448 addi r3,r1,STACK_FRAME_OVERHEAD
9449 + bl save_nvgprs
9450 bl do_page_fault
9451 cmpdi r3,0
9452 beq+ 12f
9453 - bl save_nvgprs
9454 mr r5,r3
9455 addi r3,r1,STACK_FRAME_OVERHEAD
9456 lwz r4,_DAR(r1)
9457 diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
9458 index 4c5891d..a5d88bb 100644
9459 --- a/arch/powerpc/kernel/irq.c
9460 +++ b/arch/powerpc/kernel/irq.c
9461 @@ -461,6 +461,8 @@ void migrate_irqs(void)
9462 }
9463 #endif
9464
9465 +extern void gr_handle_kernel_exploit(void);
9466 +
9467 static inline void check_stack_overflow(void)
9468 {
9469 #ifdef CONFIG_DEBUG_STACKOVERFLOW
9470 @@ -473,6 +475,7 @@ static inline void check_stack_overflow(void)
9471 printk("do_IRQ: stack overflow: %ld\n",
9472 sp - sizeof(struct thread_info));
9473 dump_stack();
9474 + gr_handle_kernel_exploit();
9475 }
9476 #endif
9477 }
9478 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
9479 index 6cff040..74ac5d1b 100644
9480 --- a/arch/powerpc/kernel/module_32.c
9481 +++ b/arch/powerpc/kernel/module_32.c
9482 @@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
9483 me->arch.core_plt_section = i;
9484 }
9485 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
9486 - printk("Module doesn't contain .plt or .init.plt sections.\n");
9487 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
9488 return -ENOEXEC;
9489 }
9490
9491 @@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
9492
9493 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
9494 /* Init, or core PLT? */
9495 - if (location >= mod->module_core
9496 - && location < mod->module_core + mod->core_size)
9497 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
9498 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
9499 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
9500 - else
9501 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
9502 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
9503 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
9504 + else {
9505 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
9506 + return ~0UL;
9507 + }
9508
9509 /* Find this entry, or if that fails, the next avail. entry */
9510 while (entry->jump[0]) {
9511 @@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
9512 }
9513 #ifdef CONFIG_DYNAMIC_FTRACE
9514 module->arch.tramp =
9515 - do_plt_call(module->module_core,
9516 + do_plt_call(module->module_core_rx,
9517 (unsigned long)ftrace_caller,
9518 sechdrs, module);
9519 #endif
9520 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
9521 index bf44ae9..6d2ce71 100644
9522 --- a/arch/powerpc/kernel/process.c
9523 +++ b/arch/powerpc/kernel/process.c
9524 @@ -1039,8 +1039,8 @@ void show_regs(struct pt_regs * regs)
9525 * Lookup NIP late so we have the best change of getting the
9526 * above info out without failing
9527 */
9528 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
9529 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
9530 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
9531 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
9532 #endif
9533 show_stack(current, (unsigned long *) regs->gpr[1]);
9534 if (!user_mode(regs))
9535 @@ -1558,10 +1558,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
9536 newsp = stack[0];
9537 ip = stack[STACK_FRAME_LR_SAVE];
9538 if (!firstframe || ip != lr) {
9539 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
9540 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
9541 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
9542 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
9543 - printk(" (%pS)",
9544 + printk(" (%pA)",
9545 (void *)current->ret_stack[curr_frame].ret);
9546 curr_frame--;
9547 }
9548 @@ -1581,7 +1581,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
9549 struct pt_regs *regs = (struct pt_regs *)
9550 (sp + STACK_FRAME_OVERHEAD);
9551 lr = regs->link;
9552 - printk("--- interrupt: %lx at %pS\n LR = %pS\n",
9553 + printk("--- interrupt: %lx at %pA\n LR = %pA\n",
9554 regs->trap, (void *)regs->nip, (void *)lr);
9555 firstframe = 1;
9556 }
9557 @@ -1617,58 +1617,3 @@ void notrace __ppc64_runlatch_off(void)
9558 mtspr(SPRN_CTRLT, ctrl);
9559 }
9560 #endif /* CONFIG_PPC64 */
9561 -
9562 -unsigned long arch_align_stack(unsigned long sp)
9563 -{
9564 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9565 - sp -= get_random_int() & ~PAGE_MASK;
9566 - return sp & ~0xf;
9567 -}
9568 -
9569 -static inline unsigned long brk_rnd(void)
9570 -{
9571 - unsigned long rnd = 0;
9572 -
9573 - /* 8MB for 32bit, 1GB for 64bit */
9574 - if (is_32bit_task())
9575 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
9576 - else
9577 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
9578 -
9579 - return rnd << PAGE_SHIFT;
9580 -}
9581 -
9582 -unsigned long arch_randomize_brk(struct mm_struct *mm)
9583 -{
9584 - unsigned long base = mm->brk;
9585 - unsigned long ret;
9586 -
9587 -#ifdef CONFIG_PPC_STD_MMU_64
9588 - /*
9589 - * If we are using 1TB segments and we are allowed to randomise
9590 - * the heap, we can put it above 1TB so it is backed by a 1TB
9591 - * segment. Otherwise the heap will be in the bottom 1TB
9592 - * which always uses 256MB segments and this may result in a
9593 - * performance penalty.
9594 - */
9595 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
9596 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
9597 -#endif
9598 -
9599 - ret = PAGE_ALIGN(base + brk_rnd());
9600 -
9601 - if (ret < mm->brk)
9602 - return mm->brk;
9603 -
9604 - return ret;
9605 -}
9606 -
9607 -unsigned long randomize_et_dyn(unsigned long base)
9608 -{
9609 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
9610 -
9611 - if (ret < base)
9612 - return base;
9613 -
9614 - return ret;
9615 -}
9616 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
9617 index 2e3d2bf..35df241 100644
9618 --- a/arch/powerpc/kernel/ptrace.c
9619 +++ b/arch/powerpc/kernel/ptrace.c
9620 @@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
9621 return ret;
9622 }
9623
9624 +#ifdef CONFIG_GRKERNSEC_SETXID
9625 +extern void gr_delayed_cred_worker(void);
9626 +#endif
9627 +
9628 /*
9629 * We must return the syscall number to actually look up in the table.
9630 * This can be -1L to skip running any syscall at all.
9631 @@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
9632
9633 secure_computing_strict(regs->gpr[0]);
9634
9635 +#ifdef CONFIG_GRKERNSEC_SETXID
9636 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9637 + gr_delayed_cred_worker();
9638 +#endif
9639 +
9640 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
9641 tracehook_report_syscall_entry(regs))
9642 /*
9643 @@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
9644 {
9645 int step;
9646
9647 +#ifdef CONFIG_GRKERNSEC_SETXID
9648 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9649 + gr_delayed_cred_worker();
9650 +#endif
9651 +
9652 audit_syscall_exit(regs);
9653
9654 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
9655 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
9656 index b171001..4ac7ac5 100644
9657 --- a/arch/powerpc/kernel/signal_32.c
9658 +++ b/arch/powerpc/kernel/signal_32.c
9659 @@ -1011,7 +1011,7 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,
9660 /* Save user registers on the stack */
9661 frame = &rt_sf->uc.uc_mcontext;
9662 addr = frame;
9663 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
9664 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
9665 sigret = 0;
9666 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
9667 } else {
9668 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
9669 index 2cb0c94..c0c0bc9 100644
9670 --- a/arch/powerpc/kernel/signal_64.c
9671 +++ b/arch/powerpc/kernel/signal_64.c
9672 @@ -754,7 +754,7 @@ int handle_rt_signal64(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs
9673 current->thread.fp_state.fpscr = 0;
9674
9675 /* Set up to return from userspace. */
9676 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
9677 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
9678 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
9679 } else {
9680 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
9681 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
9682 index 0dc43f9..a885d33 100644
9683 --- a/arch/powerpc/kernel/traps.c
9684 +++ b/arch/powerpc/kernel/traps.c
9685 @@ -36,6 +36,7 @@
9686 #include <linux/debugfs.h>
9687 #include <linux/ratelimit.h>
9688 #include <linux/context_tracking.h>
9689 +#include <linux/uaccess.h>
9690
9691 #include <asm/emulated_ops.h>
9692 #include <asm/pgtable.h>
9693 @@ -142,6 +143,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
9694 return flags;
9695 }
9696
9697 +extern void gr_handle_kernel_exploit(void);
9698 +
9699 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
9700 int signr)
9701 {
9702 @@ -191,6 +194,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
9703 panic("Fatal exception in interrupt");
9704 if (panic_on_oops)
9705 panic("Fatal exception");
9706 +
9707 + gr_handle_kernel_exploit();
9708 +
9709 do_exit(signr);
9710 }
9711
9712 @@ -1137,6 +1143,26 @@ void __kprobes program_check_exception(struct pt_regs *regs)
9713 enum ctx_state prev_state = exception_enter();
9714 unsigned int reason = get_reason(regs);
9715
9716 +#ifdef CONFIG_PAX_REFCOUNT
9717 + unsigned int bkpt;
9718 + const struct exception_table_entry *entry;
9719 +
9720 + if (reason & REASON_ILLEGAL) {
9721 + /* Check if PaX bad instruction */
9722 + if (!probe_kernel_address(regs->nip, bkpt) && bkpt == 0xc00b00) {
9723 + current->thread.trap_nr = 0;
9724 + pax_report_refcount_overflow(regs);
9725 + /* fixup_exception() for PowerPC does not exist, simulate its job */
9726 + if ((entry = search_exception_tables(regs->nip)) != NULL) {
9727 + regs->nip = entry->fixup;
9728 + return;
9729 + }
9730 + /* fixup_exception() could not handle */
9731 + goto bail;
9732 + }
9733 + }
9734 +#endif
9735 +
9736 /* We can now get here via a FP Unavailable exception if the core
9737 * has no FPU, in that case the reason flags will be 0 */
9738
9739 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
9740 index f174351..5722009 100644
9741 --- a/arch/powerpc/kernel/vdso.c
9742 +++ b/arch/powerpc/kernel/vdso.c
9743 @@ -35,6 +35,7 @@
9744 #include <asm/vdso.h>
9745 #include <asm/vdso_datapage.h>
9746 #include <asm/setup.h>
9747 +#include <asm/mman.h>
9748
9749 #undef DEBUG
9750
9751 @@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
9752 vdso_base = VDSO32_MBASE;
9753 #endif
9754
9755 - current->mm->context.vdso_base = 0;
9756 + current->mm->context.vdso_base = ~0UL;
9757
9758 /* vDSO has a problem and was disabled, just don't "enable" it for the
9759 * process
9760 @@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
9761 vdso_base = get_unmapped_area(NULL, vdso_base,
9762 (vdso_pages << PAGE_SHIFT) +
9763 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
9764 - 0, 0);
9765 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
9766 if (IS_ERR_VALUE(vdso_base)) {
9767 rc = vdso_base;
9768 goto fail_mmapsem;
9769 diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
9770 index 4c79284..0e462c3 100644
9771 --- a/arch/powerpc/kvm/powerpc.c
9772 +++ b/arch/powerpc/kvm/powerpc.c
9773 @@ -1338,7 +1338,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
9774 }
9775 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
9776
9777 -int kvm_arch_init(void *opaque)
9778 +int kvm_arch_init(const void *opaque)
9779 {
9780 return 0;
9781 }
9782 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
9783 index 5eea6f3..5d10396 100644
9784 --- a/arch/powerpc/lib/usercopy_64.c
9785 +++ b/arch/powerpc/lib/usercopy_64.c
9786 @@ -9,22 +9,6 @@
9787 #include <linux/module.h>
9788 #include <asm/uaccess.h>
9789
9790 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9791 -{
9792 - if (likely(access_ok(VERIFY_READ, from, n)))
9793 - n = __copy_from_user(to, from, n);
9794 - else
9795 - memset(to, 0, n);
9796 - return n;
9797 -}
9798 -
9799 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9800 -{
9801 - if (likely(access_ok(VERIFY_WRITE, to, n)))
9802 - n = __copy_to_user(to, from, n);
9803 - return n;
9804 -}
9805 -
9806 unsigned long copy_in_user(void __user *to, const void __user *from,
9807 unsigned long n)
9808 {
9809 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
9810 return n;
9811 }
9812
9813 -EXPORT_SYMBOL(copy_from_user);
9814 -EXPORT_SYMBOL(copy_to_user);
9815 EXPORT_SYMBOL(copy_in_user);
9816
9817 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
9818 index 51ab9e7..7d3c78b 100644
9819 --- a/arch/powerpc/mm/fault.c
9820 +++ b/arch/powerpc/mm/fault.c
9821 @@ -33,6 +33,10 @@
9822 #include <linux/magic.h>
9823 #include <linux/ratelimit.h>
9824 #include <linux/context_tracking.h>
9825 +#include <linux/slab.h>
9826 +#include <linux/pagemap.h>
9827 +#include <linux/compiler.h>
9828 +#include <linux/unistd.h>
9829
9830 #include <asm/firmware.h>
9831 #include <asm/page.h>
9832 @@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
9833 }
9834 #endif
9835
9836 +#ifdef CONFIG_PAX_PAGEEXEC
9837 +/*
9838 + * PaX: decide what to do with offenders (regs->nip = fault address)
9839 + *
9840 + * returns 1 when task should be killed
9841 + */
9842 +static int pax_handle_fetch_fault(struct pt_regs *regs)
9843 +{
9844 + return 1;
9845 +}
9846 +
9847 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9848 +{
9849 + unsigned long i;
9850 +
9851 + printk(KERN_ERR "PAX: bytes at PC: ");
9852 + for (i = 0; i < 5; i++) {
9853 + unsigned int c;
9854 + if (get_user(c, (unsigned int __user *)pc+i))
9855 + printk(KERN_CONT "???????? ");
9856 + else
9857 + printk(KERN_CONT "%08x ", c);
9858 + }
9859 + printk("\n");
9860 +}
9861 +#endif
9862 +
9863 /*
9864 * Check whether the instruction at regs->nip is a store using
9865 * an update addressing form which will update r1.
9866 @@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
9867 * indicate errors in DSISR but can validly be set in SRR1.
9868 */
9869 if (trap == 0x400)
9870 - error_code &= 0x48200000;
9871 + error_code &= 0x58200000;
9872 else
9873 is_write = error_code & DSISR_ISSTORE;
9874 #else
9875 @@ -378,7 +409,7 @@ good_area:
9876 * "undefined". Of those that can be set, this is the only
9877 * one which seems bad.
9878 */
9879 - if (error_code & 0x10000000)
9880 + if (error_code & DSISR_GUARDED)
9881 /* Guarded storage error. */
9882 goto bad_area;
9883 #endif /* CONFIG_8xx */
9884 @@ -393,7 +424,7 @@ good_area:
9885 * processors use the same I/D cache coherency mechanism
9886 * as embedded.
9887 */
9888 - if (error_code & DSISR_PROTFAULT)
9889 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
9890 goto bad_area;
9891 #endif /* CONFIG_PPC_STD_MMU */
9892
9893 @@ -483,6 +514,23 @@ bad_area:
9894 bad_area_nosemaphore:
9895 /* User mode accesses cause a SIGSEGV */
9896 if (user_mode(regs)) {
9897 +
9898 +#ifdef CONFIG_PAX_PAGEEXEC
9899 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
9900 +#ifdef CONFIG_PPC_STD_MMU
9901 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
9902 +#else
9903 + if (is_exec && regs->nip == address) {
9904 +#endif
9905 + switch (pax_handle_fetch_fault(regs)) {
9906 + }
9907 +
9908 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
9909 + do_group_exit(SIGKILL);
9910 + }
9911 + }
9912 +#endif
9913 +
9914 _exception(SIGSEGV, regs, code, address);
9915 goto bail;
9916 }
9917 diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
9918 index cb8bdbe..cde4bc7 100644
9919 --- a/arch/powerpc/mm/mmap.c
9920 +++ b/arch/powerpc/mm/mmap.c
9921 @@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
9922 return sysctl_legacy_va_layout;
9923 }
9924
9925 -static unsigned long mmap_rnd(void)
9926 +static unsigned long mmap_rnd(struct mm_struct *mm)
9927 {
9928 unsigned long rnd = 0;
9929
9930 +#ifdef CONFIG_PAX_RANDMMAP
9931 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9932 +#endif
9933 +
9934 if (current->flags & PF_RANDOMIZE) {
9935 /* 8MB for 32bit, 1GB for 64bit */
9936 if (is_32bit_task())
9937 @@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
9938 return rnd << PAGE_SHIFT;
9939 }
9940
9941 -static inline unsigned long mmap_base(void)
9942 +static inline unsigned long mmap_base(struct mm_struct *mm)
9943 {
9944 unsigned long gap = rlimit(RLIMIT_STACK);
9945
9946 @@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
9947 else if (gap > MAX_GAP)
9948 gap = MAX_GAP;
9949
9950 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
9951 + return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
9952 }
9953
9954 /*
9955 @@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9956 */
9957 if (mmap_is_legacy()) {
9958 mm->mmap_base = TASK_UNMAPPED_BASE;
9959 +
9960 +#ifdef CONFIG_PAX_RANDMMAP
9961 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9962 + mm->mmap_base += mm->delta_mmap;
9963 +#endif
9964 +
9965 mm->get_unmapped_area = arch_get_unmapped_area;
9966 } else {
9967 - mm->mmap_base = mmap_base();
9968 + mm->mmap_base = mmap_base(mm);
9969 +
9970 +#ifdef CONFIG_PAX_RANDMMAP
9971 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9972 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9973 +#endif
9974 +
9975 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9976 }
9977 }
9978 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
9979 index b0c75cc..ef7fb93 100644
9980 --- a/arch/powerpc/mm/slice.c
9981 +++ b/arch/powerpc/mm/slice.c
9982 @@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
9983 if ((mm->task_size - len) < addr)
9984 return 0;
9985 vma = find_vma(mm, addr);
9986 - return (!vma || (addr + len) <= vma->vm_start);
9987 + return check_heap_stack_gap(vma, addr, len, 0);
9988 }
9989
9990 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
9991 @@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
9992 info.align_offset = 0;
9993
9994 addr = TASK_UNMAPPED_BASE;
9995 +
9996 +#ifdef CONFIG_PAX_RANDMMAP
9997 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9998 + addr += mm->delta_mmap;
9999 +#endif
10000 +
10001 while (addr < TASK_SIZE) {
10002 info.low_limit = addr;
10003 if (!slice_scan_available(addr, available, 1, &addr))
10004 @@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
10005 if (fixed && addr > (mm->task_size - len))
10006 return -ENOMEM;
10007
10008 +#ifdef CONFIG_PAX_RANDMMAP
10009 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
10010 + addr = 0;
10011 +#endif
10012 +
10013 /* If hint, make sure it matches our alignment restrictions */
10014 if (!fixed && addr) {
10015 addr = _ALIGN_UP(addr, 1ul << pshift);
10016 diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c
10017 index 3afa6f4..40c53ff 100644
10018 --- a/arch/powerpc/net/bpf_jit_comp.c
10019 +++ b/arch/powerpc/net/bpf_jit_comp.c
10020 @@ -697,5 +697,6 @@ void bpf_jit_free(struct bpf_prog *fp)
10021 {
10022 if (fp->jited)
10023 module_free(NULL, fp->bpf_func);
10024 - kfree(fp);
10025 +
10026 + bpf_prog_unlock_free(fp);
10027 }
10028 diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
10029 index 4278acf..67fd0e6 100644
10030 --- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
10031 +++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
10032 @@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
10033 }
10034
10035 static struct pci_ops scc_pciex_pci_ops = {
10036 - scc_pciex_read_config,
10037 - scc_pciex_write_config,
10038 + .read = scc_pciex_read_config,
10039 + .write = scc_pciex_write_config,
10040 };
10041
10042 static void pciex_clear_intr_all(unsigned int __iomem *base)
10043 diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
10044 index d966bbe..372124a 100644
10045 --- a/arch/powerpc/platforms/cell/spufs/file.c
10046 +++ b/arch/powerpc/platforms/cell/spufs/file.c
10047 @@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10048 return VM_FAULT_NOPAGE;
10049 }
10050
10051 -static int spufs_mem_mmap_access(struct vm_area_struct *vma,
10052 +static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
10053 unsigned long address,
10054 - void *buf, int len, int write)
10055 + void *buf, size_t len, int write)
10056 {
10057 struct spu_context *ctx = vma->vm_file->private_data;
10058 unsigned long offset = address - vma->vm_start;
10059 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
10060 index fa934fe..c296056 100644
10061 --- a/arch/s390/include/asm/atomic.h
10062 +++ b/arch/s390/include/asm/atomic.h
10063 @@ -412,4 +412,14 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
10064 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
10065 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10066
10067 +#define atomic64_read_unchecked(v) atomic64_read(v)
10068 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
10069 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
10070 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
10071 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
10072 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
10073 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
10074 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
10075 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
10076 +
10077 #endif /* __ARCH_S390_ATOMIC__ */
10078 diff --git a/arch/s390/include/asm/barrier.h b/arch/s390/include/asm/barrier.h
10079 index 19ff956..8d39cb1 100644
10080 --- a/arch/s390/include/asm/barrier.h
10081 +++ b/arch/s390/include/asm/barrier.h
10082 @@ -37,7 +37,7 @@
10083 do { \
10084 compiletime_assert_atomic_type(*p); \
10085 barrier(); \
10086 - ACCESS_ONCE(*p) = (v); \
10087 + ACCESS_ONCE_RW(*p) = (v); \
10088 } while (0)
10089
10090 #define smp_load_acquire(p) \
10091 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
10092 index 4d7ccac..d03d0ad 100644
10093 --- a/arch/s390/include/asm/cache.h
10094 +++ b/arch/s390/include/asm/cache.h
10095 @@ -9,8 +9,10 @@
10096 #ifndef __ARCH_S390_CACHE_H
10097 #define __ARCH_S390_CACHE_H
10098
10099 -#define L1_CACHE_BYTES 256
10100 +#include <linux/const.h>
10101 +
10102 #define L1_CACHE_SHIFT 8
10103 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10104 #define NET_SKB_PAD 32
10105
10106 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10107 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
10108 index 78f4f87..598ce39 100644
10109 --- a/arch/s390/include/asm/elf.h
10110 +++ b/arch/s390/include/asm/elf.h
10111 @@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
10112 the loader. We need to make sure that it is out of the way of the program
10113 that it will "exec", and that there is sufficient room for the brk. */
10114
10115 -extern unsigned long randomize_et_dyn(unsigned long base);
10116 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
10117 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
10118 +
10119 +#ifdef CONFIG_PAX_ASLR
10120 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
10121 +
10122 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
10123 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
10124 +#endif
10125
10126 /* This yields a mask that user programs can use to figure out what
10127 instruction set this CPU supports. */
10128 @@ -222,9 +228,6 @@ struct linux_binprm;
10129 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
10130 int arch_setup_additional_pages(struct linux_binprm *, int);
10131
10132 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10133 -#define arch_randomize_brk arch_randomize_brk
10134 -
10135 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
10136
10137 #endif
10138 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
10139 index c4a93d6..4d2a9b4 100644
10140 --- a/arch/s390/include/asm/exec.h
10141 +++ b/arch/s390/include/asm/exec.h
10142 @@ -7,6 +7,6 @@
10143 #ifndef __ASM_EXEC_H
10144 #define __ASM_EXEC_H
10145
10146 -extern unsigned long arch_align_stack(unsigned long sp);
10147 +#define arch_align_stack(x) ((x) & ~0xfUL)
10148
10149 #endif /* __ASM_EXEC_H */
10150 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
10151 index cd4c68e..6764641 100644
10152 --- a/arch/s390/include/asm/uaccess.h
10153 +++ b/arch/s390/include/asm/uaccess.h
10154 @@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
10155 __range_ok((unsigned long)(addr), (size)); \
10156 })
10157
10158 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
10159 #define access_ok(type, addr, size) __access_ok(addr, size)
10160
10161 /*
10162 @@ -275,6 +276,10 @@ static inline unsigned long __must_check
10163 copy_to_user(void __user *to, const void *from, unsigned long n)
10164 {
10165 might_fault();
10166 +
10167 + if ((long)n < 0)
10168 + return n;
10169 +
10170 return __copy_to_user(to, from, n);
10171 }
10172
10173 @@ -303,10 +308,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
10174 static inline unsigned long __must_check
10175 copy_from_user(void *to, const void __user *from, unsigned long n)
10176 {
10177 - unsigned int sz = __compiletime_object_size(to);
10178 + size_t sz = __compiletime_object_size(to);
10179
10180 might_fault();
10181 - if (unlikely(sz != -1 && sz < n)) {
10182 +
10183 + if ((long)n < 0)
10184 + return n;
10185 +
10186 + if (unlikely(sz != (size_t)-1 && sz < n)) {
10187 copy_from_user_overflow();
10188 return n;
10189 }
10190 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
10191 index b89b591..fd9609d 100644
10192 --- a/arch/s390/kernel/module.c
10193 +++ b/arch/s390/kernel/module.c
10194 @@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
10195
10196 /* Increase core size by size of got & plt and set start
10197 offsets for got and plt. */
10198 - me->core_size = ALIGN(me->core_size, 4);
10199 - me->arch.got_offset = me->core_size;
10200 - me->core_size += me->arch.got_size;
10201 - me->arch.plt_offset = me->core_size;
10202 - me->core_size += me->arch.plt_size;
10203 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
10204 + me->arch.got_offset = me->core_size_rw;
10205 + me->core_size_rw += me->arch.got_size;
10206 + me->arch.plt_offset = me->core_size_rx;
10207 + me->core_size_rx += me->arch.plt_size;
10208 return 0;
10209 }
10210
10211 @@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
10212 if (info->got_initialized == 0) {
10213 Elf_Addr *gotent;
10214
10215 - gotent = me->module_core + me->arch.got_offset +
10216 + gotent = me->module_core_rw + me->arch.got_offset +
10217 info->got_offset;
10218 *gotent = val;
10219 info->got_initialized = 1;
10220 @@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
10221 rc = apply_rela_bits(loc, val, 0, 64, 0);
10222 else if (r_type == R_390_GOTENT ||
10223 r_type == R_390_GOTPLTENT) {
10224 - val += (Elf_Addr) me->module_core - loc;
10225 + val += (Elf_Addr) me->module_core_rw - loc;
10226 rc = apply_rela_bits(loc, val, 1, 32, 1);
10227 }
10228 break;
10229 @@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
10230 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
10231 if (info->plt_initialized == 0) {
10232 unsigned int *ip;
10233 - ip = me->module_core + me->arch.plt_offset +
10234 + ip = me->module_core_rx + me->arch.plt_offset +
10235 info->plt_offset;
10236 #ifndef CONFIG_64BIT
10237 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
10238 @@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
10239 val - loc + 0xffffUL < 0x1ffffeUL) ||
10240 (r_type == R_390_PLT32DBL &&
10241 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
10242 - val = (Elf_Addr) me->module_core +
10243 + val = (Elf_Addr) me->module_core_rx +
10244 me->arch.plt_offset +
10245 info->plt_offset;
10246 val += rela->r_addend - loc;
10247 @@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
10248 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
10249 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
10250 val = val + rela->r_addend -
10251 - ((Elf_Addr) me->module_core + me->arch.got_offset);
10252 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
10253 if (r_type == R_390_GOTOFF16)
10254 rc = apply_rela_bits(loc, val, 0, 16, 0);
10255 else if (r_type == R_390_GOTOFF32)
10256 @@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
10257 break;
10258 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
10259 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
10260 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
10261 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
10262 rela->r_addend - loc;
10263 if (r_type == R_390_GOTPC)
10264 rc = apply_rela_bits(loc, val, 1, 32, 0);
10265 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
10266 index 93b9ca4..4ea1454 100644
10267 --- a/arch/s390/kernel/process.c
10268 +++ b/arch/s390/kernel/process.c
10269 @@ -242,37 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
10270 }
10271 return 0;
10272 }
10273 -
10274 -unsigned long arch_align_stack(unsigned long sp)
10275 -{
10276 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
10277 - sp -= get_random_int() & ~PAGE_MASK;
10278 - return sp & ~0xf;
10279 -}
10280 -
10281 -static inline unsigned long brk_rnd(void)
10282 -{
10283 - /* 8MB for 32bit, 1GB for 64bit */
10284 - if (is_32bit_task())
10285 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
10286 - else
10287 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
10288 -}
10289 -
10290 -unsigned long arch_randomize_brk(struct mm_struct *mm)
10291 -{
10292 - unsigned long ret;
10293 -
10294 - ret = PAGE_ALIGN(mm->brk + brk_rnd());
10295 - return (ret > mm->brk) ? ret : mm->brk;
10296 -}
10297 -
10298 -unsigned long randomize_et_dyn(unsigned long base)
10299 -{
10300 - unsigned long ret;
10301 -
10302 - if (!(current->flags & PF_RANDOMIZE))
10303 - return base;
10304 - ret = PAGE_ALIGN(base + brk_rnd());
10305 - return (ret > base) ? ret : base;
10306 -}
10307 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
10308 index 9b436c2..54fbf0a 100644
10309 --- a/arch/s390/mm/mmap.c
10310 +++ b/arch/s390/mm/mmap.c
10311 @@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10312 */
10313 if (mmap_is_legacy()) {
10314 mm->mmap_base = mmap_base_legacy();
10315 +
10316 +#ifdef CONFIG_PAX_RANDMMAP
10317 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10318 + mm->mmap_base += mm->delta_mmap;
10319 +#endif
10320 +
10321 mm->get_unmapped_area = arch_get_unmapped_area;
10322 } else {
10323 mm->mmap_base = mmap_base();
10324 +
10325 +#ifdef CONFIG_PAX_RANDMMAP
10326 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10327 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10328 +#endif
10329 +
10330 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10331 }
10332 }
10333 @@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10334 */
10335 if (mmap_is_legacy()) {
10336 mm->mmap_base = mmap_base_legacy();
10337 +
10338 +#ifdef CONFIG_PAX_RANDMMAP
10339 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10340 + mm->mmap_base += mm->delta_mmap;
10341 +#endif
10342 +
10343 mm->get_unmapped_area = s390_get_unmapped_area;
10344 } else {
10345 mm->mmap_base = mmap_base();
10346 +
10347 +#ifdef CONFIG_PAX_RANDMMAP
10348 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10349 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10350 +#endif
10351 +
10352 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
10353 }
10354 }
10355 diff --git a/arch/s390/net/bpf_jit_comp.c b/arch/s390/net/bpf_jit_comp.c
10356 index 61e45b7..f2833c5 100644
10357 --- a/arch/s390/net/bpf_jit_comp.c
10358 +++ b/arch/s390/net/bpf_jit_comp.c
10359 @@ -887,5 +887,5 @@ void bpf_jit_free(struct bpf_prog *fp)
10360 module_free(NULL, header);
10361
10362 free_filter:
10363 - kfree(fp);
10364 + bpf_prog_unlock_free(fp);
10365 }
10366 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
10367 index ae3d59f..f65f075 100644
10368 --- a/arch/score/include/asm/cache.h
10369 +++ b/arch/score/include/asm/cache.h
10370 @@ -1,7 +1,9 @@
10371 #ifndef _ASM_SCORE_CACHE_H
10372 #define _ASM_SCORE_CACHE_H
10373
10374 +#include <linux/const.h>
10375 +
10376 #define L1_CACHE_SHIFT 4
10377 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10378 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10379
10380 #endif /* _ASM_SCORE_CACHE_H */
10381 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
10382 index f9f3cd5..58ff438 100644
10383 --- a/arch/score/include/asm/exec.h
10384 +++ b/arch/score/include/asm/exec.h
10385 @@ -1,6 +1,6 @@
10386 #ifndef _ASM_SCORE_EXEC_H
10387 #define _ASM_SCORE_EXEC_H
10388
10389 -extern unsigned long arch_align_stack(unsigned long sp);
10390 +#define arch_align_stack(x) (x)
10391
10392 #endif /* _ASM_SCORE_EXEC_H */
10393 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
10394 index a1519ad3..e8ac1ff 100644
10395 --- a/arch/score/kernel/process.c
10396 +++ b/arch/score/kernel/process.c
10397 @@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
10398
10399 return task_pt_regs(task)->cp0_epc;
10400 }
10401 -
10402 -unsigned long arch_align_stack(unsigned long sp)
10403 -{
10404 - return sp;
10405 -}
10406 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
10407 index ef9e555..331bd29 100644
10408 --- a/arch/sh/include/asm/cache.h
10409 +++ b/arch/sh/include/asm/cache.h
10410 @@ -9,10 +9,11 @@
10411 #define __ASM_SH_CACHE_H
10412 #ifdef __KERNEL__
10413
10414 +#include <linux/const.h>
10415 #include <linux/init.h>
10416 #include <cpu/cache.h>
10417
10418 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10419 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10420
10421 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10422
10423 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
10424 index 6777177..cb5e44f 100644
10425 --- a/arch/sh/mm/mmap.c
10426 +++ b/arch/sh/mm/mmap.c
10427 @@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
10428 struct mm_struct *mm = current->mm;
10429 struct vm_area_struct *vma;
10430 int do_colour_align;
10431 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10432 struct vm_unmapped_area_info info;
10433
10434 if (flags & MAP_FIXED) {
10435 @@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
10436 if (filp || (flags & MAP_SHARED))
10437 do_colour_align = 1;
10438
10439 +#ifdef CONFIG_PAX_RANDMMAP
10440 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10441 +#endif
10442 +
10443 if (addr) {
10444 if (do_colour_align)
10445 addr = COLOUR_ALIGN(addr, pgoff);
10446 @@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
10447 addr = PAGE_ALIGN(addr);
10448
10449 vma = find_vma(mm, addr);
10450 - if (TASK_SIZE - len >= addr &&
10451 - (!vma || addr + len <= vma->vm_start))
10452 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10453 return addr;
10454 }
10455
10456 info.flags = 0;
10457 info.length = len;
10458 - info.low_limit = TASK_UNMAPPED_BASE;
10459 + info.low_limit = mm->mmap_base;
10460 info.high_limit = TASK_SIZE;
10461 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
10462 info.align_offset = pgoff << PAGE_SHIFT;
10463 @@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10464 struct mm_struct *mm = current->mm;
10465 unsigned long addr = addr0;
10466 int do_colour_align;
10467 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10468 struct vm_unmapped_area_info info;
10469
10470 if (flags & MAP_FIXED) {
10471 @@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10472 if (filp || (flags & MAP_SHARED))
10473 do_colour_align = 1;
10474
10475 +#ifdef CONFIG_PAX_RANDMMAP
10476 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10477 +#endif
10478 +
10479 /* requesting a specific address */
10480 if (addr) {
10481 if (do_colour_align)
10482 @@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10483 addr = PAGE_ALIGN(addr);
10484
10485 vma = find_vma(mm, addr);
10486 - if (TASK_SIZE - len >= addr &&
10487 - (!vma || addr + len <= vma->vm_start))
10488 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10489 return addr;
10490 }
10491
10492 @@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10493 VM_BUG_ON(addr != -ENOMEM);
10494 info.flags = 0;
10495 info.low_limit = TASK_UNMAPPED_BASE;
10496 +
10497 +#ifdef CONFIG_PAX_RANDMMAP
10498 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10499 + info.low_limit += mm->delta_mmap;
10500 +#endif
10501 +
10502 info.high_limit = TASK_SIZE;
10503 addr = vm_unmapped_area(&info);
10504 }
10505 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
10506 index bb894c8..8141d5c 100644
10507 --- a/arch/sparc/include/asm/atomic_64.h
10508 +++ b/arch/sparc/include/asm/atomic_64.h
10509 @@ -15,18 +15,40 @@
10510 #define ATOMIC64_INIT(i) { (i) }
10511
10512 #define atomic_read(v) (*(volatile int *)&(v)->counter)
10513 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
10514 +{
10515 + return v->counter;
10516 +}
10517 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
10518 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
10519 +{
10520 + return v->counter;
10521 +}
10522
10523 #define atomic_set(v, i) (((v)->counter) = i)
10524 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
10525 +{
10526 + v->counter = i;
10527 +}
10528 #define atomic64_set(v, i) (((v)->counter) = i)
10529 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
10530 +{
10531 + v->counter = i;
10532 +}
10533
10534 void atomic_add(int, atomic_t *);
10535 +void atomic_add_unchecked(int, atomic_unchecked_t *);
10536 void atomic64_add(long, atomic64_t *);
10537 +void atomic64_add_unchecked(long, atomic64_unchecked_t *);
10538 void atomic_sub(int, atomic_t *);
10539 +void atomic_sub_unchecked(int, atomic_unchecked_t *);
10540 void atomic64_sub(long, atomic64_t *);
10541 +void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
10542
10543 int atomic_add_ret(int, atomic_t *);
10544 +int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
10545 long atomic64_add_ret(long, atomic64_t *);
10546 +long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
10547 int atomic_sub_ret(int, atomic_t *);
10548 long atomic64_sub_ret(long, atomic64_t *);
10549
10550 @@ -34,13 +56,29 @@ long atomic64_sub_ret(long, atomic64_t *);
10551 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
10552
10553 #define atomic_inc_return(v) atomic_add_ret(1, v)
10554 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
10555 +{
10556 + return atomic_add_ret_unchecked(1, v);
10557 +}
10558 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
10559 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10560 +{
10561 + return atomic64_add_ret_unchecked(1, v);
10562 +}
10563
10564 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
10565 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
10566
10567 #define atomic_add_return(i, v) atomic_add_ret(i, v)
10568 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
10569 +{
10570 + return atomic_add_ret_unchecked(i, v);
10571 +}
10572 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
10573 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
10574 +{
10575 + return atomic64_add_ret_unchecked(i, v);
10576 +}
10577
10578 /*
10579 * atomic_inc_and_test - increment and test
10580 @@ -51,6 +89,10 @@ long atomic64_sub_ret(long, atomic64_t *);
10581 * other cases.
10582 */
10583 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
10584 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
10585 +{
10586 + return atomic_inc_return_unchecked(v) == 0;
10587 +}
10588 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
10589
10590 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
10591 @@ -60,25 +102,60 @@ long atomic64_sub_ret(long, atomic64_t *);
10592 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
10593
10594 #define atomic_inc(v) atomic_add(1, v)
10595 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
10596 +{
10597 + atomic_add_unchecked(1, v);
10598 +}
10599 #define atomic64_inc(v) atomic64_add(1, v)
10600 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
10601 +{
10602 + atomic64_add_unchecked(1, v);
10603 +}
10604
10605 #define atomic_dec(v) atomic_sub(1, v)
10606 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
10607 +{
10608 + atomic_sub_unchecked(1, v);
10609 +}
10610 #define atomic64_dec(v) atomic64_sub(1, v)
10611 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
10612 +{
10613 + atomic64_sub_unchecked(1, v);
10614 +}
10615
10616 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
10617 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
10618
10619 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
10620 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
10621 +{
10622 + return cmpxchg(&v->counter, old, new);
10623 +}
10624 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
10625 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
10626 +{
10627 + return xchg(&v->counter, new);
10628 +}
10629
10630 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10631 {
10632 - int c, old;
10633 + int c, old, new;
10634 c = atomic_read(v);
10635 for (;;) {
10636 - if (unlikely(c == (u)))
10637 + if (unlikely(c == u))
10638 break;
10639 - old = atomic_cmpxchg((v), c, c + (a));
10640 +
10641 + asm volatile("addcc %2, %0, %0\n"
10642 +
10643 +#ifdef CONFIG_PAX_REFCOUNT
10644 + "tvs %%icc, 6\n"
10645 +#endif
10646 +
10647 + : "=r" (new)
10648 + : "0" (c), "ir" (a)
10649 + : "cc");
10650 +
10651 + old = atomic_cmpxchg(v, c, new);
10652 if (likely(old == c))
10653 break;
10654 c = old;
10655 @@ -89,20 +166,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10656 #define atomic64_cmpxchg(v, o, n) \
10657 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
10658 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
10659 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
10660 +{
10661 + return xchg(&v->counter, new);
10662 +}
10663
10664 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
10665 {
10666 - long c, old;
10667 + long c, old, new;
10668 c = atomic64_read(v);
10669 for (;;) {
10670 - if (unlikely(c == (u)))
10671 + if (unlikely(c == u))
10672 break;
10673 - old = atomic64_cmpxchg((v), c, c + (a));
10674 +
10675 + asm volatile("addcc %2, %0, %0\n"
10676 +
10677 +#ifdef CONFIG_PAX_REFCOUNT
10678 + "tvs %%xcc, 6\n"
10679 +#endif
10680 +
10681 + : "=r" (new)
10682 + : "0" (c), "ir" (a)
10683 + : "cc");
10684 +
10685 + old = atomic64_cmpxchg(v, c, new);
10686 if (likely(old == c))
10687 break;
10688 c = old;
10689 }
10690 - return c != (u);
10691 + return c != u;
10692 }
10693
10694 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10695 diff --git a/arch/sparc/include/asm/barrier_64.h b/arch/sparc/include/asm/barrier_64.h
10696 index 305dcc3..7835030 100644
10697 --- a/arch/sparc/include/asm/barrier_64.h
10698 +++ b/arch/sparc/include/asm/barrier_64.h
10699 @@ -57,7 +57,7 @@ do { __asm__ __volatile__("ba,pt %%xcc, 1f\n\t" \
10700 do { \
10701 compiletime_assert_atomic_type(*p); \
10702 barrier(); \
10703 - ACCESS_ONCE(*p) = (v); \
10704 + ACCESS_ONCE_RW(*p) = (v); \
10705 } while (0)
10706
10707 #define smp_load_acquire(p) \
10708 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
10709 index 5bb6991..5c2132e 100644
10710 --- a/arch/sparc/include/asm/cache.h
10711 +++ b/arch/sparc/include/asm/cache.h
10712 @@ -7,10 +7,12 @@
10713 #ifndef _SPARC_CACHE_H
10714 #define _SPARC_CACHE_H
10715
10716 +#include <linux/const.h>
10717 +
10718 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
10719
10720 #define L1_CACHE_SHIFT 5
10721 -#define L1_CACHE_BYTES 32
10722 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10723
10724 #ifdef CONFIG_SPARC32
10725 #define SMP_CACHE_BYTES_SHIFT 5
10726 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
10727 index a24e41f..47677ff 100644
10728 --- a/arch/sparc/include/asm/elf_32.h
10729 +++ b/arch/sparc/include/asm/elf_32.h
10730 @@ -114,6 +114,13 @@ typedef struct {
10731
10732 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
10733
10734 +#ifdef CONFIG_PAX_ASLR
10735 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
10736 +
10737 +#define PAX_DELTA_MMAP_LEN 16
10738 +#define PAX_DELTA_STACK_LEN 16
10739 +#endif
10740 +
10741 /* This yields a mask that user programs can use to figure out what
10742 instruction set this cpu supports. This can NOT be done in userspace
10743 on Sparc. */
10744 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
10745 index 370ca1e..d4f4a98 100644
10746 --- a/arch/sparc/include/asm/elf_64.h
10747 +++ b/arch/sparc/include/asm/elf_64.h
10748 @@ -189,6 +189,13 @@ typedef struct {
10749 #define ELF_ET_DYN_BASE 0x0000010000000000UL
10750 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
10751
10752 +#ifdef CONFIG_PAX_ASLR
10753 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
10754 +
10755 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
10756 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
10757 +#endif
10758 +
10759 extern unsigned long sparc64_elf_hwcap;
10760 #define ELF_HWCAP sparc64_elf_hwcap
10761
10762 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
10763 index a3890da..f6a408e 100644
10764 --- a/arch/sparc/include/asm/pgalloc_32.h
10765 +++ b/arch/sparc/include/asm/pgalloc_32.h
10766 @@ -35,6 +35,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
10767 }
10768
10769 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
10770 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
10771
10772 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
10773 unsigned long address)
10774 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
10775 index 5e31871..b71c9d7 100644
10776 --- a/arch/sparc/include/asm/pgalloc_64.h
10777 +++ b/arch/sparc/include/asm/pgalloc_64.h
10778 @@ -38,6 +38,7 @@ static inline void __pud_populate(pud_t *pud, pmd_t *pmd)
10779 }
10780
10781 #define pud_populate(MM, PUD, PMD) __pud_populate(PUD, PMD)
10782 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
10783
10784 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
10785 {
10786 diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
10787 index 59ba6f6..4518128 100644
10788 --- a/arch/sparc/include/asm/pgtable.h
10789 +++ b/arch/sparc/include/asm/pgtable.h
10790 @@ -5,4 +5,8 @@
10791 #else
10792 #include <asm/pgtable_32.h>
10793 #endif
10794 +
10795 +#define ktla_ktva(addr) (addr)
10796 +#define ktva_ktla(addr) (addr)
10797 +
10798 #endif
10799 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
10800 index b9b91ae..950b91e 100644
10801 --- a/arch/sparc/include/asm/pgtable_32.h
10802 +++ b/arch/sparc/include/asm/pgtable_32.h
10803 @@ -51,6 +51,9 @@ unsigned long __init bootmem_init(unsigned long *pages_avail);
10804 #define PAGE_SHARED SRMMU_PAGE_SHARED
10805 #define PAGE_COPY SRMMU_PAGE_COPY
10806 #define PAGE_READONLY SRMMU_PAGE_RDONLY
10807 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
10808 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
10809 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
10810 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
10811
10812 /* Top-level page directory - dummy used by init-mm.
10813 @@ -63,18 +66,18 @@ extern unsigned long ptr_in_current_pgd;
10814
10815 /* xwr */
10816 #define __P000 PAGE_NONE
10817 -#define __P001 PAGE_READONLY
10818 -#define __P010 PAGE_COPY
10819 -#define __P011 PAGE_COPY
10820 +#define __P001 PAGE_READONLY_NOEXEC
10821 +#define __P010 PAGE_COPY_NOEXEC
10822 +#define __P011 PAGE_COPY_NOEXEC
10823 #define __P100 PAGE_READONLY
10824 #define __P101 PAGE_READONLY
10825 #define __P110 PAGE_COPY
10826 #define __P111 PAGE_COPY
10827
10828 #define __S000 PAGE_NONE
10829 -#define __S001 PAGE_READONLY
10830 -#define __S010 PAGE_SHARED
10831 -#define __S011 PAGE_SHARED
10832 +#define __S001 PAGE_READONLY_NOEXEC
10833 +#define __S010 PAGE_SHARED_NOEXEC
10834 +#define __S011 PAGE_SHARED_NOEXEC
10835 #define __S100 PAGE_READONLY
10836 #define __S101 PAGE_READONLY
10837 #define __S110 PAGE_SHARED
10838 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
10839 index 79da178..c2eede8 100644
10840 --- a/arch/sparc/include/asm/pgtsrmmu.h
10841 +++ b/arch/sparc/include/asm/pgtsrmmu.h
10842 @@ -115,6 +115,11 @@
10843 SRMMU_EXEC | SRMMU_REF)
10844 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
10845 SRMMU_EXEC | SRMMU_REF)
10846 +
10847 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
10848 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10849 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10850 +
10851 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
10852 SRMMU_DIRTY | SRMMU_REF)
10853
10854 diff --git a/arch/sparc/include/asm/setup.h b/arch/sparc/include/asm/setup.h
10855 index 29d64b1..4272fe8 100644
10856 --- a/arch/sparc/include/asm/setup.h
10857 +++ b/arch/sparc/include/asm/setup.h
10858 @@ -55,8 +55,8 @@ int handle_ldf_stq(u32 insn, struct pt_regs *regs);
10859 void handle_ld_nf(u32 insn, struct pt_regs *regs);
10860
10861 /* init_64.c */
10862 -extern atomic_t dcpage_flushes;
10863 -extern atomic_t dcpage_flushes_xcall;
10864 +extern atomic_unchecked_t dcpage_flushes;
10865 +extern atomic_unchecked_t dcpage_flushes_xcall;
10866
10867 extern int sysctl_tsb_ratio;
10868 #endif
10869 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
10870 index 9689176..63c18ea 100644
10871 --- a/arch/sparc/include/asm/spinlock_64.h
10872 +++ b/arch/sparc/include/asm/spinlock_64.h
10873 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
10874
10875 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
10876
10877 -static void inline arch_read_lock(arch_rwlock_t *lock)
10878 +static inline void arch_read_lock(arch_rwlock_t *lock)
10879 {
10880 unsigned long tmp1, tmp2;
10881
10882 __asm__ __volatile__ (
10883 "1: ldsw [%2], %0\n"
10884 " brlz,pn %0, 2f\n"
10885 -"4: add %0, 1, %1\n"
10886 +"4: addcc %0, 1, %1\n"
10887 +
10888 +#ifdef CONFIG_PAX_REFCOUNT
10889 +" tvs %%icc, 6\n"
10890 +#endif
10891 +
10892 " cas [%2], %0, %1\n"
10893 " cmp %0, %1\n"
10894 " bne,pn %%icc, 1b\n"
10895 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
10896 " .previous"
10897 : "=&r" (tmp1), "=&r" (tmp2)
10898 : "r" (lock)
10899 - : "memory");
10900 + : "memory", "cc");
10901 }
10902
10903 -static int inline arch_read_trylock(arch_rwlock_t *lock)
10904 +static inline int arch_read_trylock(arch_rwlock_t *lock)
10905 {
10906 int tmp1, tmp2;
10907
10908 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10909 "1: ldsw [%2], %0\n"
10910 " brlz,a,pn %0, 2f\n"
10911 " mov 0, %0\n"
10912 -" add %0, 1, %1\n"
10913 +" addcc %0, 1, %1\n"
10914 +
10915 +#ifdef CONFIG_PAX_REFCOUNT
10916 +" tvs %%icc, 6\n"
10917 +#endif
10918 +
10919 " cas [%2], %0, %1\n"
10920 " cmp %0, %1\n"
10921 " bne,pn %%icc, 1b\n"
10922 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10923 return tmp1;
10924 }
10925
10926 -static void inline arch_read_unlock(arch_rwlock_t *lock)
10927 +static inline void arch_read_unlock(arch_rwlock_t *lock)
10928 {
10929 unsigned long tmp1, tmp2;
10930
10931 __asm__ __volatile__(
10932 "1: lduw [%2], %0\n"
10933 -" sub %0, 1, %1\n"
10934 +" subcc %0, 1, %1\n"
10935 +
10936 +#ifdef CONFIG_PAX_REFCOUNT
10937 +" tvs %%icc, 6\n"
10938 +#endif
10939 +
10940 " cas [%2], %0, %1\n"
10941 " cmp %0, %1\n"
10942 " bne,pn %%xcc, 1b\n"
10943 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
10944 : "memory");
10945 }
10946
10947 -static void inline arch_write_lock(arch_rwlock_t *lock)
10948 +static inline void arch_write_lock(arch_rwlock_t *lock)
10949 {
10950 unsigned long mask, tmp1, tmp2;
10951
10952 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
10953 : "memory");
10954 }
10955
10956 -static void inline arch_write_unlock(arch_rwlock_t *lock)
10957 +static inline void arch_write_unlock(arch_rwlock_t *lock)
10958 {
10959 __asm__ __volatile__(
10960 " stw %%g0, [%0]"
10961 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
10962 : "memory");
10963 }
10964
10965 -static int inline arch_write_trylock(arch_rwlock_t *lock)
10966 +static inline int arch_write_trylock(arch_rwlock_t *lock)
10967 {
10968 unsigned long mask, tmp1, tmp2, result;
10969
10970 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
10971 index 96efa7a..16858bf 100644
10972 --- a/arch/sparc/include/asm/thread_info_32.h
10973 +++ b/arch/sparc/include/asm/thread_info_32.h
10974 @@ -49,6 +49,8 @@ struct thread_info {
10975 unsigned long w_saved;
10976
10977 struct restart_block restart_block;
10978 +
10979 + unsigned long lowest_stack;
10980 };
10981
10982 /*
10983 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
10984 index cc6275c..7eb8e21 100644
10985 --- a/arch/sparc/include/asm/thread_info_64.h
10986 +++ b/arch/sparc/include/asm/thread_info_64.h
10987 @@ -63,6 +63,8 @@ struct thread_info {
10988 struct pt_regs *kern_una_regs;
10989 unsigned int kern_una_insn;
10990
10991 + unsigned long lowest_stack;
10992 +
10993 unsigned long fpregs[(7 * 256) / sizeof(unsigned long)]
10994 __attribute__ ((aligned(64)));
10995 };
10996 @@ -190,12 +192,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
10997 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
10998 /* flag bit 4 is available */
10999 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
11000 -/* flag bit 6 is available */
11001 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
11002 #define TIF_32BIT 7 /* 32-bit binary */
11003 #define TIF_NOHZ 8 /* in adaptive nohz mode */
11004 #define TIF_SECCOMP 9 /* secure computing */
11005 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
11006 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
11007 +
11008 /* NOTE: Thread flags >= 12 should be ones we have no interest
11009 * in using in assembly, else we can't use the mask as
11010 * an immediate value in instructions such as andcc.
11011 @@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
11012 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
11013 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
11014 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
11015 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
11016
11017 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
11018 _TIF_DO_NOTIFY_RESUME_MASK | \
11019 _TIF_NEED_RESCHED)
11020 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
11021
11022 +#define _TIF_WORK_SYSCALL \
11023 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
11024 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
11025 +
11026 +
11027 /*
11028 * Thread-synchronous status.
11029 *
11030 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
11031 index bd56c28..4b63d83 100644
11032 --- a/arch/sparc/include/asm/uaccess.h
11033 +++ b/arch/sparc/include/asm/uaccess.h
11034 @@ -1,5 +1,6 @@
11035 #ifndef ___ASM_SPARC_UACCESS_H
11036 #define ___ASM_SPARC_UACCESS_H
11037 +
11038 #if defined(__sparc__) && defined(__arch64__)
11039 #include <asm/uaccess_64.h>
11040 #else
11041 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
11042 index 9634d08..f55fe4f 100644
11043 --- a/arch/sparc/include/asm/uaccess_32.h
11044 +++ b/arch/sparc/include/asm/uaccess_32.h
11045 @@ -250,27 +250,46 @@ unsigned long __copy_user(void __user *to, const void __user *from, unsigned lon
11046
11047 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
11048 {
11049 - if (n && __access_ok((unsigned long) to, n))
11050 + if ((long)n < 0)
11051 + return n;
11052 +
11053 + if (n && __access_ok((unsigned long) to, n)) {
11054 + if (!__builtin_constant_p(n))
11055 + check_object_size(from, n, true);
11056 return __copy_user(to, (__force void __user *) from, n);
11057 - else
11058 + } else
11059 return n;
11060 }
11061
11062 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
11063 {
11064 + if ((long)n < 0)
11065 + return n;
11066 +
11067 + if (!__builtin_constant_p(n))
11068 + check_object_size(from, n, true);
11069 +
11070 return __copy_user(to, (__force void __user *) from, n);
11071 }
11072
11073 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
11074 {
11075 - if (n && __access_ok((unsigned long) from, n))
11076 + if ((long)n < 0)
11077 + return n;
11078 +
11079 + if (n && __access_ok((unsigned long) from, n)) {
11080 + if (!__builtin_constant_p(n))
11081 + check_object_size(to, n, false);
11082 return __copy_user((__force void __user *) to, from, n);
11083 - else
11084 + } else
11085 return n;
11086 }
11087
11088 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
11089 {
11090 + if ((long)n < 0)
11091 + return n;
11092 +
11093 return __copy_user((__force void __user *) to, from, n);
11094 }
11095
11096 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
11097 index c990a5e..f17b9c1 100644
11098 --- a/arch/sparc/include/asm/uaccess_64.h
11099 +++ b/arch/sparc/include/asm/uaccess_64.h
11100 @@ -10,6 +10,7 @@
11101 #include <linux/compiler.h>
11102 #include <linux/string.h>
11103 #include <linux/thread_info.h>
11104 +#include <linux/kernel.h>
11105 #include <asm/asi.h>
11106 #include <asm/spitfire.h>
11107 #include <asm-generic/uaccess-unaligned.h>
11108 @@ -214,8 +215,15 @@ unsigned long copy_from_user_fixup(void *to, const void __user *from,
11109 static inline unsigned long __must_check
11110 copy_from_user(void *to, const void __user *from, unsigned long size)
11111 {
11112 - unsigned long ret = ___copy_from_user(to, from, size);
11113 + unsigned long ret;
11114
11115 + if ((long)size < 0 || size > INT_MAX)
11116 + return size;
11117 +
11118 + if (!__builtin_constant_p(size))
11119 + check_object_size(to, size, false);
11120 +
11121 + ret = ___copy_from_user(to, from, size);
11122 if (unlikely(ret))
11123 ret = copy_from_user_fixup(to, from, size);
11124
11125 @@ -231,8 +239,15 @@ unsigned long copy_to_user_fixup(void __user *to, const void *from,
11126 static inline unsigned long __must_check
11127 copy_to_user(void __user *to, const void *from, unsigned long size)
11128 {
11129 - unsigned long ret = ___copy_to_user(to, from, size);
11130 + unsigned long ret;
11131
11132 + if ((long)size < 0 || size > INT_MAX)
11133 + return size;
11134 +
11135 + if (!__builtin_constant_p(size))
11136 + check_object_size(from, size, true);
11137 +
11138 + ret = ___copy_to_user(to, from, size);
11139 if (unlikely(ret))
11140 ret = copy_to_user_fixup(to, from, size);
11141 return ret;
11142 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
11143 index 7cf9c6e..6206648 100644
11144 --- a/arch/sparc/kernel/Makefile
11145 +++ b/arch/sparc/kernel/Makefile
11146 @@ -4,7 +4,7 @@
11147 #
11148
11149 asflags-y := -ansi
11150 -ccflags-y := -Werror
11151 +#ccflags-y := -Werror
11152
11153 extra-y := head_$(BITS).o
11154
11155 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
11156 index 50e7b62..79fae35 100644
11157 --- a/arch/sparc/kernel/process_32.c
11158 +++ b/arch/sparc/kernel/process_32.c
11159 @@ -123,14 +123,14 @@ void show_regs(struct pt_regs *r)
11160
11161 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
11162 r->psr, r->pc, r->npc, r->y, print_tainted());
11163 - printk("PC: <%pS>\n", (void *) r->pc);
11164 + printk("PC: <%pA>\n", (void *) r->pc);
11165 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
11166 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
11167 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
11168 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
11169 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
11170 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
11171 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
11172 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
11173
11174 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
11175 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
11176 @@ -167,7 +167,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
11177 rw = (struct reg_window32 *) fp;
11178 pc = rw->ins[7];
11179 printk("[%08lx : ", pc);
11180 - printk("%pS ] ", (void *) pc);
11181 + printk("%pA ] ", (void *) pc);
11182 fp = rw->ins[6];
11183 } while (++count < 16);
11184 printk("\n");
11185 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
11186 index 0be7bf9..2b1cba8 100644
11187 --- a/arch/sparc/kernel/process_64.c
11188 +++ b/arch/sparc/kernel/process_64.c
11189 @@ -161,7 +161,7 @@ static void show_regwindow(struct pt_regs *regs)
11190 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
11191 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
11192 if (regs->tstate & TSTATE_PRIV)
11193 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
11194 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
11195 }
11196
11197 void show_regs(struct pt_regs *regs)
11198 @@ -170,7 +170,7 @@ void show_regs(struct pt_regs *regs)
11199
11200 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
11201 regs->tpc, regs->tnpc, regs->y, print_tainted());
11202 - printk("TPC: <%pS>\n", (void *) regs->tpc);
11203 + printk("TPC: <%pA>\n", (void *) regs->tpc);
11204 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
11205 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
11206 regs->u_regs[3]);
11207 @@ -183,7 +183,7 @@ void show_regs(struct pt_regs *regs)
11208 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
11209 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
11210 regs->u_regs[15]);
11211 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
11212 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
11213 show_regwindow(regs);
11214 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
11215 }
11216 @@ -278,7 +278,7 @@ void arch_trigger_all_cpu_backtrace(bool include_self)
11217 ((tp && tp->task) ? tp->task->pid : -1));
11218
11219 if (gp->tstate & TSTATE_PRIV) {
11220 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
11221 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
11222 (void *) gp->tpc,
11223 (void *) gp->o7,
11224 (void *) gp->i7,
11225 diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
11226 index 79cc0d1..ec62734 100644
11227 --- a/arch/sparc/kernel/prom_common.c
11228 +++ b/arch/sparc/kernel/prom_common.c
11229 @@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
11230
11231 unsigned int prom_early_allocated __initdata;
11232
11233 -static struct of_pdt_ops prom_sparc_ops __initdata = {
11234 +static struct of_pdt_ops prom_sparc_ops __initconst = {
11235 .nextprop = prom_common_nextprop,
11236 .getproplen = prom_getproplen,
11237 .getproperty = prom_getproperty,
11238 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
11239 index c13c9f2..d572c34 100644
11240 --- a/arch/sparc/kernel/ptrace_64.c
11241 +++ b/arch/sparc/kernel/ptrace_64.c
11242 @@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
11243 return ret;
11244 }
11245
11246 +#ifdef CONFIG_GRKERNSEC_SETXID
11247 +extern void gr_delayed_cred_worker(void);
11248 +#endif
11249 +
11250 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
11251 {
11252 int ret = 0;
11253 @@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
11254 if (test_thread_flag(TIF_NOHZ))
11255 user_exit();
11256
11257 +#ifdef CONFIG_GRKERNSEC_SETXID
11258 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
11259 + gr_delayed_cred_worker();
11260 +#endif
11261 +
11262 if (test_thread_flag(TIF_SYSCALL_TRACE))
11263 ret = tracehook_report_syscall_entry(regs);
11264
11265 @@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
11266 if (test_thread_flag(TIF_NOHZ))
11267 user_exit();
11268
11269 +#ifdef CONFIG_GRKERNSEC_SETXID
11270 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
11271 + gr_delayed_cred_worker();
11272 +#endif
11273 +
11274 audit_syscall_exit(regs);
11275
11276 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
11277 diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
11278 index 81954ee..6cfaa98 100644
11279 --- a/arch/sparc/kernel/smp_64.c
11280 +++ b/arch/sparc/kernel/smp_64.c
11281 @@ -887,7 +887,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
11282 return;
11283
11284 #ifdef CONFIG_DEBUG_DCFLUSH
11285 - atomic_inc(&dcpage_flushes);
11286 + atomic_inc_unchecked(&dcpage_flushes);
11287 #endif
11288
11289 this_cpu = get_cpu();
11290 @@ -911,7 +911,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
11291 xcall_deliver(data0, __pa(pg_addr),
11292 (u64) pg_addr, cpumask_of(cpu));
11293 #ifdef CONFIG_DEBUG_DCFLUSH
11294 - atomic_inc(&dcpage_flushes_xcall);
11295 + atomic_inc_unchecked(&dcpage_flushes_xcall);
11296 #endif
11297 }
11298 }
11299 @@ -930,7 +930,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
11300 preempt_disable();
11301
11302 #ifdef CONFIG_DEBUG_DCFLUSH
11303 - atomic_inc(&dcpage_flushes);
11304 + atomic_inc_unchecked(&dcpage_flushes);
11305 #endif
11306 data0 = 0;
11307 pg_addr = page_address(page);
11308 @@ -947,7 +947,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
11309 xcall_deliver(data0, __pa(pg_addr),
11310 (u64) pg_addr, cpu_online_mask);
11311 #ifdef CONFIG_DEBUG_DCFLUSH
11312 - atomic_inc(&dcpage_flushes_xcall);
11313 + atomic_inc_unchecked(&dcpage_flushes_xcall);
11314 #endif
11315 }
11316 __local_flush_dcache_page(page);
11317 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
11318 index 646988d..b88905f 100644
11319 --- a/arch/sparc/kernel/sys_sparc_32.c
11320 +++ b/arch/sparc/kernel/sys_sparc_32.c
11321 @@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
11322 if (len > TASK_SIZE - PAGE_SIZE)
11323 return -ENOMEM;
11324 if (!addr)
11325 - addr = TASK_UNMAPPED_BASE;
11326 + addr = current->mm->mmap_base;
11327
11328 info.flags = 0;
11329 info.length = len;
11330 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
11331 index c85403d..6af95c9 100644
11332 --- a/arch/sparc/kernel/sys_sparc_64.c
11333 +++ b/arch/sparc/kernel/sys_sparc_64.c
11334 @@ -89,13 +89,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
11335 struct vm_area_struct * vma;
11336 unsigned long task_size = TASK_SIZE;
11337 int do_color_align;
11338 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
11339 struct vm_unmapped_area_info info;
11340
11341 if (flags & MAP_FIXED) {
11342 /* We do not accept a shared mapping if it would violate
11343 * cache aliasing constraints.
11344 */
11345 - if ((flags & MAP_SHARED) &&
11346 + if ((filp || (flags & MAP_SHARED)) &&
11347 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
11348 return -EINVAL;
11349 return addr;
11350 @@ -110,6 +111,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
11351 if (filp || (flags & MAP_SHARED))
11352 do_color_align = 1;
11353
11354 +#ifdef CONFIG_PAX_RANDMMAP
11355 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11356 +#endif
11357 +
11358 if (addr) {
11359 if (do_color_align)
11360 addr = COLOR_ALIGN(addr, pgoff);
11361 @@ -117,22 +122,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
11362 addr = PAGE_ALIGN(addr);
11363
11364 vma = find_vma(mm, addr);
11365 - if (task_size - len >= addr &&
11366 - (!vma || addr + len <= vma->vm_start))
11367 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11368 return addr;
11369 }
11370
11371 info.flags = 0;
11372 info.length = len;
11373 - info.low_limit = TASK_UNMAPPED_BASE;
11374 + info.low_limit = mm->mmap_base;
11375 info.high_limit = min(task_size, VA_EXCLUDE_START);
11376 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
11377 info.align_offset = pgoff << PAGE_SHIFT;
11378 + info.threadstack_offset = offset;
11379 addr = vm_unmapped_area(&info);
11380
11381 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11382 VM_BUG_ON(addr != -ENOMEM);
11383 info.low_limit = VA_EXCLUDE_END;
11384 +
11385 +#ifdef CONFIG_PAX_RANDMMAP
11386 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11387 + info.low_limit += mm->delta_mmap;
11388 +#endif
11389 +
11390 info.high_limit = task_size;
11391 addr = vm_unmapped_area(&info);
11392 }
11393 @@ -150,6 +161,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11394 unsigned long task_size = STACK_TOP32;
11395 unsigned long addr = addr0;
11396 int do_color_align;
11397 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
11398 struct vm_unmapped_area_info info;
11399
11400 /* This should only ever run for 32-bit processes. */
11401 @@ -159,7 +171,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11402 /* We do not accept a shared mapping if it would violate
11403 * cache aliasing constraints.
11404 */
11405 - if ((flags & MAP_SHARED) &&
11406 + if ((filp || (flags & MAP_SHARED)) &&
11407 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
11408 return -EINVAL;
11409 return addr;
11410 @@ -172,6 +184,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11411 if (filp || (flags & MAP_SHARED))
11412 do_color_align = 1;
11413
11414 +#ifdef CONFIG_PAX_RANDMMAP
11415 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11416 +#endif
11417 +
11418 /* requesting a specific address */
11419 if (addr) {
11420 if (do_color_align)
11421 @@ -180,8 +196,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11422 addr = PAGE_ALIGN(addr);
11423
11424 vma = find_vma(mm, addr);
11425 - if (task_size - len >= addr &&
11426 - (!vma || addr + len <= vma->vm_start))
11427 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11428 return addr;
11429 }
11430
11431 @@ -191,6 +206,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11432 info.high_limit = mm->mmap_base;
11433 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
11434 info.align_offset = pgoff << PAGE_SHIFT;
11435 + info.threadstack_offset = offset;
11436 addr = vm_unmapped_area(&info);
11437
11438 /*
11439 @@ -203,6 +219,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11440 VM_BUG_ON(addr != -ENOMEM);
11441 info.flags = 0;
11442 info.low_limit = TASK_UNMAPPED_BASE;
11443 +
11444 +#ifdef CONFIG_PAX_RANDMMAP
11445 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11446 + info.low_limit += mm->delta_mmap;
11447 +#endif
11448 +
11449 info.high_limit = STACK_TOP32;
11450 addr = vm_unmapped_area(&info);
11451 }
11452 @@ -259,10 +281,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
11453 EXPORT_SYMBOL(get_fb_unmapped_area);
11454
11455 /* Essentially the same as PowerPC. */
11456 -static unsigned long mmap_rnd(void)
11457 +static unsigned long mmap_rnd(struct mm_struct *mm)
11458 {
11459 unsigned long rnd = 0UL;
11460
11461 +#ifdef CONFIG_PAX_RANDMMAP
11462 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11463 +#endif
11464 +
11465 if (current->flags & PF_RANDOMIZE) {
11466 unsigned long val = get_random_int();
11467 if (test_thread_flag(TIF_32BIT))
11468 @@ -275,7 +301,7 @@ static unsigned long mmap_rnd(void)
11469
11470 void arch_pick_mmap_layout(struct mm_struct *mm)
11471 {
11472 - unsigned long random_factor = mmap_rnd();
11473 + unsigned long random_factor = mmap_rnd(mm);
11474 unsigned long gap;
11475
11476 /*
11477 @@ -288,6 +314,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
11478 gap == RLIM_INFINITY ||
11479 sysctl_legacy_va_layout) {
11480 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
11481 +
11482 +#ifdef CONFIG_PAX_RANDMMAP
11483 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11484 + mm->mmap_base += mm->delta_mmap;
11485 +#endif
11486 +
11487 mm->get_unmapped_area = arch_get_unmapped_area;
11488 } else {
11489 /* We know it's 32-bit */
11490 @@ -299,6 +331,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
11491 gap = (task_size / 6 * 5);
11492
11493 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
11494 +
11495 +#ifdef CONFIG_PAX_RANDMMAP
11496 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11497 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
11498 +#endif
11499 +
11500 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
11501 }
11502 }
11503 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
11504 index 33a17e7..d87fb1f 100644
11505 --- a/arch/sparc/kernel/syscalls.S
11506 +++ b/arch/sparc/kernel/syscalls.S
11507 @@ -52,7 +52,7 @@ sys32_rt_sigreturn:
11508 #endif
11509 .align 32
11510 1: ldx [%g6 + TI_FLAGS], %l5
11511 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11512 + andcc %l5, _TIF_WORK_SYSCALL, %g0
11513 be,pt %icc, rtrap
11514 nop
11515 call syscall_trace_leave
11516 @@ -184,7 +184,7 @@ linux_sparc_syscall32:
11517
11518 srl %i3, 0, %o3 ! IEU0
11519 srl %i2, 0, %o2 ! IEU0 Group
11520 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11521 + andcc %l0, _TIF_WORK_SYSCALL, %g0
11522 bne,pn %icc, linux_syscall_trace32 ! CTI
11523 mov %i0, %l5 ! IEU1
11524 5: call %l7 ! CTI Group brk forced
11525 @@ -208,7 +208,7 @@ linux_sparc_syscall:
11526
11527 mov %i3, %o3 ! IEU1
11528 mov %i4, %o4 ! IEU0 Group
11529 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11530 + andcc %l0, _TIF_WORK_SYSCALL, %g0
11531 bne,pn %icc, linux_syscall_trace ! CTI Group
11532 mov %i0, %l5 ! IEU0
11533 2: call %l7 ! CTI Group brk forced
11534 @@ -223,7 +223,7 @@ ret_sys_call:
11535
11536 cmp %o0, -ERESTART_RESTARTBLOCK
11537 bgeu,pn %xcc, 1f
11538 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11539 + andcc %l0, _TIF_WORK_SYSCALL, %g0
11540 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
11541
11542 2:
11543 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
11544 index 6fd386c5..6907d81 100644
11545 --- a/arch/sparc/kernel/traps_32.c
11546 +++ b/arch/sparc/kernel/traps_32.c
11547 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
11548 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
11549 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
11550
11551 +extern void gr_handle_kernel_exploit(void);
11552 +
11553 void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11554 {
11555 static int die_counter;
11556 @@ -76,15 +78,17 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11557 count++ < 30 &&
11558 (((unsigned long) rw) >= PAGE_OFFSET) &&
11559 !(((unsigned long) rw) & 0x7)) {
11560 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
11561 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
11562 (void *) rw->ins[7]);
11563 rw = (struct reg_window32 *)rw->ins[6];
11564 }
11565 }
11566 printk("Instruction DUMP:");
11567 instruction_dump ((unsigned long *) regs->pc);
11568 - if(regs->psr & PSR_PS)
11569 + if(regs->psr & PSR_PS) {
11570 + gr_handle_kernel_exploit();
11571 do_exit(SIGKILL);
11572 + }
11573 do_exit(SIGSEGV);
11574 }
11575
11576 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
11577 index 981a769..d906eda 100644
11578 --- a/arch/sparc/kernel/traps_64.c
11579 +++ b/arch/sparc/kernel/traps_64.c
11580 @@ -79,7 +79,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
11581 i + 1,
11582 p->trapstack[i].tstate, p->trapstack[i].tpc,
11583 p->trapstack[i].tnpc, p->trapstack[i].tt);
11584 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
11585 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
11586 }
11587 }
11588
11589 @@ -99,6 +99,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
11590
11591 lvl -= 0x100;
11592 if (regs->tstate & TSTATE_PRIV) {
11593 +
11594 +#ifdef CONFIG_PAX_REFCOUNT
11595 + if (lvl == 6)
11596 + pax_report_refcount_overflow(regs);
11597 +#endif
11598 +
11599 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
11600 die_if_kernel(buffer, regs);
11601 }
11602 @@ -117,11 +123,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
11603 void bad_trap_tl1(struct pt_regs *regs, long lvl)
11604 {
11605 char buffer[32];
11606 -
11607 +
11608 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
11609 0, lvl, SIGTRAP) == NOTIFY_STOP)
11610 return;
11611
11612 +#ifdef CONFIG_PAX_REFCOUNT
11613 + if (lvl == 6)
11614 + pax_report_refcount_overflow(regs);
11615 +#endif
11616 +
11617 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
11618
11619 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
11620 @@ -1151,7 +1162,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
11621 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
11622 printk("%s" "ERROR(%d): ",
11623 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
11624 - printk("TPC<%pS>\n", (void *) regs->tpc);
11625 + printk("TPC<%pA>\n", (void *) regs->tpc);
11626 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
11627 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
11628 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
11629 @@ -1758,7 +1769,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
11630 smp_processor_id(),
11631 (type & 0x1) ? 'I' : 'D',
11632 regs->tpc);
11633 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
11634 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
11635 panic("Irrecoverable Cheetah+ parity error.");
11636 }
11637
11638 @@ -1766,7 +1777,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
11639 smp_processor_id(),
11640 (type & 0x1) ? 'I' : 'D',
11641 regs->tpc);
11642 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
11643 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
11644 }
11645
11646 struct sun4v_error_entry {
11647 @@ -1839,8 +1850,8 @@ struct sun4v_error_entry {
11648 /*0x38*/u64 reserved_5;
11649 };
11650
11651 -static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
11652 -static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
11653 +static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
11654 +static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
11655
11656 static const char *sun4v_err_type_to_str(u8 type)
11657 {
11658 @@ -1932,7 +1943,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
11659 }
11660
11661 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
11662 - int cpu, const char *pfx, atomic_t *ocnt)
11663 + int cpu, const char *pfx, atomic_unchecked_t *ocnt)
11664 {
11665 u64 *raw_ptr = (u64 *) ent;
11666 u32 attrs;
11667 @@ -1990,8 +2001,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
11668
11669 show_regs(regs);
11670
11671 - if ((cnt = atomic_read(ocnt)) != 0) {
11672 - atomic_set(ocnt, 0);
11673 + if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
11674 + atomic_set_unchecked(ocnt, 0);
11675 wmb();
11676 printk("%s: Queue overflowed %d times.\n",
11677 pfx, cnt);
11678 @@ -2048,7 +2059,7 @@ out:
11679 */
11680 void sun4v_resum_overflow(struct pt_regs *regs)
11681 {
11682 - atomic_inc(&sun4v_resum_oflow_cnt);
11683 + atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
11684 }
11685
11686 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
11687 @@ -2101,7 +2112,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
11688 /* XXX Actually even this can make not that much sense. Perhaps
11689 * XXX we should just pull the plug and panic directly from here?
11690 */
11691 - atomic_inc(&sun4v_nonresum_oflow_cnt);
11692 + atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
11693 }
11694
11695 static void sun4v_tlb_error(struct pt_regs *regs)
11696 @@ -2120,9 +2131,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
11697
11698 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
11699 regs->tpc, tl);
11700 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
11701 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
11702 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
11703 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
11704 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
11705 (void *) regs->u_regs[UREG_I7]);
11706 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
11707 "pte[%lx] error[%lx]\n",
11708 @@ -2143,9 +2154,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
11709
11710 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
11711 regs->tpc, tl);
11712 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
11713 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
11714 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
11715 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
11716 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
11717 (void *) regs->u_regs[UREG_I7]);
11718 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
11719 "pte[%lx] error[%lx]\n",
11720 @@ -2362,13 +2373,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
11721 fp = (unsigned long)sf->fp + STACK_BIAS;
11722 }
11723
11724 - printk(" [%016lx] %pS\n", pc, (void *) pc);
11725 + printk(" [%016lx] %pA\n", pc, (void *) pc);
11726 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
11727 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
11728 int index = tsk->curr_ret_stack;
11729 if (tsk->ret_stack && index >= graph) {
11730 pc = tsk->ret_stack[index - graph].ret;
11731 - printk(" [%016lx] %pS\n", pc, (void *) pc);
11732 + printk(" [%016lx] %pA\n", pc, (void *) pc);
11733 graph++;
11734 }
11735 }
11736 @@ -2386,6 +2397,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
11737 return (struct reg_window *) (fp + STACK_BIAS);
11738 }
11739
11740 +extern void gr_handle_kernel_exploit(void);
11741 +
11742 void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11743 {
11744 static int die_counter;
11745 @@ -2414,7 +2427,7 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11746 while (rw &&
11747 count++ < 30 &&
11748 kstack_valid(tp, (unsigned long) rw)) {
11749 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
11750 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
11751 (void *) rw->ins[7]);
11752
11753 rw = kernel_stack_up(rw);
11754 @@ -2427,8 +2440,10 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11755 }
11756 user_instruction_dump ((unsigned int __user *) regs->tpc);
11757 }
11758 - if (regs->tstate & TSTATE_PRIV)
11759 + if (regs->tstate & TSTATE_PRIV) {
11760 + gr_handle_kernel_exploit();
11761 do_exit(SIGKILL);
11762 + }
11763 do_exit(SIGSEGV);
11764 }
11765 EXPORT_SYMBOL(die_if_kernel);
11766 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
11767 index 62098a8..547ab2c 100644
11768 --- a/arch/sparc/kernel/unaligned_64.c
11769 +++ b/arch/sparc/kernel/unaligned_64.c
11770 @@ -297,7 +297,7 @@ static void log_unaligned(struct pt_regs *regs)
11771 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
11772
11773 if (__ratelimit(&ratelimit)) {
11774 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
11775 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
11776 regs->tpc, (void *) regs->tpc);
11777 }
11778 }
11779 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
11780 index 3269b02..64f5231 100644
11781 --- a/arch/sparc/lib/Makefile
11782 +++ b/arch/sparc/lib/Makefile
11783 @@ -2,7 +2,7 @@
11784 #
11785
11786 asflags-y := -ansi -DST_DIV0=0x02
11787 -ccflags-y := -Werror
11788 +#ccflags-y := -Werror
11789
11790 lib-$(CONFIG_SPARC32) += ashrdi3.o
11791 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
11792 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
11793 index 85c233d..68500e0 100644
11794 --- a/arch/sparc/lib/atomic_64.S
11795 +++ b/arch/sparc/lib/atomic_64.S
11796 @@ -17,7 +17,12 @@
11797 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
11798 BACKOFF_SETUP(%o2)
11799 1: lduw [%o1], %g1
11800 - add %g1, %o0, %g7
11801 + addcc %g1, %o0, %g7
11802 +
11803 +#ifdef CONFIG_PAX_REFCOUNT
11804 + tvs %icc, 6
11805 +#endif
11806 +
11807 cas [%o1], %g1, %g7
11808 cmp %g1, %g7
11809 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11810 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
11811 2: BACKOFF_SPIN(%o2, %o3, 1b)
11812 ENDPROC(atomic_add)
11813
11814 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11815 + BACKOFF_SETUP(%o2)
11816 +1: lduw [%o1], %g1
11817 + add %g1, %o0, %g7
11818 + cas [%o1], %g1, %g7
11819 + cmp %g1, %g7
11820 + bne,pn %icc, 2f
11821 + nop
11822 + retl
11823 + nop
11824 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11825 +ENDPROC(atomic_add_unchecked)
11826 +
11827 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11828 BACKOFF_SETUP(%o2)
11829 1: lduw [%o1], %g1
11830 - sub %g1, %o0, %g7
11831 + subcc %g1, %o0, %g7
11832 +
11833 +#ifdef CONFIG_PAX_REFCOUNT
11834 + tvs %icc, 6
11835 +#endif
11836 +
11837 cas [%o1], %g1, %g7
11838 cmp %g1, %g7
11839 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11840 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11841 2: BACKOFF_SPIN(%o2, %o3, 1b)
11842 ENDPROC(atomic_sub)
11843
11844 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
11845 + BACKOFF_SETUP(%o2)
11846 +1: lduw [%o1], %g1
11847 + sub %g1, %o0, %g7
11848 + cas [%o1], %g1, %g7
11849 + cmp %g1, %g7
11850 + bne,pn %icc, 2f
11851 + nop
11852 + retl
11853 + nop
11854 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11855 +ENDPROC(atomic_sub_unchecked)
11856 +
11857 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11858 BACKOFF_SETUP(%o2)
11859 1: lduw [%o1], %g1
11860 - add %g1, %o0, %g7
11861 + addcc %g1, %o0, %g7
11862 +
11863 +#ifdef CONFIG_PAX_REFCOUNT
11864 + tvs %icc, 6
11865 +#endif
11866 +
11867 cas [%o1], %g1, %g7
11868 cmp %g1, %g7
11869 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11870 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11871 2: BACKOFF_SPIN(%o2, %o3, 1b)
11872 ENDPROC(atomic_add_ret)
11873
11874 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11875 + BACKOFF_SETUP(%o2)
11876 +1: lduw [%o1], %g1
11877 + addcc %g1, %o0, %g7
11878 + cas [%o1], %g1, %g7
11879 + cmp %g1, %g7
11880 + bne,pn %icc, 2f
11881 + add %g7, %o0, %g7
11882 + sra %g7, 0, %o0
11883 + retl
11884 + nop
11885 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11886 +ENDPROC(atomic_add_ret_unchecked)
11887 +
11888 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
11889 BACKOFF_SETUP(%o2)
11890 1: lduw [%o1], %g1
11891 - sub %g1, %o0, %g7
11892 + subcc %g1, %o0, %g7
11893 +
11894 +#ifdef CONFIG_PAX_REFCOUNT
11895 + tvs %icc, 6
11896 +#endif
11897 +
11898 cas [%o1], %g1, %g7
11899 cmp %g1, %g7
11900 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11901 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
11902 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
11903 BACKOFF_SETUP(%o2)
11904 1: ldx [%o1], %g1
11905 - add %g1, %o0, %g7
11906 + addcc %g1, %o0, %g7
11907 +
11908 +#ifdef CONFIG_PAX_REFCOUNT
11909 + tvs %xcc, 6
11910 +#endif
11911 +
11912 casx [%o1], %g1, %g7
11913 cmp %g1, %g7
11914 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11915 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
11916 2: BACKOFF_SPIN(%o2, %o3, 1b)
11917 ENDPROC(atomic64_add)
11918
11919 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11920 + BACKOFF_SETUP(%o2)
11921 +1: ldx [%o1], %g1
11922 + addcc %g1, %o0, %g7
11923 + casx [%o1], %g1, %g7
11924 + cmp %g1, %g7
11925 + bne,pn %xcc, 2f
11926 + nop
11927 + retl
11928 + nop
11929 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11930 +ENDPROC(atomic64_add_unchecked)
11931 +
11932 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11933 BACKOFF_SETUP(%o2)
11934 1: ldx [%o1], %g1
11935 - sub %g1, %o0, %g7
11936 + subcc %g1, %o0, %g7
11937 +
11938 +#ifdef CONFIG_PAX_REFCOUNT
11939 + tvs %xcc, 6
11940 +#endif
11941 +
11942 casx [%o1], %g1, %g7
11943 cmp %g1, %g7
11944 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11945 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11946 2: BACKOFF_SPIN(%o2, %o3, 1b)
11947 ENDPROC(atomic64_sub)
11948
11949 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
11950 + BACKOFF_SETUP(%o2)
11951 +1: ldx [%o1], %g1
11952 + subcc %g1, %o0, %g7
11953 + casx [%o1], %g1, %g7
11954 + cmp %g1, %g7
11955 + bne,pn %xcc, 2f
11956 + nop
11957 + retl
11958 + nop
11959 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11960 +ENDPROC(atomic64_sub_unchecked)
11961 +
11962 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11963 BACKOFF_SETUP(%o2)
11964 1: ldx [%o1], %g1
11965 - add %g1, %o0, %g7
11966 + addcc %g1, %o0, %g7
11967 +
11968 +#ifdef CONFIG_PAX_REFCOUNT
11969 + tvs %xcc, 6
11970 +#endif
11971 +
11972 casx [%o1], %g1, %g7
11973 cmp %g1, %g7
11974 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11975 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11976 2: BACKOFF_SPIN(%o2, %o3, 1b)
11977 ENDPROC(atomic64_add_ret)
11978
11979 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11980 + BACKOFF_SETUP(%o2)
11981 +1: ldx [%o1], %g1
11982 + addcc %g1, %o0, %g7
11983 + casx [%o1], %g1, %g7
11984 + cmp %g1, %g7
11985 + bne,pn %xcc, 2f
11986 + add %g7, %o0, %g7
11987 + mov %g7, %o0
11988 + retl
11989 + nop
11990 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11991 +ENDPROC(atomic64_add_ret_unchecked)
11992 +
11993 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
11994 BACKOFF_SETUP(%o2)
11995 1: ldx [%o1], %g1
11996 - sub %g1, %o0, %g7
11997 + subcc %g1, %o0, %g7
11998 +
11999 +#ifdef CONFIG_PAX_REFCOUNT
12000 + tvs %xcc, 6
12001 +#endif
12002 +
12003 casx [%o1], %g1, %g7
12004 cmp %g1, %g7
12005 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
12006 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
12007 index 323335b..ed85ea2 100644
12008 --- a/arch/sparc/lib/ksyms.c
12009 +++ b/arch/sparc/lib/ksyms.c
12010 @@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
12011
12012 /* Atomic counter implementation. */
12013 EXPORT_SYMBOL(atomic_add);
12014 +EXPORT_SYMBOL(atomic_add_unchecked);
12015 EXPORT_SYMBOL(atomic_add_ret);
12016 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
12017 EXPORT_SYMBOL(atomic_sub);
12018 +EXPORT_SYMBOL(atomic_sub_unchecked);
12019 EXPORT_SYMBOL(atomic_sub_ret);
12020 EXPORT_SYMBOL(atomic64_add);
12021 +EXPORT_SYMBOL(atomic64_add_unchecked);
12022 EXPORT_SYMBOL(atomic64_add_ret);
12023 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
12024 EXPORT_SYMBOL(atomic64_sub);
12025 +EXPORT_SYMBOL(atomic64_sub_unchecked);
12026 EXPORT_SYMBOL(atomic64_sub_ret);
12027 EXPORT_SYMBOL(atomic64_dec_if_positive);
12028
12029 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
12030 index 30c3ecc..736f015 100644
12031 --- a/arch/sparc/mm/Makefile
12032 +++ b/arch/sparc/mm/Makefile
12033 @@ -2,7 +2,7 @@
12034 #
12035
12036 asflags-y := -ansi
12037 -ccflags-y := -Werror
12038 +#ccflags-y := -Werror
12039
12040 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
12041 obj-y += fault_$(BITS).o
12042 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
12043 index 908e8c1..1524793 100644
12044 --- a/arch/sparc/mm/fault_32.c
12045 +++ b/arch/sparc/mm/fault_32.c
12046 @@ -21,6 +21,9 @@
12047 #include <linux/perf_event.h>
12048 #include <linux/interrupt.h>
12049 #include <linux/kdebug.h>
12050 +#include <linux/slab.h>
12051 +#include <linux/pagemap.h>
12052 +#include <linux/compiler.h>
12053
12054 #include <asm/page.h>
12055 #include <asm/pgtable.h>
12056 @@ -156,6 +159,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
12057 return safe_compute_effective_address(regs, insn);
12058 }
12059
12060 +#ifdef CONFIG_PAX_PAGEEXEC
12061 +#ifdef CONFIG_PAX_DLRESOLVE
12062 +static void pax_emuplt_close(struct vm_area_struct *vma)
12063 +{
12064 + vma->vm_mm->call_dl_resolve = 0UL;
12065 +}
12066 +
12067 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
12068 +{
12069 + unsigned int *kaddr;
12070 +
12071 + vmf->page = alloc_page(GFP_HIGHUSER);
12072 + if (!vmf->page)
12073 + return VM_FAULT_OOM;
12074 +
12075 + kaddr = kmap(vmf->page);
12076 + memset(kaddr, 0, PAGE_SIZE);
12077 + kaddr[0] = 0x9DE3BFA8U; /* save */
12078 + flush_dcache_page(vmf->page);
12079 + kunmap(vmf->page);
12080 + return VM_FAULT_MAJOR;
12081 +}
12082 +
12083 +static const struct vm_operations_struct pax_vm_ops = {
12084 + .close = pax_emuplt_close,
12085 + .fault = pax_emuplt_fault
12086 +};
12087 +
12088 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
12089 +{
12090 + int ret;
12091 +
12092 + INIT_LIST_HEAD(&vma->anon_vma_chain);
12093 + vma->vm_mm = current->mm;
12094 + vma->vm_start = addr;
12095 + vma->vm_end = addr + PAGE_SIZE;
12096 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
12097 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
12098 + vma->vm_ops = &pax_vm_ops;
12099 +
12100 + ret = insert_vm_struct(current->mm, vma);
12101 + if (ret)
12102 + return ret;
12103 +
12104 + ++current->mm->total_vm;
12105 + return 0;
12106 +}
12107 +#endif
12108 +
12109 +/*
12110 + * PaX: decide what to do with offenders (regs->pc = fault address)
12111 + *
12112 + * returns 1 when task should be killed
12113 + * 2 when patched PLT trampoline was detected
12114 + * 3 when unpatched PLT trampoline was detected
12115 + */
12116 +static int pax_handle_fetch_fault(struct pt_regs *regs)
12117 +{
12118 +
12119 +#ifdef CONFIG_PAX_EMUPLT
12120 + int err;
12121 +
12122 + do { /* PaX: patched PLT emulation #1 */
12123 + unsigned int sethi1, sethi2, jmpl;
12124 +
12125 + err = get_user(sethi1, (unsigned int *)regs->pc);
12126 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
12127 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
12128 +
12129 + if (err)
12130 + break;
12131 +
12132 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
12133 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
12134 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
12135 + {
12136 + unsigned int addr;
12137 +
12138 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
12139 + addr = regs->u_regs[UREG_G1];
12140 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
12141 + regs->pc = addr;
12142 + regs->npc = addr+4;
12143 + return 2;
12144 + }
12145 + } while (0);
12146 +
12147 + do { /* PaX: patched PLT emulation #2 */
12148 + unsigned int ba;
12149 +
12150 + err = get_user(ba, (unsigned int *)regs->pc);
12151 +
12152 + if (err)
12153 + break;
12154 +
12155 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
12156 + unsigned int addr;
12157 +
12158 + if ((ba & 0xFFC00000U) == 0x30800000U)
12159 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
12160 + else
12161 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
12162 + regs->pc = addr;
12163 + regs->npc = addr+4;
12164 + return 2;
12165 + }
12166 + } while (0);
12167 +
12168 + do { /* PaX: patched PLT emulation #3 */
12169 + unsigned int sethi, bajmpl, nop;
12170 +
12171 + err = get_user(sethi, (unsigned int *)regs->pc);
12172 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
12173 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
12174 +
12175 + if (err)
12176 + break;
12177 +
12178 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12179 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
12180 + nop == 0x01000000U)
12181 + {
12182 + unsigned int addr;
12183 +
12184 + addr = (sethi & 0x003FFFFFU) << 10;
12185 + regs->u_regs[UREG_G1] = addr;
12186 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
12187 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
12188 + else
12189 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
12190 + regs->pc = addr;
12191 + regs->npc = addr+4;
12192 + return 2;
12193 + }
12194 + } while (0);
12195 +
12196 + do { /* PaX: unpatched PLT emulation step 1 */
12197 + unsigned int sethi, ba, nop;
12198 +
12199 + err = get_user(sethi, (unsigned int *)regs->pc);
12200 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
12201 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
12202 +
12203 + if (err)
12204 + break;
12205 +
12206 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12207 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
12208 + nop == 0x01000000U)
12209 + {
12210 + unsigned int addr, save, call;
12211 +
12212 + if ((ba & 0xFFC00000U) == 0x30800000U)
12213 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
12214 + else
12215 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
12216 +
12217 + err = get_user(save, (unsigned int *)addr);
12218 + err |= get_user(call, (unsigned int *)(addr+4));
12219 + err |= get_user(nop, (unsigned int *)(addr+8));
12220 + if (err)
12221 + break;
12222 +
12223 +#ifdef CONFIG_PAX_DLRESOLVE
12224 + if (save == 0x9DE3BFA8U &&
12225 + (call & 0xC0000000U) == 0x40000000U &&
12226 + nop == 0x01000000U)
12227 + {
12228 + struct vm_area_struct *vma;
12229 + unsigned long call_dl_resolve;
12230 +
12231 + down_read(&current->mm->mmap_sem);
12232 + call_dl_resolve = current->mm->call_dl_resolve;
12233 + up_read(&current->mm->mmap_sem);
12234 + if (likely(call_dl_resolve))
12235 + goto emulate;
12236 +
12237 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
12238 +
12239 + down_write(&current->mm->mmap_sem);
12240 + if (current->mm->call_dl_resolve) {
12241 + call_dl_resolve = current->mm->call_dl_resolve;
12242 + up_write(&current->mm->mmap_sem);
12243 + if (vma)
12244 + kmem_cache_free(vm_area_cachep, vma);
12245 + goto emulate;
12246 + }
12247 +
12248 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
12249 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
12250 + up_write(&current->mm->mmap_sem);
12251 + if (vma)
12252 + kmem_cache_free(vm_area_cachep, vma);
12253 + return 1;
12254 + }
12255 +
12256 + if (pax_insert_vma(vma, call_dl_resolve)) {
12257 + up_write(&current->mm->mmap_sem);
12258 + kmem_cache_free(vm_area_cachep, vma);
12259 + return 1;
12260 + }
12261 +
12262 + current->mm->call_dl_resolve = call_dl_resolve;
12263 + up_write(&current->mm->mmap_sem);
12264 +
12265 +emulate:
12266 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12267 + regs->pc = call_dl_resolve;
12268 + regs->npc = addr+4;
12269 + return 3;
12270 + }
12271 +#endif
12272 +
12273 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
12274 + if ((save & 0xFFC00000U) == 0x05000000U &&
12275 + (call & 0xFFFFE000U) == 0x85C0A000U &&
12276 + nop == 0x01000000U)
12277 + {
12278 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12279 + regs->u_regs[UREG_G2] = addr + 4;
12280 + addr = (save & 0x003FFFFFU) << 10;
12281 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
12282 + regs->pc = addr;
12283 + regs->npc = addr+4;
12284 + return 3;
12285 + }
12286 + }
12287 + } while (0);
12288 +
12289 + do { /* PaX: unpatched PLT emulation step 2 */
12290 + unsigned int save, call, nop;
12291 +
12292 + err = get_user(save, (unsigned int *)(regs->pc-4));
12293 + err |= get_user(call, (unsigned int *)regs->pc);
12294 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
12295 + if (err)
12296 + break;
12297 +
12298 + if (save == 0x9DE3BFA8U &&
12299 + (call & 0xC0000000U) == 0x40000000U &&
12300 + nop == 0x01000000U)
12301 + {
12302 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
12303 +
12304 + regs->u_regs[UREG_RETPC] = regs->pc;
12305 + regs->pc = dl_resolve;
12306 + regs->npc = dl_resolve+4;
12307 + return 3;
12308 + }
12309 + } while (0);
12310 +#endif
12311 +
12312 + return 1;
12313 +}
12314 +
12315 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
12316 +{
12317 + unsigned long i;
12318 +
12319 + printk(KERN_ERR "PAX: bytes at PC: ");
12320 + for (i = 0; i < 8; i++) {
12321 + unsigned int c;
12322 + if (get_user(c, (unsigned int *)pc+i))
12323 + printk(KERN_CONT "???????? ");
12324 + else
12325 + printk(KERN_CONT "%08x ", c);
12326 + }
12327 + printk("\n");
12328 +}
12329 +#endif
12330 +
12331 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
12332 int text_fault)
12333 {
12334 @@ -226,6 +500,24 @@ good_area:
12335 if (!(vma->vm_flags & VM_WRITE))
12336 goto bad_area;
12337 } else {
12338 +
12339 +#ifdef CONFIG_PAX_PAGEEXEC
12340 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
12341 + up_read(&mm->mmap_sem);
12342 + switch (pax_handle_fetch_fault(regs)) {
12343 +
12344 +#ifdef CONFIG_PAX_EMUPLT
12345 + case 2:
12346 + case 3:
12347 + return;
12348 +#endif
12349 +
12350 + }
12351 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
12352 + do_group_exit(SIGKILL);
12353 + }
12354 +#endif
12355 +
12356 /* Allow reads even for write-only mappings */
12357 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
12358 goto bad_area;
12359 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
12360 index 18fcd71..e4fe821 100644
12361 --- a/arch/sparc/mm/fault_64.c
12362 +++ b/arch/sparc/mm/fault_64.c
12363 @@ -22,6 +22,9 @@
12364 #include <linux/kdebug.h>
12365 #include <linux/percpu.h>
12366 #include <linux/context_tracking.h>
12367 +#include <linux/slab.h>
12368 +#include <linux/pagemap.h>
12369 +#include <linux/compiler.h>
12370
12371 #include <asm/page.h>
12372 #include <asm/pgtable.h>
12373 @@ -76,7 +79,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
12374 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
12375 regs->tpc);
12376 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
12377 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
12378 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
12379 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
12380 dump_stack();
12381 unhandled_fault(regs->tpc, current, regs);
12382 @@ -279,6 +282,466 @@ static void noinline __kprobes bogus_32bit_fault_tpc(struct pt_regs *regs)
12383 show_regs(regs);
12384 }
12385
12386 +#ifdef CONFIG_PAX_PAGEEXEC
12387 +#ifdef CONFIG_PAX_DLRESOLVE
12388 +static void pax_emuplt_close(struct vm_area_struct *vma)
12389 +{
12390 + vma->vm_mm->call_dl_resolve = 0UL;
12391 +}
12392 +
12393 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
12394 +{
12395 + unsigned int *kaddr;
12396 +
12397 + vmf->page = alloc_page(GFP_HIGHUSER);
12398 + if (!vmf->page)
12399 + return VM_FAULT_OOM;
12400 +
12401 + kaddr = kmap(vmf->page);
12402 + memset(kaddr, 0, PAGE_SIZE);
12403 + kaddr[0] = 0x9DE3BFA8U; /* save */
12404 + flush_dcache_page(vmf->page);
12405 + kunmap(vmf->page);
12406 + return VM_FAULT_MAJOR;
12407 +}
12408 +
12409 +static const struct vm_operations_struct pax_vm_ops = {
12410 + .close = pax_emuplt_close,
12411 + .fault = pax_emuplt_fault
12412 +};
12413 +
12414 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
12415 +{
12416 + int ret;
12417 +
12418 + INIT_LIST_HEAD(&vma->anon_vma_chain);
12419 + vma->vm_mm = current->mm;
12420 + vma->vm_start = addr;
12421 + vma->vm_end = addr + PAGE_SIZE;
12422 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
12423 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
12424 + vma->vm_ops = &pax_vm_ops;
12425 +
12426 + ret = insert_vm_struct(current->mm, vma);
12427 + if (ret)
12428 + return ret;
12429 +
12430 + ++current->mm->total_vm;
12431 + return 0;
12432 +}
12433 +#endif
12434 +
12435 +/*
12436 + * PaX: decide what to do with offenders (regs->tpc = fault address)
12437 + *
12438 + * returns 1 when task should be killed
12439 + * 2 when patched PLT trampoline was detected
12440 + * 3 when unpatched PLT trampoline was detected
12441 + */
12442 +static int pax_handle_fetch_fault(struct pt_regs *regs)
12443 +{
12444 +
12445 +#ifdef CONFIG_PAX_EMUPLT
12446 + int err;
12447 +
12448 + do { /* PaX: patched PLT emulation #1 */
12449 + unsigned int sethi1, sethi2, jmpl;
12450 +
12451 + err = get_user(sethi1, (unsigned int *)regs->tpc);
12452 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
12453 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
12454 +
12455 + if (err)
12456 + break;
12457 +
12458 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
12459 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
12460 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
12461 + {
12462 + unsigned long addr;
12463 +
12464 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
12465 + addr = regs->u_regs[UREG_G1];
12466 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
12467 +
12468 + if (test_thread_flag(TIF_32BIT))
12469 + addr &= 0xFFFFFFFFUL;
12470 +
12471 + regs->tpc = addr;
12472 + regs->tnpc = addr+4;
12473 + return 2;
12474 + }
12475 + } while (0);
12476 +
12477 + do { /* PaX: patched PLT emulation #2 */
12478 + unsigned int ba;
12479 +
12480 + err = get_user(ba, (unsigned int *)regs->tpc);
12481 +
12482 + if (err)
12483 + break;
12484 +
12485 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
12486 + unsigned long addr;
12487 +
12488 + if ((ba & 0xFFC00000U) == 0x30800000U)
12489 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
12490 + else
12491 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12492 +
12493 + if (test_thread_flag(TIF_32BIT))
12494 + addr &= 0xFFFFFFFFUL;
12495 +
12496 + regs->tpc = addr;
12497 + regs->tnpc = addr+4;
12498 + return 2;
12499 + }
12500 + } while (0);
12501 +
12502 + do { /* PaX: patched PLT emulation #3 */
12503 + unsigned int sethi, bajmpl, nop;
12504 +
12505 + err = get_user(sethi, (unsigned int *)regs->tpc);
12506 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
12507 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12508 +
12509 + if (err)
12510 + break;
12511 +
12512 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12513 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
12514 + nop == 0x01000000U)
12515 + {
12516 + unsigned long addr;
12517 +
12518 + addr = (sethi & 0x003FFFFFU) << 10;
12519 + regs->u_regs[UREG_G1] = addr;
12520 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
12521 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
12522 + else
12523 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12524 +
12525 + if (test_thread_flag(TIF_32BIT))
12526 + addr &= 0xFFFFFFFFUL;
12527 +
12528 + regs->tpc = addr;
12529 + regs->tnpc = addr+4;
12530 + return 2;
12531 + }
12532 + } while (0);
12533 +
12534 + do { /* PaX: patched PLT emulation #4 */
12535 + unsigned int sethi, mov1, call, mov2;
12536 +
12537 + err = get_user(sethi, (unsigned int *)regs->tpc);
12538 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
12539 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
12540 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
12541 +
12542 + if (err)
12543 + break;
12544 +
12545 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12546 + mov1 == 0x8210000FU &&
12547 + (call & 0xC0000000U) == 0x40000000U &&
12548 + mov2 == 0x9E100001U)
12549 + {
12550 + unsigned long addr;
12551 +
12552 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
12553 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
12554 +
12555 + if (test_thread_flag(TIF_32BIT))
12556 + addr &= 0xFFFFFFFFUL;
12557 +
12558 + regs->tpc = addr;
12559 + regs->tnpc = addr+4;
12560 + return 2;
12561 + }
12562 + } while (0);
12563 +
12564 + do { /* PaX: patched PLT emulation #5 */
12565 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
12566 +
12567 + err = get_user(sethi, (unsigned int *)regs->tpc);
12568 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
12569 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
12570 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
12571 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
12572 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
12573 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
12574 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
12575 +
12576 + if (err)
12577 + break;
12578 +
12579 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12580 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
12581 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12582 + (or1 & 0xFFFFE000U) == 0x82106000U &&
12583 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
12584 + sllx == 0x83287020U &&
12585 + jmpl == 0x81C04005U &&
12586 + nop == 0x01000000U)
12587 + {
12588 + unsigned long addr;
12589 +
12590 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
12591 + regs->u_regs[UREG_G1] <<= 32;
12592 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
12593 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
12594 + regs->tpc = addr;
12595 + regs->tnpc = addr+4;
12596 + return 2;
12597 + }
12598 + } while (0);
12599 +
12600 + do { /* PaX: patched PLT emulation #6 */
12601 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
12602 +
12603 + err = get_user(sethi, (unsigned int *)regs->tpc);
12604 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
12605 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
12606 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
12607 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
12608 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
12609 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
12610 +
12611 + if (err)
12612 + break;
12613 +
12614 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12615 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
12616 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12617 + sllx == 0x83287020U &&
12618 + (or & 0xFFFFE000U) == 0x8A116000U &&
12619 + jmpl == 0x81C04005U &&
12620 + nop == 0x01000000U)
12621 + {
12622 + unsigned long addr;
12623 +
12624 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
12625 + regs->u_regs[UREG_G1] <<= 32;
12626 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
12627 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
12628 + regs->tpc = addr;
12629 + regs->tnpc = addr+4;
12630 + return 2;
12631 + }
12632 + } while (0);
12633 +
12634 + do { /* PaX: unpatched PLT emulation step 1 */
12635 + unsigned int sethi, ba, nop;
12636 +
12637 + err = get_user(sethi, (unsigned int *)regs->tpc);
12638 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
12639 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12640 +
12641 + if (err)
12642 + break;
12643 +
12644 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12645 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
12646 + nop == 0x01000000U)
12647 + {
12648 + unsigned long addr;
12649 + unsigned int save, call;
12650 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
12651 +
12652 + if ((ba & 0xFFC00000U) == 0x30800000U)
12653 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
12654 + else
12655 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12656 +
12657 + if (test_thread_flag(TIF_32BIT))
12658 + addr &= 0xFFFFFFFFUL;
12659 +
12660 + err = get_user(save, (unsigned int *)addr);
12661 + err |= get_user(call, (unsigned int *)(addr+4));
12662 + err |= get_user(nop, (unsigned int *)(addr+8));
12663 + if (err)
12664 + break;
12665 +
12666 +#ifdef CONFIG_PAX_DLRESOLVE
12667 + if (save == 0x9DE3BFA8U &&
12668 + (call & 0xC0000000U) == 0x40000000U &&
12669 + nop == 0x01000000U)
12670 + {
12671 + struct vm_area_struct *vma;
12672 + unsigned long call_dl_resolve;
12673 +
12674 + down_read(&current->mm->mmap_sem);
12675 + call_dl_resolve = current->mm->call_dl_resolve;
12676 + up_read(&current->mm->mmap_sem);
12677 + if (likely(call_dl_resolve))
12678 + goto emulate;
12679 +
12680 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
12681 +
12682 + down_write(&current->mm->mmap_sem);
12683 + if (current->mm->call_dl_resolve) {
12684 + call_dl_resolve = current->mm->call_dl_resolve;
12685 + up_write(&current->mm->mmap_sem);
12686 + if (vma)
12687 + kmem_cache_free(vm_area_cachep, vma);
12688 + goto emulate;
12689 + }
12690 +
12691 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
12692 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
12693 + up_write(&current->mm->mmap_sem);
12694 + if (vma)
12695 + kmem_cache_free(vm_area_cachep, vma);
12696 + return 1;
12697 + }
12698 +
12699 + if (pax_insert_vma(vma, call_dl_resolve)) {
12700 + up_write(&current->mm->mmap_sem);
12701 + kmem_cache_free(vm_area_cachep, vma);
12702 + return 1;
12703 + }
12704 +
12705 + current->mm->call_dl_resolve = call_dl_resolve;
12706 + up_write(&current->mm->mmap_sem);
12707 +
12708 +emulate:
12709 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12710 + regs->tpc = call_dl_resolve;
12711 + regs->tnpc = addr+4;
12712 + return 3;
12713 + }
12714 +#endif
12715 +
12716 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
12717 + if ((save & 0xFFC00000U) == 0x05000000U &&
12718 + (call & 0xFFFFE000U) == 0x85C0A000U &&
12719 + nop == 0x01000000U)
12720 + {
12721 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12722 + regs->u_regs[UREG_G2] = addr + 4;
12723 + addr = (save & 0x003FFFFFU) << 10;
12724 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
12725 +
12726 + if (test_thread_flag(TIF_32BIT))
12727 + addr &= 0xFFFFFFFFUL;
12728 +
12729 + regs->tpc = addr;
12730 + regs->tnpc = addr+4;
12731 + return 3;
12732 + }
12733 +
12734 + /* PaX: 64-bit PLT stub */
12735 + err = get_user(sethi1, (unsigned int *)addr);
12736 + err |= get_user(sethi2, (unsigned int *)(addr+4));
12737 + err |= get_user(or1, (unsigned int *)(addr+8));
12738 + err |= get_user(or2, (unsigned int *)(addr+12));
12739 + err |= get_user(sllx, (unsigned int *)(addr+16));
12740 + err |= get_user(add, (unsigned int *)(addr+20));
12741 + err |= get_user(jmpl, (unsigned int *)(addr+24));
12742 + err |= get_user(nop, (unsigned int *)(addr+28));
12743 + if (err)
12744 + break;
12745 +
12746 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
12747 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12748 + (or1 & 0xFFFFE000U) == 0x88112000U &&
12749 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
12750 + sllx == 0x89293020U &&
12751 + add == 0x8A010005U &&
12752 + jmpl == 0x89C14000U &&
12753 + nop == 0x01000000U)
12754 + {
12755 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12756 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
12757 + regs->u_regs[UREG_G4] <<= 32;
12758 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
12759 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
12760 + regs->u_regs[UREG_G4] = addr + 24;
12761 + addr = regs->u_regs[UREG_G5];
12762 + regs->tpc = addr;
12763 + regs->tnpc = addr+4;
12764 + return 3;
12765 + }
12766 + }
12767 + } while (0);
12768 +
12769 +#ifdef CONFIG_PAX_DLRESOLVE
12770 + do { /* PaX: unpatched PLT emulation step 2 */
12771 + unsigned int save, call, nop;
12772 +
12773 + err = get_user(save, (unsigned int *)(regs->tpc-4));
12774 + err |= get_user(call, (unsigned int *)regs->tpc);
12775 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
12776 + if (err)
12777 + break;
12778 +
12779 + if (save == 0x9DE3BFA8U &&
12780 + (call & 0xC0000000U) == 0x40000000U &&
12781 + nop == 0x01000000U)
12782 + {
12783 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
12784 +
12785 + if (test_thread_flag(TIF_32BIT))
12786 + dl_resolve &= 0xFFFFFFFFUL;
12787 +
12788 + regs->u_regs[UREG_RETPC] = regs->tpc;
12789 + regs->tpc = dl_resolve;
12790 + regs->tnpc = dl_resolve+4;
12791 + return 3;
12792 + }
12793 + } while (0);
12794 +#endif
12795 +
12796 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
12797 + unsigned int sethi, ba, nop;
12798 +
12799 + err = get_user(sethi, (unsigned int *)regs->tpc);
12800 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
12801 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12802 +
12803 + if (err)
12804 + break;
12805 +
12806 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12807 + (ba & 0xFFF00000U) == 0x30600000U &&
12808 + nop == 0x01000000U)
12809 + {
12810 + unsigned long addr;
12811 +
12812 + addr = (sethi & 0x003FFFFFU) << 10;
12813 + regs->u_regs[UREG_G1] = addr;
12814 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12815 +
12816 + if (test_thread_flag(TIF_32BIT))
12817 + addr &= 0xFFFFFFFFUL;
12818 +
12819 + regs->tpc = addr;
12820 + regs->tnpc = addr+4;
12821 + return 2;
12822 + }
12823 + } while (0);
12824 +
12825 +#endif
12826 +
12827 + return 1;
12828 +}
12829 +
12830 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
12831 +{
12832 + unsigned long i;
12833 +
12834 + printk(KERN_ERR "PAX: bytes at PC: ");
12835 + for (i = 0; i < 8; i++) {
12836 + unsigned int c;
12837 + if (get_user(c, (unsigned int *)pc+i))
12838 + printk(KERN_CONT "???????? ");
12839 + else
12840 + printk(KERN_CONT "%08x ", c);
12841 + }
12842 + printk("\n");
12843 +}
12844 +#endif
12845 +
12846 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
12847 {
12848 enum ctx_state prev_state = exception_enter();
12849 @@ -353,6 +816,29 @@ retry:
12850 if (!vma)
12851 goto bad_area;
12852
12853 +#ifdef CONFIG_PAX_PAGEEXEC
12854 + /* PaX: detect ITLB misses on non-exec pages */
12855 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
12856 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
12857 + {
12858 + if (address != regs->tpc)
12859 + goto good_area;
12860 +
12861 + up_read(&mm->mmap_sem);
12862 + switch (pax_handle_fetch_fault(regs)) {
12863 +
12864 +#ifdef CONFIG_PAX_EMUPLT
12865 + case 2:
12866 + case 3:
12867 + return;
12868 +#endif
12869 +
12870 + }
12871 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
12872 + do_group_exit(SIGKILL);
12873 + }
12874 +#endif
12875 +
12876 /* Pure DTLB misses do not tell us whether the fault causing
12877 * load/store/atomic was a write or not, it only says that there
12878 * was no match. So in such a case we (carefully) read the
12879 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
12880 index d329537..2c3746a 100644
12881 --- a/arch/sparc/mm/hugetlbpage.c
12882 +++ b/arch/sparc/mm/hugetlbpage.c
12883 @@ -25,8 +25,10 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12884 unsigned long addr,
12885 unsigned long len,
12886 unsigned long pgoff,
12887 - unsigned long flags)
12888 + unsigned long flags,
12889 + unsigned long offset)
12890 {
12891 + struct mm_struct *mm = current->mm;
12892 unsigned long task_size = TASK_SIZE;
12893 struct vm_unmapped_area_info info;
12894
12895 @@ -35,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12896
12897 info.flags = 0;
12898 info.length = len;
12899 - info.low_limit = TASK_UNMAPPED_BASE;
12900 + info.low_limit = mm->mmap_base;
12901 info.high_limit = min(task_size, VA_EXCLUDE_START);
12902 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12903 info.align_offset = 0;
12904 + info.threadstack_offset = offset;
12905 addr = vm_unmapped_area(&info);
12906
12907 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
12908 VM_BUG_ON(addr != -ENOMEM);
12909 info.low_limit = VA_EXCLUDE_END;
12910 +
12911 +#ifdef CONFIG_PAX_RANDMMAP
12912 + if (mm->pax_flags & MF_PAX_RANDMMAP)
12913 + info.low_limit += mm->delta_mmap;
12914 +#endif
12915 +
12916 info.high_limit = task_size;
12917 addr = vm_unmapped_area(&info);
12918 }
12919 @@ -55,7 +64,8 @@ static unsigned long
12920 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12921 const unsigned long len,
12922 const unsigned long pgoff,
12923 - const unsigned long flags)
12924 + const unsigned long flags,
12925 + const unsigned long offset)
12926 {
12927 struct mm_struct *mm = current->mm;
12928 unsigned long addr = addr0;
12929 @@ -70,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12930 info.high_limit = mm->mmap_base;
12931 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12932 info.align_offset = 0;
12933 + info.threadstack_offset = offset;
12934 addr = vm_unmapped_area(&info);
12935
12936 /*
12937 @@ -82,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12938 VM_BUG_ON(addr != -ENOMEM);
12939 info.flags = 0;
12940 info.low_limit = TASK_UNMAPPED_BASE;
12941 +
12942 +#ifdef CONFIG_PAX_RANDMMAP
12943 + if (mm->pax_flags & MF_PAX_RANDMMAP)
12944 + info.low_limit += mm->delta_mmap;
12945 +#endif
12946 +
12947 info.high_limit = STACK_TOP32;
12948 addr = vm_unmapped_area(&info);
12949 }
12950 @@ -96,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12951 struct mm_struct *mm = current->mm;
12952 struct vm_area_struct *vma;
12953 unsigned long task_size = TASK_SIZE;
12954 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
12955
12956 if (test_thread_flag(TIF_32BIT))
12957 task_size = STACK_TOP32;
12958 @@ -111,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12959 return addr;
12960 }
12961
12962 +#ifdef CONFIG_PAX_RANDMMAP
12963 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
12964 +#endif
12965 +
12966 if (addr) {
12967 addr = ALIGN(addr, HPAGE_SIZE);
12968 vma = find_vma(mm, addr);
12969 - if (task_size - len >= addr &&
12970 - (!vma || addr + len <= vma->vm_start))
12971 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
12972 return addr;
12973 }
12974 if (mm->get_unmapped_area == arch_get_unmapped_area)
12975 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
12976 - pgoff, flags);
12977 + pgoff, flags, offset);
12978 else
12979 return hugetlb_get_unmapped_area_topdown(file, addr, len,
12980 - pgoff, flags);
12981 + pgoff, flags, offset);
12982 }
12983
12984 pte_t *huge_pte_alloc(struct mm_struct *mm,
12985 diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
12986 index 04bc826..0fefab9 100644
12987 --- a/arch/sparc/mm/init_64.c
12988 +++ b/arch/sparc/mm/init_64.c
12989 @@ -186,9 +186,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
12990 int num_kernel_image_mappings;
12991
12992 #ifdef CONFIG_DEBUG_DCFLUSH
12993 -atomic_t dcpage_flushes = ATOMIC_INIT(0);
12994 +atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
12995 #ifdef CONFIG_SMP
12996 -atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12997 +atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12998 #endif
12999 #endif
13000
13001 @@ -196,7 +196,7 @@ inline void flush_dcache_page_impl(struct page *page)
13002 {
13003 BUG_ON(tlb_type == hypervisor);
13004 #ifdef CONFIG_DEBUG_DCFLUSH
13005 - atomic_inc(&dcpage_flushes);
13006 + atomic_inc_unchecked(&dcpage_flushes);
13007 #endif
13008
13009 #ifdef DCACHE_ALIASING_POSSIBLE
13010 @@ -468,10 +468,10 @@ void mmu_info(struct seq_file *m)
13011
13012 #ifdef CONFIG_DEBUG_DCFLUSH
13013 seq_printf(m, "DCPageFlushes\t: %d\n",
13014 - atomic_read(&dcpage_flushes));
13015 + atomic_read_unchecked(&dcpage_flushes));
13016 #ifdef CONFIG_SMP
13017 seq_printf(m, "DCPageFlushesXC\t: %d\n",
13018 - atomic_read(&dcpage_flushes_xcall));
13019 + atomic_read_unchecked(&dcpage_flushes_xcall));
13020 #endif /* CONFIG_SMP */
13021 #endif /* CONFIG_DEBUG_DCFLUSH */
13022 }
13023 diff --git a/arch/sparc/net/bpf_jit_comp.c b/arch/sparc/net/bpf_jit_comp.c
13024 index ece4af0..f04b862 100644
13025 --- a/arch/sparc/net/bpf_jit_comp.c
13026 +++ b/arch/sparc/net/bpf_jit_comp.c
13027 @@ -823,5 +823,6 @@ void bpf_jit_free(struct bpf_prog *fp)
13028 {
13029 if (fp->jited)
13030 module_free(NULL, fp->bpf_func);
13031 - kfree(fp);
13032 +
13033 + bpf_prog_unlock_free(fp);
13034 }
13035 diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
13036 index 7fcd492..1311074 100644
13037 --- a/arch/tile/Kconfig
13038 +++ b/arch/tile/Kconfig
13039 @@ -191,6 +191,7 @@ source "kernel/Kconfig.hz"
13040
13041 config KEXEC
13042 bool "kexec system call"
13043 + depends on !GRKERNSEC_KMEM
13044 ---help---
13045 kexec is a system call that implements the ability to shutdown your
13046 current kernel, and to start another kernel. It is like a reboot
13047 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
13048 index 7b11c5f..755a026 100644
13049 --- a/arch/tile/include/asm/atomic_64.h
13050 +++ b/arch/tile/include/asm/atomic_64.h
13051 @@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
13052
13053 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
13054
13055 +#define atomic64_read_unchecked(v) atomic64_read(v)
13056 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
13057 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
13058 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
13059 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
13060 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
13061 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
13062 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
13063 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
13064 +
13065 /* Define this to indicate that cmpxchg is an efficient operation. */
13066 #define __HAVE_ARCH_CMPXCHG
13067
13068 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
13069 index 6160761..00cac88 100644
13070 --- a/arch/tile/include/asm/cache.h
13071 +++ b/arch/tile/include/asm/cache.h
13072 @@ -15,11 +15,12 @@
13073 #ifndef _ASM_TILE_CACHE_H
13074 #define _ASM_TILE_CACHE_H
13075
13076 +#include <linux/const.h>
13077 #include <arch/chip.h>
13078
13079 /* bytes per L1 data cache line */
13080 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
13081 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
13082 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
13083
13084 /* bytes per L2 cache line */
13085 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
13086 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
13087 index b6cde32..c0cb736 100644
13088 --- a/arch/tile/include/asm/uaccess.h
13089 +++ b/arch/tile/include/asm/uaccess.h
13090 @@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
13091 const void __user *from,
13092 unsigned long n)
13093 {
13094 - int sz = __compiletime_object_size(to);
13095 + size_t sz = __compiletime_object_size(to);
13096
13097 - if (likely(sz == -1 || sz >= n))
13098 + if (likely(sz == (size_t)-1 || sz >= n))
13099 n = _copy_from_user(to, from, n);
13100 else
13101 copy_from_user_overflow();
13102 diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
13103 index e514899..f8743c4 100644
13104 --- a/arch/tile/mm/hugetlbpage.c
13105 +++ b/arch/tile/mm/hugetlbpage.c
13106 @@ -207,6 +207,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
13107 info.high_limit = TASK_SIZE;
13108 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
13109 info.align_offset = 0;
13110 + info.threadstack_offset = 0;
13111 return vm_unmapped_area(&info);
13112 }
13113
13114 @@ -224,6 +225,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
13115 info.high_limit = current->mm->mmap_base;
13116 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
13117 info.align_offset = 0;
13118 + info.threadstack_offset = 0;
13119 addr = vm_unmapped_area(&info);
13120
13121 /*
13122 diff --git a/arch/um/Makefile b/arch/um/Makefile
13123 index e4b1a96..16162f8 100644
13124 --- a/arch/um/Makefile
13125 +++ b/arch/um/Makefile
13126 @@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
13127 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
13128 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
13129
13130 +ifdef CONSTIFY_PLUGIN
13131 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
13132 +endif
13133 +
13134 #This will adjust *FLAGS accordingly to the platform.
13135 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
13136
13137 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
13138 index 19e1bdd..3665b77 100644
13139 --- a/arch/um/include/asm/cache.h
13140 +++ b/arch/um/include/asm/cache.h
13141 @@ -1,6 +1,7 @@
13142 #ifndef __UM_CACHE_H
13143 #define __UM_CACHE_H
13144
13145 +#include <linux/const.h>
13146
13147 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
13148 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
13149 @@ -12,6 +13,6 @@
13150 # define L1_CACHE_SHIFT 5
13151 #endif
13152
13153 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
13154 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
13155
13156 #endif
13157 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
13158 index 2e0a6b1..a64d0f5 100644
13159 --- a/arch/um/include/asm/kmap_types.h
13160 +++ b/arch/um/include/asm/kmap_types.h
13161 @@ -8,6 +8,6 @@
13162
13163 /* No more #include "asm/arch/kmap_types.h" ! */
13164
13165 -#define KM_TYPE_NR 14
13166 +#define KM_TYPE_NR 15
13167
13168 #endif
13169 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
13170 index 71c5d13..4c7b9f1 100644
13171 --- a/arch/um/include/asm/page.h
13172 +++ b/arch/um/include/asm/page.h
13173 @@ -14,6 +14,9 @@
13174 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
13175 #define PAGE_MASK (~(PAGE_SIZE-1))
13176
13177 +#define ktla_ktva(addr) (addr)
13178 +#define ktva_ktla(addr) (addr)
13179 +
13180 #ifndef __ASSEMBLY__
13181
13182 struct page;
13183 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
13184 index 0032f92..cd151e0 100644
13185 --- a/arch/um/include/asm/pgtable-3level.h
13186 +++ b/arch/um/include/asm/pgtable-3level.h
13187 @@ -58,6 +58,7 @@
13188 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
13189 #define pud_populate(mm, pud, pmd) \
13190 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
13191 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
13192
13193 #ifdef CONFIG_64BIT
13194 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
13195 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
13196 index f17bca8..48adb87 100644
13197 --- a/arch/um/kernel/process.c
13198 +++ b/arch/um/kernel/process.c
13199 @@ -356,22 +356,6 @@ int singlestepping(void * t)
13200 return 2;
13201 }
13202
13203 -/*
13204 - * Only x86 and x86_64 have an arch_align_stack().
13205 - * All other arches have "#define arch_align_stack(x) (x)"
13206 - * in their asm/exec.h
13207 - * As this is included in UML from asm-um/system-generic.h,
13208 - * we can use it to behave as the subarch does.
13209 - */
13210 -#ifndef arch_align_stack
13211 -unsigned long arch_align_stack(unsigned long sp)
13212 -{
13213 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
13214 - sp -= get_random_int() % 8192;
13215 - return sp & ~0xf;
13216 -}
13217 -#endif
13218 -
13219 unsigned long get_wchan(struct task_struct *p)
13220 {
13221 unsigned long stack_page, sp, ip;
13222 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
13223 index ad8f795..2c7eec6 100644
13224 --- a/arch/unicore32/include/asm/cache.h
13225 +++ b/arch/unicore32/include/asm/cache.h
13226 @@ -12,8 +12,10 @@
13227 #ifndef __UNICORE_CACHE_H__
13228 #define __UNICORE_CACHE_H__
13229
13230 -#define L1_CACHE_SHIFT (5)
13231 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
13232 +#include <linux/const.h>
13233 +
13234 +#define L1_CACHE_SHIFT 5
13235 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
13236
13237 /*
13238 * Memory returned by kmalloc() may be used for DMA, so we must make
13239 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
13240 index 3632743..630a8bb 100644
13241 --- a/arch/x86/Kconfig
13242 +++ b/arch/x86/Kconfig
13243 @@ -130,7 +130,7 @@ config X86
13244 select RTC_LIB
13245 select HAVE_DEBUG_STACKOVERFLOW
13246 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
13247 - select HAVE_CC_STACKPROTECTOR
13248 + select HAVE_CC_STACKPROTECTOR if X86_64 || !PAX_MEMORY_UDEREF
13249 select GENERIC_CPU_AUTOPROBE
13250 select HAVE_ARCH_AUDITSYSCALL
13251 select ARCH_SUPPORTS_ATOMIC_RMW
13252 @@ -258,7 +258,7 @@ config X86_HT
13253
13254 config X86_32_LAZY_GS
13255 def_bool y
13256 - depends on X86_32 && !CC_STACKPROTECTOR
13257 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
13258
13259 config ARCH_HWEIGHT_CFLAGS
13260 string
13261 @@ -555,6 +555,7 @@ config SCHED_OMIT_FRAME_POINTER
13262
13263 menuconfig HYPERVISOR_GUEST
13264 bool "Linux guest support"
13265 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
13266 ---help---
13267 Say Y here to enable options for running Linux under various hyper-
13268 visors. This option enables basic hypervisor detection and platform
13269 @@ -1083,6 +1084,7 @@ choice
13270
13271 config NOHIGHMEM
13272 bool "off"
13273 + depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
13274 ---help---
13275 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
13276 However, the address space of 32-bit x86 processors is only 4
13277 @@ -1119,6 +1121,7 @@ config NOHIGHMEM
13278
13279 config HIGHMEM4G
13280 bool "4GB"
13281 + depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
13282 ---help---
13283 Select this if you have a 32-bit processor and between 1 and 4
13284 gigabytes of physical RAM.
13285 @@ -1171,7 +1174,7 @@ config PAGE_OFFSET
13286 hex
13287 default 0xB0000000 if VMSPLIT_3G_OPT
13288 default 0x80000000 if VMSPLIT_2G
13289 - default 0x78000000 if VMSPLIT_2G_OPT
13290 + default 0x70000000 if VMSPLIT_2G_OPT
13291 default 0x40000000 if VMSPLIT_1G
13292 default 0xC0000000
13293 depends on X86_32
13294 @@ -1586,6 +1589,7 @@ source kernel/Kconfig.hz
13295
13296 config KEXEC
13297 bool "kexec system call"
13298 + depends on !GRKERNSEC_KMEM
13299 ---help---
13300 kexec is a system call that implements the ability to shutdown your
13301 current kernel, and to start another kernel. It is like a reboot
13302 @@ -1771,7 +1775,9 @@ config X86_NEED_RELOCS
13303
13304 config PHYSICAL_ALIGN
13305 hex "Alignment value to which kernel should be aligned"
13306 - default "0x200000"
13307 + default "0x1000000"
13308 + range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
13309 + range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
13310 range 0x2000 0x1000000 if X86_32
13311 range 0x200000 0x1000000 if X86_64
13312 ---help---
13313 @@ -1854,6 +1860,7 @@ config COMPAT_VDSO
13314 def_bool n
13315 prompt "Disable the 32-bit vDSO (needed for glibc 2.3.3)"
13316 depends on X86_32 || IA32_EMULATION
13317 + depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
13318 ---help---
13319 Certain buggy versions of glibc will crash if they are
13320 presented with a 32-bit vDSO that is not mapped at the address
13321 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
13322 index 6983314..54ad7e8 100644
13323 --- a/arch/x86/Kconfig.cpu
13324 +++ b/arch/x86/Kconfig.cpu
13325 @@ -319,7 +319,7 @@ config X86_PPRO_FENCE
13326
13327 config X86_F00F_BUG
13328 def_bool y
13329 - depends on M586MMX || M586TSC || M586 || M486
13330 + depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
13331
13332 config X86_INVD_BUG
13333 def_bool y
13334 @@ -327,7 +327,7 @@ config X86_INVD_BUG
13335
13336 config X86_ALIGNMENT_16
13337 def_bool y
13338 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
13339 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
13340
13341 config X86_INTEL_USERCOPY
13342 def_bool y
13343 @@ -369,7 +369,7 @@ config X86_CMPXCHG64
13344 # generates cmov.
13345 config X86_CMOV
13346 def_bool y
13347 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
13348 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
13349
13350 config X86_MINIMUM_CPU_FAMILY
13351 int
13352 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
13353 index 61bd2ad..50b625d 100644
13354 --- a/arch/x86/Kconfig.debug
13355 +++ b/arch/x86/Kconfig.debug
13356 @@ -93,7 +93,7 @@ config EFI_PGT_DUMP
13357 config DEBUG_RODATA
13358 bool "Write protect kernel read-only data structures"
13359 default y
13360 - depends on DEBUG_KERNEL
13361 + depends on DEBUG_KERNEL && BROKEN
13362 ---help---
13363 Mark the kernel read-only data as write-protected in the pagetables,
13364 in order to catch accidental (and incorrect) writes to such const
13365 @@ -111,7 +111,7 @@ config DEBUG_RODATA_TEST
13366
13367 config DEBUG_SET_MODULE_RONX
13368 bool "Set loadable kernel module data as NX and text as RO"
13369 - depends on MODULES
13370 + depends on MODULES && BROKEN
13371 ---help---
13372 This option helps catch unintended modifications to loadable
13373 kernel module's text and read-only data. It also prevents execution
13374 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
13375 index 60087ca..9d9500e 100644
13376 --- a/arch/x86/Makefile
13377 +++ b/arch/x86/Makefile
13378 @@ -68,9 +68,6 @@ ifeq ($(CONFIG_X86_32),y)
13379 # CPU-specific tuning. Anything which can be shared with UML should go here.
13380 include $(srctree)/arch/x86/Makefile_32.cpu
13381 KBUILD_CFLAGS += $(cflags-y)
13382 -
13383 - # temporary until string.h is fixed
13384 - KBUILD_CFLAGS += -ffreestanding
13385 else
13386 BITS := 64
13387 UTS_MACHINE := x86_64
13388 @@ -111,6 +108,9 @@ else
13389 KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args)
13390 endif
13391
13392 +# temporary until string.h is fixed
13393 +KBUILD_CFLAGS += -ffreestanding
13394 +
13395 # Make sure compiler does not have buggy stack-protector support.
13396 ifdef CONFIG_CC_STACKPROTECTOR
13397 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
13398 @@ -184,6 +184,7 @@ archheaders:
13399 $(Q)$(MAKE) $(build)=arch/x86/syscalls all
13400
13401 archprepare:
13402 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
13403 ifeq ($(CONFIG_KEXEC_FILE),y)
13404 $(Q)$(MAKE) $(build)=arch/x86/purgatory arch/x86/purgatory/kexec-purgatory.c
13405 endif
13406 @@ -274,3 +275,9 @@ define archhelp
13407 echo ' FDINITRD=file initrd for the booted kernel'
13408 echo ' kvmconfig - Enable additional options for guest kernel support'
13409 endef
13410 +
13411 +define OLD_LD
13412 +
13413 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
13414 +*** Please upgrade your binutils to 2.18 or newer
13415 +endef
13416 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
13417 index dbe8dd2..2f0a98f 100644
13418 --- a/arch/x86/boot/Makefile
13419 +++ b/arch/x86/boot/Makefile
13420 @@ -52,6 +52,9 @@ $(obj)/cpustr.h: $(obj)/mkcpustr FORCE
13421 # ---------------------------------------------------------------------------
13422
13423 KBUILD_CFLAGS := $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
13424 +ifdef CONSTIFY_PLUGIN
13425 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
13426 +endif
13427 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
13428 GCOV_PROFILE := n
13429
13430 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
13431 index 878e4b9..20537ab 100644
13432 --- a/arch/x86/boot/bitops.h
13433 +++ b/arch/x86/boot/bitops.h
13434 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
13435 u8 v;
13436 const u32 *p = (const u32 *)addr;
13437
13438 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
13439 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
13440 return v;
13441 }
13442
13443 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
13444
13445 static inline void set_bit(int nr, void *addr)
13446 {
13447 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
13448 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
13449 }
13450
13451 #endif /* BOOT_BITOPS_H */
13452 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
13453 index bd49ec6..94c7f58 100644
13454 --- a/arch/x86/boot/boot.h
13455 +++ b/arch/x86/boot/boot.h
13456 @@ -84,7 +84,7 @@ static inline void io_delay(void)
13457 static inline u16 ds(void)
13458 {
13459 u16 seg;
13460 - asm("movw %%ds,%0" : "=rm" (seg));
13461 + asm volatile("movw %%ds,%0" : "=rm" (seg));
13462 return seg;
13463 }
13464
13465 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
13466 index 14fe7cb..829b962 100644
13467 --- a/arch/x86/boot/compressed/Makefile
13468 +++ b/arch/x86/boot/compressed/Makefile
13469 @@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
13470 KBUILD_CFLAGS += -mno-mmx -mno-sse
13471 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
13472 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
13473 +ifdef CONSTIFY_PLUGIN
13474 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
13475 +endif
13476
13477 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
13478 GCOV_PROFILE := n
13479 diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
13480 index a53440e..c3dbf1e 100644
13481 --- a/arch/x86/boot/compressed/efi_stub_32.S
13482 +++ b/arch/x86/boot/compressed/efi_stub_32.S
13483 @@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
13484 * parameter 2, ..., param n. To make things easy, we save the return
13485 * address of efi_call_phys in a global variable.
13486 */
13487 - popl %ecx
13488 - movl %ecx, saved_return_addr(%edx)
13489 - /* get the function pointer into ECX*/
13490 - popl %ecx
13491 - movl %ecx, efi_rt_function_ptr(%edx)
13492 + popl saved_return_addr(%edx)
13493 + popl efi_rt_function_ptr(%edx)
13494
13495 /*
13496 * 3. Call the physical function.
13497 */
13498 - call *%ecx
13499 + call *efi_rt_function_ptr(%edx)
13500
13501 /*
13502 * 4. Balance the stack. And because EAX contain the return value,
13503 @@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
13504 1: popl %edx
13505 subl $1b, %edx
13506
13507 - movl efi_rt_function_ptr(%edx), %ecx
13508 - pushl %ecx
13509 + pushl efi_rt_function_ptr(%edx)
13510
13511 /*
13512 * 10. Push the saved return address onto the stack and return.
13513 */
13514 - movl saved_return_addr(%edx), %ecx
13515 - pushl %ecx
13516 - ret
13517 + jmpl *saved_return_addr(%edx)
13518 ENDPROC(efi_call_phys)
13519 .previous
13520
13521 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
13522 index 1d7fbbc..36ecd58 100644
13523 --- a/arch/x86/boot/compressed/head_32.S
13524 +++ b/arch/x86/boot/compressed/head_32.S
13525 @@ -140,10 +140,10 @@ preferred_addr:
13526 addl %eax, %ebx
13527 notl %eax
13528 andl %eax, %ebx
13529 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
13530 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
13531 jge 1f
13532 #endif
13533 - movl $LOAD_PHYSICAL_ADDR, %ebx
13534 + movl $____LOAD_PHYSICAL_ADDR, %ebx
13535 1:
13536
13537 /* Target address to relocate to for decompression */
13538 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
13539 index 6b1766c..ad465c9 100644
13540 --- a/arch/x86/boot/compressed/head_64.S
13541 +++ b/arch/x86/boot/compressed/head_64.S
13542 @@ -94,10 +94,10 @@ ENTRY(startup_32)
13543 addl %eax, %ebx
13544 notl %eax
13545 andl %eax, %ebx
13546 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
13547 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
13548 jge 1f
13549 #endif
13550 - movl $LOAD_PHYSICAL_ADDR, %ebx
13551 + movl $____LOAD_PHYSICAL_ADDR, %ebx
13552 1:
13553
13554 /* Target address to relocate to for decompression */
13555 @@ -322,10 +322,10 @@ preferred_addr:
13556 addq %rax, %rbp
13557 notq %rax
13558 andq %rax, %rbp
13559 - cmpq $LOAD_PHYSICAL_ADDR, %rbp
13560 + cmpq $____LOAD_PHYSICAL_ADDR, %rbp
13561 jge 1f
13562 #endif
13563 - movq $LOAD_PHYSICAL_ADDR, %rbp
13564 + movq $____LOAD_PHYSICAL_ADDR, %rbp
13565 1:
13566
13567 /* Target address to relocate to for decompression */
13568 @@ -434,8 +434,8 @@ gdt:
13569 .long gdt
13570 .word 0
13571 .quad 0x0000000000000000 /* NULL descriptor */
13572 - .quad 0x00af9a000000ffff /* __KERNEL_CS */
13573 - .quad 0x00cf92000000ffff /* __KERNEL_DS */
13574 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
13575 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
13576 .quad 0x0080890000000000 /* TS descriptor */
13577 .quad 0x0000000000000000 /* TS continued */
13578 gdt_end:
13579 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
13580 index 30dd59a..cd9edc3 100644
13581 --- a/arch/x86/boot/compressed/misc.c
13582 +++ b/arch/x86/boot/compressed/misc.c
13583 @@ -242,7 +242,7 @@ static void handle_relocations(void *output, unsigned long output_len)
13584 * Calculate the delta between where vmlinux was linked to load
13585 * and where it was actually loaded.
13586 */
13587 - delta = min_addr - LOAD_PHYSICAL_ADDR;
13588 + delta = min_addr - ____LOAD_PHYSICAL_ADDR;
13589 if (!delta) {
13590 debug_putstr("No relocation needed... ");
13591 return;
13592 @@ -312,7 +312,7 @@ static void parse_elf(void *output)
13593 Elf32_Ehdr ehdr;
13594 Elf32_Phdr *phdrs, *phdr;
13595 #endif
13596 - void *dest;
13597 + void *dest, *prev;
13598 int i;
13599
13600 memcpy(&ehdr, output, sizeof(ehdr));
13601 @@ -339,13 +339,16 @@ static void parse_elf(void *output)
13602 case PT_LOAD:
13603 #ifdef CONFIG_RELOCATABLE
13604 dest = output;
13605 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
13606 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
13607 #else
13608 dest = (void *)(phdr->p_paddr);
13609 #endif
13610 memcpy(dest,
13611 output + phdr->p_offset,
13612 phdr->p_filesz);
13613 + if (i)
13614 + memset(prev, 0xff, dest - prev);
13615 + prev = dest + phdr->p_filesz;
13616 break;
13617 default: /* Ignore other PT_* */ break;
13618 }
13619 @@ -402,7 +405,7 @@ asmlinkage __visible void *decompress_kernel(void *rmode, memptr heap,
13620 error("Destination address too large");
13621 #endif
13622 #ifndef CONFIG_RELOCATABLE
13623 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
13624 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
13625 error("Wrong destination address");
13626 #endif
13627
13628 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
13629 index 1fd7d57..0f7d096 100644
13630 --- a/arch/x86/boot/cpucheck.c
13631 +++ b/arch/x86/boot/cpucheck.c
13632 @@ -125,9 +125,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
13633 u32 ecx = MSR_K7_HWCR;
13634 u32 eax, edx;
13635
13636 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13637 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13638 eax &= ~(1 << 15);
13639 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13640 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13641
13642 get_cpuflags(); /* Make sure it really did something */
13643 err = check_cpuflags();
13644 @@ -140,9 +140,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
13645 u32 ecx = MSR_VIA_FCR;
13646 u32 eax, edx;
13647
13648 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13649 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13650 eax |= (1<<1)|(1<<7);
13651 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13652 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13653
13654 set_bit(X86_FEATURE_CX8, cpu.flags);
13655 err = check_cpuflags();
13656 @@ -153,12 +153,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
13657 u32 eax, edx;
13658 u32 level = 1;
13659
13660 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13661 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
13662 - asm("cpuid"
13663 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13664 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
13665 + asm volatile("cpuid"
13666 : "+a" (level), "=d" (cpu.flags[0])
13667 : : "ecx", "ebx");
13668 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13669 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13670
13671 err = check_cpuflags();
13672 } else if (err == 0x01 &&
13673 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
13674 index 16ef025..91e033b 100644
13675 --- a/arch/x86/boot/header.S
13676 +++ b/arch/x86/boot/header.S
13677 @@ -438,10 +438,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
13678 # single linked list of
13679 # struct setup_data
13680
13681 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
13682 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
13683
13684 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
13685 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13686 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
13687 +#else
13688 #define VO_INIT_SIZE (VO__end - VO__text)
13689 +#endif
13690 #if ZO_INIT_SIZE > VO_INIT_SIZE
13691 #define INIT_SIZE ZO_INIT_SIZE
13692 #else
13693 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
13694 index db75d07..8e6d0af 100644
13695 --- a/arch/x86/boot/memory.c
13696 +++ b/arch/x86/boot/memory.c
13697 @@ -19,7 +19,7 @@
13698
13699 static int detect_memory_e820(void)
13700 {
13701 - int count = 0;
13702 + unsigned int count = 0;
13703 struct biosregs ireg, oreg;
13704 struct e820entry *desc = boot_params.e820_map;
13705 static struct e820entry buf; /* static so it is zeroed */
13706 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
13707 index ba3e100..6501b8f 100644
13708 --- a/arch/x86/boot/video-vesa.c
13709 +++ b/arch/x86/boot/video-vesa.c
13710 @@ -201,6 +201,7 @@ static void vesa_store_pm_info(void)
13711
13712 boot_params.screen_info.vesapm_seg = oreg.es;
13713 boot_params.screen_info.vesapm_off = oreg.di;
13714 + boot_params.screen_info.vesapm_size = oreg.cx;
13715 }
13716
13717 /*
13718 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
13719 index 43eda28..5ab5fdb 100644
13720 --- a/arch/x86/boot/video.c
13721 +++ b/arch/x86/boot/video.c
13722 @@ -96,7 +96,7 @@ static void store_mode_params(void)
13723 static unsigned int get_entry(void)
13724 {
13725 char entry_buf[4];
13726 - int i, len = 0;
13727 + unsigned int i, len = 0;
13728 int key;
13729 unsigned int v;
13730
13731 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
13732 index 9105655..41779c1 100644
13733 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
13734 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
13735 @@ -8,6 +8,8 @@
13736 * including this sentence is retained in full.
13737 */
13738
13739 +#include <asm/alternative-asm.h>
13740 +
13741 .extern crypto_ft_tab
13742 .extern crypto_it_tab
13743 .extern crypto_fl_tab
13744 @@ -70,6 +72,8 @@
13745 je B192; \
13746 leaq 32(r9),r9;
13747
13748 +#define ret pax_force_retaddr; ret
13749 +
13750 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
13751 movq r1,r2; \
13752 movq r3,r4; \
13753 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
13754 index 477e9d7..c92c7d8 100644
13755 --- a/arch/x86/crypto/aesni-intel_asm.S
13756 +++ b/arch/x86/crypto/aesni-intel_asm.S
13757 @@ -31,6 +31,7 @@
13758
13759 #include <linux/linkage.h>
13760 #include <asm/inst.h>
13761 +#include <asm/alternative-asm.h>
13762
13763 #ifdef __x86_64__
13764 .data
13765 @@ -205,7 +206,7 @@ enc: .octa 0x2
13766 * num_initial_blocks = b mod 4
13767 * encrypt the initial num_initial_blocks blocks and apply ghash on
13768 * the ciphertext
13769 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13770 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13771 * are clobbered
13772 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13773 */
13774 @@ -214,8 +215,8 @@ enc: .octa 0x2
13775 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13776 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13777 mov arg7, %r10 # %r10 = AAD
13778 - mov arg8, %r12 # %r12 = aadLen
13779 - mov %r12, %r11
13780 + mov arg8, %r15 # %r15 = aadLen
13781 + mov %r15, %r11
13782 pxor %xmm\i, %xmm\i
13783 _get_AAD_loop\num_initial_blocks\operation:
13784 movd (%r10), \TMP1
13785 @@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13786 psrldq $4, %xmm\i
13787 pxor \TMP1, %xmm\i
13788 add $4, %r10
13789 - sub $4, %r12
13790 + sub $4, %r15
13791 jne _get_AAD_loop\num_initial_blocks\operation
13792 cmp $16, %r11
13793 je _get_AAD_loop2_done\num_initial_blocks\operation
13794 - mov $16, %r12
13795 + mov $16, %r15
13796 _get_AAD_loop2\num_initial_blocks\operation:
13797 psrldq $4, %xmm\i
13798 - sub $4, %r12
13799 - cmp %r11, %r12
13800 + sub $4, %r15
13801 + cmp %r11, %r15
13802 jne _get_AAD_loop2\num_initial_blocks\operation
13803 _get_AAD_loop2_done\num_initial_blocks\operation:
13804 movdqa SHUF_MASK(%rip), %xmm14
13805 @@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
13806 * num_initial_blocks = b mod 4
13807 * encrypt the initial num_initial_blocks blocks and apply ghash on
13808 * the ciphertext
13809 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13810 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13811 * are clobbered
13812 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13813 */
13814 @@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
13815 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13816 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13817 mov arg7, %r10 # %r10 = AAD
13818 - mov arg8, %r12 # %r12 = aadLen
13819 - mov %r12, %r11
13820 + mov arg8, %r15 # %r15 = aadLen
13821 + mov %r15, %r11
13822 pxor %xmm\i, %xmm\i
13823 _get_AAD_loop\num_initial_blocks\operation:
13824 movd (%r10), \TMP1
13825 @@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13826 psrldq $4, %xmm\i
13827 pxor \TMP1, %xmm\i
13828 add $4, %r10
13829 - sub $4, %r12
13830 + sub $4, %r15
13831 jne _get_AAD_loop\num_initial_blocks\operation
13832 cmp $16, %r11
13833 je _get_AAD_loop2_done\num_initial_blocks\operation
13834 - mov $16, %r12
13835 + mov $16, %r15
13836 _get_AAD_loop2\num_initial_blocks\operation:
13837 psrldq $4, %xmm\i
13838 - sub $4, %r12
13839 - cmp %r11, %r12
13840 + sub $4, %r15
13841 + cmp %r11, %r15
13842 jne _get_AAD_loop2\num_initial_blocks\operation
13843 _get_AAD_loop2_done\num_initial_blocks\operation:
13844 movdqa SHUF_MASK(%rip), %xmm14
13845 @@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
13846 *
13847 *****************************************************************************/
13848 ENTRY(aesni_gcm_dec)
13849 - push %r12
13850 + push %r15
13851 push %r13
13852 push %r14
13853 mov %rsp, %r14
13854 @@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
13855 */
13856 sub $VARIABLE_OFFSET, %rsp
13857 and $~63, %rsp # align rsp to 64 bytes
13858 - mov %arg6, %r12
13859 - movdqu (%r12), %xmm13 # %xmm13 = HashKey
13860 + mov %arg6, %r15
13861 + movdqu (%r15), %xmm13 # %xmm13 = HashKey
13862 movdqa SHUF_MASK(%rip), %xmm2
13863 PSHUFB_XMM %xmm2, %xmm13
13864
13865 @@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
13866 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
13867 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
13868 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
13869 - mov %r13, %r12
13870 - and $(3<<4), %r12
13871 + mov %r13, %r15
13872 + and $(3<<4), %r15
13873 jz _initial_num_blocks_is_0_decrypt
13874 - cmp $(2<<4), %r12
13875 + cmp $(2<<4), %r15
13876 jb _initial_num_blocks_is_1_decrypt
13877 je _initial_num_blocks_is_2_decrypt
13878 _initial_num_blocks_is_3_decrypt:
13879 @@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
13880 sub $16, %r11
13881 add %r13, %r11
13882 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
13883 - lea SHIFT_MASK+16(%rip), %r12
13884 - sub %r13, %r12
13885 + lea SHIFT_MASK+16(%rip), %r15
13886 + sub %r13, %r15
13887 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
13888 # (%r13 is the number of bytes in plaintext mod 16)
13889 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13890 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13891 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
13892
13893 movdqa %xmm1, %xmm2
13894 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
13895 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13896 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13897 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
13898 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
13899 pand %xmm1, %xmm2
13900 @@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
13901 sub $1, %r13
13902 jne _less_than_8_bytes_left_decrypt
13903 _multiple_of_16_bytes_decrypt:
13904 - mov arg8, %r12 # %r13 = aadLen (number of bytes)
13905 - shl $3, %r12 # convert into number of bits
13906 - movd %r12d, %xmm15 # len(A) in %xmm15
13907 + mov arg8, %r15 # %r13 = aadLen (number of bytes)
13908 + shl $3, %r15 # convert into number of bits
13909 + movd %r15d, %xmm15 # len(A) in %xmm15
13910 shl $3, %arg4 # len(C) in bits (*128)
13911 MOVQ_R64_XMM %arg4, %xmm1
13912 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13913 @@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
13914 mov %r14, %rsp
13915 pop %r14
13916 pop %r13
13917 - pop %r12
13918 + pop %r15
13919 + pax_force_retaddr
13920 ret
13921 ENDPROC(aesni_gcm_dec)
13922
13923 @@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
13924 * poly = x^128 + x^127 + x^126 + x^121 + 1
13925 ***************************************************************************/
13926 ENTRY(aesni_gcm_enc)
13927 - push %r12
13928 + push %r15
13929 push %r13
13930 push %r14
13931 mov %rsp, %r14
13932 @@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
13933 #
13934 sub $VARIABLE_OFFSET, %rsp
13935 and $~63, %rsp
13936 - mov %arg6, %r12
13937 - movdqu (%r12), %xmm13
13938 + mov %arg6, %r15
13939 + movdqu (%r15), %xmm13
13940 movdqa SHUF_MASK(%rip), %xmm2
13941 PSHUFB_XMM %xmm2, %xmm13
13942
13943 @@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
13944 movdqa %xmm13, HashKey(%rsp)
13945 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
13946 and $-16, %r13
13947 - mov %r13, %r12
13948 + mov %r13, %r15
13949
13950 # Encrypt first few blocks
13951
13952 - and $(3<<4), %r12
13953 + and $(3<<4), %r15
13954 jz _initial_num_blocks_is_0_encrypt
13955 - cmp $(2<<4), %r12
13956 + cmp $(2<<4), %r15
13957 jb _initial_num_blocks_is_1_encrypt
13958 je _initial_num_blocks_is_2_encrypt
13959 _initial_num_blocks_is_3_encrypt:
13960 @@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
13961 sub $16, %r11
13962 add %r13, %r11
13963 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
13964 - lea SHIFT_MASK+16(%rip), %r12
13965 - sub %r13, %r12
13966 + lea SHIFT_MASK+16(%rip), %r15
13967 + sub %r13, %r15
13968 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
13969 # (%r13 is the number of bytes in plaintext mod 16)
13970 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13971 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13972 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
13973 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
13974 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13975 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13976 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
13977 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
13978 movdqa SHUF_MASK(%rip), %xmm10
13979 @@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
13980 sub $1, %r13
13981 jne _less_than_8_bytes_left_encrypt
13982 _multiple_of_16_bytes_encrypt:
13983 - mov arg8, %r12 # %r12 = addLen (number of bytes)
13984 - shl $3, %r12
13985 - movd %r12d, %xmm15 # len(A) in %xmm15
13986 + mov arg8, %r15 # %r15 = addLen (number of bytes)
13987 + shl $3, %r15
13988 + movd %r15d, %xmm15 # len(A) in %xmm15
13989 shl $3, %arg4 # len(C) in bits (*128)
13990 MOVQ_R64_XMM %arg4, %xmm1
13991 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13992 @@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
13993 mov %r14, %rsp
13994 pop %r14
13995 pop %r13
13996 - pop %r12
13997 + pop %r15
13998 + pax_force_retaddr
13999 ret
14000 ENDPROC(aesni_gcm_enc)
14001
14002 @@ -1722,6 +1725,7 @@ _key_expansion_256a:
14003 pxor %xmm1, %xmm0
14004 movaps %xmm0, (TKEYP)
14005 add $0x10, TKEYP
14006 + pax_force_retaddr
14007 ret
14008 ENDPROC(_key_expansion_128)
14009 ENDPROC(_key_expansion_256a)
14010 @@ -1748,6 +1752,7 @@ _key_expansion_192a:
14011 shufps $0b01001110, %xmm2, %xmm1
14012 movaps %xmm1, 0x10(TKEYP)
14013 add $0x20, TKEYP
14014 + pax_force_retaddr
14015 ret
14016 ENDPROC(_key_expansion_192a)
14017
14018 @@ -1768,6 +1773,7 @@ _key_expansion_192b:
14019
14020 movaps %xmm0, (TKEYP)
14021 add $0x10, TKEYP
14022 + pax_force_retaddr
14023 ret
14024 ENDPROC(_key_expansion_192b)
14025
14026 @@ -1781,6 +1787,7 @@ _key_expansion_256b:
14027 pxor %xmm1, %xmm2
14028 movaps %xmm2, (TKEYP)
14029 add $0x10, TKEYP
14030 + pax_force_retaddr
14031 ret
14032 ENDPROC(_key_expansion_256b)
14033
14034 @@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
14035 #ifndef __x86_64__
14036 popl KEYP
14037 #endif
14038 + pax_force_retaddr
14039 ret
14040 ENDPROC(aesni_set_key)
14041
14042 @@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
14043 popl KLEN
14044 popl KEYP
14045 #endif
14046 + pax_force_retaddr
14047 ret
14048 ENDPROC(aesni_enc)
14049
14050 @@ -1974,6 +1983,7 @@ _aesni_enc1:
14051 AESENC KEY STATE
14052 movaps 0x70(TKEYP), KEY
14053 AESENCLAST KEY STATE
14054 + pax_force_retaddr
14055 ret
14056 ENDPROC(_aesni_enc1)
14057
14058 @@ -2083,6 +2093,7 @@ _aesni_enc4:
14059 AESENCLAST KEY STATE2
14060 AESENCLAST KEY STATE3
14061 AESENCLAST KEY STATE4
14062 + pax_force_retaddr
14063 ret
14064 ENDPROC(_aesni_enc4)
14065
14066 @@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
14067 popl KLEN
14068 popl KEYP
14069 #endif
14070 + pax_force_retaddr
14071 ret
14072 ENDPROC(aesni_dec)
14073
14074 @@ -2164,6 +2176,7 @@ _aesni_dec1:
14075 AESDEC KEY STATE
14076 movaps 0x70(TKEYP), KEY
14077 AESDECLAST KEY STATE
14078 + pax_force_retaddr
14079 ret
14080 ENDPROC(_aesni_dec1)
14081
14082 @@ -2273,6 +2286,7 @@ _aesni_dec4:
14083 AESDECLAST KEY STATE2
14084 AESDECLAST KEY STATE3
14085 AESDECLAST KEY STATE4
14086 + pax_force_retaddr
14087 ret
14088 ENDPROC(_aesni_dec4)
14089
14090 @@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
14091 popl KEYP
14092 popl LEN
14093 #endif
14094 + pax_force_retaddr
14095 ret
14096 ENDPROC(aesni_ecb_enc)
14097
14098 @@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
14099 popl KEYP
14100 popl LEN
14101 #endif
14102 + pax_force_retaddr
14103 ret
14104 ENDPROC(aesni_ecb_dec)
14105
14106 @@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
14107 popl LEN
14108 popl IVP
14109 #endif
14110 + pax_force_retaddr
14111 ret
14112 ENDPROC(aesni_cbc_enc)
14113
14114 @@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
14115 popl LEN
14116 popl IVP
14117 #endif
14118 + pax_force_retaddr
14119 ret
14120 ENDPROC(aesni_cbc_dec)
14121
14122 @@ -2550,6 +2568,7 @@ _aesni_inc_init:
14123 mov $1, TCTR_LOW
14124 MOVQ_R64_XMM TCTR_LOW INC
14125 MOVQ_R64_XMM CTR TCTR_LOW
14126 + pax_force_retaddr
14127 ret
14128 ENDPROC(_aesni_inc_init)
14129
14130 @@ -2579,6 +2598,7 @@ _aesni_inc:
14131 .Linc_low:
14132 movaps CTR, IV
14133 PSHUFB_XMM BSWAP_MASK IV
14134 + pax_force_retaddr
14135 ret
14136 ENDPROC(_aesni_inc)
14137
14138 @@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
14139 .Lctr_enc_ret:
14140 movups IV, (IVP)
14141 .Lctr_enc_just_ret:
14142 + pax_force_retaddr
14143 ret
14144 ENDPROC(aesni_ctr_enc)
14145
14146 @@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
14147 pxor INC, STATE4
14148 movdqu STATE4, 0x70(OUTP)
14149
14150 + pax_force_retaddr
14151 ret
14152 ENDPROC(aesni_xts_crypt8)
14153
14154 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
14155 index 246c670..466e2d6 100644
14156 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
14157 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
14158 @@ -21,6 +21,7 @@
14159 */
14160
14161 #include <linux/linkage.h>
14162 +#include <asm/alternative-asm.h>
14163
14164 .file "blowfish-x86_64-asm.S"
14165 .text
14166 @@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
14167 jnz .L__enc_xor;
14168
14169 write_block();
14170 + pax_force_retaddr
14171 ret;
14172 .L__enc_xor:
14173 xor_block();
14174 + pax_force_retaddr
14175 ret;
14176 ENDPROC(__blowfish_enc_blk)
14177
14178 @@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
14179
14180 movq %r11, %rbp;
14181
14182 + pax_force_retaddr
14183 ret;
14184 ENDPROC(blowfish_dec_blk)
14185
14186 @@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
14187
14188 popq %rbx;
14189 popq %rbp;
14190 + pax_force_retaddr
14191 ret;
14192
14193 .L__enc_xor4:
14194 @@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
14195
14196 popq %rbx;
14197 popq %rbp;
14198 + pax_force_retaddr
14199 ret;
14200 ENDPROC(__blowfish_enc_blk_4way)
14201
14202 @@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
14203 popq %rbx;
14204 popq %rbp;
14205
14206 + pax_force_retaddr
14207 ret;
14208 ENDPROC(blowfish_dec_blk_4way)
14209 diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
14210 index ce71f92..1dce7ec 100644
14211 --- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
14212 +++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
14213 @@ -16,6 +16,7 @@
14214 */
14215
14216 #include <linux/linkage.h>
14217 +#include <asm/alternative-asm.h>
14218
14219 #define CAMELLIA_TABLE_BYTE_LEN 272
14220
14221 @@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
14222 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
14223 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
14224 %rcx, (%r9));
14225 + pax_force_retaddr
14226 ret;
14227 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
14228
14229 @@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
14230 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
14231 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
14232 %rax, (%r9));
14233 + pax_force_retaddr
14234 ret;
14235 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
14236
14237 @@ -780,6 +783,7 @@ __camellia_enc_blk16:
14238 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
14239 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
14240
14241 + pax_force_retaddr
14242 ret;
14243
14244 .align 8
14245 @@ -865,6 +869,7 @@ __camellia_dec_blk16:
14246 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
14247 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
14248
14249 + pax_force_retaddr
14250 ret;
14251
14252 .align 8
14253 @@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
14254 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
14255 %xmm8, %rsi);
14256
14257 + pax_force_retaddr
14258 ret;
14259 ENDPROC(camellia_ecb_enc_16way)
14260
14261 @@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
14262 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
14263 %xmm8, %rsi);
14264
14265 + pax_force_retaddr
14266 ret;
14267 ENDPROC(camellia_ecb_dec_16way)
14268
14269 @@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
14270 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
14271 %xmm8, %rsi);
14272
14273 + pax_force_retaddr
14274 ret;
14275 ENDPROC(camellia_cbc_dec_16way)
14276
14277 @@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
14278 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
14279 %xmm8, %rsi);
14280
14281 + pax_force_retaddr
14282 ret;
14283 ENDPROC(camellia_ctr_16way)
14284
14285 @@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
14286 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
14287 %xmm8, %rsi);
14288
14289 + pax_force_retaddr
14290 ret;
14291 ENDPROC(camellia_xts_crypt_16way)
14292
14293 diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
14294 index 0e0b886..5a3123c 100644
14295 --- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
14296 +++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
14297 @@ -11,6 +11,7 @@
14298 */
14299
14300 #include <linux/linkage.h>
14301 +#include <asm/alternative-asm.h>
14302
14303 #define CAMELLIA_TABLE_BYTE_LEN 272
14304
14305 @@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
14306 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
14307 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
14308 %rcx, (%r9));
14309 + pax_force_retaddr
14310 ret;
14311 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
14312
14313 @@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
14314 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
14315 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
14316 %rax, (%r9));
14317 + pax_force_retaddr
14318 ret;
14319 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
14320
14321 @@ -820,6 +823,7 @@ __camellia_enc_blk32:
14322 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
14323 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
14324
14325 + pax_force_retaddr
14326 ret;
14327
14328 .align 8
14329 @@ -905,6 +909,7 @@ __camellia_dec_blk32:
14330 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
14331 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
14332
14333 + pax_force_retaddr
14334 ret;
14335
14336 .align 8
14337 @@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
14338
14339 vzeroupper;
14340
14341 + pax_force_retaddr
14342 ret;
14343 ENDPROC(camellia_ecb_enc_32way)
14344
14345 @@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
14346
14347 vzeroupper;
14348
14349 + pax_force_retaddr
14350 ret;
14351 ENDPROC(camellia_ecb_dec_32way)
14352
14353 @@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
14354
14355 vzeroupper;
14356
14357 + pax_force_retaddr
14358 ret;
14359 ENDPROC(camellia_cbc_dec_32way)
14360
14361 @@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
14362
14363 vzeroupper;
14364
14365 + pax_force_retaddr
14366 ret;
14367 ENDPROC(camellia_ctr_32way)
14368
14369 @@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
14370
14371 vzeroupper;
14372
14373 + pax_force_retaddr
14374 ret;
14375 ENDPROC(camellia_xts_crypt_32way)
14376
14377 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
14378 index 310319c..db3d7b5 100644
14379 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
14380 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
14381 @@ -21,6 +21,7 @@
14382 */
14383
14384 #include <linux/linkage.h>
14385 +#include <asm/alternative-asm.h>
14386
14387 .file "camellia-x86_64-asm_64.S"
14388 .text
14389 @@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
14390 enc_outunpack(mov, RT1);
14391
14392 movq RRBP, %rbp;
14393 + pax_force_retaddr
14394 ret;
14395
14396 .L__enc_xor:
14397 enc_outunpack(xor, RT1);
14398
14399 movq RRBP, %rbp;
14400 + pax_force_retaddr
14401 ret;
14402 ENDPROC(__camellia_enc_blk)
14403
14404 @@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
14405 dec_outunpack();
14406
14407 movq RRBP, %rbp;
14408 + pax_force_retaddr
14409 ret;
14410 ENDPROC(camellia_dec_blk)
14411
14412 @@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
14413
14414 movq RRBP, %rbp;
14415 popq %rbx;
14416 + pax_force_retaddr
14417 ret;
14418
14419 .L__enc2_xor:
14420 @@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
14421
14422 movq RRBP, %rbp;
14423 popq %rbx;
14424 + pax_force_retaddr
14425 ret;
14426 ENDPROC(__camellia_enc_blk_2way)
14427
14428 @@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
14429
14430 movq RRBP, %rbp;
14431 movq RXOR, %rbx;
14432 + pax_force_retaddr
14433 ret;
14434 ENDPROC(camellia_dec_blk_2way)
14435 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
14436 index c35fd5d..2d8c7db 100644
14437 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
14438 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
14439 @@ -24,6 +24,7 @@
14440 */
14441
14442 #include <linux/linkage.h>
14443 +#include <asm/alternative-asm.h>
14444
14445 .file "cast5-avx-x86_64-asm_64.S"
14446
14447 @@ -281,6 +282,7 @@ __cast5_enc_blk16:
14448 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
14449 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
14450
14451 + pax_force_retaddr
14452 ret;
14453 ENDPROC(__cast5_enc_blk16)
14454
14455 @@ -352,6 +354,7 @@ __cast5_dec_blk16:
14456 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
14457 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
14458
14459 + pax_force_retaddr
14460 ret;
14461
14462 .L__skip_dec:
14463 @@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
14464 vmovdqu RR4, (6*4*4)(%r11);
14465 vmovdqu RL4, (7*4*4)(%r11);
14466
14467 + pax_force_retaddr
14468 ret;
14469 ENDPROC(cast5_ecb_enc_16way)
14470
14471 @@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
14472 vmovdqu RR4, (6*4*4)(%r11);
14473 vmovdqu RL4, (7*4*4)(%r11);
14474
14475 + pax_force_retaddr
14476 ret;
14477 ENDPROC(cast5_ecb_dec_16way)
14478
14479 @@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
14480 * %rdx: src
14481 */
14482
14483 - pushq %r12;
14484 + pushq %r14;
14485
14486 movq %rsi, %r11;
14487 - movq %rdx, %r12;
14488 + movq %rdx, %r14;
14489
14490 vmovdqu (0*16)(%rdx), RL1;
14491 vmovdqu (1*16)(%rdx), RR1;
14492 @@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
14493 call __cast5_dec_blk16;
14494
14495 /* xor with src */
14496 - vmovq (%r12), RX;
14497 + vmovq (%r14), RX;
14498 vpshufd $0x4f, RX, RX;
14499 vpxor RX, RR1, RR1;
14500 - vpxor 0*16+8(%r12), RL1, RL1;
14501 - vpxor 1*16+8(%r12), RR2, RR2;
14502 - vpxor 2*16+8(%r12), RL2, RL2;
14503 - vpxor 3*16+8(%r12), RR3, RR3;
14504 - vpxor 4*16+8(%r12), RL3, RL3;
14505 - vpxor 5*16+8(%r12), RR4, RR4;
14506 - vpxor 6*16+8(%r12), RL4, RL4;
14507 + vpxor 0*16+8(%r14), RL1, RL1;
14508 + vpxor 1*16+8(%r14), RR2, RR2;
14509 + vpxor 2*16+8(%r14), RL2, RL2;
14510 + vpxor 3*16+8(%r14), RR3, RR3;
14511 + vpxor 4*16+8(%r14), RL3, RL3;
14512 + vpxor 5*16+8(%r14), RR4, RR4;
14513 + vpxor 6*16+8(%r14), RL4, RL4;
14514
14515 vmovdqu RR1, (0*16)(%r11);
14516 vmovdqu RL1, (1*16)(%r11);
14517 @@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
14518 vmovdqu RR4, (6*16)(%r11);
14519 vmovdqu RL4, (7*16)(%r11);
14520
14521 - popq %r12;
14522 + popq %r14;
14523
14524 + pax_force_retaddr
14525 ret;
14526 ENDPROC(cast5_cbc_dec_16way)
14527
14528 @@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
14529 * %rcx: iv (big endian, 64bit)
14530 */
14531
14532 - pushq %r12;
14533 + pushq %r14;
14534
14535 movq %rsi, %r11;
14536 - movq %rdx, %r12;
14537 + movq %rdx, %r14;
14538
14539 vpcmpeqd RTMP, RTMP, RTMP;
14540 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
14541 @@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
14542 call __cast5_enc_blk16;
14543
14544 /* dst = src ^ iv */
14545 - vpxor (0*16)(%r12), RR1, RR1;
14546 - vpxor (1*16)(%r12), RL1, RL1;
14547 - vpxor (2*16)(%r12), RR2, RR2;
14548 - vpxor (3*16)(%r12), RL2, RL2;
14549 - vpxor (4*16)(%r12), RR3, RR3;
14550 - vpxor (5*16)(%r12), RL3, RL3;
14551 - vpxor (6*16)(%r12), RR4, RR4;
14552 - vpxor (7*16)(%r12), RL4, RL4;
14553 + vpxor (0*16)(%r14), RR1, RR1;
14554 + vpxor (1*16)(%r14), RL1, RL1;
14555 + vpxor (2*16)(%r14), RR2, RR2;
14556 + vpxor (3*16)(%r14), RL2, RL2;
14557 + vpxor (4*16)(%r14), RR3, RR3;
14558 + vpxor (5*16)(%r14), RL3, RL3;
14559 + vpxor (6*16)(%r14), RR4, RR4;
14560 + vpxor (7*16)(%r14), RL4, RL4;
14561 vmovdqu RR1, (0*16)(%r11);
14562 vmovdqu RL1, (1*16)(%r11);
14563 vmovdqu RR2, (2*16)(%r11);
14564 @@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
14565 vmovdqu RR4, (6*16)(%r11);
14566 vmovdqu RL4, (7*16)(%r11);
14567
14568 - popq %r12;
14569 + popq %r14;
14570
14571 + pax_force_retaddr
14572 ret;
14573 ENDPROC(cast5_ctr_16way)
14574 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
14575 index e3531f8..e123f35 100644
14576 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
14577 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
14578 @@ -24,6 +24,7 @@
14579 */
14580
14581 #include <linux/linkage.h>
14582 +#include <asm/alternative-asm.h>
14583 #include "glue_helper-asm-avx.S"
14584
14585 .file "cast6-avx-x86_64-asm_64.S"
14586 @@ -295,6 +296,7 @@ __cast6_enc_blk8:
14587 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
14588 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
14589
14590 + pax_force_retaddr
14591 ret;
14592 ENDPROC(__cast6_enc_blk8)
14593
14594 @@ -340,6 +342,7 @@ __cast6_dec_blk8:
14595 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
14596 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
14597
14598 + pax_force_retaddr
14599 ret;
14600 ENDPROC(__cast6_dec_blk8)
14601
14602 @@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
14603
14604 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14605
14606 + pax_force_retaddr
14607 ret;
14608 ENDPROC(cast6_ecb_enc_8way)
14609
14610 @@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
14611
14612 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14613
14614 + pax_force_retaddr
14615 ret;
14616 ENDPROC(cast6_ecb_dec_8way)
14617
14618 @@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
14619 * %rdx: src
14620 */
14621
14622 - pushq %r12;
14623 + pushq %r14;
14624
14625 movq %rsi, %r11;
14626 - movq %rdx, %r12;
14627 + movq %rdx, %r14;
14628
14629 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14630
14631 call __cast6_dec_blk8;
14632
14633 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14634 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14635
14636 - popq %r12;
14637 + popq %r14;
14638
14639 + pax_force_retaddr
14640 ret;
14641 ENDPROC(cast6_cbc_dec_8way)
14642
14643 @@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
14644 * %rcx: iv (little endian, 128bit)
14645 */
14646
14647 - pushq %r12;
14648 + pushq %r14;
14649
14650 movq %rsi, %r11;
14651 - movq %rdx, %r12;
14652 + movq %rdx, %r14;
14653
14654 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14655 RD2, RX, RKR, RKM);
14656
14657 call __cast6_enc_blk8;
14658
14659 - store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14660 + store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14661
14662 - popq %r12;
14663 + popq %r14;
14664
14665 + pax_force_retaddr
14666 ret;
14667 ENDPROC(cast6_ctr_8way)
14668
14669 @@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
14670 /* dst <= regs xor IVs(in dst) */
14671 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14672
14673 + pax_force_retaddr
14674 ret;
14675 ENDPROC(cast6_xts_enc_8way)
14676
14677 @@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
14678 /* dst <= regs xor IVs(in dst) */
14679 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14680
14681 + pax_force_retaddr
14682 ret;
14683 ENDPROC(cast6_xts_dec_8way)
14684 diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14685 index 26d49eb..c0a8c84 100644
14686 --- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14687 +++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14688 @@ -45,6 +45,7 @@
14689
14690 #include <asm/inst.h>
14691 #include <linux/linkage.h>
14692 +#include <asm/alternative-asm.h>
14693
14694 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
14695
14696 @@ -309,6 +310,7 @@ do_return:
14697 popq %rsi
14698 popq %rdi
14699 popq %rbx
14700 + pax_force_retaddr
14701 ret
14702
14703 ################################################################
14704 diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14705 index 5d1e007..098cb4f 100644
14706 --- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
14707 +++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14708 @@ -18,6 +18,7 @@
14709
14710 #include <linux/linkage.h>
14711 #include <asm/inst.h>
14712 +#include <asm/alternative-asm.h>
14713
14714 .data
14715
14716 @@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
14717 psrlq $1, T2
14718 pxor T2, T1
14719 pxor T1, DATA
14720 + pax_force_retaddr
14721 ret
14722 ENDPROC(__clmul_gf128mul_ble)
14723
14724 @@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
14725 call __clmul_gf128mul_ble
14726 PSHUFB_XMM BSWAP DATA
14727 movups DATA, (%rdi)
14728 + pax_force_retaddr
14729 ret
14730 ENDPROC(clmul_ghash_mul)
14731
14732 @@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
14733 PSHUFB_XMM BSWAP DATA
14734 movups DATA, (%rdi)
14735 .Lupdate_just_ret:
14736 + pax_force_retaddr
14737 ret
14738 ENDPROC(clmul_ghash_update)
14739 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14740 index 9279e0b..c4b3d2c 100644
14741 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
14742 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14743 @@ -1,4 +1,5 @@
14744 #include <linux/linkage.h>
14745 +#include <asm/alternative-asm.h>
14746
14747 # enter salsa20_encrypt_bytes
14748 ENTRY(salsa20_encrypt_bytes)
14749 @@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
14750 add %r11,%rsp
14751 mov %rdi,%rax
14752 mov %rsi,%rdx
14753 + pax_force_retaddr
14754 ret
14755 # bytesatleast65:
14756 ._bytesatleast65:
14757 @@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
14758 add %r11,%rsp
14759 mov %rdi,%rax
14760 mov %rsi,%rdx
14761 + pax_force_retaddr
14762 ret
14763 ENDPROC(salsa20_keysetup)
14764
14765 @@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
14766 add %r11,%rsp
14767 mov %rdi,%rax
14768 mov %rsi,%rdx
14769 + pax_force_retaddr
14770 ret
14771 ENDPROC(salsa20_ivsetup)
14772 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14773 index 2f202f4..d9164d6 100644
14774 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14775 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14776 @@ -24,6 +24,7 @@
14777 */
14778
14779 #include <linux/linkage.h>
14780 +#include <asm/alternative-asm.h>
14781 #include "glue_helper-asm-avx.S"
14782
14783 .file "serpent-avx-x86_64-asm_64.S"
14784 @@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
14785 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14786 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14787
14788 + pax_force_retaddr
14789 ret;
14790 ENDPROC(__serpent_enc_blk8_avx)
14791
14792 @@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
14793 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14794 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14795
14796 + pax_force_retaddr
14797 ret;
14798 ENDPROC(__serpent_dec_blk8_avx)
14799
14800 @@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
14801
14802 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14803
14804 + pax_force_retaddr
14805 ret;
14806 ENDPROC(serpent_ecb_enc_8way_avx)
14807
14808 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
14809
14810 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14811
14812 + pax_force_retaddr
14813 ret;
14814 ENDPROC(serpent_ecb_dec_8way_avx)
14815
14816 @@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
14817
14818 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14819
14820 + pax_force_retaddr
14821 ret;
14822 ENDPROC(serpent_cbc_dec_8way_avx)
14823
14824 @@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
14825
14826 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14827
14828 + pax_force_retaddr
14829 ret;
14830 ENDPROC(serpent_ctr_8way_avx)
14831
14832 @@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
14833 /* dst <= regs xor IVs(in dst) */
14834 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14835
14836 + pax_force_retaddr
14837 ret;
14838 ENDPROC(serpent_xts_enc_8way_avx)
14839
14840 @@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
14841 /* dst <= regs xor IVs(in dst) */
14842 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14843
14844 + pax_force_retaddr
14845 ret;
14846 ENDPROC(serpent_xts_dec_8way_avx)
14847 diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
14848 index b222085..abd483c 100644
14849 --- a/arch/x86/crypto/serpent-avx2-asm_64.S
14850 +++ b/arch/x86/crypto/serpent-avx2-asm_64.S
14851 @@ -15,6 +15,7 @@
14852 */
14853
14854 #include <linux/linkage.h>
14855 +#include <asm/alternative-asm.h>
14856 #include "glue_helper-asm-avx2.S"
14857
14858 .file "serpent-avx2-asm_64.S"
14859 @@ -610,6 +611,7 @@ __serpent_enc_blk16:
14860 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14861 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14862
14863 + pax_force_retaddr
14864 ret;
14865 ENDPROC(__serpent_enc_blk16)
14866
14867 @@ -664,6 +666,7 @@ __serpent_dec_blk16:
14868 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14869 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14870
14871 + pax_force_retaddr
14872 ret;
14873 ENDPROC(__serpent_dec_blk16)
14874
14875 @@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
14876
14877 vzeroupper;
14878
14879 + pax_force_retaddr
14880 ret;
14881 ENDPROC(serpent_ecb_enc_16way)
14882
14883 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
14884
14885 vzeroupper;
14886
14887 + pax_force_retaddr
14888 ret;
14889 ENDPROC(serpent_ecb_dec_16way)
14890
14891 @@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
14892
14893 vzeroupper;
14894
14895 + pax_force_retaddr
14896 ret;
14897 ENDPROC(serpent_cbc_dec_16way)
14898
14899 @@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
14900
14901 vzeroupper;
14902
14903 + pax_force_retaddr
14904 ret;
14905 ENDPROC(serpent_ctr_16way)
14906
14907 @@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
14908
14909 vzeroupper;
14910
14911 + pax_force_retaddr
14912 ret;
14913 ENDPROC(serpent_xts_enc_16way)
14914
14915 @@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
14916
14917 vzeroupper;
14918
14919 + pax_force_retaddr
14920 ret;
14921 ENDPROC(serpent_xts_dec_16way)
14922 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14923 index acc066c..1559cc4 100644
14924 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14925 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14926 @@ -25,6 +25,7 @@
14927 */
14928
14929 #include <linux/linkage.h>
14930 +#include <asm/alternative-asm.h>
14931
14932 .file "serpent-sse2-x86_64-asm_64.S"
14933 .text
14934 @@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
14935 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14936 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14937
14938 + pax_force_retaddr
14939 ret;
14940
14941 .L__enc_xor8:
14942 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14943 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14944
14945 + pax_force_retaddr
14946 ret;
14947 ENDPROC(__serpent_enc_blk_8way)
14948
14949 @@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
14950 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14951 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14952
14953 + pax_force_retaddr
14954 ret;
14955 ENDPROC(serpent_dec_blk_8way)
14956 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
14957 index a410950..9dfe7ad 100644
14958 --- a/arch/x86/crypto/sha1_ssse3_asm.S
14959 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
14960 @@ -29,6 +29,7 @@
14961 */
14962
14963 #include <linux/linkage.h>
14964 +#include <asm/alternative-asm.h>
14965
14966 #define CTX %rdi // arg1
14967 #define BUF %rsi // arg2
14968 @@ -75,9 +76,9 @@
14969
14970 push %rbx
14971 push %rbp
14972 - push %r12
14973 + push %r14
14974
14975 - mov %rsp, %r12
14976 + mov %rsp, %r14
14977 sub $64, %rsp # allocate workspace
14978 and $~15, %rsp # align stack
14979
14980 @@ -99,11 +100,12 @@
14981 xor %rax, %rax
14982 rep stosq
14983
14984 - mov %r12, %rsp # deallocate workspace
14985 + mov %r14, %rsp # deallocate workspace
14986
14987 - pop %r12
14988 + pop %r14
14989 pop %rbp
14990 pop %rbx
14991 + pax_force_retaddr
14992 ret
14993
14994 ENDPROC(\name)
14995 diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
14996 index 642f156..51a513c 100644
14997 --- a/arch/x86/crypto/sha256-avx-asm.S
14998 +++ b/arch/x86/crypto/sha256-avx-asm.S
14999 @@ -49,6 +49,7 @@
15000
15001 #ifdef CONFIG_AS_AVX
15002 #include <linux/linkage.h>
15003 +#include <asm/alternative-asm.h>
15004
15005 ## assume buffers not aligned
15006 #define VMOVDQ vmovdqu
15007 @@ -460,6 +461,7 @@ done_hash:
15008 popq %r13
15009 popq %rbp
15010 popq %rbx
15011 + pax_force_retaddr
15012 ret
15013 ENDPROC(sha256_transform_avx)
15014
15015 diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
15016 index 9e86944..3795e6a 100644
15017 --- a/arch/x86/crypto/sha256-avx2-asm.S
15018 +++ b/arch/x86/crypto/sha256-avx2-asm.S
15019 @@ -50,6 +50,7 @@
15020
15021 #ifdef CONFIG_AS_AVX2
15022 #include <linux/linkage.h>
15023 +#include <asm/alternative-asm.h>
15024
15025 ## assume buffers not aligned
15026 #define VMOVDQ vmovdqu
15027 @@ -720,6 +721,7 @@ done_hash:
15028 popq %r12
15029 popq %rbp
15030 popq %rbx
15031 + pax_force_retaddr
15032 ret
15033 ENDPROC(sha256_transform_rorx)
15034
15035 diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
15036 index f833b74..8c62a9e 100644
15037 --- a/arch/x86/crypto/sha256-ssse3-asm.S
15038 +++ b/arch/x86/crypto/sha256-ssse3-asm.S
15039 @@ -47,6 +47,7 @@
15040 ########################################################################
15041
15042 #include <linux/linkage.h>
15043 +#include <asm/alternative-asm.h>
15044
15045 ## assume buffers not aligned
15046 #define MOVDQ movdqu
15047 @@ -471,6 +472,7 @@ done_hash:
15048 popq %rbp
15049 popq %rbx
15050
15051 + pax_force_retaddr
15052 ret
15053 ENDPROC(sha256_transform_ssse3)
15054
15055 diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
15056 index 974dde9..a823ff9 100644
15057 --- a/arch/x86/crypto/sha512-avx-asm.S
15058 +++ b/arch/x86/crypto/sha512-avx-asm.S
15059 @@ -49,6 +49,7 @@
15060
15061 #ifdef CONFIG_AS_AVX
15062 #include <linux/linkage.h>
15063 +#include <asm/alternative-asm.h>
15064
15065 .text
15066
15067 @@ -364,6 +365,7 @@ updateblock:
15068 mov frame_RSPSAVE(%rsp), %rsp
15069
15070 nowork:
15071 + pax_force_retaddr
15072 ret
15073 ENDPROC(sha512_transform_avx)
15074
15075 diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
15076 index 568b961..ed20c37 100644
15077 --- a/arch/x86/crypto/sha512-avx2-asm.S
15078 +++ b/arch/x86/crypto/sha512-avx2-asm.S
15079 @@ -51,6 +51,7 @@
15080
15081 #ifdef CONFIG_AS_AVX2
15082 #include <linux/linkage.h>
15083 +#include <asm/alternative-asm.h>
15084
15085 .text
15086
15087 @@ -678,6 +679,7 @@ done_hash:
15088
15089 # Restore Stack Pointer
15090 mov frame_RSPSAVE(%rsp), %rsp
15091 + pax_force_retaddr
15092 ret
15093 ENDPROC(sha512_transform_rorx)
15094
15095 diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
15096 index fb56855..6edd768 100644
15097 --- a/arch/x86/crypto/sha512-ssse3-asm.S
15098 +++ b/arch/x86/crypto/sha512-ssse3-asm.S
15099 @@ -48,6 +48,7 @@
15100 ########################################################################
15101
15102 #include <linux/linkage.h>
15103 +#include <asm/alternative-asm.h>
15104
15105 .text
15106
15107 @@ -363,6 +364,7 @@ updateblock:
15108 mov frame_RSPSAVE(%rsp), %rsp
15109
15110 nowork:
15111 + pax_force_retaddr
15112 ret
15113 ENDPROC(sha512_transform_ssse3)
15114
15115 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
15116 index 0505813..b067311 100644
15117 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
15118 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
15119 @@ -24,6 +24,7 @@
15120 */
15121
15122 #include <linux/linkage.h>
15123 +#include <asm/alternative-asm.h>
15124 #include "glue_helper-asm-avx.S"
15125
15126 .file "twofish-avx-x86_64-asm_64.S"
15127 @@ -284,6 +285,7 @@ __twofish_enc_blk8:
15128 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
15129 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
15130
15131 + pax_force_retaddr
15132 ret;
15133 ENDPROC(__twofish_enc_blk8)
15134
15135 @@ -324,6 +326,7 @@ __twofish_dec_blk8:
15136 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
15137 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
15138
15139 + pax_force_retaddr
15140 ret;
15141 ENDPROC(__twofish_dec_blk8)
15142
15143 @@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
15144
15145 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
15146
15147 + pax_force_retaddr
15148 ret;
15149 ENDPROC(twofish_ecb_enc_8way)
15150
15151 @@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
15152
15153 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
15154
15155 + pax_force_retaddr
15156 ret;
15157 ENDPROC(twofish_ecb_dec_8way)
15158
15159 @@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
15160 * %rdx: src
15161 */
15162
15163 - pushq %r12;
15164 + pushq %r14;
15165
15166 movq %rsi, %r11;
15167 - movq %rdx, %r12;
15168 + movq %rdx, %r14;
15169
15170 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
15171
15172 call __twofish_dec_blk8;
15173
15174 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
15175 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
15176
15177 - popq %r12;
15178 + popq %r14;
15179
15180 + pax_force_retaddr
15181 ret;
15182 ENDPROC(twofish_cbc_dec_8way)
15183
15184 @@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
15185 * %rcx: iv (little endian, 128bit)
15186 */
15187
15188 - pushq %r12;
15189 + pushq %r14;
15190
15191 movq %rsi, %r11;
15192 - movq %rdx, %r12;
15193 + movq %rdx, %r14;
15194
15195 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
15196 RD2, RX0, RX1, RY0);
15197
15198 call __twofish_enc_blk8;
15199
15200 - store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
15201 + store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
15202
15203 - popq %r12;
15204 + popq %r14;
15205
15206 + pax_force_retaddr
15207 ret;
15208 ENDPROC(twofish_ctr_8way)
15209
15210 @@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
15211 /* dst <= regs xor IVs(in dst) */
15212 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
15213
15214 + pax_force_retaddr
15215 ret;
15216 ENDPROC(twofish_xts_enc_8way)
15217
15218 @@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
15219 /* dst <= regs xor IVs(in dst) */
15220 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
15221
15222 + pax_force_retaddr
15223 ret;
15224 ENDPROC(twofish_xts_dec_8way)
15225 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
15226 index 1c3b7ce..02f578d 100644
15227 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
15228 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
15229 @@ -21,6 +21,7 @@
15230 */
15231
15232 #include <linux/linkage.h>
15233 +#include <asm/alternative-asm.h>
15234
15235 .file "twofish-x86_64-asm-3way.S"
15236 .text
15237 @@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
15238 popq %r13;
15239 popq %r14;
15240 popq %r15;
15241 + pax_force_retaddr
15242 ret;
15243
15244 .L__enc_xor3:
15245 @@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
15246 popq %r13;
15247 popq %r14;
15248 popq %r15;
15249 + pax_force_retaddr
15250 ret;
15251 ENDPROC(__twofish_enc_blk_3way)
15252
15253 @@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
15254 popq %r13;
15255 popq %r14;
15256 popq %r15;
15257 + pax_force_retaddr
15258 ret;
15259 ENDPROC(twofish_dec_blk_3way)
15260 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
15261 index a039d21..524b8b2 100644
15262 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
15263 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
15264 @@ -22,6 +22,7 @@
15265
15266 #include <linux/linkage.h>
15267 #include <asm/asm-offsets.h>
15268 +#include <asm/alternative-asm.h>
15269
15270 #define a_offset 0
15271 #define b_offset 4
15272 @@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
15273
15274 popq R1
15275 movq $1,%rax
15276 + pax_force_retaddr
15277 ret
15278 ENDPROC(twofish_enc_blk)
15279
15280 @@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
15281
15282 popq R1
15283 movq $1,%rax
15284 + pax_force_retaddr
15285 ret
15286 ENDPROC(twofish_dec_blk)
15287 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
15288 index d21ff89..6da8e6e 100644
15289 --- a/arch/x86/ia32/ia32_aout.c
15290 +++ b/arch/x86/ia32/ia32_aout.c
15291 @@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
15292 unsigned long dump_start, dump_size;
15293 struct user32 dump;
15294
15295 + memset(&dump, 0, sizeof(dump));
15296 +
15297 fs = get_fs();
15298 set_fs(KERNEL_DS);
15299 has_dumped = 1;
15300 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
15301 index f9e181a..db313b5 100644
15302 --- a/arch/x86/ia32/ia32_signal.c
15303 +++ b/arch/x86/ia32/ia32_signal.c
15304 @@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
15305 if (__get_user(set.sig[0], &frame->sc.oldmask)
15306 || (_COMPAT_NSIG_WORDS > 1
15307 && __copy_from_user((((char *) &set.sig) + 4),
15308 - &frame->extramask,
15309 + frame->extramask,
15310 sizeof(frame->extramask))))
15311 goto badframe;
15312
15313 @@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
15314 sp -= frame_size;
15315 /* Align the stack pointer according to the i386 ABI,
15316 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
15317 - sp = ((sp + 4) & -16ul) - 4;
15318 + sp = ((sp - 12) & -16ul) - 4;
15319 return (void __user *) sp;
15320 }
15321
15322 @@ -383,10 +383,10 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
15323 } else {
15324 /* Return stub is in 32bit vsyscall page */
15325 if (current->mm->context.vdso)
15326 - restorer = current->mm->context.vdso +
15327 - selected_vdso32->sym___kernel_sigreturn;
15328 + restorer = (void __force_user *)(current->mm->context.vdso +
15329 + selected_vdso32->sym___kernel_sigreturn);
15330 else
15331 - restorer = &frame->retcode;
15332 + restorer = frame->retcode;
15333 }
15334
15335 put_user_try {
15336 @@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
15337 * These are actually not used anymore, but left because some
15338 * gdb versions depend on them as a marker.
15339 */
15340 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
15341 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
15342 } put_user_catch(err);
15343
15344 if (err)
15345 @@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
15346 0xb8,
15347 __NR_ia32_rt_sigreturn,
15348 0x80cd,
15349 - 0,
15350 + 0
15351 };
15352
15353 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
15354 @@ -461,16 +461,19 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
15355
15356 if (ksig->ka.sa.sa_flags & SA_RESTORER)
15357 restorer = ksig->ka.sa.sa_restorer;
15358 - else
15359 + else if (current->mm->context.vdso)
15360 + /* Return stub is in 32bit vsyscall page */
15361 restorer = current->mm->context.vdso +
15362 selected_vdso32->sym___kernel_rt_sigreturn;
15363 + else
15364 + restorer = frame->retcode;
15365 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
15366
15367 /*
15368 * Not actually used anymore, but left because some gdb
15369 * versions need it.
15370 */
15371 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
15372 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
15373 } put_user_catch(err);
15374
15375 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
15376 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
15377 index 92a2e93..cd4d95f 100644
15378 --- a/arch/x86/ia32/ia32entry.S
15379 +++ b/arch/x86/ia32/ia32entry.S
15380 @@ -15,8 +15,10 @@
15381 #include <asm/irqflags.h>
15382 #include <asm/asm.h>
15383 #include <asm/smap.h>
15384 +#include <asm/pgtable.h>
15385 #include <linux/linkage.h>
15386 #include <linux/err.h>
15387 +#include <asm/alternative-asm.h>
15388
15389 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15390 #include <linux/elf-em.h>
15391 @@ -62,12 +64,12 @@
15392 */
15393 .macro LOAD_ARGS32 offset, _r9=0
15394 .if \_r9
15395 - movl \offset+16(%rsp),%r9d
15396 + movl \offset+R9(%rsp),%r9d
15397 .endif
15398 - movl \offset+40(%rsp),%ecx
15399 - movl \offset+48(%rsp),%edx
15400 - movl \offset+56(%rsp),%esi
15401 - movl \offset+64(%rsp),%edi
15402 + movl \offset+RCX(%rsp),%ecx
15403 + movl \offset+RDX(%rsp),%edx
15404 + movl \offset+RSI(%rsp),%esi
15405 + movl \offset+RDI(%rsp),%edi
15406 movl %eax,%eax /* zero extension */
15407 .endm
15408
15409 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
15410 ENDPROC(native_irq_enable_sysexit)
15411 #endif
15412
15413 + .macro pax_enter_kernel_user
15414 + pax_set_fptr_mask
15415 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15416 + call pax_enter_kernel_user
15417 +#endif
15418 + .endm
15419 +
15420 + .macro pax_exit_kernel_user
15421 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15422 + call pax_exit_kernel_user
15423 +#endif
15424 +#ifdef CONFIG_PAX_RANDKSTACK
15425 + pushq %rax
15426 + pushq %r11
15427 + call pax_randomize_kstack
15428 + popq %r11
15429 + popq %rax
15430 +#endif
15431 + .endm
15432 +
15433 + .macro pax_erase_kstack
15434 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15435 + call pax_erase_kstack
15436 +#endif
15437 + .endm
15438 +
15439 /*
15440 * 32bit SYSENTER instruction entry.
15441 *
15442 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
15443 CFI_REGISTER rsp,rbp
15444 SWAPGS_UNSAFE_STACK
15445 movq PER_CPU_VAR(kernel_stack), %rsp
15446 - addq $(KERNEL_STACK_OFFSET),%rsp
15447 - /*
15448 - * No need to follow this irqs on/off section: the syscall
15449 - * disabled irqs, here we enable it straight after entry:
15450 - */
15451 - ENABLE_INTERRUPTS(CLBR_NONE)
15452 movl %ebp,%ebp /* zero extension */
15453 pushq_cfi $__USER32_DS
15454 /*CFI_REL_OFFSET ss,0*/
15455 @@ -135,23 +157,46 @@ ENTRY(ia32_sysenter_target)
15456 CFI_REL_OFFSET rsp,0
15457 pushfq_cfi
15458 /*CFI_REL_OFFSET rflags,0*/
15459 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
15460 - CFI_REGISTER rip,r10
15461 + orl $X86_EFLAGS_IF,(%rsp)
15462 + GET_THREAD_INFO(%r11)
15463 + movl TI_sysenter_return(%r11), %r11d
15464 + CFI_REGISTER rip,r11
15465 pushq_cfi $__USER32_CS
15466 /*CFI_REL_OFFSET cs,0*/
15467 movl %eax, %eax
15468 - pushq_cfi %r10
15469 + pushq_cfi %r11
15470 CFI_REL_OFFSET rip,0
15471 pushq_cfi %rax
15472 cld
15473 SAVE_ARGS 0,1,0
15474 + pax_enter_kernel_user
15475 +
15476 +#ifdef CONFIG_PAX_RANDKSTACK
15477 + pax_erase_kstack
15478 +#endif
15479 +
15480 + /*
15481 + * No need to follow this irqs on/off section: the syscall
15482 + * disabled irqs, here we enable it straight after entry:
15483 + */
15484 + ENABLE_INTERRUPTS(CLBR_NONE)
15485 /* no need to do an access_ok check here because rbp has been
15486 32bit zero extended */
15487 +
15488 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15489 + addq pax_user_shadow_base,%rbp
15490 + ASM_PAX_OPEN_USERLAND
15491 +#endif
15492 +
15493 ASM_STAC
15494 1: movl (%rbp),%ebp
15495 _ASM_EXTABLE(1b,ia32_badarg)
15496 ASM_CLAC
15497
15498 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15499 + ASM_PAX_CLOSE_USERLAND
15500 +#endif
15501 +
15502 /*
15503 * Sysenter doesn't filter flags, so we need to clear NT
15504 * ourselves. To save a few cycles, we can check whether
15505 @@ -161,8 +206,9 @@ ENTRY(ia32_sysenter_target)
15506 jnz sysenter_fix_flags
15507 sysenter_flags_fixed:
15508
15509 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15510 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15511 + GET_THREAD_INFO(%r11)
15512 + orl $TS_COMPAT,TI_status(%r11)
15513 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15514 CFI_REMEMBER_STATE
15515 jnz sysenter_tracesys
15516 cmpq $(IA32_NR_syscalls-1),%rax
15517 @@ -172,15 +218,18 @@ sysenter_do_call:
15518 sysenter_dispatch:
15519 call *ia32_sys_call_table(,%rax,8)
15520 movq %rax,RAX-ARGOFFSET(%rsp)
15521 + GET_THREAD_INFO(%r11)
15522 DISABLE_INTERRUPTS(CLBR_NONE)
15523 TRACE_IRQS_OFF
15524 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15525 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
15526 jnz sysexit_audit
15527 sysexit_from_sys_call:
15528 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15529 + pax_exit_kernel_user
15530 + pax_erase_kstack
15531 + andl $~TS_COMPAT,TI_status(%r11)
15532 /* clear IF, that popfq doesn't enable interrupts early */
15533 - andl $~0x200,EFLAGS-R11(%rsp)
15534 - movl RIP-R11(%rsp),%edx /* User %eip */
15535 + andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
15536 + movl RIP(%rsp),%edx /* User %eip */
15537 CFI_REGISTER rip,rdx
15538 RESTORE_ARGS 0,24,0,0,0,0
15539 xorq %r8,%r8
15540 @@ -205,6 +254,9 @@ sysexit_from_sys_call:
15541 movl %eax,%esi /* 2nd arg: syscall number */
15542 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
15543 call __audit_syscall_entry
15544 +
15545 + pax_erase_kstack
15546 +
15547 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
15548 cmpq $(IA32_NR_syscalls-1),%rax
15549 ja ia32_badsys
15550 @@ -216,7 +268,7 @@ sysexit_from_sys_call:
15551 .endm
15552
15553 .macro auditsys_exit exit
15554 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15555 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
15556 jnz ia32_ret_from_sys_call
15557 TRACE_IRQS_ON
15558 ENABLE_INTERRUPTS(CLBR_NONE)
15559 @@ -227,11 +279,12 @@ sysexit_from_sys_call:
15560 1: setbe %al /* 1 if error, 0 if not */
15561 movzbl %al,%edi /* zero-extend that into %edi */
15562 call __audit_syscall_exit
15563 + GET_THREAD_INFO(%r11)
15564 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
15565 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
15566 DISABLE_INTERRUPTS(CLBR_NONE)
15567 TRACE_IRQS_OFF
15568 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15569 + testl %edi,TI_flags(%r11)
15570 jz \exit
15571 CLEAR_RREGS -ARGOFFSET
15572 jmp int_with_check
15573 @@ -253,7 +306,7 @@ sysenter_fix_flags:
15574
15575 sysenter_tracesys:
15576 #ifdef CONFIG_AUDITSYSCALL
15577 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15578 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
15579 jz sysenter_auditsys
15580 #endif
15581 SAVE_REST
15582 @@ -265,6 +318,9 @@ sysenter_tracesys:
15583 RESTORE_REST
15584 cmpq $(IA32_NR_syscalls-1),%rax
15585 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
15586 +
15587 + pax_erase_kstack
15588 +
15589 jmp sysenter_do_call
15590 CFI_ENDPROC
15591 ENDPROC(ia32_sysenter_target)
15592 @@ -292,19 +348,25 @@ ENDPROC(ia32_sysenter_target)
15593 ENTRY(ia32_cstar_target)
15594 CFI_STARTPROC32 simple
15595 CFI_SIGNAL_FRAME
15596 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
15597 + CFI_DEF_CFA rsp,0
15598 CFI_REGISTER rip,rcx
15599 /*CFI_REGISTER rflags,r11*/
15600 SWAPGS_UNSAFE_STACK
15601 movl %esp,%r8d
15602 CFI_REGISTER rsp,r8
15603 movq PER_CPU_VAR(kernel_stack),%rsp
15604 + SAVE_ARGS 8*6,0,0
15605 + pax_enter_kernel_user
15606 +
15607 +#ifdef CONFIG_PAX_RANDKSTACK
15608 + pax_erase_kstack
15609 +#endif
15610 +
15611 /*
15612 * No need to follow this irqs on/off section: the syscall
15613 * disabled irqs and here we enable it straight after entry:
15614 */
15615 ENABLE_INTERRUPTS(CLBR_NONE)
15616 - SAVE_ARGS 8,0,0
15617 movl %eax,%eax /* zero extension */
15618 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
15619 movq %rcx,RIP-ARGOFFSET(%rsp)
15620 @@ -320,12 +382,25 @@ ENTRY(ia32_cstar_target)
15621 /* no need to do an access_ok check here because r8 has been
15622 32bit zero extended */
15623 /* hardware stack frame is complete now */
15624 +
15625 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15626 + ASM_PAX_OPEN_USERLAND
15627 + movq pax_user_shadow_base,%r8
15628 + addq RSP-ARGOFFSET(%rsp),%r8
15629 +#endif
15630 +
15631 ASM_STAC
15632 1: movl (%r8),%r9d
15633 _ASM_EXTABLE(1b,ia32_badarg)
15634 ASM_CLAC
15635 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15636 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15637 +
15638 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15639 + ASM_PAX_CLOSE_USERLAND
15640 +#endif
15641 +
15642 + GET_THREAD_INFO(%r11)
15643 + orl $TS_COMPAT,TI_status(%r11)
15644 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15645 CFI_REMEMBER_STATE
15646 jnz cstar_tracesys
15647 cmpq $IA32_NR_syscalls-1,%rax
15648 @@ -335,13 +410,16 @@ cstar_do_call:
15649 cstar_dispatch:
15650 call *ia32_sys_call_table(,%rax,8)
15651 movq %rax,RAX-ARGOFFSET(%rsp)
15652 + GET_THREAD_INFO(%r11)
15653 DISABLE_INTERRUPTS(CLBR_NONE)
15654 TRACE_IRQS_OFF
15655 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15656 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
15657 jnz sysretl_audit
15658 sysretl_from_sys_call:
15659 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15660 - RESTORE_ARGS 0,-ARG_SKIP,0,0,0
15661 + pax_exit_kernel_user
15662 + pax_erase_kstack
15663 + andl $~TS_COMPAT,TI_status(%r11)
15664 + RESTORE_ARGS 0,-ORIG_RAX,0,0,0
15665 movl RIP-ARGOFFSET(%rsp),%ecx
15666 CFI_REGISTER rip,rcx
15667 movl EFLAGS-ARGOFFSET(%rsp),%r11d
15668 @@ -368,7 +446,7 @@ sysretl_audit:
15669
15670 cstar_tracesys:
15671 #ifdef CONFIG_AUDITSYSCALL
15672 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15673 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
15674 jz cstar_auditsys
15675 #endif
15676 xchgl %r9d,%ebp
15677 @@ -382,11 +460,19 @@ cstar_tracesys:
15678 xchgl %ebp,%r9d
15679 cmpq $(IA32_NR_syscalls-1),%rax
15680 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
15681 +
15682 + pax_erase_kstack
15683 +
15684 jmp cstar_do_call
15685 END(ia32_cstar_target)
15686
15687 ia32_badarg:
15688 ASM_CLAC
15689 +
15690 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15691 + ASM_PAX_CLOSE_USERLAND
15692 +#endif
15693 +
15694 movq $-EFAULT,%rax
15695 jmp ia32_sysret
15696 CFI_ENDPROC
15697 @@ -423,19 +509,26 @@ ENTRY(ia32_syscall)
15698 CFI_REL_OFFSET rip,RIP-RIP
15699 PARAVIRT_ADJUST_EXCEPTION_FRAME
15700 SWAPGS
15701 - /*
15702 - * No need to follow this irqs on/off section: the syscall
15703 - * disabled irqs and here we enable it straight after entry:
15704 - */
15705 - ENABLE_INTERRUPTS(CLBR_NONE)
15706 movl %eax,%eax
15707 pushq_cfi %rax
15708 cld
15709 /* note the registers are not zero extended to the sf.
15710 this could be a problem. */
15711 SAVE_ARGS 0,1,0
15712 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15713 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15714 + pax_enter_kernel_user
15715 +
15716 +#ifdef CONFIG_PAX_RANDKSTACK
15717 + pax_erase_kstack
15718 +#endif
15719 +
15720 + /*
15721 + * No need to follow this irqs on/off section: the syscall
15722 + * disabled irqs and here we enable it straight after entry:
15723 + */
15724 + ENABLE_INTERRUPTS(CLBR_NONE)
15725 + GET_THREAD_INFO(%r11)
15726 + orl $TS_COMPAT,TI_status(%r11)
15727 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15728 jnz ia32_tracesys
15729 cmpq $(IA32_NR_syscalls-1),%rax
15730 ja ia32_badsys
15731 @@ -458,6 +551,9 @@ ia32_tracesys:
15732 RESTORE_REST
15733 cmpq $(IA32_NR_syscalls-1),%rax
15734 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
15735 +
15736 + pax_erase_kstack
15737 +
15738 jmp ia32_do_call
15739 END(ia32_syscall)
15740
15741 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
15742 index 8e0ceec..af13504 100644
15743 --- a/arch/x86/ia32/sys_ia32.c
15744 +++ b/arch/x86/ia32/sys_ia32.c
15745 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
15746 */
15747 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
15748 {
15749 - typeof(ubuf->st_uid) uid = 0;
15750 - typeof(ubuf->st_gid) gid = 0;
15751 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
15752 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
15753 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
15754 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
15755 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
15756 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
15757 index 372231c..51b537d 100644
15758 --- a/arch/x86/include/asm/alternative-asm.h
15759 +++ b/arch/x86/include/asm/alternative-asm.h
15760 @@ -18,6 +18,45 @@
15761 .endm
15762 #endif
15763
15764 +#ifdef KERNEXEC_PLUGIN
15765 + .macro pax_force_retaddr_bts rip=0
15766 + btsq $63,\rip(%rsp)
15767 + .endm
15768 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
15769 + .macro pax_force_retaddr rip=0, reload=0
15770 + btsq $63,\rip(%rsp)
15771 + .endm
15772 + .macro pax_force_fptr ptr
15773 + btsq $63,\ptr
15774 + .endm
15775 + .macro pax_set_fptr_mask
15776 + .endm
15777 +#endif
15778 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15779 + .macro pax_force_retaddr rip=0, reload=0
15780 + .if \reload
15781 + pax_set_fptr_mask
15782 + .endif
15783 + orq %r12,\rip(%rsp)
15784 + .endm
15785 + .macro pax_force_fptr ptr
15786 + orq %r12,\ptr
15787 + .endm
15788 + .macro pax_set_fptr_mask
15789 + movabs $0x8000000000000000,%r12
15790 + .endm
15791 +#endif
15792 +#else
15793 + .macro pax_force_retaddr rip=0, reload=0
15794 + .endm
15795 + .macro pax_force_fptr ptr
15796 + .endm
15797 + .macro pax_force_retaddr_bts rip=0
15798 + .endm
15799 + .macro pax_set_fptr_mask
15800 + .endm
15801 +#endif
15802 +
15803 .macro altinstruction_entry orig alt feature orig_len alt_len
15804 .long \orig - .
15805 .long \alt - .
15806 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
15807 index 473bdbe..b1e3377 100644
15808 --- a/arch/x86/include/asm/alternative.h
15809 +++ b/arch/x86/include/asm/alternative.h
15810 @@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15811 ".pushsection .discard,\"aw\",@progbits\n" \
15812 DISCARD_ENTRY(1) \
15813 ".popsection\n" \
15814 - ".pushsection .altinstr_replacement, \"ax\"\n" \
15815 + ".pushsection .altinstr_replacement, \"a\"\n" \
15816 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
15817 ".popsection"
15818
15819 @@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15820 DISCARD_ENTRY(1) \
15821 DISCARD_ENTRY(2) \
15822 ".popsection\n" \
15823 - ".pushsection .altinstr_replacement, \"ax\"\n" \
15824 + ".pushsection .altinstr_replacement, \"a\"\n" \
15825 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
15826 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
15827 ".popsection"
15828 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
15829 index 465b309..ab7e51f 100644
15830 --- a/arch/x86/include/asm/apic.h
15831 +++ b/arch/x86/include/asm/apic.h
15832 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
15833
15834 #ifdef CONFIG_X86_LOCAL_APIC
15835
15836 -extern unsigned int apic_verbosity;
15837 +extern int apic_verbosity;
15838 extern int local_apic_timer_c2_ok;
15839
15840 extern int disable_apic;
15841 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
15842 index 20370c6..a2eb9b0 100644
15843 --- a/arch/x86/include/asm/apm.h
15844 +++ b/arch/x86/include/asm/apm.h
15845 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
15846 __asm__ __volatile__(APM_DO_ZERO_SEGS
15847 "pushl %%edi\n\t"
15848 "pushl %%ebp\n\t"
15849 - "lcall *%%cs:apm_bios_entry\n\t"
15850 + "lcall *%%ss:apm_bios_entry\n\t"
15851 "setc %%al\n\t"
15852 "popl %%ebp\n\t"
15853 "popl %%edi\n\t"
15854 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
15855 __asm__ __volatile__(APM_DO_ZERO_SEGS
15856 "pushl %%edi\n\t"
15857 "pushl %%ebp\n\t"
15858 - "lcall *%%cs:apm_bios_entry\n\t"
15859 + "lcall *%%ss:apm_bios_entry\n\t"
15860 "setc %%bl\n\t"
15861 "popl %%ebp\n\t"
15862 "popl %%edi\n\t"
15863 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
15864 index 6dd1c7dd..2edd216 100644
15865 --- a/arch/x86/include/asm/atomic.h
15866 +++ b/arch/x86/include/asm/atomic.h
15867 @@ -24,7 +24,18 @@
15868 */
15869 static inline int atomic_read(const atomic_t *v)
15870 {
15871 - return (*(volatile int *)&(v)->counter);
15872 + return (*(volatile const int *)&(v)->counter);
15873 +}
15874 +
15875 +/**
15876 + * atomic_read_unchecked - read atomic variable
15877 + * @v: pointer of type atomic_unchecked_t
15878 + *
15879 + * Atomically reads the value of @v.
15880 + */
15881 +static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
15882 +{
15883 + return (*(volatile const int *)&(v)->counter);
15884 }
15885
15886 /**
15887 @@ -40,6 +51,18 @@ static inline void atomic_set(atomic_t *v, int i)
15888 }
15889
15890 /**
15891 + * atomic_set_unchecked - set atomic variable
15892 + * @v: pointer of type atomic_unchecked_t
15893 + * @i: required value
15894 + *
15895 + * Atomically sets the value of @v to @i.
15896 + */
15897 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
15898 +{
15899 + v->counter = i;
15900 +}
15901 +
15902 +/**
15903 * atomic_add - add integer to atomic variable
15904 * @i: integer value to add
15905 * @v: pointer of type atomic_t
15906 @@ -48,7 +71,29 @@ static inline void atomic_set(atomic_t *v, int i)
15907 */
15908 static inline void atomic_add(int i, atomic_t *v)
15909 {
15910 - asm volatile(LOCK_PREFIX "addl %1,%0"
15911 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
15912 +
15913 +#ifdef CONFIG_PAX_REFCOUNT
15914 + "jno 0f\n"
15915 + LOCK_PREFIX "subl %1,%0\n"
15916 + "int $4\n0:\n"
15917 + _ASM_EXTABLE(0b, 0b)
15918 +#endif
15919 +
15920 + : "+m" (v->counter)
15921 + : "ir" (i));
15922 +}
15923 +
15924 +/**
15925 + * atomic_add_unchecked - add integer to atomic variable
15926 + * @i: integer value to add
15927 + * @v: pointer of type atomic_unchecked_t
15928 + *
15929 + * Atomically adds @i to @v.
15930 + */
15931 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
15932 +{
15933 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
15934 : "+m" (v->counter)
15935 : "ir" (i));
15936 }
15937 @@ -62,7 +107,29 @@ static inline void atomic_add(int i, atomic_t *v)
15938 */
15939 static inline void atomic_sub(int i, atomic_t *v)
15940 {
15941 - asm volatile(LOCK_PREFIX "subl %1,%0"
15942 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
15943 +
15944 +#ifdef CONFIG_PAX_REFCOUNT
15945 + "jno 0f\n"
15946 + LOCK_PREFIX "addl %1,%0\n"
15947 + "int $4\n0:\n"
15948 + _ASM_EXTABLE(0b, 0b)
15949 +#endif
15950 +
15951 + : "+m" (v->counter)
15952 + : "ir" (i));
15953 +}
15954 +
15955 +/**
15956 + * atomic_sub_unchecked - subtract integer from atomic variable
15957 + * @i: integer value to subtract
15958 + * @v: pointer of type atomic_unchecked_t
15959 + *
15960 + * Atomically subtracts @i from @v.
15961 + */
15962 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
15963 +{
15964 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
15965 : "+m" (v->counter)
15966 : "ir" (i));
15967 }
15968 @@ -78,7 +145,7 @@ static inline void atomic_sub(int i, atomic_t *v)
15969 */
15970 static inline int atomic_sub_and_test(int i, atomic_t *v)
15971 {
15972 - GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
15973 + GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
15974 }
15975
15976 /**
15977 @@ -89,7 +156,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
15978 */
15979 static inline void atomic_inc(atomic_t *v)
15980 {
15981 - asm volatile(LOCK_PREFIX "incl %0"
15982 + asm volatile(LOCK_PREFIX "incl %0\n"
15983 +
15984 +#ifdef CONFIG_PAX_REFCOUNT
15985 + "jno 0f\n"
15986 + LOCK_PREFIX "decl %0\n"
15987 + "int $4\n0:\n"
15988 + _ASM_EXTABLE(0b, 0b)
15989 +#endif
15990 +
15991 + : "+m" (v->counter));
15992 +}
15993 +
15994 +/**
15995 + * atomic_inc_unchecked - increment atomic variable
15996 + * @v: pointer of type atomic_unchecked_t
15997 + *
15998 + * Atomically increments @v by 1.
15999 + */
16000 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
16001 +{
16002 + asm volatile(LOCK_PREFIX "incl %0\n"
16003 : "+m" (v->counter));
16004 }
16005
16006 @@ -101,7 +188,27 @@ static inline void atomic_inc(atomic_t *v)
16007 */
16008 static inline void atomic_dec(atomic_t *v)
16009 {
16010 - asm volatile(LOCK_PREFIX "decl %0"
16011 + asm volatile(LOCK_PREFIX "decl %0\n"
16012 +
16013 +#ifdef CONFIG_PAX_REFCOUNT
16014 + "jno 0f\n"
16015 + LOCK_PREFIX "incl %0\n"
16016 + "int $4\n0:\n"
16017 + _ASM_EXTABLE(0b, 0b)
16018 +#endif
16019 +
16020 + : "+m" (v->counter));
16021 +}
16022 +
16023 +/**
16024 + * atomic_dec_unchecked - decrement atomic variable
16025 + * @v: pointer of type atomic_unchecked_t
16026 + *
16027 + * Atomically decrements @v by 1.
16028 + */
16029 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
16030 +{
16031 + asm volatile(LOCK_PREFIX "decl %0\n"
16032 : "+m" (v->counter));
16033 }
16034
16035 @@ -115,7 +222,7 @@ static inline void atomic_dec(atomic_t *v)
16036 */
16037 static inline int atomic_dec_and_test(atomic_t *v)
16038 {
16039 - GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
16040 + GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
16041 }
16042
16043 /**
16044 @@ -128,7 +235,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
16045 */
16046 static inline int atomic_inc_and_test(atomic_t *v)
16047 {
16048 - GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
16049 + GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
16050 +}
16051 +
16052 +/**
16053 + * atomic_inc_and_test_unchecked - increment and test
16054 + * @v: pointer of type atomic_unchecked_t
16055 + *
16056 + * Atomically increments @v by 1
16057 + * and returns true if the result is zero, or false for all
16058 + * other cases.
16059 + */
16060 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
16061 +{
16062 + GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
16063 }
16064
16065 /**
16066 @@ -142,7 +262,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
16067 */
16068 static inline int atomic_add_negative(int i, atomic_t *v)
16069 {
16070 - GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
16071 + GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
16072 }
16073
16074 /**
16075 @@ -154,6 +274,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
16076 */
16077 static inline int atomic_add_return(int i, atomic_t *v)
16078 {
16079 + return i + xadd_check_overflow(&v->counter, i);
16080 +}
16081 +
16082 +/**
16083 + * atomic_add_return_unchecked - add integer and return
16084 + * @i: integer value to add
16085 + * @v: pointer of type atomic_unchecked_t
16086 + *
16087 + * Atomically adds @i to @v and returns @i + @v
16088 + */
16089 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
16090 +{
16091 return i + xadd(&v->counter, i);
16092 }
16093
16094 @@ -170,9 +302,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
16095 }
16096
16097 #define atomic_inc_return(v) (atomic_add_return(1, v))
16098 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
16099 +{
16100 + return atomic_add_return_unchecked(1, v);
16101 +}
16102 #define atomic_dec_return(v) (atomic_sub_return(1, v))
16103
16104 -static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
16105 +static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
16106 +{
16107 + return cmpxchg(&v->counter, old, new);
16108 +}
16109 +
16110 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
16111 {
16112 return cmpxchg(&v->counter, old, new);
16113 }
16114 @@ -182,6 +323,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
16115 return xchg(&v->counter, new);
16116 }
16117
16118 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
16119 +{
16120 + return xchg(&v->counter, new);
16121 +}
16122 +
16123 /**
16124 * __atomic_add_unless - add unless the number is already a given value
16125 * @v: pointer of type atomic_t
16126 @@ -191,14 +337,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
16127 * Atomically adds @a to @v, so long as @v was not already @u.
16128 * Returns the old value of @v.
16129 */
16130 -static inline int __atomic_add_unless(atomic_t *v, int a, int u)
16131 +static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
16132 {
16133 - int c, old;
16134 + int c, old, new;
16135 c = atomic_read(v);
16136 for (;;) {
16137 - if (unlikely(c == (u)))
16138 + if (unlikely(c == u))
16139 break;
16140 - old = atomic_cmpxchg((v), c, c + (a));
16141 +
16142 + asm volatile("addl %2,%0\n"
16143 +
16144 +#ifdef CONFIG_PAX_REFCOUNT
16145 + "jno 0f\n"
16146 + "subl %2,%0\n"
16147 + "int $4\n0:\n"
16148 + _ASM_EXTABLE(0b, 0b)
16149 +#endif
16150 +
16151 + : "=r" (new)
16152 + : "0" (c), "ir" (a));
16153 +
16154 + old = atomic_cmpxchg(v, c, new);
16155 if (likely(old == c))
16156 break;
16157 c = old;
16158 @@ -207,6 +366,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
16159 }
16160
16161 /**
16162 + * atomic_inc_not_zero_hint - increment if not null
16163 + * @v: pointer of type atomic_t
16164 + * @hint: probable value of the atomic before the increment
16165 + *
16166 + * This version of atomic_inc_not_zero() gives a hint of probable
16167 + * value of the atomic. This helps processor to not read the memory
16168 + * before doing the atomic read/modify/write cycle, lowering
16169 + * number of bus transactions on some arches.
16170 + *
16171 + * Returns: 0 if increment was not done, 1 otherwise.
16172 + */
16173 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
16174 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
16175 +{
16176 + int val, c = hint, new;
16177 +
16178 + /* sanity test, should be removed by compiler if hint is a constant */
16179 + if (!hint)
16180 + return __atomic_add_unless(v, 1, 0);
16181 +
16182 + do {
16183 + asm volatile("incl %0\n"
16184 +
16185 +#ifdef CONFIG_PAX_REFCOUNT
16186 + "jno 0f\n"
16187 + "decl %0\n"
16188 + "int $4\n0:\n"
16189 + _ASM_EXTABLE(0b, 0b)
16190 +#endif
16191 +
16192 + : "=r" (new)
16193 + : "0" (c));
16194 +
16195 + val = atomic_cmpxchg(v, c, new);
16196 + if (val == c)
16197 + return 1;
16198 + c = val;
16199 + } while (c);
16200 +
16201 + return 0;
16202 +}
16203 +
16204 +/**
16205 * atomic_inc_short - increment of a short integer
16206 * @v: pointer to type int
16207 *
16208 @@ -235,14 +437,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
16209 #endif
16210
16211 /* These are x86-specific, used by some header files */
16212 -#define atomic_clear_mask(mask, addr) \
16213 - asm volatile(LOCK_PREFIX "andl %0,%1" \
16214 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
16215 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
16216 +{
16217 + asm volatile(LOCK_PREFIX "andl %1,%0"
16218 + : "+m" (v->counter)
16219 + : "r" (~(mask))
16220 + : "memory");
16221 +}
16222
16223 -#define atomic_set_mask(mask, addr) \
16224 - asm volatile(LOCK_PREFIX "orl %0,%1" \
16225 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
16226 - : "memory")
16227 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
16228 +{
16229 + asm volatile(LOCK_PREFIX "andl %1,%0"
16230 + : "+m" (v->counter)
16231 + : "r" (~(mask))
16232 + : "memory");
16233 +}
16234 +
16235 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
16236 +{
16237 + asm volatile(LOCK_PREFIX "orl %1,%0"
16238 + : "+m" (v->counter)
16239 + : "r" (mask)
16240 + : "memory");
16241 +}
16242 +
16243 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
16244 +{
16245 + asm volatile(LOCK_PREFIX "orl %1,%0"
16246 + : "+m" (v->counter)
16247 + : "r" (mask)
16248 + : "memory");
16249 +}
16250
16251 #ifdef CONFIG_X86_32
16252 # include <asm/atomic64_32.h>
16253 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
16254 index b154de7..bf18a5a 100644
16255 --- a/arch/x86/include/asm/atomic64_32.h
16256 +++ b/arch/x86/include/asm/atomic64_32.h
16257 @@ -12,6 +12,14 @@ typedef struct {
16258 u64 __aligned(8) counter;
16259 } atomic64_t;
16260
16261 +#ifdef CONFIG_PAX_REFCOUNT
16262 +typedef struct {
16263 + u64 __aligned(8) counter;
16264 +} atomic64_unchecked_t;
16265 +#else
16266 +typedef atomic64_t atomic64_unchecked_t;
16267 +#endif
16268 +
16269 #define ATOMIC64_INIT(val) { (val) }
16270
16271 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
16272 @@ -37,21 +45,31 @@ typedef struct {
16273 ATOMIC64_DECL_ONE(sym##_386)
16274
16275 ATOMIC64_DECL_ONE(add_386);
16276 +ATOMIC64_DECL_ONE(add_unchecked_386);
16277 ATOMIC64_DECL_ONE(sub_386);
16278 +ATOMIC64_DECL_ONE(sub_unchecked_386);
16279 ATOMIC64_DECL_ONE(inc_386);
16280 +ATOMIC64_DECL_ONE(inc_unchecked_386);
16281 ATOMIC64_DECL_ONE(dec_386);
16282 +ATOMIC64_DECL_ONE(dec_unchecked_386);
16283 #endif
16284
16285 #define alternative_atomic64(f, out, in...) \
16286 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
16287
16288 ATOMIC64_DECL(read);
16289 +ATOMIC64_DECL(read_unchecked);
16290 ATOMIC64_DECL(set);
16291 +ATOMIC64_DECL(set_unchecked);
16292 ATOMIC64_DECL(xchg);
16293 ATOMIC64_DECL(add_return);
16294 +ATOMIC64_DECL(add_return_unchecked);
16295 ATOMIC64_DECL(sub_return);
16296 +ATOMIC64_DECL(sub_return_unchecked);
16297 ATOMIC64_DECL(inc_return);
16298 +ATOMIC64_DECL(inc_return_unchecked);
16299 ATOMIC64_DECL(dec_return);
16300 +ATOMIC64_DECL(dec_return_unchecked);
16301 ATOMIC64_DECL(dec_if_positive);
16302 ATOMIC64_DECL(inc_not_zero);
16303 ATOMIC64_DECL(add_unless);
16304 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
16305 }
16306
16307 /**
16308 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
16309 + * @p: pointer to type atomic64_unchecked_t
16310 + * @o: expected value
16311 + * @n: new value
16312 + *
16313 + * Atomically sets @v to @n if it was equal to @o and returns
16314 + * the old value.
16315 + */
16316 +
16317 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
16318 +{
16319 + return cmpxchg64(&v->counter, o, n);
16320 +}
16321 +
16322 +/**
16323 * atomic64_xchg - xchg atomic64 variable
16324 * @v: pointer to type atomic64_t
16325 * @n: value to assign
16326 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
16327 }
16328
16329 /**
16330 + * atomic64_set_unchecked - set atomic64 variable
16331 + * @v: pointer to type atomic64_unchecked_t
16332 + * @n: value to assign
16333 + *
16334 + * Atomically sets the value of @v to @n.
16335 + */
16336 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
16337 +{
16338 + unsigned high = (unsigned)(i >> 32);
16339 + unsigned low = (unsigned)i;
16340 + alternative_atomic64(set, /* no output */,
16341 + "S" (v), "b" (low), "c" (high)
16342 + : "eax", "edx", "memory");
16343 +}
16344 +
16345 +/**
16346 * atomic64_read - read atomic64 variable
16347 * @v: pointer to type atomic64_t
16348 *
16349 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
16350 }
16351
16352 /**
16353 + * atomic64_read_unchecked - read atomic64 variable
16354 + * @v: pointer to type atomic64_unchecked_t
16355 + *
16356 + * Atomically reads the value of @v and returns it.
16357 + */
16358 +static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
16359 +{
16360 + long long r;
16361 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
16362 + return r;
16363 + }
16364 +
16365 +/**
16366 * atomic64_add_return - add and return
16367 * @i: integer value to add
16368 * @v: pointer to type atomic64_t
16369 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
16370 return i;
16371 }
16372
16373 +/**
16374 + * atomic64_add_return_unchecked - add and return
16375 + * @i: integer value to add
16376 + * @v: pointer to type atomic64_unchecked_t
16377 + *
16378 + * Atomically adds @i to @v and returns @i + *@v
16379 + */
16380 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
16381 +{
16382 + alternative_atomic64(add_return_unchecked,
16383 + ASM_OUTPUT2("+A" (i), "+c" (v)),
16384 + ASM_NO_INPUT_CLOBBER("memory"));
16385 + return i;
16386 +}
16387 +
16388 /*
16389 * Other variants with different arithmetic operators:
16390 */
16391 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
16392 return a;
16393 }
16394
16395 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
16396 +{
16397 + long long a;
16398 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
16399 + "S" (v) : "memory", "ecx");
16400 + return a;
16401 +}
16402 +
16403 static inline long long atomic64_dec_return(atomic64_t *v)
16404 {
16405 long long a;
16406 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
16407 }
16408
16409 /**
16410 + * atomic64_add_unchecked - add integer to atomic64 variable
16411 + * @i: integer value to add
16412 + * @v: pointer to type atomic64_unchecked_t
16413 + *
16414 + * Atomically adds @i to @v.
16415 + */
16416 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
16417 +{
16418 + __alternative_atomic64(add_unchecked, add_return_unchecked,
16419 + ASM_OUTPUT2("+A" (i), "+c" (v)),
16420 + ASM_NO_INPUT_CLOBBER("memory"));
16421 + return i;
16422 +}
16423 +
16424 +/**
16425 * atomic64_sub - subtract the atomic64 variable
16426 * @i: integer value to subtract
16427 * @v: pointer to type atomic64_t
16428 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
16429 index 46e9052..ae45136 100644
16430 --- a/arch/x86/include/asm/atomic64_64.h
16431 +++ b/arch/x86/include/asm/atomic64_64.h
16432 @@ -18,7 +18,19 @@
16433 */
16434 static inline long atomic64_read(const atomic64_t *v)
16435 {
16436 - return (*(volatile long *)&(v)->counter);
16437 + return (*(volatile const long *)&(v)->counter);
16438 +}
16439 +
16440 +/**
16441 + * atomic64_read_unchecked - read atomic64 variable
16442 + * @v: pointer of type atomic64_unchecked_t
16443 + *
16444 + * Atomically reads the value of @v.
16445 + * Doesn't imply a read memory barrier.
16446 + */
16447 +static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
16448 +{
16449 + return (*(volatile const long *)&(v)->counter);
16450 }
16451
16452 /**
16453 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
16454 }
16455
16456 /**
16457 + * atomic64_set_unchecked - set atomic64 variable
16458 + * @v: pointer to type atomic64_unchecked_t
16459 + * @i: required value
16460 + *
16461 + * Atomically sets the value of @v to @i.
16462 + */
16463 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
16464 +{
16465 + v->counter = i;
16466 +}
16467 +
16468 +/**
16469 * atomic64_add - add integer to atomic64 variable
16470 * @i: integer value to add
16471 * @v: pointer to type atomic64_t
16472 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
16473 */
16474 static inline void atomic64_add(long i, atomic64_t *v)
16475 {
16476 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
16477 +
16478 +#ifdef CONFIG_PAX_REFCOUNT
16479 + "jno 0f\n"
16480 + LOCK_PREFIX "subq %1,%0\n"
16481 + "int $4\n0:\n"
16482 + _ASM_EXTABLE(0b, 0b)
16483 +#endif
16484 +
16485 + : "=m" (v->counter)
16486 + : "er" (i), "m" (v->counter));
16487 +}
16488 +
16489 +/**
16490 + * atomic64_add_unchecked - add integer to atomic64 variable
16491 + * @i: integer value to add
16492 + * @v: pointer to type atomic64_unchecked_t
16493 + *
16494 + * Atomically adds @i to @v.
16495 + */
16496 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
16497 +{
16498 asm volatile(LOCK_PREFIX "addq %1,%0"
16499 : "=m" (v->counter)
16500 : "er" (i), "m" (v->counter));
16501 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
16502 */
16503 static inline void atomic64_sub(long i, atomic64_t *v)
16504 {
16505 - asm volatile(LOCK_PREFIX "subq %1,%0"
16506 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
16507 +
16508 +#ifdef CONFIG_PAX_REFCOUNT
16509 + "jno 0f\n"
16510 + LOCK_PREFIX "addq %1,%0\n"
16511 + "int $4\n0:\n"
16512 + _ASM_EXTABLE(0b, 0b)
16513 +#endif
16514 +
16515 + : "=m" (v->counter)
16516 + : "er" (i), "m" (v->counter));
16517 +}
16518 +
16519 +/**
16520 + * atomic64_sub_unchecked - subtract the atomic64 variable
16521 + * @i: integer value to subtract
16522 + * @v: pointer to type atomic64_unchecked_t
16523 + *
16524 + * Atomically subtracts @i from @v.
16525 + */
16526 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
16527 +{
16528 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
16529 : "=m" (v->counter)
16530 : "er" (i), "m" (v->counter));
16531 }
16532 @@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
16533 */
16534 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
16535 {
16536 - GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
16537 + GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
16538 }
16539
16540 /**
16541 @@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
16542 */
16543 static inline void atomic64_inc(atomic64_t *v)
16544 {
16545 + asm volatile(LOCK_PREFIX "incq %0\n"
16546 +
16547 +#ifdef CONFIG_PAX_REFCOUNT
16548 + "jno 0f\n"
16549 + LOCK_PREFIX "decq %0\n"
16550 + "int $4\n0:\n"
16551 + _ASM_EXTABLE(0b, 0b)
16552 +#endif
16553 +
16554 + : "=m" (v->counter)
16555 + : "m" (v->counter));
16556 +}
16557 +
16558 +/**
16559 + * atomic64_inc_unchecked - increment atomic64 variable
16560 + * @v: pointer to type atomic64_unchecked_t
16561 + *
16562 + * Atomically increments @v by 1.
16563 + */
16564 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
16565 +{
16566 asm volatile(LOCK_PREFIX "incq %0"
16567 : "=m" (v->counter)
16568 : "m" (v->counter));
16569 @@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
16570 */
16571 static inline void atomic64_dec(atomic64_t *v)
16572 {
16573 - asm volatile(LOCK_PREFIX "decq %0"
16574 + asm volatile(LOCK_PREFIX "decq %0\n"
16575 +
16576 +#ifdef CONFIG_PAX_REFCOUNT
16577 + "jno 0f\n"
16578 + LOCK_PREFIX "incq %0\n"
16579 + "int $4\n0:\n"
16580 + _ASM_EXTABLE(0b, 0b)
16581 +#endif
16582 +
16583 + : "=m" (v->counter)
16584 + : "m" (v->counter));
16585 +}
16586 +
16587 +/**
16588 + * atomic64_dec_unchecked - decrement atomic64 variable
16589 + * @v: pointer to type atomic64_t
16590 + *
16591 + * Atomically decrements @v by 1.
16592 + */
16593 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
16594 +{
16595 + asm volatile(LOCK_PREFIX "decq %0\n"
16596 : "=m" (v->counter)
16597 : "m" (v->counter));
16598 }
16599 @@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
16600 */
16601 static inline int atomic64_dec_and_test(atomic64_t *v)
16602 {
16603 - GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
16604 + GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
16605 }
16606
16607 /**
16608 @@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
16609 */
16610 static inline int atomic64_inc_and_test(atomic64_t *v)
16611 {
16612 - GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
16613 + GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
16614 }
16615
16616 /**
16617 @@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
16618 */
16619 static inline int atomic64_add_negative(long i, atomic64_t *v)
16620 {
16621 - GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
16622 + GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
16623 }
16624
16625 /**
16626 @@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
16627 */
16628 static inline long atomic64_add_return(long i, atomic64_t *v)
16629 {
16630 + return i + xadd_check_overflow(&v->counter, i);
16631 +}
16632 +
16633 +/**
16634 + * atomic64_add_return_unchecked - add and return
16635 + * @i: integer value to add
16636 + * @v: pointer to type atomic64_unchecked_t
16637 + *
16638 + * Atomically adds @i to @v and returns @i + @v
16639 + */
16640 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
16641 +{
16642 return i + xadd(&v->counter, i);
16643 }
16644
16645 @@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
16646 }
16647
16648 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
16649 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
16650 +{
16651 + return atomic64_add_return_unchecked(1, v);
16652 +}
16653 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
16654
16655 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
16656 @@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
16657 return cmpxchg(&v->counter, old, new);
16658 }
16659
16660 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
16661 +{
16662 + return cmpxchg(&v->counter, old, new);
16663 +}
16664 +
16665 static inline long atomic64_xchg(atomic64_t *v, long new)
16666 {
16667 return xchg(&v->counter, new);
16668 @@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
16669 */
16670 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
16671 {
16672 - long c, old;
16673 + long c, old, new;
16674 c = atomic64_read(v);
16675 for (;;) {
16676 - if (unlikely(c == (u)))
16677 + if (unlikely(c == u))
16678 break;
16679 - old = atomic64_cmpxchg((v), c, c + (a));
16680 +
16681 + asm volatile("add %2,%0\n"
16682 +
16683 +#ifdef CONFIG_PAX_REFCOUNT
16684 + "jno 0f\n"
16685 + "sub %2,%0\n"
16686 + "int $4\n0:\n"
16687 + _ASM_EXTABLE(0b, 0b)
16688 +#endif
16689 +
16690 + : "=r" (new)
16691 + : "0" (c), "ir" (a));
16692 +
16693 + old = atomic64_cmpxchg(v, c, new);
16694 if (likely(old == c))
16695 break;
16696 c = old;
16697 }
16698 - return c != (u);
16699 + return c != u;
16700 }
16701
16702 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
16703 diff --git a/arch/x86/include/asm/barrier.h b/arch/x86/include/asm/barrier.h
16704 index 0f4460b..fa1ee19 100644
16705 --- a/arch/x86/include/asm/barrier.h
16706 +++ b/arch/x86/include/asm/barrier.h
16707 @@ -107,7 +107,7 @@
16708 do { \
16709 compiletime_assert_atomic_type(*p); \
16710 smp_mb(); \
16711 - ACCESS_ONCE(*p) = (v); \
16712 + ACCESS_ONCE_RW(*p) = (v); \
16713 } while (0)
16714
16715 #define smp_load_acquire(p) \
16716 @@ -124,7 +124,7 @@ do { \
16717 do { \
16718 compiletime_assert_atomic_type(*p); \
16719 barrier(); \
16720 - ACCESS_ONCE(*p) = (v); \
16721 + ACCESS_ONCE_RW(*p) = (v); \
16722 } while (0)
16723
16724 #define smp_load_acquire(p) \
16725 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
16726 index cfe3b95..d01b118 100644
16727 --- a/arch/x86/include/asm/bitops.h
16728 +++ b/arch/x86/include/asm/bitops.h
16729 @@ -50,7 +50,7 @@
16730 * a mask operation on a byte.
16731 */
16732 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
16733 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
16734 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
16735 #define CONST_MASK(nr) (1 << ((nr) & 7))
16736
16737 /**
16738 @@ -203,7 +203,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
16739 */
16740 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
16741 {
16742 - GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16743 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16744 }
16745
16746 /**
16747 @@ -249,7 +249,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
16748 */
16749 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
16750 {
16751 - GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16752 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16753 }
16754
16755 /**
16756 @@ -302,7 +302,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
16757 */
16758 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
16759 {
16760 - GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16761 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16762 }
16763
16764 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
16765 @@ -343,7 +343,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
16766 *
16767 * Undefined if no bit exists, so code should check against 0 first.
16768 */
16769 -static inline unsigned long __ffs(unsigned long word)
16770 +static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
16771 {
16772 asm("rep; bsf %1,%0"
16773 : "=r" (word)
16774 @@ -357,7 +357,7 @@ static inline unsigned long __ffs(unsigned long word)
16775 *
16776 * Undefined if no zero exists, so code should check against ~0UL first.
16777 */
16778 -static inline unsigned long ffz(unsigned long word)
16779 +static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
16780 {
16781 asm("rep; bsf %1,%0"
16782 : "=r" (word)
16783 @@ -371,7 +371,7 @@ static inline unsigned long ffz(unsigned long word)
16784 *
16785 * Undefined if no set bit exists, so code should check against 0 first.
16786 */
16787 -static inline unsigned long __fls(unsigned long word)
16788 +static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
16789 {
16790 asm("bsr %1,%0"
16791 : "=r" (word)
16792 @@ -434,7 +434,7 @@ static inline int ffs(int x)
16793 * set bit if value is nonzero. The last (most significant) bit is
16794 * at position 32.
16795 */
16796 -static inline int fls(int x)
16797 +static inline int __intentional_overflow(-1) fls(int x)
16798 {
16799 int r;
16800
16801 @@ -476,7 +476,7 @@ static inline int fls(int x)
16802 * at position 64.
16803 */
16804 #ifdef CONFIG_X86_64
16805 -static __always_inline int fls64(__u64 x)
16806 +static __always_inline __intentional_overflow(-1) int fls64(__u64 x)
16807 {
16808 int bitpos = -1;
16809 /*
16810 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
16811 index 4fa687a..60f2d39 100644
16812 --- a/arch/x86/include/asm/boot.h
16813 +++ b/arch/x86/include/asm/boot.h
16814 @@ -6,10 +6,15 @@
16815 #include <uapi/asm/boot.h>
16816
16817 /* Physical address where kernel should be loaded. */
16818 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16819 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16820 + (CONFIG_PHYSICAL_ALIGN - 1)) \
16821 & ~(CONFIG_PHYSICAL_ALIGN - 1))
16822
16823 +#ifndef __ASSEMBLY__
16824 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
16825 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
16826 +#endif
16827 +
16828 /* Minimum kernel alignment, as a power of two */
16829 #ifdef CONFIG_X86_64
16830 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
16831 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
16832 index 48f99f1..d78ebf9 100644
16833 --- a/arch/x86/include/asm/cache.h
16834 +++ b/arch/x86/include/asm/cache.h
16835 @@ -5,12 +5,13 @@
16836
16837 /* L1 cache line size */
16838 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
16839 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
16840 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
16841
16842 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
16843 +#define __read_only __attribute__((__section__(".data..read_only")))
16844
16845 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
16846 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
16847 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
16848
16849 #ifdef CONFIG_X86_VSMP
16850 #ifdef CONFIG_SMP
16851 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
16852 index 9863ee3..4a1f8e1 100644
16853 --- a/arch/x86/include/asm/cacheflush.h
16854 +++ b/arch/x86/include/asm/cacheflush.h
16855 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
16856 unsigned long pg_flags = pg->flags & _PGMT_MASK;
16857
16858 if (pg_flags == _PGMT_DEFAULT)
16859 - return -1;
16860 + return ~0UL;
16861 else if (pg_flags == _PGMT_WC)
16862 return _PAGE_CACHE_WC;
16863 else if (pg_flags == _PGMT_UC_MINUS)
16864 diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
16865 index cb4c73b..c473c29 100644
16866 --- a/arch/x86/include/asm/calling.h
16867 +++ b/arch/x86/include/asm/calling.h
16868 @@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
16869 #define RSP 152
16870 #define SS 160
16871
16872 -#define ARGOFFSET R11
16873 -#define SWFRAME ORIG_RAX
16874 +#define ARGOFFSET R15
16875
16876 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
16877 - subq $9*8+\addskip, %rsp
16878 - CFI_ADJUST_CFA_OFFSET 9*8+\addskip
16879 - movq_cfi rdi, 8*8
16880 - movq_cfi rsi, 7*8
16881 - movq_cfi rdx, 6*8
16882 + subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
16883 + CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
16884 + movq_cfi rdi, RDI
16885 + movq_cfi rsi, RSI
16886 + movq_cfi rdx, RDX
16887
16888 .if \save_rcx
16889 - movq_cfi rcx, 5*8
16890 + movq_cfi rcx, RCX
16891 .endif
16892
16893 - movq_cfi rax, 4*8
16894 + movq_cfi rax, RAX
16895
16896 .if \save_r891011
16897 - movq_cfi r8, 3*8
16898 - movq_cfi r9, 2*8
16899 - movq_cfi r10, 1*8
16900 - movq_cfi r11, 0*8
16901 + movq_cfi r8, R8
16902 + movq_cfi r9, R9
16903 + movq_cfi r10, R10
16904 + movq_cfi r11, R11
16905 .endif
16906
16907 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16908 + movq_cfi r12, R12
16909 +#endif
16910 +
16911 .endm
16912
16913 -#define ARG_SKIP (9*8)
16914 +#define ARG_SKIP ORIG_RAX
16915
16916 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
16917 rstor_r8910=1, rstor_rdx=1
16918 +
16919 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16920 + movq_cfi_restore R12, r12
16921 +#endif
16922 +
16923 .if \rstor_r11
16924 - movq_cfi_restore 0*8, r11
16925 + movq_cfi_restore R11, r11
16926 .endif
16927
16928 .if \rstor_r8910
16929 - movq_cfi_restore 1*8, r10
16930 - movq_cfi_restore 2*8, r9
16931 - movq_cfi_restore 3*8, r8
16932 + movq_cfi_restore R10, r10
16933 + movq_cfi_restore R9, r9
16934 + movq_cfi_restore R8, r8
16935 .endif
16936
16937 .if \rstor_rax
16938 - movq_cfi_restore 4*8, rax
16939 + movq_cfi_restore RAX, rax
16940 .endif
16941
16942 .if \rstor_rcx
16943 - movq_cfi_restore 5*8, rcx
16944 + movq_cfi_restore RCX, rcx
16945 .endif
16946
16947 .if \rstor_rdx
16948 - movq_cfi_restore 6*8, rdx
16949 + movq_cfi_restore RDX, rdx
16950 .endif
16951
16952 - movq_cfi_restore 7*8, rsi
16953 - movq_cfi_restore 8*8, rdi
16954 + movq_cfi_restore RSI, rsi
16955 + movq_cfi_restore RDI, rdi
16956
16957 - .if ARG_SKIP+\addskip > 0
16958 - addq $ARG_SKIP+\addskip, %rsp
16959 - CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
16960 + .if ORIG_RAX+\addskip > 0
16961 + addq $ORIG_RAX+\addskip, %rsp
16962 + CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
16963 .endif
16964 .endm
16965
16966 - .macro LOAD_ARGS offset, skiprax=0
16967 - movq \offset(%rsp), %r11
16968 - movq \offset+8(%rsp), %r10
16969 - movq \offset+16(%rsp), %r9
16970 - movq \offset+24(%rsp), %r8
16971 - movq \offset+40(%rsp), %rcx
16972 - movq \offset+48(%rsp), %rdx
16973 - movq \offset+56(%rsp), %rsi
16974 - movq \offset+64(%rsp), %rdi
16975 + .macro LOAD_ARGS skiprax=0
16976 + movq R11(%rsp), %r11
16977 + movq R10(%rsp), %r10
16978 + movq R9(%rsp), %r9
16979 + movq R8(%rsp), %r8
16980 + movq RCX(%rsp), %rcx
16981 + movq RDX(%rsp), %rdx
16982 + movq RSI(%rsp), %rsi
16983 + movq RDI(%rsp), %rdi
16984 .if \skiprax
16985 .else
16986 - movq \offset+72(%rsp), %rax
16987 + movq RAX(%rsp), %rax
16988 .endif
16989 .endm
16990
16991 -#define REST_SKIP (6*8)
16992 -
16993 .macro SAVE_REST
16994 - subq $REST_SKIP, %rsp
16995 - CFI_ADJUST_CFA_OFFSET REST_SKIP
16996 - movq_cfi rbx, 5*8
16997 - movq_cfi rbp, 4*8
16998 - movq_cfi r12, 3*8
16999 - movq_cfi r13, 2*8
17000 - movq_cfi r14, 1*8
17001 - movq_cfi r15, 0*8
17002 + movq_cfi rbx, RBX
17003 + movq_cfi rbp, RBP
17004 +
17005 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
17006 + movq_cfi r12, R12
17007 +#endif
17008 +
17009 + movq_cfi r13, R13
17010 + movq_cfi r14, R14
17011 + movq_cfi r15, R15
17012 .endm
17013
17014 .macro RESTORE_REST
17015 - movq_cfi_restore 0*8, r15
17016 - movq_cfi_restore 1*8, r14
17017 - movq_cfi_restore 2*8, r13
17018 - movq_cfi_restore 3*8, r12
17019 - movq_cfi_restore 4*8, rbp
17020 - movq_cfi_restore 5*8, rbx
17021 - addq $REST_SKIP, %rsp
17022 - CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
17023 + movq_cfi_restore R15, r15
17024 + movq_cfi_restore R14, r14
17025 + movq_cfi_restore R13, r13
17026 +
17027 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
17028 + movq_cfi_restore R12, r12
17029 +#endif
17030 +
17031 + movq_cfi_restore RBP, rbp
17032 + movq_cfi_restore RBX, rbx
17033 .endm
17034
17035 .macro SAVE_ALL
17036 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
17037 index f50de69..2b0a458 100644
17038 --- a/arch/x86/include/asm/checksum_32.h
17039 +++ b/arch/x86/include/asm/checksum_32.h
17040 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
17041 int len, __wsum sum,
17042 int *src_err_ptr, int *dst_err_ptr);
17043
17044 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
17045 + int len, __wsum sum,
17046 + int *src_err_ptr, int *dst_err_ptr);
17047 +
17048 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
17049 + int len, __wsum sum,
17050 + int *src_err_ptr, int *dst_err_ptr);
17051 +
17052 /*
17053 * Note: when you get a NULL pointer exception here this means someone
17054 * passed in an incorrect kernel address to one of these functions.
17055 @@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
17056
17057 might_sleep();
17058 stac();
17059 - ret = csum_partial_copy_generic((__force void *)src, dst,
17060 + ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
17061 len, sum, err_ptr, NULL);
17062 clac();
17063
17064 @@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
17065 might_sleep();
17066 if (access_ok(VERIFY_WRITE, dst, len)) {
17067 stac();
17068 - ret = csum_partial_copy_generic(src, (__force void *)dst,
17069 + ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
17070 len, sum, NULL, err_ptr);
17071 clac();
17072 return ret;
17073 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
17074 index 99c105d7..2f667ac 100644
17075 --- a/arch/x86/include/asm/cmpxchg.h
17076 +++ b/arch/x86/include/asm/cmpxchg.h
17077 @@ -16,8 +16,12 @@ extern void __cmpxchg_wrong_size(void)
17078 __compiletime_error("Bad argument size for cmpxchg");
17079 extern void __xadd_wrong_size(void)
17080 __compiletime_error("Bad argument size for xadd");
17081 +extern void __xadd_check_overflow_wrong_size(void)
17082 + __compiletime_error("Bad argument size for xadd_check_overflow");
17083 extern void __add_wrong_size(void)
17084 __compiletime_error("Bad argument size for add");
17085 +extern void __add_check_overflow_wrong_size(void)
17086 + __compiletime_error("Bad argument size for add_check_overflow");
17087
17088 /*
17089 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
17090 @@ -69,6 +73,38 @@ extern void __add_wrong_size(void)
17091 __ret; \
17092 })
17093
17094 +#ifdef CONFIG_PAX_REFCOUNT
17095 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
17096 + ({ \
17097 + __typeof__ (*(ptr)) __ret = (arg); \
17098 + switch (sizeof(*(ptr))) { \
17099 + case __X86_CASE_L: \
17100 + asm volatile (lock #op "l %0, %1\n" \
17101 + "jno 0f\n" \
17102 + "mov %0,%1\n" \
17103 + "int $4\n0:\n" \
17104 + _ASM_EXTABLE(0b, 0b) \
17105 + : "+r" (__ret), "+m" (*(ptr)) \
17106 + : : "memory", "cc"); \
17107 + break; \
17108 + case __X86_CASE_Q: \
17109 + asm volatile (lock #op "q %q0, %1\n" \
17110 + "jno 0f\n" \
17111 + "mov %0,%1\n" \
17112 + "int $4\n0:\n" \
17113 + _ASM_EXTABLE(0b, 0b) \
17114 + : "+r" (__ret), "+m" (*(ptr)) \
17115 + : : "memory", "cc"); \
17116 + break; \
17117 + default: \
17118 + __ ## op ## _check_overflow_wrong_size(); \
17119 + } \
17120 + __ret; \
17121 + })
17122 +#else
17123 +#define __xchg_op_check_overflow(ptr, arg, op, lock) __xchg_op(ptr, arg, op, lock)
17124 +#endif
17125 +
17126 /*
17127 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
17128 * Since this is generally used to protect other memory information, we
17129 @@ -167,6 +203,9 @@ extern void __add_wrong_size(void)
17130 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
17131 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
17132
17133 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
17134 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
17135 +
17136 #define __add(ptr, inc, lock) \
17137 ({ \
17138 __typeof__ (*(ptr)) __ret = (inc); \
17139 diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
17140 index 59c6c40..5e0b22c 100644
17141 --- a/arch/x86/include/asm/compat.h
17142 +++ b/arch/x86/include/asm/compat.h
17143 @@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
17144 typedef u32 compat_uint_t;
17145 typedef u32 compat_ulong_t;
17146 typedef u64 __attribute__((aligned(4))) compat_u64;
17147 -typedef u32 compat_uptr_t;
17148 +typedef u32 __user compat_uptr_t;
17149
17150 struct compat_timespec {
17151 compat_time_t tv_sec;
17152 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
17153 index bb9b258..5fad1bf 100644
17154 --- a/arch/x86/include/asm/cpufeature.h
17155 +++ b/arch/x86/include/asm/cpufeature.h
17156 @@ -203,14 +203,14 @@
17157 #define X86_FEATURE_PAUSEFILTER ( 8*32+13) /* AMD filtered pause intercept */
17158 #define X86_FEATURE_PFTHRESHOLD ( 8*32+14) /* AMD pause filter threshold */
17159
17160 -
17161 +#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
17162 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
17163 #define X86_FEATURE_FSGSBASE ( 9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
17164 #define X86_FEATURE_TSC_ADJUST ( 9*32+ 1) /* TSC adjustment MSR 0x3b */
17165 #define X86_FEATURE_BMI1 ( 9*32+ 3) /* 1st group bit manipulation extensions */
17166 #define X86_FEATURE_HLE ( 9*32+ 4) /* Hardware Lock Elision */
17167 #define X86_FEATURE_AVX2 ( 9*32+ 5) /* AVX2 instructions */
17168 -#define X86_FEATURE_SMEP ( 9*32+ 7) /* Supervisor Mode Execution Protection */
17169 +#define X86_FEATURE_SMEP ( 9*32+ 7) /* Supervisor Mode Execution Prevention */
17170 #define X86_FEATURE_BMI2 ( 9*32+ 8) /* 2nd group bit manipulation extensions */
17171 #define X86_FEATURE_ERMS ( 9*32+ 9) /* Enhanced REP MOVSB/STOSB */
17172 #define X86_FEATURE_INVPCID ( 9*32+10) /* Invalidate Processor Context ID */
17173 @@ -370,6 +370,7 @@ extern const char * const x86_bug_flags[NBUGINTS*32];
17174 #undef cpu_has_centaur_mcr
17175 #define cpu_has_centaur_mcr 0
17176
17177 +#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
17178 #endif /* CONFIG_X86_64 */
17179
17180 #if __GNUC__ >= 4
17181 @@ -422,7 +423,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
17182
17183 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
17184 t_warn:
17185 - warn_pre_alternatives();
17186 + if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
17187 + warn_pre_alternatives();
17188 return false;
17189 #endif
17190
17191 @@ -442,7 +444,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
17192 ".section .discard,\"aw\",@progbits\n"
17193 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
17194 ".previous\n"
17195 - ".section .altinstr_replacement,\"ax\"\n"
17196 + ".section .altinstr_replacement,\"a\"\n"
17197 "3: movb $1,%0\n"
17198 "4:\n"
17199 ".previous\n"
17200 @@ -479,7 +481,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
17201 " .byte 2b - 1b\n" /* src len */
17202 " .byte 4f - 3f\n" /* repl len */
17203 ".previous\n"
17204 - ".section .altinstr_replacement,\"ax\"\n"
17205 + ".section .altinstr_replacement,\"a\"\n"
17206 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
17207 "4:\n"
17208 ".previous\n"
17209 @@ -512,7 +514,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
17210 ".section .discard,\"aw\",@progbits\n"
17211 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
17212 ".previous\n"
17213 - ".section .altinstr_replacement,\"ax\"\n"
17214 + ".section .altinstr_replacement,\"a\"\n"
17215 "3: movb $0,%0\n"
17216 "4:\n"
17217 ".previous\n"
17218 @@ -526,7 +528,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
17219 ".section .discard,\"aw\",@progbits\n"
17220 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
17221 ".previous\n"
17222 - ".section .altinstr_replacement,\"ax\"\n"
17223 + ".section .altinstr_replacement,\"a\"\n"
17224 "5: movb $1,%0\n"
17225 "6:\n"
17226 ".previous\n"
17227 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
17228 index 50d033a..37deb26 100644
17229 --- a/arch/x86/include/asm/desc.h
17230 +++ b/arch/x86/include/asm/desc.h
17231 @@ -4,6 +4,7 @@
17232 #include <asm/desc_defs.h>
17233 #include <asm/ldt.h>
17234 #include <asm/mmu.h>
17235 +#include <asm/pgtable.h>
17236
17237 #include <linux/smp.h>
17238 #include <linux/percpu.h>
17239 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
17240
17241 desc->type = (info->read_exec_only ^ 1) << 1;
17242 desc->type |= info->contents << 2;
17243 + desc->type |= info->seg_not_present ^ 1;
17244
17245 desc->s = 1;
17246 desc->dpl = 0x3;
17247 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
17248 }
17249
17250 extern struct desc_ptr idt_descr;
17251 -extern gate_desc idt_table[];
17252 -extern struct desc_ptr debug_idt_descr;
17253 -extern gate_desc debug_idt_table[];
17254 -
17255 -struct gdt_page {
17256 - struct desc_struct gdt[GDT_ENTRIES];
17257 -} __attribute__((aligned(PAGE_SIZE)));
17258 -
17259 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
17260 +extern gate_desc idt_table[IDT_ENTRIES];
17261 +extern const struct desc_ptr debug_idt_descr;
17262 +extern gate_desc debug_idt_table[IDT_ENTRIES];
17263
17264 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
17265 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
17266 {
17267 - return per_cpu(gdt_page, cpu).gdt;
17268 + return cpu_gdt_table[cpu];
17269 }
17270
17271 #ifdef CONFIG_X86_64
17272 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
17273 unsigned long base, unsigned dpl, unsigned flags,
17274 unsigned short seg)
17275 {
17276 - gate->a = (seg << 16) | (base & 0xffff);
17277 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
17278 + gate->gate.offset_low = base;
17279 + gate->gate.seg = seg;
17280 + gate->gate.reserved = 0;
17281 + gate->gate.type = type;
17282 + gate->gate.s = 0;
17283 + gate->gate.dpl = dpl;
17284 + gate->gate.p = 1;
17285 + gate->gate.offset_high = base >> 16;
17286 }
17287
17288 #endif
17289 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
17290
17291 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
17292 {
17293 + pax_open_kernel();
17294 memcpy(&idt[entry], gate, sizeof(*gate));
17295 + pax_close_kernel();
17296 }
17297
17298 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
17299 {
17300 + pax_open_kernel();
17301 memcpy(&ldt[entry], desc, 8);
17302 + pax_close_kernel();
17303 }
17304
17305 static inline void
17306 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
17307 default: size = sizeof(*gdt); break;
17308 }
17309
17310 + pax_open_kernel();
17311 memcpy(&gdt[entry], desc, size);
17312 + pax_close_kernel();
17313 }
17314
17315 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
17316 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
17317
17318 static inline void native_load_tr_desc(void)
17319 {
17320 + pax_open_kernel();
17321 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
17322 + pax_close_kernel();
17323 }
17324
17325 static inline void native_load_gdt(const struct desc_ptr *dtr)
17326 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
17327 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
17328 unsigned int i;
17329
17330 + pax_open_kernel();
17331 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
17332 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
17333 + pax_close_kernel();
17334 }
17335
17336 #define _LDT_empty(info) \
17337 @@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
17338 preempt_enable();
17339 }
17340
17341 -static inline unsigned long get_desc_base(const struct desc_struct *desc)
17342 +static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
17343 {
17344 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
17345 }
17346 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
17347 }
17348
17349 #ifdef CONFIG_X86_64
17350 -static inline void set_nmi_gate(int gate, void *addr)
17351 +static inline void set_nmi_gate(int gate, const void *addr)
17352 {
17353 gate_desc s;
17354
17355 @@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
17356 #endif
17357
17358 #ifdef CONFIG_TRACING
17359 -extern struct desc_ptr trace_idt_descr;
17360 -extern gate_desc trace_idt_table[];
17361 +extern const struct desc_ptr trace_idt_descr;
17362 +extern gate_desc trace_idt_table[IDT_ENTRIES];
17363 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
17364 {
17365 write_idt_entry(trace_idt_table, entry, gate);
17366 }
17367
17368 -static inline void _trace_set_gate(int gate, unsigned type, void *addr,
17369 +static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
17370 unsigned dpl, unsigned ist, unsigned seg)
17371 {
17372 gate_desc s;
17373 @@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
17374 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
17375 #endif
17376
17377 -static inline void _set_gate(int gate, unsigned type, void *addr,
17378 +static inline void _set_gate(int gate, unsigned type, const void *addr,
17379 unsigned dpl, unsigned ist, unsigned seg)
17380 {
17381 gate_desc s;
17382 @@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
17383 #define set_intr_gate(n, addr) \
17384 do { \
17385 BUG_ON((unsigned)n > 0xFF); \
17386 - _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
17387 + _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
17388 __KERNEL_CS); \
17389 - _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
17390 + _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
17391 0, 0, __KERNEL_CS); \
17392 } while (0)
17393
17394 @@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
17395 /*
17396 * This routine sets up an interrupt gate at directory privilege level 3.
17397 */
17398 -static inline void set_system_intr_gate(unsigned int n, void *addr)
17399 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
17400 {
17401 BUG_ON((unsigned)n > 0xFF);
17402 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
17403 }
17404
17405 -static inline void set_system_trap_gate(unsigned int n, void *addr)
17406 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
17407 {
17408 BUG_ON((unsigned)n > 0xFF);
17409 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
17410 }
17411
17412 -static inline void set_trap_gate(unsigned int n, void *addr)
17413 +static inline void set_trap_gate(unsigned int n, const void *addr)
17414 {
17415 BUG_ON((unsigned)n > 0xFF);
17416 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
17417 @@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
17418 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
17419 {
17420 BUG_ON((unsigned)n > 0xFF);
17421 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
17422 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
17423 }
17424
17425 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
17426 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
17427 {
17428 BUG_ON((unsigned)n > 0xFF);
17429 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
17430 }
17431
17432 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
17433 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
17434 {
17435 BUG_ON((unsigned)n > 0xFF);
17436 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
17437 @@ -503,4 +516,17 @@ static inline void load_current_idt(void)
17438 else
17439 load_idt((const struct desc_ptr *)&idt_descr);
17440 }
17441 +
17442 +#ifdef CONFIG_X86_32
17443 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
17444 +{
17445 + struct desc_struct d;
17446 +
17447 + if (likely(limit))
17448 + limit = (limit - 1UL) >> PAGE_SHIFT;
17449 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
17450 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
17451 +}
17452 +#endif
17453 +
17454 #endif /* _ASM_X86_DESC_H */
17455 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
17456 index 278441f..b95a174 100644
17457 --- a/arch/x86/include/asm/desc_defs.h
17458 +++ b/arch/x86/include/asm/desc_defs.h
17459 @@ -31,6 +31,12 @@ struct desc_struct {
17460 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
17461 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
17462 };
17463 + struct {
17464 + u16 offset_low;
17465 + u16 seg;
17466 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
17467 + unsigned offset_high: 16;
17468 + } gate;
17469 };
17470 } __attribute__((packed));
17471
17472 diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
17473 index ced283a..ffe04cc 100644
17474 --- a/arch/x86/include/asm/div64.h
17475 +++ b/arch/x86/include/asm/div64.h
17476 @@ -39,7 +39,7 @@
17477 __mod; \
17478 })
17479
17480 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
17481 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
17482 {
17483 union {
17484 u64 v64;
17485 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
17486 index ca3347a..1a5082a 100644
17487 --- a/arch/x86/include/asm/elf.h
17488 +++ b/arch/x86/include/asm/elf.h
17489 @@ -75,9 +75,6 @@ typedef struct user_fxsr_struct elf_fpxregset_t;
17490
17491 #include <asm/vdso.h>
17492
17493 -#ifdef CONFIG_X86_64
17494 -extern unsigned int vdso64_enabled;
17495 -#endif
17496 #if defined(CONFIG_X86_32) || defined(CONFIG_COMPAT)
17497 extern unsigned int vdso32_enabled;
17498 #endif
17499 @@ -249,7 +246,25 @@ extern int force_personality32;
17500 the loader. We need to make sure that it is out of the way of the program
17501 that it will "exec", and that there is sufficient room for the brk. */
17502
17503 +#ifdef CONFIG_PAX_SEGMEXEC
17504 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
17505 +#else
17506 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
17507 +#endif
17508 +
17509 +#ifdef CONFIG_PAX_ASLR
17510 +#ifdef CONFIG_X86_32
17511 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
17512 +
17513 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
17514 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
17515 +#else
17516 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
17517 +
17518 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
17519 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
17520 +#endif
17521 +#endif
17522
17523 /* This yields a mask that user programs can use to figure out what
17524 instruction set this CPU supports. This could be done in user space,
17525 @@ -298,17 +313,13 @@ do { \
17526
17527 #define ARCH_DLINFO \
17528 do { \
17529 - if (vdso64_enabled) \
17530 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
17531 - (unsigned long __force)current->mm->context.vdso); \
17532 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
17533 } while (0)
17534
17535 /* As a historical oddity, the x32 and x86_64 vDSOs are controlled together. */
17536 #define ARCH_DLINFO_X32 \
17537 do { \
17538 - if (vdso64_enabled) \
17539 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
17540 - (unsigned long __force)current->mm->context.vdso); \
17541 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
17542 } while (0)
17543
17544 #define AT_SYSINFO 32
17545 @@ -323,10 +334,10 @@ else \
17546
17547 #endif /* !CONFIG_X86_32 */
17548
17549 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
17550 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
17551
17552 #define VDSO_ENTRY \
17553 - ((unsigned long)current->mm->context.vdso + \
17554 + (current->mm->context.vdso + \
17555 selected_vdso32->sym___kernel_vsyscall)
17556
17557 struct linux_binprm;
17558 @@ -338,9 +349,6 @@ extern int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
17559 int uses_interp);
17560 #define compat_arch_setup_additional_pages compat_arch_setup_additional_pages
17561
17562 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
17563 -#define arch_randomize_brk arch_randomize_brk
17564 -
17565 /*
17566 * True on X86_32 or when emulating IA32 on X86_64
17567 */
17568 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
17569 index 77a99ac..39ff7f5 100644
17570 --- a/arch/x86/include/asm/emergency-restart.h
17571 +++ b/arch/x86/include/asm/emergency-restart.h
17572 @@ -1,6 +1,6 @@
17573 #ifndef _ASM_X86_EMERGENCY_RESTART_H
17574 #define _ASM_X86_EMERGENCY_RESTART_H
17575
17576 -extern void machine_emergency_restart(void);
17577 +extern void machine_emergency_restart(void) __noreturn;
17578
17579 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
17580 diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
17581 index 1c7eefe..d0e4702 100644
17582 --- a/arch/x86/include/asm/floppy.h
17583 +++ b/arch/x86/include/asm/floppy.h
17584 @@ -229,18 +229,18 @@ static struct fd_routine_l {
17585 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
17586 } fd_routine[] = {
17587 {
17588 - request_dma,
17589 - free_dma,
17590 - get_dma_residue,
17591 - dma_mem_alloc,
17592 - hard_dma_setup
17593 + ._request_dma = request_dma,
17594 + ._free_dma = free_dma,
17595 + ._get_dma_residue = get_dma_residue,
17596 + ._dma_mem_alloc = dma_mem_alloc,
17597 + ._dma_setup = hard_dma_setup
17598 },
17599 {
17600 - vdma_request_dma,
17601 - vdma_nop,
17602 - vdma_get_dma_residue,
17603 - vdma_mem_alloc,
17604 - vdma_dma_setup
17605 + ._request_dma = vdma_request_dma,
17606 + ._free_dma = vdma_nop,
17607 + ._get_dma_residue = vdma_get_dma_residue,
17608 + ._dma_mem_alloc = vdma_mem_alloc,
17609 + ._dma_setup = vdma_dma_setup
17610 }
17611 };
17612
17613 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
17614 index 412ecec..c1ea43a 100644
17615 --- a/arch/x86/include/asm/fpu-internal.h
17616 +++ b/arch/x86/include/asm/fpu-internal.h
17617 @@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
17618 #define user_insn(insn, output, input...) \
17619 ({ \
17620 int err; \
17621 + pax_open_userland(); \
17622 asm volatile(ASM_STAC "\n" \
17623 - "1:" #insn "\n\t" \
17624 + "1:" \
17625 + __copyuser_seg \
17626 + #insn "\n\t" \
17627 "2: " ASM_CLAC "\n" \
17628 ".section .fixup,\"ax\"\n" \
17629 "3: movl $-1,%[err]\n" \
17630 @@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
17631 _ASM_EXTABLE(1b, 3b) \
17632 : [err] "=r" (err), output \
17633 : "0"(0), input); \
17634 + pax_close_userland(); \
17635 err; \
17636 })
17637
17638 @@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
17639 "fnclex\n\t"
17640 "emms\n\t"
17641 "fildl %P[addr]" /* set F?P to defined value */
17642 - : : [addr] "m" (tsk->thread.fpu.has_fpu));
17643 + : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
17644 }
17645
17646 return fpu_restore_checking(&tsk->thread.fpu);
17647 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
17648 index b4c1f54..e290c08 100644
17649 --- a/arch/x86/include/asm/futex.h
17650 +++ b/arch/x86/include/asm/futex.h
17651 @@ -12,6 +12,7 @@
17652 #include <asm/smap.h>
17653
17654 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
17655 + typecheck(u32 __user *, uaddr); \
17656 asm volatile("\t" ASM_STAC "\n" \
17657 "1:\t" insn "\n" \
17658 "2:\t" ASM_CLAC "\n" \
17659 @@ -20,15 +21,16 @@
17660 "\tjmp\t2b\n" \
17661 "\t.previous\n" \
17662 _ASM_EXTABLE(1b, 3b) \
17663 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
17664 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
17665 : "i" (-EFAULT), "0" (oparg), "1" (0))
17666
17667 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
17668 + typecheck(u32 __user *, uaddr); \
17669 asm volatile("\t" ASM_STAC "\n" \
17670 "1:\tmovl %2, %0\n" \
17671 "\tmovl\t%0, %3\n" \
17672 "\t" insn "\n" \
17673 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
17674 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
17675 "\tjnz\t1b\n" \
17676 "3:\t" ASM_CLAC "\n" \
17677 "\t.section .fixup,\"ax\"\n" \
17678 @@ -38,7 +40,7 @@
17679 _ASM_EXTABLE(1b, 4b) \
17680 _ASM_EXTABLE(2b, 4b) \
17681 : "=&a" (oldval), "=&r" (ret), \
17682 - "+m" (*uaddr), "=&r" (tem) \
17683 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
17684 : "r" (oparg), "i" (-EFAULT), "1" (0))
17685
17686 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17687 @@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17688
17689 pagefault_disable();
17690
17691 + pax_open_userland();
17692 switch (op) {
17693 case FUTEX_OP_SET:
17694 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
17695 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
17696 break;
17697 case FUTEX_OP_ADD:
17698 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
17699 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
17700 uaddr, oparg);
17701 break;
17702 case FUTEX_OP_OR:
17703 @@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17704 default:
17705 ret = -ENOSYS;
17706 }
17707 + pax_close_userland();
17708
17709 pagefault_enable();
17710
17711 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
17712 index 4615906..788c817 100644
17713 --- a/arch/x86/include/asm/hw_irq.h
17714 +++ b/arch/x86/include/asm/hw_irq.h
17715 @@ -164,8 +164,8 @@ extern void setup_ioapic_dest(void);
17716 extern void enable_IO_APIC(void);
17717
17718 /* Statistics */
17719 -extern atomic_t irq_err_count;
17720 -extern atomic_t irq_mis_count;
17721 +extern atomic_unchecked_t irq_err_count;
17722 +extern atomic_unchecked_t irq_mis_count;
17723
17724 /* EISA */
17725 extern void eisa_set_level_irq(unsigned int irq);
17726 diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
17727 index ccffa53..3c90c87 100644
17728 --- a/arch/x86/include/asm/i8259.h
17729 +++ b/arch/x86/include/asm/i8259.h
17730 @@ -62,7 +62,7 @@ struct legacy_pic {
17731 void (*init)(int auto_eoi);
17732 int (*irq_pending)(unsigned int irq);
17733 void (*make_irq)(unsigned int irq);
17734 -};
17735 +} __do_const;
17736
17737 extern struct legacy_pic *legacy_pic;
17738 extern struct legacy_pic null_legacy_pic;
17739 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
17740 index b8237d8..3e8864e 100644
17741 --- a/arch/x86/include/asm/io.h
17742 +++ b/arch/x86/include/asm/io.h
17743 @@ -52,12 +52,12 @@ static inline void name(type val, volatile void __iomem *addr) \
17744 "m" (*(volatile type __force *)addr) barrier); }
17745
17746 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
17747 -build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
17748 -build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
17749 +build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
17750 +build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
17751
17752 build_mmio_read(__readb, "b", unsigned char, "=q", )
17753 -build_mmio_read(__readw, "w", unsigned short, "=r", )
17754 -build_mmio_read(__readl, "l", unsigned int, "=r", )
17755 +build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
17756 +build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
17757
17758 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
17759 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
17760 @@ -109,7 +109,7 @@ build_mmio_write(writeq, "q", unsigned long, "r", :"memory")
17761 * this function
17762 */
17763
17764 -static inline phys_addr_t virt_to_phys(volatile void *address)
17765 +static inline phys_addr_t __intentional_overflow(-1) virt_to_phys(volatile void *address)
17766 {
17767 return __pa(address);
17768 }
17769 @@ -185,7 +185,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
17770 return ioremap_nocache(offset, size);
17771 }
17772
17773 -extern void iounmap(volatile void __iomem *addr);
17774 +extern void iounmap(const volatile void __iomem *addr);
17775
17776 extern void set_iounmap_nonlazy(void);
17777
17778 @@ -195,6 +195,17 @@ extern void set_iounmap_nonlazy(void);
17779
17780 #include <linux/vmalloc.h>
17781
17782 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
17783 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
17784 +{
17785 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17786 +}
17787 +
17788 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
17789 +{
17790 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17791 +}
17792 +
17793 /*
17794 * Convert a virtual cached pointer to an uncached pointer
17795 */
17796 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
17797 index 0a8b519..80e7d5b 100644
17798 --- a/arch/x86/include/asm/irqflags.h
17799 +++ b/arch/x86/include/asm/irqflags.h
17800 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
17801 sti; \
17802 sysexit
17803
17804 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
17805 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
17806 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
17807 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
17808 +
17809 #else
17810 #define INTERRUPT_RETURN iret
17811 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
17812 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
17813 index 53cdfb2..d1369e6 100644
17814 --- a/arch/x86/include/asm/kprobes.h
17815 +++ b/arch/x86/include/asm/kprobes.h
17816 @@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
17817 #define RELATIVEJUMP_SIZE 5
17818 #define RELATIVECALL_OPCODE 0xe8
17819 #define RELATIVE_ADDR_SIZE 4
17820 -#define MAX_STACK_SIZE 64
17821 -#define MIN_STACK_SIZE(ADDR) \
17822 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
17823 - THREAD_SIZE - (unsigned long)(ADDR))) \
17824 - ? (MAX_STACK_SIZE) \
17825 - : (((unsigned long)current_thread_info()) + \
17826 - THREAD_SIZE - (unsigned long)(ADDR)))
17827 +#define MAX_STACK_SIZE 64UL
17828 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
17829
17830 #define flush_insn_slot(p) do { } while (0)
17831
17832 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
17833 index 4ad6560..75c7bdd 100644
17834 --- a/arch/x86/include/asm/local.h
17835 +++ b/arch/x86/include/asm/local.h
17836 @@ -10,33 +10,97 @@ typedef struct {
17837 atomic_long_t a;
17838 } local_t;
17839
17840 +typedef struct {
17841 + atomic_long_unchecked_t a;
17842 +} local_unchecked_t;
17843 +
17844 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
17845
17846 #define local_read(l) atomic_long_read(&(l)->a)
17847 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
17848 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
17849 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
17850
17851 static inline void local_inc(local_t *l)
17852 {
17853 - asm volatile(_ASM_INC "%0"
17854 + asm volatile(_ASM_INC "%0\n"
17855 +
17856 +#ifdef CONFIG_PAX_REFCOUNT
17857 + "jno 0f\n"
17858 + _ASM_DEC "%0\n"
17859 + "int $4\n0:\n"
17860 + _ASM_EXTABLE(0b, 0b)
17861 +#endif
17862 +
17863 + : "+m" (l->a.counter));
17864 +}
17865 +
17866 +static inline void local_inc_unchecked(local_unchecked_t *l)
17867 +{
17868 + asm volatile(_ASM_INC "%0\n"
17869 : "+m" (l->a.counter));
17870 }
17871
17872 static inline void local_dec(local_t *l)
17873 {
17874 - asm volatile(_ASM_DEC "%0"
17875 + asm volatile(_ASM_DEC "%0\n"
17876 +
17877 +#ifdef CONFIG_PAX_REFCOUNT
17878 + "jno 0f\n"
17879 + _ASM_INC "%0\n"
17880 + "int $4\n0:\n"
17881 + _ASM_EXTABLE(0b, 0b)
17882 +#endif
17883 +
17884 + : "+m" (l->a.counter));
17885 +}
17886 +
17887 +static inline void local_dec_unchecked(local_unchecked_t *l)
17888 +{
17889 + asm volatile(_ASM_DEC "%0\n"
17890 : "+m" (l->a.counter));
17891 }
17892
17893 static inline void local_add(long i, local_t *l)
17894 {
17895 - asm volatile(_ASM_ADD "%1,%0"
17896 + asm volatile(_ASM_ADD "%1,%0\n"
17897 +
17898 +#ifdef CONFIG_PAX_REFCOUNT
17899 + "jno 0f\n"
17900 + _ASM_SUB "%1,%0\n"
17901 + "int $4\n0:\n"
17902 + _ASM_EXTABLE(0b, 0b)
17903 +#endif
17904 +
17905 + : "+m" (l->a.counter)
17906 + : "ir" (i));
17907 +}
17908 +
17909 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
17910 +{
17911 + asm volatile(_ASM_ADD "%1,%0\n"
17912 : "+m" (l->a.counter)
17913 : "ir" (i));
17914 }
17915
17916 static inline void local_sub(long i, local_t *l)
17917 {
17918 - asm volatile(_ASM_SUB "%1,%0"
17919 + asm volatile(_ASM_SUB "%1,%0\n"
17920 +
17921 +#ifdef CONFIG_PAX_REFCOUNT
17922 + "jno 0f\n"
17923 + _ASM_ADD "%1,%0\n"
17924 + "int $4\n0:\n"
17925 + _ASM_EXTABLE(0b, 0b)
17926 +#endif
17927 +
17928 + : "+m" (l->a.counter)
17929 + : "ir" (i));
17930 +}
17931 +
17932 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
17933 +{
17934 + asm volatile(_ASM_SUB "%1,%0\n"
17935 : "+m" (l->a.counter)
17936 : "ir" (i));
17937 }
17938 @@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
17939 */
17940 static inline int local_sub_and_test(long i, local_t *l)
17941 {
17942 - GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
17943 + GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
17944 }
17945
17946 /**
17947 @@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
17948 */
17949 static inline int local_dec_and_test(local_t *l)
17950 {
17951 - GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
17952 + GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
17953 }
17954
17955 /**
17956 @@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
17957 */
17958 static inline int local_inc_and_test(local_t *l)
17959 {
17960 - GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
17961 + GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
17962 }
17963
17964 /**
17965 @@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
17966 */
17967 static inline int local_add_negative(long i, local_t *l)
17968 {
17969 - GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
17970 + GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
17971 }
17972
17973 /**
17974 @@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
17975 static inline long local_add_return(long i, local_t *l)
17976 {
17977 long __i = i;
17978 + asm volatile(_ASM_XADD "%0, %1\n"
17979 +
17980 +#ifdef CONFIG_PAX_REFCOUNT
17981 + "jno 0f\n"
17982 + _ASM_MOV "%0,%1\n"
17983 + "int $4\n0:\n"
17984 + _ASM_EXTABLE(0b, 0b)
17985 +#endif
17986 +
17987 + : "+r" (i), "+m" (l->a.counter)
17988 + : : "memory");
17989 + return i + __i;
17990 +}
17991 +
17992 +/**
17993 + * local_add_return_unchecked - add and return
17994 + * @i: integer value to add
17995 + * @l: pointer to type local_unchecked_t
17996 + *
17997 + * Atomically adds @i to @l and returns @i + @l
17998 + */
17999 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
18000 +{
18001 + long __i = i;
18002 asm volatile(_ASM_XADD "%0, %1;"
18003 : "+r" (i), "+m" (l->a.counter)
18004 : : "memory");
18005 @@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
18006
18007 #define local_cmpxchg(l, o, n) \
18008 (cmpxchg_local(&((l)->a.counter), (o), (n)))
18009 +#define local_cmpxchg_unchecked(l, o, n) \
18010 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
18011 /* Always has a lock prefix */
18012 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
18013
18014 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
18015 new file mode 100644
18016 index 0000000..2bfd3ba
18017 --- /dev/null
18018 +++ b/arch/x86/include/asm/mman.h
18019 @@ -0,0 +1,15 @@
18020 +#ifndef _X86_MMAN_H
18021 +#define _X86_MMAN_H
18022 +
18023 +#include <uapi/asm/mman.h>
18024 +
18025 +#ifdef __KERNEL__
18026 +#ifndef __ASSEMBLY__
18027 +#ifdef CONFIG_X86_32
18028 +#define arch_mmap_check i386_mmap_check
18029 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
18030 +#endif
18031 +#endif
18032 +#endif
18033 +
18034 +#endif /* X86_MMAN_H */
18035 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
18036 index 876e74e..e20bfb1 100644
18037 --- a/arch/x86/include/asm/mmu.h
18038 +++ b/arch/x86/include/asm/mmu.h
18039 @@ -9,7 +9,7 @@
18040 * we put the segment information here.
18041 */
18042 typedef struct {
18043 - void *ldt;
18044 + struct desc_struct *ldt;
18045 int size;
18046
18047 #ifdef CONFIG_X86_64
18048 @@ -18,7 +18,19 @@ typedef struct {
18049 #endif
18050
18051 struct mutex lock;
18052 - void __user *vdso;
18053 + unsigned long vdso;
18054 +
18055 +#ifdef CONFIG_X86_32
18056 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18057 + unsigned long user_cs_base;
18058 + unsigned long user_cs_limit;
18059 +
18060 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18061 + cpumask_t cpu_user_cs_mask;
18062 +#endif
18063 +
18064 +#endif
18065 +#endif
18066 } mm_context_t;
18067
18068 #ifdef CONFIG_SMP
18069 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
18070 index 166af2a..648c200 100644
18071 --- a/arch/x86/include/asm/mmu_context.h
18072 +++ b/arch/x86/include/asm/mmu_context.h
18073 @@ -28,6 +28,20 @@ void destroy_context(struct mm_struct *mm);
18074
18075 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
18076 {
18077 +
18078 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18079 + if (!(static_cpu_has(X86_FEATURE_PCID))) {
18080 + unsigned int i;
18081 + pgd_t *pgd;
18082 +
18083 + pax_open_kernel();
18084 + pgd = get_cpu_pgd(smp_processor_id(), kernel);
18085 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
18086 + set_pgd_batched(pgd+i, native_make_pgd(0));
18087 + pax_close_kernel();
18088 + }
18089 +#endif
18090 +
18091 #ifdef CONFIG_SMP
18092 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
18093 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
18094 @@ -38,16 +52,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
18095 struct task_struct *tsk)
18096 {
18097 unsigned cpu = smp_processor_id();
18098 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
18099 + int tlbstate = TLBSTATE_OK;
18100 +#endif
18101
18102 if (likely(prev != next)) {
18103 #ifdef CONFIG_SMP
18104 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
18105 + tlbstate = this_cpu_read(cpu_tlbstate.state);
18106 +#endif
18107 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
18108 this_cpu_write(cpu_tlbstate.active_mm, next);
18109 #endif
18110 cpumask_set_cpu(cpu, mm_cpumask(next));
18111
18112 /* Re-load page tables */
18113 +#ifdef CONFIG_PAX_PER_CPU_PGD
18114 + pax_open_kernel();
18115 +
18116 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18117 + if (static_cpu_has(X86_FEATURE_PCID))
18118 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
18119 + else
18120 +#endif
18121 +
18122 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
18123 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
18124 + pax_close_kernel();
18125 + 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));
18126 +
18127 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18128 + if (static_cpu_has(X86_FEATURE_PCID)) {
18129 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
18130 + u64 descriptor[2];
18131 + descriptor[0] = PCID_USER;
18132 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
18133 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
18134 + descriptor[0] = PCID_KERNEL;
18135 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
18136 + }
18137 + } else {
18138 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
18139 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
18140 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
18141 + else
18142 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
18143 + }
18144 + } else
18145 +#endif
18146 +
18147 + load_cr3(get_cpu_pgd(cpu, kernel));
18148 +#else
18149 load_cr3(next->pgd);
18150 +#endif
18151 trace_tlb_flush(TLB_FLUSH_ON_TASK_SWITCH, TLB_FLUSH_ALL);
18152
18153 /* Stop flush ipis for the previous mm */
18154 @@ -56,9 +113,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
18155 /* Load the LDT, if the LDT is different: */
18156 if (unlikely(prev->context.ldt != next->context.ldt))
18157 load_LDT_nolock(&next->context);
18158 +
18159 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18160 + if (!(__supported_pte_mask & _PAGE_NX)) {
18161 + smp_mb__before_atomic();
18162 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
18163 + smp_mb__after_atomic();
18164 + cpu_set(cpu, next->context.cpu_user_cs_mask);
18165 + }
18166 +#endif
18167 +
18168 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
18169 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
18170 + prev->context.user_cs_limit != next->context.user_cs_limit))
18171 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
18172 +#ifdef CONFIG_SMP
18173 + else if (unlikely(tlbstate != TLBSTATE_OK))
18174 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
18175 +#endif
18176 +#endif
18177 +
18178 }
18179 + else {
18180 +
18181 +#ifdef CONFIG_PAX_PER_CPU_PGD
18182 + pax_open_kernel();
18183 +
18184 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18185 + if (static_cpu_has(X86_FEATURE_PCID))
18186 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
18187 + else
18188 +#endif
18189 +
18190 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
18191 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
18192 + pax_close_kernel();
18193 + 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));
18194 +
18195 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18196 + if (static_cpu_has(X86_FEATURE_PCID)) {
18197 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
18198 + u64 descriptor[2];
18199 + descriptor[0] = PCID_USER;
18200 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
18201 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
18202 + descriptor[0] = PCID_KERNEL;
18203 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
18204 + }
18205 + } else {
18206 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
18207 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
18208 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
18209 + else
18210 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
18211 + }
18212 + } else
18213 +#endif
18214 +
18215 + load_cr3(get_cpu_pgd(cpu, kernel));
18216 +#endif
18217 +
18218 #ifdef CONFIG_SMP
18219 - else {
18220 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
18221 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
18222
18223 @@ -75,12 +190,29 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
18224 * tlb flush IPI delivery. We must reload CR3
18225 * to make sure to use no freed page tables.
18226 */
18227 +
18228 +#ifndef CONFIG_PAX_PER_CPU_PGD
18229 load_cr3(next->pgd);
18230 trace_tlb_flush(TLB_FLUSH_ON_TASK_SWITCH, TLB_FLUSH_ALL);
18231 +#endif
18232 +
18233 load_LDT_nolock(&next->context);
18234 +
18235 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
18236 + if (!(__supported_pte_mask & _PAGE_NX))
18237 + cpu_set(cpu, next->context.cpu_user_cs_mask);
18238 +#endif
18239 +
18240 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
18241 +#ifdef CONFIG_PAX_PAGEEXEC
18242 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
18243 +#endif
18244 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
18245 +#endif
18246 +
18247 }
18248 +#endif
18249 }
18250 -#endif
18251 }
18252
18253 #define activate_mm(prev, next) \
18254 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
18255 index e3b7819..b257c64 100644
18256 --- a/arch/x86/include/asm/module.h
18257 +++ b/arch/x86/include/asm/module.h
18258 @@ -5,6 +5,7 @@
18259
18260 #ifdef CONFIG_X86_64
18261 /* X86_64 does not define MODULE_PROC_FAMILY */
18262 +#define MODULE_PROC_FAMILY ""
18263 #elif defined CONFIG_M486
18264 #define MODULE_PROC_FAMILY "486 "
18265 #elif defined CONFIG_M586
18266 @@ -57,8 +58,20 @@
18267 #error unknown processor family
18268 #endif
18269
18270 -#ifdef CONFIG_X86_32
18271 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
18272 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
18273 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
18274 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
18275 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
18276 +#else
18277 +#define MODULE_PAX_KERNEXEC ""
18278 #endif
18279
18280 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18281 +#define MODULE_PAX_UDEREF "UDEREF "
18282 +#else
18283 +#define MODULE_PAX_UDEREF ""
18284 +#endif
18285 +
18286 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
18287 +
18288 #endif /* _ASM_X86_MODULE_H */
18289 diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
18290 index 5f2fc44..106caa6 100644
18291 --- a/arch/x86/include/asm/nmi.h
18292 +++ b/arch/x86/include/asm/nmi.h
18293 @@ -36,26 +36,35 @@ enum {
18294
18295 typedef int (*nmi_handler_t)(unsigned int, struct pt_regs *);
18296
18297 +struct nmiaction;
18298 +
18299 +struct nmiwork {
18300 + const struct nmiaction *action;
18301 + u64 max_duration;
18302 + struct irq_work irq_work;
18303 +};
18304 +
18305 struct nmiaction {
18306 struct list_head list;
18307 nmi_handler_t handler;
18308 - u64 max_duration;
18309 - struct irq_work irq_work;
18310 unsigned long flags;
18311 const char *name;
18312 -};
18313 + struct nmiwork *work;
18314 +} __do_const;
18315
18316 #define register_nmi_handler(t, fn, fg, n, init...) \
18317 ({ \
18318 - static struct nmiaction init fn##_na = { \
18319 + static struct nmiwork fn##_nw; \
18320 + static const struct nmiaction init fn##_na = { \
18321 .handler = (fn), \
18322 .name = (n), \
18323 .flags = (fg), \
18324 + .work = &fn##_nw, \
18325 }; \
18326 __register_nmi_handler((t), &fn##_na); \
18327 })
18328
18329 -int __register_nmi_handler(unsigned int, struct nmiaction *);
18330 +int __register_nmi_handler(unsigned int, const struct nmiaction *);
18331
18332 void unregister_nmi_handler(unsigned int, const char *);
18333
18334 diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
18335 index 802dde3..9183e68 100644
18336 --- a/arch/x86/include/asm/page.h
18337 +++ b/arch/x86/include/asm/page.h
18338 @@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
18339 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
18340
18341 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
18342 +#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
18343
18344 #define __boot_va(x) __va(x)
18345 #define __boot_pa(x) __pa(x)
18346 @@ -60,11 +61,21 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
18347 * virt_to_page(kaddr) returns a valid pointer if and only if
18348 * virt_addr_valid(kaddr) returns true.
18349 */
18350 -#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
18351 #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
18352 extern bool __virt_addr_valid(unsigned long kaddr);
18353 #define virt_addr_valid(kaddr) __virt_addr_valid((unsigned long) (kaddr))
18354
18355 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
18356 +#define virt_to_page(kaddr) \
18357 + ({ \
18358 + const void *__kaddr = (const void *)(kaddr); \
18359 + BUG_ON(!virt_addr_valid(__kaddr)); \
18360 + pfn_to_page(__pa(__kaddr) >> PAGE_SHIFT); \
18361 + })
18362 +#else
18363 +#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
18364 +#endif
18365 +
18366 #endif /* __ASSEMBLY__ */
18367
18368 #include <asm-generic/memory_model.h>
18369 diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
18370 index f408caf..4a0455e 100644
18371 --- a/arch/x86/include/asm/page_64.h
18372 +++ b/arch/x86/include/asm/page_64.h
18373 @@ -7,9 +7,9 @@
18374
18375 /* duplicated to the one in bootmem.h */
18376 extern unsigned long max_pfn;
18377 -extern unsigned long phys_base;
18378 +extern const unsigned long phys_base;
18379
18380 -static inline unsigned long __phys_addr_nodebug(unsigned long x)
18381 +static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
18382 {
18383 unsigned long y = x - __START_KERNEL_map;
18384
18385 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
18386 index cd6e1610..70f4418 100644
18387 --- a/arch/x86/include/asm/paravirt.h
18388 +++ b/arch/x86/include/asm/paravirt.h
18389 @@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
18390 return (pmd_t) { ret };
18391 }
18392
18393 -static inline pmdval_t pmd_val(pmd_t pmd)
18394 +static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
18395 {
18396 pmdval_t ret;
18397
18398 @@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
18399 val);
18400 }
18401
18402 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
18403 +{
18404 + pgdval_t val = native_pgd_val(pgd);
18405 +
18406 + if (sizeof(pgdval_t) > sizeof(long))
18407 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
18408 + val, (u64)val >> 32);
18409 + else
18410 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
18411 + val);
18412 +}
18413 +
18414 static inline void pgd_clear(pgd_t *pgdp)
18415 {
18416 set_pgd(pgdp, __pgd(0));
18417 @@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
18418 pv_mmu_ops.set_fixmap(idx, phys, flags);
18419 }
18420
18421 +#ifdef CONFIG_PAX_KERNEXEC
18422 +static inline unsigned long pax_open_kernel(void)
18423 +{
18424 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
18425 +}
18426 +
18427 +static inline unsigned long pax_close_kernel(void)
18428 +{
18429 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
18430 +}
18431 +#else
18432 +static inline unsigned long pax_open_kernel(void) { return 0; }
18433 +static inline unsigned long pax_close_kernel(void) { return 0; }
18434 +#endif
18435 +
18436 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
18437
18438 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
18439 @@ -906,7 +933,7 @@ extern void default_banner(void);
18440
18441 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
18442 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
18443 -#define PARA_INDIRECT(addr) *%cs:addr
18444 +#define PARA_INDIRECT(addr) *%ss:addr
18445 #endif
18446
18447 #define INTERRUPT_RETURN \
18448 @@ -981,6 +1008,21 @@ extern void default_banner(void);
18449 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
18450 CLBR_NONE, \
18451 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
18452 +
18453 +#define GET_CR0_INTO_RDI \
18454 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
18455 + mov %rax,%rdi
18456 +
18457 +#define SET_RDI_INTO_CR0 \
18458 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
18459 +
18460 +#define GET_CR3_INTO_RDI \
18461 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
18462 + mov %rax,%rdi
18463 +
18464 +#define SET_RDI_INTO_CR3 \
18465 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
18466 +
18467 #endif /* CONFIG_X86_32 */
18468
18469 #endif /* __ASSEMBLY__ */
18470 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
18471 index 7549b8b..f0edfda 100644
18472 --- a/arch/x86/include/asm/paravirt_types.h
18473 +++ b/arch/x86/include/asm/paravirt_types.h
18474 @@ -84,7 +84,7 @@ struct pv_init_ops {
18475 */
18476 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
18477 unsigned long addr, unsigned len);
18478 -};
18479 +} __no_const __no_randomize_layout;
18480
18481
18482 struct pv_lazy_ops {
18483 @@ -92,13 +92,13 @@ struct pv_lazy_ops {
18484 void (*enter)(void);
18485 void (*leave)(void);
18486 void (*flush)(void);
18487 -};
18488 +} __no_randomize_layout;
18489
18490 struct pv_time_ops {
18491 unsigned long long (*sched_clock)(void);
18492 unsigned long long (*steal_clock)(int cpu);
18493 unsigned long (*get_tsc_khz)(void);
18494 -};
18495 +} __no_const __no_randomize_layout;
18496
18497 struct pv_cpu_ops {
18498 /* hooks for various privileged instructions */
18499 @@ -192,7 +192,7 @@ struct pv_cpu_ops {
18500
18501 void (*start_context_switch)(struct task_struct *prev);
18502 void (*end_context_switch)(struct task_struct *next);
18503 -};
18504 +} __no_const __no_randomize_layout;
18505
18506 struct pv_irq_ops {
18507 /*
18508 @@ -215,7 +215,7 @@ struct pv_irq_ops {
18509 #ifdef CONFIG_X86_64
18510 void (*adjust_exception_frame)(void);
18511 #endif
18512 -};
18513 +} __no_randomize_layout;
18514
18515 struct pv_apic_ops {
18516 #ifdef CONFIG_X86_LOCAL_APIC
18517 @@ -223,7 +223,7 @@ struct pv_apic_ops {
18518 unsigned long start_eip,
18519 unsigned long start_esp);
18520 #endif
18521 -};
18522 +} __no_const __no_randomize_layout;
18523
18524 struct pv_mmu_ops {
18525 unsigned long (*read_cr2)(void);
18526 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
18527 struct paravirt_callee_save make_pud;
18528
18529 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
18530 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
18531 #endif /* PAGETABLE_LEVELS == 4 */
18532 #endif /* PAGETABLE_LEVELS >= 3 */
18533
18534 @@ -324,7 +325,13 @@ struct pv_mmu_ops {
18535 an mfn. We can tell which is which from the index. */
18536 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
18537 phys_addr_t phys, pgprot_t flags);
18538 -};
18539 +
18540 +#ifdef CONFIG_PAX_KERNEXEC
18541 + unsigned long (*pax_open_kernel)(void);
18542 + unsigned long (*pax_close_kernel)(void);
18543 +#endif
18544 +
18545 +} __no_randomize_layout;
18546
18547 struct arch_spinlock;
18548 #ifdef CONFIG_SMP
18549 @@ -336,11 +343,14 @@ typedef u16 __ticket_t;
18550 struct pv_lock_ops {
18551 struct paravirt_callee_save lock_spinning;
18552 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
18553 -};
18554 +} __no_randomize_layout;
18555
18556 /* This contains all the paravirt structures: we get a convenient
18557 * number for each function using the offset which we use to indicate
18558 - * what to patch. */
18559 + * what to patch.
18560 + * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
18561 + */
18562 +
18563 struct paravirt_patch_template {
18564 struct pv_init_ops pv_init_ops;
18565 struct pv_time_ops pv_time_ops;
18566 @@ -349,7 +359,7 @@ struct paravirt_patch_template {
18567 struct pv_apic_ops pv_apic_ops;
18568 struct pv_mmu_ops pv_mmu_ops;
18569 struct pv_lock_ops pv_lock_ops;
18570 -};
18571 +} __no_randomize_layout;
18572
18573 extern struct pv_info pv_info;
18574 extern struct pv_init_ops pv_init_ops;
18575 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
18576 index c4412e9..90e88c5 100644
18577 --- a/arch/x86/include/asm/pgalloc.h
18578 +++ b/arch/x86/include/asm/pgalloc.h
18579 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
18580 pmd_t *pmd, pte_t *pte)
18581 {
18582 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
18583 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
18584 +}
18585 +
18586 +static inline void pmd_populate_user(struct mm_struct *mm,
18587 + pmd_t *pmd, pte_t *pte)
18588 +{
18589 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
18590 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
18591 }
18592
18593 @@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
18594
18595 #ifdef CONFIG_X86_PAE
18596 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
18597 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
18598 +{
18599 + pud_populate(mm, pudp, pmd);
18600 +}
18601 #else /* !CONFIG_X86_PAE */
18602 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
18603 {
18604 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
18605 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
18606 }
18607 +
18608 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
18609 +{
18610 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
18611 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
18612 +}
18613 #endif /* CONFIG_X86_PAE */
18614
18615 #if PAGETABLE_LEVELS > 3
18616 @@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
18617 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
18618 }
18619
18620 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
18621 +{
18622 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
18623 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
18624 +}
18625 +
18626 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
18627 {
18628 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
18629 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
18630 index 206a87f..1623b06 100644
18631 --- a/arch/x86/include/asm/pgtable-2level.h
18632 +++ b/arch/x86/include/asm/pgtable-2level.h
18633 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
18634
18635 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18636 {
18637 + pax_open_kernel();
18638 *pmdp = pmd;
18639 + pax_close_kernel();
18640 }
18641
18642 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18643 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
18644 index 81bb91b..9392125 100644
18645 --- a/arch/x86/include/asm/pgtable-3level.h
18646 +++ b/arch/x86/include/asm/pgtable-3level.h
18647 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18648
18649 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18650 {
18651 + pax_open_kernel();
18652 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
18653 + pax_close_kernel();
18654 }
18655
18656 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18657 {
18658 + pax_open_kernel();
18659 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
18660 + pax_close_kernel();
18661 }
18662
18663 /*
18664 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
18665 index aa97a07..5c53c32 100644
18666 --- a/arch/x86/include/asm/pgtable.h
18667 +++ b/arch/x86/include/asm/pgtable.h
18668 @@ -46,6 +46,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
18669
18670 #ifndef __PAGETABLE_PUD_FOLDED
18671 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
18672 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
18673 #define pgd_clear(pgd) native_pgd_clear(pgd)
18674 #endif
18675
18676 @@ -83,12 +84,53 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
18677
18678 #define arch_end_context_switch(prev) do {} while(0)
18679
18680 +#define pax_open_kernel() native_pax_open_kernel()
18681 +#define pax_close_kernel() native_pax_close_kernel()
18682 #endif /* CONFIG_PARAVIRT */
18683
18684 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
18685 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
18686 +
18687 +#ifdef CONFIG_PAX_KERNEXEC
18688 +static inline unsigned long native_pax_open_kernel(void)
18689 +{
18690 + unsigned long cr0;
18691 +
18692 + preempt_disable();
18693 + barrier();
18694 + cr0 = read_cr0() ^ X86_CR0_WP;
18695 + BUG_ON(cr0 & X86_CR0_WP);
18696 + write_cr0(cr0);
18697 + barrier();
18698 + return cr0 ^ X86_CR0_WP;
18699 +}
18700 +
18701 +static inline unsigned long native_pax_close_kernel(void)
18702 +{
18703 + unsigned long cr0;
18704 +
18705 + barrier();
18706 + cr0 = read_cr0() ^ X86_CR0_WP;
18707 + BUG_ON(!(cr0 & X86_CR0_WP));
18708 + write_cr0(cr0);
18709 + barrier();
18710 + preempt_enable_no_resched();
18711 + return cr0 ^ X86_CR0_WP;
18712 +}
18713 +#else
18714 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
18715 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
18716 +#endif
18717 +
18718 /*
18719 * The following only work if pte_present() is true.
18720 * Undefined behaviour if not..
18721 */
18722 +static inline int pte_user(pte_t pte)
18723 +{
18724 + return pte_val(pte) & _PAGE_USER;
18725 +}
18726 +
18727 static inline int pte_dirty(pte_t pte)
18728 {
18729 return pte_flags(pte) & _PAGE_DIRTY;
18730 @@ -155,6 +197,11 @@ static inline unsigned long pud_pfn(pud_t pud)
18731 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
18732 }
18733
18734 +static inline unsigned long pgd_pfn(pgd_t pgd)
18735 +{
18736 + return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
18737 +}
18738 +
18739 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
18740
18741 static inline int pmd_large(pmd_t pte)
18742 @@ -208,9 +255,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
18743 return pte_clear_flags(pte, _PAGE_RW);
18744 }
18745
18746 +static inline pte_t pte_mkread(pte_t pte)
18747 +{
18748 + return __pte(pte_val(pte) | _PAGE_USER);
18749 +}
18750 +
18751 static inline pte_t pte_mkexec(pte_t pte)
18752 {
18753 - return pte_clear_flags(pte, _PAGE_NX);
18754 +#ifdef CONFIG_X86_PAE
18755 + if (__supported_pte_mask & _PAGE_NX)
18756 + return pte_clear_flags(pte, _PAGE_NX);
18757 + else
18758 +#endif
18759 + return pte_set_flags(pte, _PAGE_USER);
18760 +}
18761 +
18762 +static inline pte_t pte_exprotect(pte_t pte)
18763 +{
18764 +#ifdef CONFIG_X86_PAE
18765 + if (__supported_pte_mask & _PAGE_NX)
18766 + return pte_set_flags(pte, _PAGE_NX);
18767 + else
18768 +#endif
18769 + return pte_clear_flags(pte, _PAGE_USER);
18770 }
18771
18772 static inline pte_t pte_mkdirty(pte_t pte)
18773 @@ -440,6 +507,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
18774 #endif
18775
18776 #ifndef __ASSEMBLY__
18777 +
18778 +#ifdef CONFIG_PAX_PER_CPU_PGD
18779 +extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
18780 +enum cpu_pgd_type {kernel = 0, user = 1};
18781 +static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
18782 +{
18783 + return cpu_pgd[cpu][type];
18784 +}
18785 +#endif
18786 +
18787 #include <linux/mm_types.h>
18788 #include <linux/mmdebug.h>
18789 #include <linux/log2.h>
18790 @@ -586,7 +663,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
18791 * Currently stuck as a macro due to indirect forward reference to
18792 * linux/mmzone.h's __section_mem_map_addr() definition:
18793 */
18794 -#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
18795 +#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
18796
18797 /* Find an entry in the second-level page table.. */
18798 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
18799 @@ -626,7 +703,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
18800 * Currently stuck as a macro due to indirect forward reference to
18801 * linux/mmzone.h's __section_mem_map_addr() definition:
18802 */
18803 -#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
18804 +#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
18805
18806 /* to find an entry in a page-table-directory. */
18807 static inline unsigned long pud_index(unsigned long address)
18808 @@ -641,7 +718,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
18809
18810 static inline int pgd_bad(pgd_t pgd)
18811 {
18812 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
18813 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
18814 }
18815
18816 static inline int pgd_none(pgd_t pgd)
18817 @@ -664,7 +741,12 @@ static inline int pgd_none(pgd_t pgd)
18818 * pgd_offset() returns a (pgd_t *)
18819 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
18820 */
18821 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
18822 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
18823 +
18824 +#ifdef CONFIG_PAX_PER_CPU_PGD
18825 +#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
18826 +#endif
18827 +
18828 /*
18829 * a shortcut which implies the use of the kernel's pgd, instead
18830 * of a process's
18831 @@ -675,6 +757,23 @@ static inline int pgd_none(pgd_t pgd)
18832 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
18833 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
18834
18835 +#ifdef CONFIG_X86_32
18836 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
18837 +#else
18838 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
18839 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
18840 +
18841 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18842 +#ifdef __ASSEMBLY__
18843 +#define pax_user_shadow_base pax_user_shadow_base(%rip)
18844 +#else
18845 +extern unsigned long pax_user_shadow_base;
18846 +extern pgdval_t clone_pgd_mask;
18847 +#endif
18848 +#endif
18849 +
18850 +#endif
18851 +
18852 #ifndef __ASSEMBLY__
18853
18854 extern int direct_gbpages;
18855 @@ -841,11 +940,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
18856 * dst and src can be on the same page, but the range must not overlap,
18857 * and must not cross a page boundary.
18858 */
18859 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
18860 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
18861 {
18862 - memcpy(dst, src, count * sizeof(pgd_t));
18863 + pax_open_kernel();
18864 + while (count--)
18865 + *dst++ = *src++;
18866 + pax_close_kernel();
18867 }
18868
18869 +#ifdef CONFIG_PAX_PER_CPU_PGD
18870 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
18871 +#endif
18872 +
18873 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18874 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
18875 +#else
18876 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
18877 +#endif
18878 +
18879 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
18880 static inline int page_level_shift(enum pg_level level)
18881 {
18882 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
18883 index 9ee3221..b979c6b 100644
18884 --- a/arch/x86/include/asm/pgtable_32.h
18885 +++ b/arch/x86/include/asm/pgtable_32.h
18886 @@ -25,9 +25,6 @@
18887 struct mm_struct;
18888 struct vm_area_struct;
18889
18890 -extern pgd_t swapper_pg_dir[1024];
18891 -extern pgd_t initial_page_table[1024];
18892 -
18893 static inline void pgtable_cache_init(void) { }
18894 static inline void check_pgt_cache(void) { }
18895 void paging_init(void);
18896 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
18897 # include <asm/pgtable-2level.h>
18898 #endif
18899
18900 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
18901 +extern pgd_t initial_page_table[PTRS_PER_PGD];
18902 +#ifdef CONFIG_X86_PAE
18903 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
18904 +#endif
18905 +
18906 #if defined(CONFIG_HIGHPTE)
18907 #define pte_offset_map(dir, address) \
18908 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
18909 @@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
18910 /* Clear a kernel PTE and flush it from the TLB */
18911 #define kpte_clear_flush(ptep, vaddr) \
18912 do { \
18913 + pax_open_kernel(); \
18914 pte_clear(&init_mm, (vaddr), (ptep)); \
18915 + pax_close_kernel(); \
18916 __flush_tlb_one((vaddr)); \
18917 } while (0)
18918
18919 #endif /* !__ASSEMBLY__ */
18920
18921 +#define HAVE_ARCH_UNMAPPED_AREA
18922 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
18923 +
18924 /*
18925 * kern_addr_valid() is (1) for FLATMEM and (0) for
18926 * SPARSEMEM and DISCONTIGMEM
18927 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
18928 index ed5903b..c7fe163 100644
18929 --- a/arch/x86/include/asm/pgtable_32_types.h
18930 +++ b/arch/x86/include/asm/pgtable_32_types.h
18931 @@ -8,7 +8,7 @@
18932 */
18933 #ifdef CONFIG_X86_PAE
18934 # include <asm/pgtable-3level_types.h>
18935 -# define PMD_SIZE (1UL << PMD_SHIFT)
18936 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
18937 # define PMD_MASK (~(PMD_SIZE - 1))
18938 #else
18939 # include <asm/pgtable-2level_types.h>
18940 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
18941 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
18942 #endif
18943
18944 +#ifdef CONFIG_PAX_KERNEXEC
18945 +#ifndef __ASSEMBLY__
18946 +extern unsigned char MODULES_EXEC_VADDR[];
18947 +extern unsigned char MODULES_EXEC_END[];
18948 +#endif
18949 +#include <asm/boot.h>
18950 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
18951 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
18952 +#else
18953 +#define ktla_ktva(addr) (addr)
18954 +#define ktva_ktla(addr) (addr)
18955 +#endif
18956 +
18957 #define MODULES_VADDR VMALLOC_START
18958 #define MODULES_END VMALLOC_END
18959 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
18960 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
18961 index 3874693..d7906ac 100644
18962 --- a/arch/x86/include/asm/pgtable_64.h
18963 +++ b/arch/x86/include/asm/pgtable_64.h
18964 @@ -16,11 +16,16 @@
18965
18966 extern pud_t level3_kernel_pgt[512];
18967 extern pud_t level3_ident_pgt[512];
18968 +extern pud_t level3_vmalloc_start_pgt[512];
18969 +extern pud_t level3_vmalloc_end_pgt[512];
18970 +extern pud_t level3_vmemmap_pgt[512];
18971 +extern pud_t level2_vmemmap_pgt[512];
18972 extern pmd_t level2_kernel_pgt[512];
18973 extern pmd_t level2_fixmap_pgt[512];
18974 -extern pmd_t level2_ident_pgt[512];
18975 +extern pmd_t level2_ident_pgt[512*2];
18976 extern pte_t level1_fixmap_pgt[512];
18977 -extern pgd_t init_level4_pgt[];
18978 +extern pte_t level1_vsyscall_pgt[512];
18979 +extern pgd_t init_level4_pgt[512];
18980
18981 #define swapper_pg_dir init_level4_pgt
18982
18983 @@ -62,7 +67,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18984
18985 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18986 {
18987 + pax_open_kernel();
18988 *pmdp = pmd;
18989 + pax_close_kernel();
18990 }
18991
18992 static inline void native_pmd_clear(pmd_t *pmd)
18993 @@ -98,7 +105,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
18994
18995 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18996 {
18997 + pax_open_kernel();
18998 *pudp = pud;
18999 + pax_close_kernel();
19000 }
19001
19002 static inline void native_pud_clear(pud_t *pud)
19003 @@ -108,6 +117,13 @@ static inline void native_pud_clear(pud_t *pud)
19004
19005 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
19006 {
19007 + pax_open_kernel();
19008 + *pgdp = pgd;
19009 + pax_close_kernel();
19010 +}
19011 +
19012 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
19013 +{
19014 *pgdp = pgd;
19015 }
19016
19017 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
19018 index 7166e25..baaa6fe 100644
19019 --- a/arch/x86/include/asm/pgtable_64_types.h
19020 +++ b/arch/x86/include/asm/pgtable_64_types.h
19021 @@ -61,9 +61,14 @@ typedef struct { pteval_t pte; } pte_t;
19022 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
19023 #define MODULES_END _AC(0xffffffffff000000, UL)
19024 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
19025 +#define MODULES_EXEC_VADDR MODULES_VADDR
19026 +#define MODULES_EXEC_END MODULES_END
19027 #define ESPFIX_PGD_ENTRY _AC(-2, UL)
19028 #define ESPFIX_BASE_ADDR (ESPFIX_PGD_ENTRY << PGDIR_SHIFT)
19029
19030 +#define ktla_ktva(addr) (addr)
19031 +#define ktva_ktla(addr) (addr)
19032 +
19033 #define EARLY_DYNAMIC_PAGE_TABLES 64
19034
19035 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
19036 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
19037 index f216963..6bd7c21 100644
19038 --- a/arch/x86/include/asm/pgtable_types.h
19039 +++ b/arch/x86/include/asm/pgtable_types.h
19040 @@ -111,8 +111,10 @@
19041
19042 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
19043 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
19044 -#else
19045 +#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
19046 #define _PAGE_NX (_AT(pteval_t, 0))
19047 +#else
19048 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
19049 #endif
19050
19051 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
19052 @@ -151,6 +153,9 @@
19053 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
19054 _PAGE_ACCESSED)
19055
19056 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
19057 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
19058 +
19059 #define __PAGE_KERNEL_EXEC \
19060 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
19061 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
19062 @@ -161,7 +166,7 @@
19063 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
19064 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
19065 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
19066 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
19067 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
19068 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
19069 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
19070 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
19071 @@ -218,7 +223,7 @@
19072 #ifdef CONFIG_X86_64
19073 #define __PAGE_KERNEL_IDENT_LARGE_EXEC __PAGE_KERNEL_LARGE_EXEC
19074 #else
19075 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
19076 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
19077 #define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
19078 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
19079 #endif
19080 @@ -257,7 +262,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
19081 {
19082 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
19083 }
19084 +#endif
19085
19086 +#if PAGETABLE_LEVELS == 3
19087 +#include <asm-generic/pgtable-nopud.h>
19088 +#endif
19089 +
19090 +#if PAGETABLE_LEVELS == 2
19091 +#include <asm-generic/pgtable-nopmd.h>
19092 +#endif
19093 +
19094 +#ifndef __ASSEMBLY__
19095 #if PAGETABLE_LEVELS > 3
19096 typedef struct { pudval_t pud; } pud_t;
19097
19098 @@ -271,8 +286,6 @@ static inline pudval_t native_pud_val(pud_t pud)
19099 return pud.pud;
19100 }
19101 #else
19102 -#include <asm-generic/pgtable-nopud.h>
19103 -
19104 static inline pudval_t native_pud_val(pud_t pud)
19105 {
19106 return native_pgd_val(pud.pgd);
19107 @@ -292,8 +305,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
19108 return pmd.pmd;
19109 }
19110 #else
19111 -#include <asm-generic/pgtable-nopmd.h>
19112 -
19113 static inline pmdval_t native_pmd_val(pmd_t pmd)
19114 {
19115 return native_pgd_val(pmd.pud.pgd);
19116 @@ -333,7 +344,6 @@ typedef struct page *pgtable_t;
19117
19118 extern pteval_t __supported_pte_mask;
19119 extern void set_nx(void);
19120 -extern int nx_enabled;
19121
19122 #define pgprot_writecombine pgprot_writecombine
19123 extern pgprot_t pgprot_writecombine(pgprot_t prot);
19124 diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
19125 index 7024c12..71c46b9 100644
19126 --- a/arch/x86/include/asm/preempt.h
19127 +++ b/arch/x86/include/asm/preempt.h
19128 @@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
19129 */
19130 static __always_inline bool __preempt_count_dec_and_test(void)
19131 {
19132 - GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
19133 + GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
19134 }
19135
19136 /*
19137 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
19138 index eb71ec7..f06532a 100644
19139 --- a/arch/x86/include/asm/processor.h
19140 +++ b/arch/x86/include/asm/processor.h
19141 @@ -127,7 +127,7 @@ struct cpuinfo_x86 {
19142 /* Index into per_cpu list: */
19143 u16 cpu_index;
19144 u32 microcode;
19145 -} __attribute__((__aligned__(SMP_CACHE_BYTES)));
19146 +} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
19147
19148 #define X86_VENDOR_INTEL 0
19149 #define X86_VENDOR_CYRIX 1
19150 @@ -198,9 +198,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
19151 : "memory");
19152 }
19153
19154 +/* invpcid (%rdx),%rax */
19155 +#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
19156 +
19157 +#define INVPCID_SINGLE_ADDRESS 0UL
19158 +#define INVPCID_SINGLE_CONTEXT 1UL
19159 +#define INVPCID_ALL_GLOBAL 2UL
19160 +#define INVPCID_ALL_NONGLOBAL 3UL
19161 +
19162 +#define PCID_KERNEL 0UL
19163 +#define PCID_USER 1UL
19164 +#define PCID_NOFLUSH (1UL << 63)
19165 +
19166 static inline void load_cr3(pgd_t *pgdir)
19167 {
19168 - write_cr3(__pa(pgdir));
19169 + write_cr3(__pa(pgdir) | PCID_KERNEL);
19170 }
19171
19172 #ifdef CONFIG_X86_32
19173 @@ -282,7 +294,7 @@ struct tss_struct {
19174
19175 } ____cacheline_aligned;
19176
19177 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
19178 +extern struct tss_struct init_tss[NR_CPUS];
19179
19180 /*
19181 * Save the original ist values for checking stack pointers during debugging
19182 @@ -478,6 +490,7 @@ struct thread_struct {
19183 unsigned short ds;
19184 unsigned short fsindex;
19185 unsigned short gsindex;
19186 + unsigned short ss;
19187 #endif
19188 #ifdef CONFIG_X86_32
19189 unsigned long ip;
19190 @@ -587,29 +600,8 @@ static inline void load_sp0(struct tss_struct *tss,
19191 extern unsigned long mmu_cr4_features;
19192 extern u32 *trampoline_cr4_features;
19193
19194 -static inline void set_in_cr4(unsigned long mask)
19195 -{
19196 - unsigned long cr4;
19197 -
19198 - mmu_cr4_features |= mask;
19199 - if (trampoline_cr4_features)
19200 - *trampoline_cr4_features = mmu_cr4_features;
19201 - cr4 = read_cr4();
19202 - cr4 |= mask;
19203 - write_cr4(cr4);
19204 -}
19205 -
19206 -static inline void clear_in_cr4(unsigned long mask)
19207 -{
19208 - unsigned long cr4;
19209 -
19210 - mmu_cr4_features &= ~mask;
19211 - if (trampoline_cr4_features)
19212 - *trampoline_cr4_features = mmu_cr4_features;
19213 - cr4 = read_cr4();
19214 - cr4 &= ~mask;
19215 - write_cr4(cr4);
19216 -}
19217 +extern void set_in_cr4(unsigned long mask);
19218 +extern void clear_in_cr4(unsigned long mask);
19219
19220 typedef struct {
19221 unsigned long seg;
19222 @@ -837,11 +829,18 @@ static inline void spin_lock_prefetch(const void *x)
19223 */
19224 #define TASK_SIZE PAGE_OFFSET
19225 #define TASK_SIZE_MAX TASK_SIZE
19226 +
19227 +#ifdef CONFIG_PAX_SEGMEXEC
19228 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
19229 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
19230 +#else
19231 #define STACK_TOP TASK_SIZE
19232 -#define STACK_TOP_MAX STACK_TOP
19233 +#endif
19234 +
19235 +#define STACK_TOP_MAX TASK_SIZE
19236
19237 #define INIT_THREAD { \
19238 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
19239 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
19240 .vm86_info = NULL, \
19241 .sysenter_cs = __KERNEL_CS, \
19242 .io_bitmap_ptr = NULL, \
19243 @@ -855,7 +854,7 @@ static inline void spin_lock_prefetch(const void *x)
19244 */
19245 #define INIT_TSS { \
19246 .x86_tss = { \
19247 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
19248 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
19249 .ss0 = __KERNEL_DS, \
19250 .ss1 = __KERNEL_CS, \
19251 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
19252 @@ -866,11 +865,7 @@ static inline void spin_lock_prefetch(const void *x)
19253 extern unsigned long thread_saved_pc(struct task_struct *tsk);
19254
19255 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
19256 -#define KSTK_TOP(info) \
19257 -({ \
19258 - unsigned long *__ptr = (unsigned long *)(info); \
19259 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
19260 -})
19261 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
19262
19263 /*
19264 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
19265 @@ -885,7 +880,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
19266 #define task_pt_regs(task) \
19267 ({ \
19268 struct pt_regs *__regs__; \
19269 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
19270 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
19271 __regs__ - 1; \
19272 })
19273
19274 @@ -895,13 +890,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
19275 /*
19276 * User space process size. 47bits minus one guard page.
19277 */
19278 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
19279 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
19280
19281 /* This decides where the kernel will search for a free chunk of vm
19282 * space during mmap's.
19283 */
19284 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
19285 - 0xc0000000 : 0xFFFFe000)
19286 + 0xc0000000 : 0xFFFFf000)
19287
19288 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
19289 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
19290 @@ -912,11 +907,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
19291 #define STACK_TOP_MAX TASK_SIZE_MAX
19292
19293 #define INIT_THREAD { \
19294 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
19295 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
19296 }
19297
19298 #define INIT_TSS { \
19299 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
19300 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
19301 }
19302
19303 /*
19304 @@ -944,6 +939,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
19305 */
19306 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
19307
19308 +#ifdef CONFIG_PAX_SEGMEXEC
19309 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
19310 +#endif
19311 +
19312 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
19313
19314 /* Get/set a process' ability to use the timestamp counter instruction */
19315 @@ -970,7 +969,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
19316 return 0;
19317 }
19318
19319 -extern unsigned long arch_align_stack(unsigned long sp);
19320 +#define arch_align_stack(x) ((x) & ~0xfUL)
19321 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
19322
19323 void default_idle(void);
19324 @@ -980,6 +979,6 @@ bool xen_set_default_idle(void);
19325 #define xen_set_default_idle 0
19326 #endif
19327
19328 -void stop_this_cpu(void *dummy);
19329 +void stop_this_cpu(void *dummy) __noreturn;
19330 void df_debug(struct pt_regs *regs, long error_code);
19331 #endif /* _ASM_X86_PROCESSOR_H */
19332 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
19333 index 6205f0c..688a3a9 100644
19334 --- a/arch/x86/include/asm/ptrace.h
19335 +++ b/arch/x86/include/asm/ptrace.h
19336 @@ -84,28 +84,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
19337 }
19338
19339 /*
19340 - * user_mode_vm(regs) determines whether a register set came from user mode.
19341 + * user_mode(regs) determines whether a register set came from user mode.
19342 * This is true if V8086 mode was enabled OR if the register set was from
19343 * protected mode with RPL-3 CS value. This tricky test checks that with
19344 * one comparison. Many places in the kernel can bypass this full check
19345 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
19346 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
19347 + * be used.
19348 */
19349 -static inline int user_mode(struct pt_regs *regs)
19350 +static inline int user_mode_novm(struct pt_regs *regs)
19351 {
19352 #ifdef CONFIG_X86_32
19353 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
19354 #else
19355 - return !!(regs->cs & 3);
19356 + return !!(regs->cs & SEGMENT_RPL_MASK);
19357 #endif
19358 }
19359
19360 -static inline int user_mode_vm(struct pt_regs *regs)
19361 +static inline int user_mode(struct pt_regs *regs)
19362 {
19363 #ifdef CONFIG_X86_32
19364 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
19365 USER_RPL;
19366 #else
19367 - return user_mode(regs);
19368 + return user_mode_novm(regs);
19369 #endif
19370 }
19371
19372 @@ -121,15 +122,16 @@ static inline int v8086_mode(struct pt_regs *regs)
19373 #ifdef CONFIG_X86_64
19374 static inline bool user_64bit_mode(struct pt_regs *regs)
19375 {
19376 + unsigned long cs = regs->cs & 0xffff;
19377 #ifndef CONFIG_PARAVIRT
19378 /*
19379 * On non-paravirt systems, this is the only long mode CPL 3
19380 * selector. We do not allow long mode selectors in the LDT.
19381 */
19382 - return regs->cs == __USER_CS;
19383 + return cs == __USER_CS;
19384 #else
19385 /* Headers are too twisted for this to go in paravirt.h. */
19386 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
19387 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
19388 #endif
19389 }
19390
19391 @@ -180,9 +182,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
19392 * Traps from the kernel do not save sp and ss.
19393 * Use the helper function to retrieve sp.
19394 */
19395 - if (offset == offsetof(struct pt_regs, sp) &&
19396 - regs->cs == __KERNEL_CS)
19397 - return kernel_stack_pointer(regs);
19398 + if (offset == offsetof(struct pt_regs, sp)) {
19399 + unsigned long cs = regs->cs & 0xffff;
19400 + if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
19401 + return kernel_stack_pointer(regs);
19402 + }
19403 #endif
19404 return *(unsigned long *)((unsigned long)regs + offset);
19405 }
19406 diff --git a/arch/x86/include/asm/qrwlock.h b/arch/x86/include/asm/qrwlock.h
19407 index ae0e241..e80b10b 100644
19408 --- a/arch/x86/include/asm/qrwlock.h
19409 +++ b/arch/x86/include/asm/qrwlock.h
19410 @@ -7,8 +7,8 @@
19411 #define queue_write_unlock queue_write_unlock
19412 static inline void queue_write_unlock(struct qrwlock *lock)
19413 {
19414 - barrier();
19415 - ACCESS_ONCE(*(u8 *)&lock->cnts) = 0;
19416 + barrier();
19417 + ACCESS_ONCE_RW(*(u8 *)&lock->cnts) = 0;
19418 }
19419 #endif
19420
19421 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
19422 index 9c6b890..5305f53 100644
19423 --- a/arch/x86/include/asm/realmode.h
19424 +++ b/arch/x86/include/asm/realmode.h
19425 @@ -22,16 +22,14 @@ struct real_mode_header {
19426 #endif
19427 /* APM/BIOS reboot */
19428 u32 machine_real_restart_asm;
19429 -#ifdef CONFIG_X86_64
19430 u32 machine_real_restart_seg;
19431 -#endif
19432 };
19433
19434 /* This must match data at trampoline_32/64.S */
19435 struct trampoline_header {
19436 #ifdef CONFIG_X86_32
19437 u32 start;
19438 - u16 gdt_pad;
19439 + u16 boot_cs;
19440 u16 gdt_limit;
19441 u32 gdt_base;
19442 #else
19443 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
19444 index a82c4f1..ac45053 100644
19445 --- a/arch/x86/include/asm/reboot.h
19446 +++ b/arch/x86/include/asm/reboot.h
19447 @@ -6,13 +6,13 @@
19448 struct pt_regs;
19449
19450 struct machine_ops {
19451 - void (*restart)(char *cmd);
19452 - void (*halt)(void);
19453 - void (*power_off)(void);
19454 + void (* __noreturn restart)(char *cmd);
19455 + void (* __noreturn halt)(void);
19456 + void (* __noreturn power_off)(void);
19457 void (*shutdown)(void);
19458 void (*crash_shutdown)(struct pt_regs *);
19459 - void (*emergency_restart)(void);
19460 -};
19461 + void (* __noreturn emergency_restart)(void);
19462 +} __no_const;
19463
19464 extern struct machine_ops machine_ops;
19465
19466 diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
19467 index 8f7866a..e442f20 100644
19468 --- a/arch/x86/include/asm/rmwcc.h
19469 +++ b/arch/x86/include/asm/rmwcc.h
19470 @@ -3,7 +3,34 @@
19471
19472 #ifdef CC_HAVE_ASM_GOTO
19473
19474 -#define __GEN_RMWcc(fullop, var, cc, ...) \
19475 +#ifdef CONFIG_PAX_REFCOUNT
19476 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
19477 +do { \
19478 + asm_volatile_goto (fullop \
19479 + ";jno 0f\n" \
19480 + fullantiop \
19481 + ";int $4\n0:\n" \
19482 + _ASM_EXTABLE(0b, 0b) \
19483 + ";j" cc " %l[cc_label]" \
19484 + : : "m" (var), ## __VA_ARGS__ \
19485 + : "memory" : cc_label); \
19486 + return 0; \
19487 +cc_label: \
19488 + return 1; \
19489 +} while (0)
19490 +#else
19491 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
19492 +do { \
19493 + asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
19494 + : : "m" (var), ## __VA_ARGS__ \
19495 + : "memory" : cc_label); \
19496 + return 0; \
19497 +cc_label: \
19498 + return 1; \
19499 +} while (0)
19500 +#endif
19501 +
19502 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
19503 do { \
19504 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
19505 : : "m" (var), ## __VA_ARGS__ \
19506 @@ -13,15 +40,46 @@ cc_label: \
19507 return 1; \
19508 } while (0)
19509
19510 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
19511 - __GEN_RMWcc(op " " arg0, var, cc)
19512 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
19513 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
19514
19515 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
19516 - __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
19517 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
19518 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
19519 +
19520 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
19521 + __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
19522 +
19523 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
19524 + __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
19525
19526 #else /* !CC_HAVE_ASM_GOTO */
19527
19528 -#define __GEN_RMWcc(fullop, var, cc, ...) \
19529 +#ifdef CONFIG_PAX_REFCOUNT
19530 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
19531 +do { \
19532 + char c; \
19533 + asm volatile (fullop \
19534 + ";jno 0f\n" \
19535 + fullantiop \
19536 + ";int $4\n0:\n" \
19537 + _ASM_EXTABLE(0b, 0b) \
19538 + "; set" cc " %1" \
19539 + : "+m" (var), "=qm" (c) \
19540 + : __VA_ARGS__ : "memory"); \
19541 + return c != 0; \
19542 +} while (0)
19543 +#else
19544 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
19545 +do { \
19546 + char c; \
19547 + asm volatile (fullop "; set" cc " %1" \
19548 + : "+m" (var), "=qm" (c) \
19549 + : __VA_ARGS__ : "memory"); \
19550 + return c != 0; \
19551 +} while (0)
19552 +#endif
19553 +
19554 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
19555 do { \
19556 char c; \
19557 asm volatile (fullop "; set" cc " %1" \
19558 @@ -30,11 +88,17 @@ do { \
19559 return c != 0; \
19560 } while (0)
19561
19562 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
19563 - __GEN_RMWcc(op " " arg0, var, cc)
19564 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
19565 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
19566 +
19567 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
19568 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
19569 +
19570 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
19571 + __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
19572
19573 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
19574 - __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
19575 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
19576 + __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
19577
19578 #endif /* CC_HAVE_ASM_GOTO */
19579
19580 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
19581 index cad82c9..2e5c5c1 100644
19582 --- a/arch/x86/include/asm/rwsem.h
19583 +++ b/arch/x86/include/asm/rwsem.h
19584 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
19585 {
19586 asm volatile("# beginning down_read\n\t"
19587 LOCK_PREFIX _ASM_INC "(%1)\n\t"
19588 +
19589 +#ifdef CONFIG_PAX_REFCOUNT
19590 + "jno 0f\n"
19591 + LOCK_PREFIX _ASM_DEC "(%1)\n"
19592 + "int $4\n0:\n"
19593 + _ASM_EXTABLE(0b, 0b)
19594 +#endif
19595 +
19596 /* adds 0x00000001 */
19597 " jns 1f\n"
19598 " call call_rwsem_down_read_failed\n"
19599 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
19600 "1:\n\t"
19601 " mov %1,%2\n\t"
19602 " add %3,%2\n\t"
19603 +
19604 +#ifdef CONFIG_PAX_REFCOUNT
19605 + "jno 0f\n"
19606 + "sub %3,%2\n"
19607 + "int $4\n0:\n"
19608 + _ASM_EXTABLE(0b, 0b)
19609 +#endif
19610 +
19611 " jle 2f\n\t"
19612 LOCK_PREFIX " cmpxchg %2,%0\n\t"
19613 " jnz 1b\n\t"
19614 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
19615 long tmp;
19616 asm volatile("# beginning down_write\n\t"
19617 LOCK_PREFIX " xadd %1,(%2)\n\t"
19618 +
19619 +#ifdef CONFIG_PAX_REFCOUNT
19620 + "jno 0f\n"
19621 + "mov %1,(%2)\n"
19622 + "int $4\n0:\n"
19623 + _ASM_EXTABLE(0b, 0b)
19624 +#endif
19625 +
19626 /* adds 0xffff0001, returns the old value */
19627 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
19628 /* was the active mask 0 before? */
19629 @@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
19630 long tmp;
19631 asm volatile("# beginning __up_read\n\t"
19632 LOCK_PREFIX " xadd %1,(%2)\n\t"
19633 +
19634 +#ifdef CONFIG_PAX_REFCOUNT
19635 + "jno 0f\n"
19636 + "mov %1,(%2)\n"
19637 + "int $4\n0:\n"
19638 + _ASM_EXTABLE(0b, 0b)
19639 +#endif
19640 +
19641 /* subtracts 1, returns the old value */
19642 " jns 1f\n\t"
19643 " call call_rwsem_wake\n" /* expects old value in %edx */
19644 @@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
19645 long tmp;
19646 asm volatile("# beginning __up_write\n\t"
19647 LOCK_PREFIX " xadd %1,(%2)\n\t"
19648 +
19649 +#ifdef CONFIG_PAX_REFCOUNT
19650 + "jno 0f\n"
19651 + "mov %1,(%2)\n"
19652 + "int $4\n0:\n"
19653 + _ASM_EXTABLE(0b, 0b)
19654 +#endif
19655 +
19656 /* subtracts 0xffff0001, returns the old value */
19657 " jns 1f\n\t"
19658 " call call_rwsem_wake\n" /* expects old value in %edx */
19659 @@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
19660 {
19661 asm volatile("# beginning __downgrade_write\n\t"
19662 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
19663 +
19664 +#ifdef CONFIG_PAX_REFCOUNT
19665 + "jno 0f\n"
19666 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
19667 + "int $4\n0:\n"
19668 + _ASM_EXTABLE(0b, 0b)
19669 +#endif
19670 +
19671 /*
19672 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
19673 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
19674 @@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
19675 */
19676 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
19677 {
19678 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
19679 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
19680 +
19681 +#ifdef CONFIG_PAX_REFCOUNT
19682 + "jno 0f\n"
19683 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
19684 + "int $4\n0:\n"
19685 + _ASM_EXTABLE(0b, 0b)
19686 +#endif
19687 +
19688 : "+m" (sem->count)
19689 : "er" (delta));
19690 }
19691 @@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
19692 */
19693 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
19694 {
19695 - return delta + xadd(&sem->count, delta);
19696 + return delta + xadd_check_overflow(&sem->count, delta);
19697 }
19698
19699 #endif /* __KERNEL__ */
19700 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
19701 index 6f1c3a8..7744f19 100644
19702 --- a/arch/x86/include/asm/segment.h
19703 +++ b/arch/x86/include/asm/segment.h
19704 @@ -64,10 +64,15 @@
19705 * 26 - ESPFIX small SS
19706 * 27 - per-cpu [ offset to per-cpu data area ]
19707 * 28 - stack_canary-20 [ for stack protector ]
19708 - * 29 - unused
19709 - * 30 - unused
19710 + * 29 - PCI BIOS CS
19711 + * 30 - PCI BIOS DS
19712 * 31 - TSS for double fault handler
19713 */
19714 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
19715 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
19716 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
19717 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
19718 +
19719 #define GDT_ENTRY_TLS_MIN 6
19720 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
19721
19722 @@ -79,6 +84,8 @@
19723
19724 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
19725
19726 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
19727 +
19728 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
19729
19730 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
19731 @@ -104,6 +111,12 @@
19732 #define __KERNEL_STACK_CANARY 0
19733 #endif
19734
19735 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
19736 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
19737 +
19738 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
19739 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
19740 +
19741 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
19742
19743 /*
19744 @@ -141,7 +154,7 @@
19745 */
19746
19747 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
19748 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
19749 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
19750
19751
19752 #else
19753 @@ -165,6 +178,8 @@
19754 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
19755 #define __USER32_DS __USER_DS
19756
19757 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
19758 +
19759 #define GDT_ENTRY_TSS 8 /* needs two entries */
19760 #define GDT_ENTRY_LDT 10 /* needs two entries */
19761 #define GDT_ENTRY_TLS_MIN 12
19762 @@ -173,6 +188,8 @@
19763 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
19764 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
19765
19766 +#define GDT_ENTRY_UDEREF_KERNEL_DS 16
19767 +
19768 /* TLS indexes for 64bit - hardcoded in arch_prctl */
19769 #define FS_TLS 0
19770 #define GS_TLS 1
19771 @@ -180,12 +197,14 @@
19772 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
19773 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
19774
19775 -#define GDT_ENTRIES 16
19776 +#define GDT_ENTRIES 17
19777
19778 #endif
19779
19780 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
19781 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
19782 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
19783 +#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
19784 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
19785 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
19786 #ifndef CONFIG_PARAVIRT
19787 @@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
19788 {
19789 unsigned long __limit;
19790 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
19791 - return __limit + 1;
19792 + return __limit;
19793 }
19794
19795 #endif /* !__ASSEMBLY__ */
19796 diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
19797 index 8d3120f..352b440 100644
19798 --- a/arch/x86/include/asm/smap.h
19799 +++ b/arch/x86/include/asm/smap.h
19800 @@ -25,11 +25,40 @@
19801
19802 #include <asm/alternative-asm.h>
19803
19804 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19805 +#define ASM_PAX_OPEN_USERLAND \
19806 + 661: jmp 663f; \
19807 + .pushsection .altinstr_replacement, "a" ; \
19808 + 662: pushq %rax; nop; \
19809 + .popsection ; \
19810 + .pushsection .altinstructions, "a" ; \
19811 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19812 + .popsection ; \
19813 + call __pax_open_userland; \
19814 + popq %rax; \
19815 + 663:
19816 +
19817 +#define ASM_PAX_CLOSE_USERLAND \
19818 + 661: jmp 663f; \
19819 + .pushsection .altinstr_replacement, "a" ; \
19820 + 662: pushq %rax; nop; \
19821 + .popsection; \
19822 + .pushsection .altinstructions, "a" ; \
19823 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19824 + .popsection; \
19825 + call __pax_close_userland; \
19826 + popq %rax; \
19827 + 663:
19828 +#else
19829 +#define ASM_PAX_OPEN_USERLAND
19830 +#define ASM_PAX_CLOSE_USERLAND
19831 +#endif
19832 +
19833 #ifdef CONFIG_X86_SMAP
19834
19835 #define ASM_CLAC \
19836 661: ASM_NOP3 ; \
19837 - .pushsection .altinstr_replacement, "ax" ; \
19838 + .pushsection .altinstr_replacement, "a" ; \
19839 662: __ASM_CLAC ; \
19840 .popsection ; \
19841 .pushsection .altinstructions, "a" ; \
19842 @@ -38,7 +67,7 @@
19843
19844 #define ASM_STAC \
19845 661: ASM_NOP3 ; \
19846 - .pushsection .altinstr_replacement, "ax" ; \
19847 + .pushsection .altinstr_replacement, "a" ; \
19848 662: __ASM_STAC ; \
19849 .popsection ; \
19850 .pushsection .altinstructions, "a" ; \
19851 @@ -56,6 +85,37 @@
19852
19853 #include <asm/alternative.h>
19854
19855 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
19856 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
19857 +
19858 +extern void __pax_open_userland(void);
19859 +static __always_inline unsigned long pax_open_userland(void)
19860 +{
19861 +
19862 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19863 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
19864 + :
19865 + : [open] "i" (__pax_open_userland)
19866 + : "memory", "rax");
19867 +#endif
19868 +
19869 + return 0;
19870 +}
19871 +
19872 +extern void __pax_close_userland(void);
19873 +static __always_inline unsigned long pax_close_userland(void)
19874 +{
19875 +
19876 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19877 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
19878 + :
19879 + : [close] "i" (__pax_close_userland)
19880 + : "memory", "rax");
19881 +#endif
19882 +
19883 + return 0;
19884 +}
19885 +
19886 #ifdef CONFIG_X86_SMAP
19887
19888 static __always_inline void clac(void)
19889 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
19890 index 8cd27e0..7f05ec8 100644
19891 --- a/arch/x86/include/asm/smp.h
19892 +++ b/arch/x86/include/asm/smp.h
19893 @@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
19894 /* cpus sharing the last level cache: */
19895 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
19896 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
19897 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
19898 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19899
19900 static inline struct cpumask *cpu_sibling_mask(int cpu)
19901 {
19902 @@ -78,7 +78,7 @@ struct smp_ops {
19903
19904 void (*send_call_func_ipi)(const struct cpumask *mask);
19905 void (*send_call_func_single_ipi)(int cpu);
19906 -};
19907 +} __no_const;
19908
19909 /* Globals due to paravirt */
19910 extern void set_cpu_sibling_map(int cpu);
19911 @@ -190,14 +190,8 @@ extern unsigned disabled_cpus;
19912 extern int safe_smp_processor_id(void);
19913
19914 #elif defined(CONFIG_X86_64_SMP)
19915 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19916 -
19917 -#define stack_smp_processor_id() \
19918 -({ \
19919 - struct thread_info *ti; \
19920 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
19921 - ti->cpu; \
19922 -})
19923 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19924 +#define stack_smp_processor_id() raw_smp_processor_id()
19925 #define safe_smp_processor_id() smp_processor_id()
19926
19927 #endif
19928 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
19929 index 54f1c80..39362a5 100644
19930 --- a/arch/x86/include/asm/spinlock.h
19931 +++ b/arch/x86/include/asm/spinlock.h
19932 @@ -223,6 +223,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
19933 static inline void arch_read_lock(arch_rwlock_t *rw)
19934 {
19935 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
19936 +
19937 +#ifdef CONFIG_PAX_REFCOUNT
19938 + "jno 0f\n"
19939 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
19940 + "int $4\n0:\n"
19941 + _ASM_EXTABLE(0b, 0b)
19942 +#endif
19943 +
19944 "jns 1f\n"
19945 "call __read_lock_failed\n\t"
19946 "1:\n"
19947 @@ -232,6 +240,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
19948 static inline void arch_write_lock(arch_rwlock_t *rw)
19949 {
19950 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
19951 +
19952 +#ifdef CONFIG_PAX_REFCOUNT
19953 + "jno 0f\n"
19954 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
19955 + "int $4\n0:\n"
19956 + _ASM_EXTABLE(0b, 0b)
19957 +#endif
19958 +
19959 "jz 1f\n"
19960 "call __write_lock_failed\n\t"
19961 "1:\n"
19962 @@ -261,13 +277,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
19963
19964 static inline void arch_read_unlock(arch_rwlock_t *rw)
19965 {
19966 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
19967 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
19968 +
19969 +#ifdef CONFIG_PAX_REFCOUNT
19970 + "jno 0f\n"
19971 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
19972 + "int $4\n0:\n"
19973 + _ASM_EXTABLE(0b, 0b)
19974 +#endif
19975 +
19976 :"+m" (rw->lock) : : "memory");
19977 }
19978
19979 static inline void arch_write_unlock(arch_rwlock_t *rw)
19980 {
19981 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
19982 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
19983 +
19984 +#ifdef CONFIG_PAX_REFCOUNT
19985 + "jno 0f\n"
19986 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
19987 + "int $4\n0:\n"
19988 + _ASM_EXTABLE(0b, 0b)
19989 +#endif
19990 +
19991 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
19992 }
19993 #else
19994 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
19995 index 6a99859..03cb807 100644
19996 --- a/arch/x86/include/asm/stackprotector.h
19997 +++ b/arch/x86/include/asm/stackprotector.h
19998 @@ -47,7 +47,7 @@
19999 * head_32 for boot CPU and setup_per_cpu_areas() for others.
20000 */
20001 #define GDT_STACK_CANARY_INIT \
20002 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
20003 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
20004
20005 /*
20006 * Initialize the stackprotector canary value.
20007 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
20008
20009 static inline void load_stack_canary_segment(void)
20010 {
20011 -#ifdef CONFIG_X86_32
20012 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
20013 asm volatile ("mov %0, %%gs" : : "r" (0));
20014 #endif
20015 }
20016 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
20017 index 70bbe39..4ae2bd4 100644
20018 --- a/arch/x86/include/asm/stacktrace.h
20019 +++ b/arch/x86/include/asm/stacktrace.h
20020 @@ -11,28 +11,20 @@
20021
20022 extern int kstack_depth_to_print;
20023
20024 -struct thread_info;
20025 +struct task_struct;
20026 struct stacktrace_ops;
20027
20028 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
20029 - unsigned long *stack,
20030 - unsigned long bp,
20031 - const struct stacktrace_ops *ops,
20032 - void *data,
20033 - unsigned long *end,
20034 - int *graph);
20035 +typedef unsigned long walk_stack_t(struct task_struct *task,
20036 + void *stack_start,
20037 + unsigned long *stack,
20038 + unsigned long bp,
20039 + const struct stacktrace_ops *ops,
20040 + void *data,
20041 + unsigned long *end,
20042 + int *graph);
20043
20044 -extern unsigned long
20045 -print_context_stack(struct thread_info *tinfo,
20046 - unsigned long *stack, unsigned long bp,
20047 - const struct stacktrace_ops *ops, void *data,
20048 - unsigned long *end, int *graph);
20049 -
20050 -extern unsigned long
20051 -print_context_stack_bp(struct thread_info *tinfo,
20052 - unsigned long *stack, unsigned long bp,
20053 - const struct stacktrace_ops *ops, void *data,
20054 - unsigned long *end, int *graph);
20055 +extern walk_stack_t print_context_stack;
20056 +extern walk_stack_t print_context_stack_bp;
20057
20058 /* Generic stack tracer with callbacks */
20059
20060 @@ -40,7 +32,7 @@ struct stacktrace_ops {
20061 void (*address)(void *data, unsigned long address, int reliable);
20062 /* On negative return stop dumping */
20063 int (*stack)(void *data, char *name);
20064 - walk_stack_t walk_stack;
20065 + walk_stack_t *walk_stack;
20066 };
20067
20068 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
20069 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
20070 index d7f3b3b..3cc39f1 100644
20071 --- a/arch/x86/include/asm/switch_to.h
20072 +++ b/arch/x86/include/asm/switch_to.h
20073 @@ -108,7 +108,7 @@ do { \
20074 "call __switch_to\n\t" \
20075 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
20076 __switch_canary \
20077 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
20078 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
20079 "movq %%rax,%%rdi\n\t" \
20080 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
20081 "jnz ret_from_fork\n\t" \
20082 @@ -119,7 +119,7 @@ do { \
20083 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
20084 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
20085 [_tif_fork] "i" (_TIF_FORK), \
20086 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
20087 + [thread_info] "m" (current_tinfo), \
20088 [current_task] "m" (current_task) \
20089 __switch_canary_iparam \
20090 : "memory", "cc" __EXTRA_CLOBBER)
20091 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
20092 index 8540538..4b0b5e9 100644
20093 --- a/arch/x86/include/asm/thread_info.h
20094 +++ b/arch/x86/include/asm/thread_info.h
20095 @@ -24,7 +24,6 @@ struct exec_domain;
20096 #include <linux/atomic.h>
20097
20098 struct thread_info {
20099 - struct task_struct *task; /* main task structure */
20100 struct exec_domain *exec_domain; /* execution domain */
20101 __u32 flags; /* low level flags */
20102 __u32 status; /* thread synchronous flags */
20103 @@ -33,13 +32,13 @@ struct thread_info {
20104 mm_segment_t addr_limit;
20105 struct restart_block restart_block;
20106 void __user *sysenter_return;
20107 + unsigned long lowest_stack;
20108 unsigned int sig_on_uaccess_error:1;
20109 unsigned int uaccess_err:1; /* uaccess failed */
20110 };
20111
20112 -#define INIT_THREAD_INFO(tsk) \
20113 +#define INIT_THREAD_INFO \
20114 { \
20115 - .task = &tsk, \
20116 .exec_domain = &default_exec_domain, \
20117 .flags = 0, \
20118 .cpu = 0, \
20119 @@ -50,7 +49,7 @@ struct thread_info {
20120 }, \
20121 }
20122
20123 -#define init_thread_info (init_thread_union.thread_info)
20124 +#define init_thread_info (init_thread_union.stack)
20125 #define init_stack (init_thread_union.stack)
20126
20127 #else /* !__ASSEMBLY__ */
20128 @@ -91,6 +90,7 @@ struct thread_info {
20129 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
20130 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
20131 #define TIF_X32 30 /* 32-bit native x86-64 binary */
20132 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
20133
20134 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
20135 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
20136 @@ -115,17 +115,18 @@ struct thread_info {
20137 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
20138 #define _TIF_ADDR32 (1 << TIF_ADDR32)
20139 #define _TIF_X32 (1 << TIF_X32)
20140 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
20141
20142 /* work to do in syscall_trace_enter() */
20143 #define _TIF_WORK_SYSCALL_ENTRY \
20144 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
20145 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
20146 - _TIF_NOHZ)
20147 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
20148
20149 /* work to do in syscall_trace_leave() */
20150 #define _TIF_WORK_SYSCALL_EXIT \
20151 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
20152 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
20153 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
20154
20155 /* work to do on interrupt/exception return */
20156 #define _TIF_WORK_MASK \
20157 @@ -136,7 +137,7 @@ struct thread_info {
20158 /* work to do on any return to user space */
20159 #define _TIF_ALLWORK_MASK \
20160 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
20161 - _TIF_NOHZ)
20162 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
20163
20164 /* Only used for 64 bit */
20165 #define _TIF_DO_NOTIFY_MASK \
20166 @@ -151,7 +152,6 @@ struct thread_info {
20167 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
20168
20169 #define STACK_WARN (THREAD_SIZE/8)
20170 -#define KERNEL_STACK_OFFSET (5*(BITS_PER_LONG/8))
20171
20172 /*
20173 * macros/functions for gaining access to the thread information structure
20174 @@ -162,26 +162,18 @@ struct thread_info {
20175
20176 DECLARE_PER_CPU(unsigned long, kernel_stack);
20177
20178 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
20179 +
20180 static inline struct thread_info *current_thread_info(void)
20181 {
20182 - struct thread_info *ti;
20183 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
20184 - KERNEL_STACK_OFFSET - THREAD_SIZE);
20185 - return ti;
20186 + return this_cpu_read_stable(current_tinfo);
20187 }
20188
20189 #else /* !__ASSEMBLY__ */
20190
20191 /* how to get the thread information struct from ASM */
20192 #define GET_THREAD_INFO(reg) \
20193 - _ASM_MOV PER_CPU_VAR(kernel_stack),reg ; \
20194 - _ASM_SUB $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg ;
20195 -
20196 -/*
20197 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
20198 - * a certain register (to be used in assembler memory operands).
20199 - */
20200 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
20201 + _ASM_MOV PER_CPU_VAR(current_tinfo),reg ;
20202
20203 #endif
20204
20205 @@ -237,5 +229,12 @@ static inline bool is_ia32_task(void)
20206 extern void arch_task_cache_init(void);
20207 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
20208 extern void arch_release_task_struct(struct task_struct *tsk);
20209 +
20210 +#define __HAVE_THREAD_FUNCTIONS
20211 +#define task_thread_info(task) (&(task)->tinfo)
20212 +#define task_stack_page(task) ((task)->stack)
20213 +#define setup_thread_stack(p, org) do {} while (0)
20214 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
20215 +
20216 #endif
20217 #endif /* _ASM_X86_THREAD_INFO_H */
20218 diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
20219 index 04905bf..1178cdf 100644
20220 --- a/arch/x86/include/asm/tlbflush.h
20221 +++ b/arch/x86/include/asm/tlbflush.h
20222 @@ -17,18 +17,44 @@
20223
20224 static inline void __native_flush_tlb(void)
20225 {
20226 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
20227 + u64 descriptor[2];
20228 +
20229 + descriptor[0] = PCID_KERNEL;
20230 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_NONGLOBAL) : "memory");
20231 + return;
20232 + }
20233 +
20234 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20235 + if (static_cpu_has(X86_FEATURE_PCID)) {
20236 + unsigned int cpu = raw_get_cpu();
20237 +
20238 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
20239 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
20240 + raw_put_cpu_no_resched();
20241 + return;
20242 + }
20243 +#endif
20244 +
20245 native_write_cr3(native_read_cr3());
20246 }
20247
20248 static inline void __native_flush_tlb_global_irq_disabled(void)
20249 {
20250 - unsigned long cr4;
20251 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
20252 + u64 descriptor[2];
20253
20254 - cr4 = native_read_cr4();
20255 - /* clear PGE */
20256 - native_write_cr4(cr4 & ~X86_CR4_PGE);
20257 - /* write old PGE again and flush TLBs */
20258 - native_write_cr4(cr4);
20259 + descriptor[0] = PCID_KERNEL;
20260 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
20261 + } else {
20262 + unsigned long cr4;
20263 +
20264 + cr4 = native_read_cr4();
20265 + /* clear PGE */
20266 + native_write_cr4(cr4 & ~X86_CR4_PGE);
20267 + /* write old PGE again and flush TLBs */
20268 + native_write_cr4(cr4);
20269 + }
20270 }
20271
20272 static inline void __native_flush_tlb_global(void)
20273 @@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
20274
20275 static inline void __native_flush_tlb_single(unsigned long addr)
20276 {
20277 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
20278 + u64 descriptor[2];
20279 +
20280 + descriptor[0] = PCID_KERNEL;
20281 + descriptor[1] = addr;
20282 +
20283 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20284 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
20285 + if (addr < TASK_SIZE_MAX)
20286 + descriptor[1] += pax_user_shadow_base;
20287 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
20288 + }
20289 +
20290 + descriptor[0] = PCID_USER;
20291 + descriptor[1] = addr;
20292 +#endif
20293 +
20294 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
20295 + return;
20296 + }
20297 +
20298 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20299 + if (static_cpu_has(X86_FEATURE_PCID)) {
20300 + unsigned int cpu = raw_get_cpu();
20301 +
20302 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
20303 + asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
20304 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
20305 + raw_put_cpu_no_resched();
20306 +
20307 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
20308 + addr += pax_user_shadow_base;
20309 + }
20310 +#endif
20311 +
20312 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
20313 }
20314
20315 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
20316 index 0d592e0..526f797 100644
20317 --- a/arch/x86/include/asm/uaccess.h
20318 +++ b/arch/x86/include/asm/uaccess.h
20319 @@ -7,6 +7,7 @@
20320 #include <linux/compiler.h>
20321 #include <linux/thread_info.h>
20322 #include <linux/string.h>
20323 +#include <linux/spinlock.h>
20324 #include <asm/asm.h>
20325 #include <asm/page.h>
20326 #include <asm/smap.h>
20327 @@ -29,7 +30,12 @@
20328
20329 #define get_ds() (KERNEL_DS)
20330 #define get_fs() (current_thread_info()->addr_limit)
20331 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20332 +void __set_fs(mm_segment_t x);
20333 +void set_fs(mm_segment_t x);
20334 +#else
20335 #define set_fs(x) (current_thread_info()->addr_limit = (x))
20336 +#endif
20337
20338 #define segment_eq(a, b) ((a).seg == (b).seg)
20339
20340 @@ -85,8 +91,36 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
20341 * checks that the pointer is in the user space range - after calling
20342 * this function, memory access functions may still return -EFAULT.
20343 */
20344 -#define access_ok(type, addr, size) \
20345 - likely(!__range_not_ok(addr, size, user_addr_max()))
20346 +extern int _cond_resched(void);
20347 +#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
20348 +#define access_ok(type, addr, size) \
20349 +({ \
20350 + unsigned long __size = size; \
20351 + unsigned long __addr = (unsigned long)addr; \
20352 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
20353 + if (__ret_ao && __size) { \
20354 + unsigned long __addr_ao = __addr & PAGE_MASK; \
20355 + unsigned long __end_ao = __addr + __size - 1; \
20356 + if (unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
20357 + while (__addr_ao <= __end_ao) { \
20358 + char __c_ao; \
20359 + __addr_ao += PAGE_SIZE; \
20360 + if (__size > PAGE_SIZE) \
20361 + _cond_resched(); \
20362 + if (__get_user(__c_ao, (char __user *)__addr)) \
20363 + break; \
20364 + if (type != VERIFY_WRITE) { \
20365 + __addr = __addr_ao; \
20366 + continue; \
20367 + } \
20368 + if (__put_user(__c_ao, (char __user *)__addr)) \
20369 + break; \
20370 + __addr = __addr_ao; \
20371 + } \
20372 + } \
20373 + } \
20374 + __ret_ao; \
20375 +})
20376
20377 /*
20378 * The exception table consists of pairs of addresses relative to the
20379 @@ -176,10 +210,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
20380 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
20381 __chk_user_ptr(ptr); \
20382 might_fault(); \
20383 + pax_open_userland(); \
20384 asm volatile("call __get_user_%P3" \
20385 : "=a" (__ret_gu), "=r" (__val_gu) \
20386 : "0" (ptr), "i" (sizeof(*(ptr)))); \
20387 (x) = (__typeof__(*(ptr))) __val_gu; \
20388 + pax_close_userland(); \
20389 __ret_gu; \
20390 })
20391
20392 @@ -187,13 +223,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
20393 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
20394 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
20395
20396 -
20397 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20398 +#define __copyuser_seg "gs;"
20399 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
20400 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
20401 +#else
20402 +#define __copyuser_seg
20403 +#define __COPYUSER_SET_ES
20404 +#define __COPYUSER_RESTORE_ES
20405 +#endif
20406
20407 #ifdef CONFIG_X86_32
20408 #define __put_user_asm_u64(x, addr, err, errret) \
20409 asm volatile(ASM_STAC "\n" \
20410 - "1: movl %%eax,0(%2)\n" \
20411 - "2: movl %%edx,4(%2)\n" \
20412 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
20413 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
20414 "3: " ASM_CLAC "\n" \
20415 ".section .fixup,\"ax\"\n" \
20416 "4: movl %3,%0\n" \
20417 @@ -206,8 +250,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
20418
20419 #define __put_user_asm_ex_u64(x, addr) \
20420 asm volatile(ASM_STAC "\n" \
20421 - "1: movl %%eax,0(%1)\n" \
20422 - "2: movl %%edx,4(%1)\n" \
20423 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
20424 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
20425 "3: " ASM_CLAC "\n" \
20426 _ASM_EXTABLE_EX(1b, 2b) \
20427 _ASM_EXTABLE_EX(2b, 3b) \
20428 @@ -257,7 +301,8 @@ extern void __put_user_8(void);
20429 __typeof__(*(ptr)) __pu_val; \
20430 __chk_user_ptr(ptr); \
20431 might_fault(); \
20432 - __pu_val = x; \
20433 + __pu_val = (x); \
20434 + pax_open_userland(); \
20435 switch (sizeof(*(ptr))) { \
20436 case 1: \
20437 __put_user_x(1, __pu_val, ptr, __ret_pu); \
20438 @@ -275,6 +320,7 @@ extern void __put_user_8(void);
20439 __put_user_x(X, __pu_val, ptr, __ret_pu); \
20440 break; \
20441 } \
20442 + pax_close_userland(); \
20443 __ret_pu; \
20444 })
20445
20446 @@ -355,8 +401,10 @@ do { \
20447 } while (0)
20448
20449 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
20450 +do { \
20451 + pax_open_userland(); \
20452 asm volatile(ASM_STAC "\n" \
20453 - "1: mov"itype" %2,%"rtype"1\n" \
20454 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
20455 "2: " ASM_CLAC "\n" \
20456 ".section .fixup,\"ax\"\n" \
20457 "3: mov %3,%0\n" \
20458 @@ -364,8 +412,10 @@ do { \
20459 " jmp 2b\n" \
20460 ".previous\n" \
20461 _ASM_EXTABLE(1b, 3b) \
20462 - : "=r" (err), ltype(x) \
20463 - : "m" (__m(addr)), "i" (errret), "0" (err))
20464 + : "=r" (err), ltype (x) \
20465 + : "m" (__m(addr)), "i" (errret), "0" (err)); \
20466 + pax_close_userland(); \
20467 +} while (0)
20468
20469 #define __get_user_size_ex(x, ptr, size) \
20470 do { \
20471 @@ -389,7 +439,7 @@ do { \
20472 } while (0)
20473
20474 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
20475 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
20476 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
20477 "2:\n" \
20478 _ASM_EXTABLE_EX(1b, 2b) \
20479 : ltype(x) : "m" (__m(addr)))
20480 @@ -406,13 +456,24 @@ do { \
20481 int __gu_err; \
20482 unsigned long __gu_val; \
20483 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
20484 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
20485 + (x) = (__typeof__(*(ptr)))__gu_val; \
20486 __gu_err; \
20487 })
20488
20489 /* FIXME: this hack is definitely wrong -AK */
20490 struct __large_struct { unsigned long buf[100]; };
20491 -#define __m(x) (*(struct __large_struct __user *)(x))
20492 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20493 +#define ____m(x) \
20494 +({ \
20495 + unsigned long ____x = (unsigned long)(x); \
20496 + if (____x < pax_user_shadow_base) \
20497 + ____x += pax_user_shadow_base; \
20498 + (typeof(x))____x; \
20499 +})
20500 +#else
20501 +#define ____m(x) (x)
20502 +#endif
20503 +#define __m(x) (*(struct __large_struct __user *)____m(x))
20504
20505 /*
20506 * Tell gcc we read from memory instead of writing: this is because
20507 @@ -420,8 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
20508 * aliasing issues.
20509 */
20510 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
20511 +do { \
20512 + pax_open_userland(); \
20513 asm volatile(ASM_STAC "\n" \
20514 - "1: mov"itype" %"rtype"1,%2\n" \
20515 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
20516 "2: " ASM_CLAC "\n" \
20517 ".section .fixup,\"ax\"\n" \
20518 "3: mov %3,%0\n" \
20519 @@ -429,10 +492,12 @@ struct __large_struct { unsigned long buf[100]; };
20520 ".previous\n" \
20521 _ASM_EXTABLE(1b, 3b) \
20522 : "=r"(err) \
20523 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
20524 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
20525 + pax_close_userland(); \
20526 +} while (0)
20527
20528 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
20529 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
20530 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
20531 "2:\n" \
20532 _ASM_EXTABLE_EX(1b, 2b) \
20533 : : ltype(x), "m" (__m(addr)))
20534 @@ -442,11 +507,13 @@ struct __large_struct { unsigned long buf[100]; };
20535 */
20536 #define uaccess_try do { \
20537 current_thread_info()->uaccess_err = 0; \
20538 + pax_open_userland(); \
20539 stac(); \
20540 barrier();
20541
20542 #define uaccess_catch(err) \
20543 clac(); \
20544 + pax_close_userland(); \
20545 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
20546 } while (0)
20547
20548 @@ -471,8 +538,12 @@ struct __large_struct { unsigned long buf[100]; };
20549 * On error, the variable @x is set to zero.
20550 */
20551
20552 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20553 +#define __get_user(x, ptr) get_user((x), (ptr))
20554 +#else
20555 #define __get_user(x, ptr) \
20556 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
20557 +#endif
20558
20559 /**
20560 * __put_user: - Write a simple value into user space, with less checking.
20561 @@ -494,8 +565,12 @@ struct __large_struct { unsigned long buf[100]; };
20562 * Returns zero on success, or -EFAULT on error.
20563 */
20564
20565 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20566 +#define __put_user(x, ptr) put_user((x), (ptr))
20567 +#else
20568 #define __put_user(x, ptr) \
20569 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
20570 +#endif
20571
20572 #define __get_user_unaligned __get_user
20573 #define __put_user_unaligned __put_user
20574 @@ -513,7 +588,7 @@ struct __large_struct { unsigned long buf[100]; };
20575 #define get_user_ex(x, ptr) do { \
20576 unsigned long __gue_val; \
20577 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
20578 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
20579 + (x) = (__typeof__(*(ptr)))__gue_val; \
20580 } while (0)
20581
20582 #define put_user_try uaccess_try
20583 @@ -542,18 +617,19 @@ extern void __cmpxchg_wrong_size(void)
20584 __typeof__(ptr) __uval = (uval); \
20585 __typeof__(*(ptr)) __old = (old); \
20586 __typeof__(*(ptr)) __new = (new); \
20587 + pax_open_userland(); \
20588 switch (size) { \
20589 case 1: \
20590 { \
20591 asm volatile("\t" ASM_STAC "\n" \
20592 - "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
20593 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
20594 "2:\t" ASM_CLAC "\n" \
20595 "\t.section .fixup, \"ax\"\n" \
20596 "3:\tmov %3, %0\n" \
20597 "\tjmp 2b\n" \
20598 "\t.previous\n" \
20599 _ASM_EXTABLE(1b, 3b) \
20600 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20601 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20602 : "i" (-EFAULT), "q" (__new), "1" (__old) \
20603 : "memory" \
20604 ); \
20605 @@ -562,14 +638,14 @@ extern void __cmpxchg_wrong_size(void)
20606 case 2: \
20607 { \
20608 asm volatile("\t" ASM_STAC "\n" \
20609 - "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
20610 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
20611 "2:\t" ASM_CLAC "\n" \
20612 "\t.section .fixup, \"ax\"\n" \
20613 "3:\tmov %3, %0\n" \
20614 "\tjmp 2b\n" \
20615 "\t.previous\n" \
20616 _ASM_EXTABLE(1b, 3b) \
20617 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20618 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20619 : "i" (-EFAULT), "r" (__new), "1" (__old) \
20620 : "memory" \
20621 ); \
20622 @@ -578,14 +654,14 @@ extern void __cmpxchg_wrong_size(void)
20623 case 4: \
20624 { \
20625 asm volatile("\t" ASM_STAC "\n" \
20626 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
20627 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
20628 "2:\t" ASM_CLAC "\n" \
20629 "\t.section .fixup, \"ax\"\n" \
20630 "3:\tmov %3, %0\n" \
20631 "\tjmp 2b\n" \
20632 "\t.previous\n" \
20633 _ASM_EXTABLE(1b, 3b) \
20634 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20635 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20636 : "i" (-EFAULT), "r" (__new), "1" (__old) \
20637 : "memory" \
20638 ); \
20639 @@ -597,14 +673,14 @@ extern void __cmpxchg_wrong_size(void)
20640 __cmpxchg_wrong_size(); \
20641 \
20642 asm volatile("\t" ASM_STAC "\n" \
20643 - "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
20644 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
20645 "2:\t" ASM_CLAC "\n" \
20646 "\t.section .fixup, \"ax\"\n" \
20647 "3:\tmov %3, %0\n" \
20648 "\tjmp 2b\n" \
20649 "\t.previous\n" \
20650 _ASM_EXTABLE(1b, 3b) \
20651 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20652 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20653 : "i" (-EFAULT), "r" (__new), "1" (__old) \
20654 : "memory" \
20655 ); \
20656 @@ -613,6 +689,7 @@ extern void __cmpxchg_wrong_size(void)
20657 default: \
20658 __cmpxchg_wrong_size(); \
20659 } \
20660 + pax_close_userland(); \
20661 *__uval = __old; \
20662 __ret; \
20663 })
20664 @@ -636,17 +713,6 @@ extern struct movsl_mask {
20665
20666 #define ARCH_HAS_NOCACHE_UACCESS 1
20667
20668 -#ifdef CONFIG_X86_32
20669 -# include <asm/uaccess_32.h>
20670 -#else
20671 -# include <asm/uaccess_64.h>
20672 -#endif
20673 -
20674 -unsigned long __must_check _copy_from_user(void *to, const void __user *from,
20675 - unsigned n);
20676 -unsigned long __must_check _copy_to_user(void __user *to, const void *from,
20677 - unsigned n);
20678 -
20679 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
20680 # define copy_user_diag __compiletime_error
20681 #else
20682 @@ -656,7 +722,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
20683 extern void copy_user_diag("copy_from_user() buffer size is too small")
20684 copy_from_user_overflow(void);
20685 extern void copy_user_diag("copy_to_user() buffer size is too small")
20686 -copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
20687 +copy_to_user_overflow(void);
20688
20689 #undef copy_user_diag
20690
20691 @@ -669,7 +735,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
20692
20693 extern void
20694 __compiletime_warning("copy_to_user() buffer size is not provably correct")
20695 -__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
20696 +__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
20697 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
20698
20699 #else
20700 @@ -684,10 +750,16 @@ __copy_from_user_overflow(int size, unsigned long count)
20701
20702 #endif
20703
20704 +#ifdef CONFIG_X86_32
20705 +# include <asm/uaccess_32.h>
20706 +#else
20707 +# include <asm/uaccess_64.h>
20708 +#endif
20709 +
20710 static inline unsigned long __must_check
20711 copy_from_user(void *to, const void __user *from, unsigned long n)
20712 {
20713 - int sz = __compiletime_object_size(to);
20714 + size_t sz = __compiletime_object_size(to);
20715
20716 might_fault();
20717
20718 @@ -709,12 +781,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20719 * case, and do only runtime checking for non-constant sizes.
20720 */
20721
20722 - if (likely(sz < 0 || sz >= n))
20723 - n = _copy_from_user(to, from, n);
20724 - else if(__builtin_constant_p(n))
20725 - copy_from_user_overflow();
20726 - else
20727 - __copy_from_user_overflow(sz, n);
20728 + if (likely(sz != (size_t)-1 && sz < n)) {
20729 + if(__builtin_constant_p(n))
20730 + copy_from_user_overflow();
20731 + else
20732 + __copy_from_user_overflow(sz, n);
20733 + } else if (access_ok(VERIFY_READ, from, n))
20734 + n = __copy_from_user(to, from, n);
20735 + else if ((long)n > 0)
20736 + memset(to, 0, n);
20737
20738 return n;
20739 }
20740 @@ -722,17 +797,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20741 static inline unsigned long __must_check
20742 copy_to_user(void __user *to, const void *from, unsigned long n)
20743 {
20744 - int sz = __compiletime_object_size(from);
20745 + size_t sz = __compiletime_object_size(from);
20746
20747 might_fault();
20748
20749 /* See the comment in copy_from_user() above. */
20750 - if (likely(sz < 0 || sz >= n))
20751 - n = _copy_to_user(to, from, n);
20752 - else if(__builtin_constant_p(n))
20753 - copy_to_user_overflow();
20754 - else
20755 - __copy_to_user_overflow(sz, n);
20756 + if (likely(sz != (size_t)-1 && sz < n)) {
20757 + if(__builtin_constant_p(n))
20758 + copy_to_user_overflow();
20759 + else
20760 + __copy_to_user_overflow(sz, n);
20761 + } else if (access_ok(VERIFY_WRITE, to, n))
20762 + n = __copy_to_user(to, from, n);
20763
20764 return n;
20765 }
20766 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
20767 index 3c03a5d..1071638 100644
20768 --- a/arch/x86/include/asm/uaccess_32.h
20769 +++ b/arch/x86/include/asm/uaccess_32.h
20770 @@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
20771 static __always_inline unsigned long __must_check
20772 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
20773 {
20774 + if ((long)n < 0)
20775 + return n;
20776 +
20777 + check_object_size(from, n, true);
20778 +
20779 if (__builtin_constant_p(n)) {
20780 unsigned long ret;
20781
20782 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
20783 __copy_to_user(void __user *to, const void *from, unsigned long n)
20784 {
20785 might_fault();
20786 +
20787 return __copy_to_user_inatomic(to, from, n);
20788 }
20789
20790 static __always_inline unsigned long
20791 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
20792 {
20793 + if ((long)n < 0)
20794 + return n;
20795 +
20796 /* Avoid zeroing the tail if the copy fails..
20797 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
20798 * but as the zeroing behaviour is only significant when n is not
20799 @@ -137,6 +146,12 @@ static __always_inline unsigned long
20800 __copy_from_user(void *to, const void __user *from, unsigned long n)
20801 {
20802 might_fault();
20803 +
20804 + if ((long)n < 0)
20805 + return n;
20806 +
20807 + check_object_size(to, n, false);
20808 +
20809 if (__builtin_constant_p(n)) {
20810 unsigned long ret;
20811
20812 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
20813 const void __user *from, unsigned long n)
20814 {
20815 might_fault();
20816 +
20817 + if ((long)n < 0)
20818 + return n;
20819 +
20820 if (__builtin_constant_p(n)) {
20821 unsigned long ret;
20822
20823 @@ -181,7 +200,10 @@ static __always_inline unsigned long
20824 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
20825 unsigned long n)
20826 {
20827 - return __copy_from_user_ll_nocache_nozero(to, from, n);
20828 + if ((long)n < 0)
20829 + return n;
20830 +
20831 + return __copy_from_user_ll_nocache_nozero(to, from, n);
20832 }
20833
20834 #endif /* _ASM_X86_UACCESS_32_H */
20835 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
20836 index 12a26b9..206c200 100644
20837 --- a/arch/x86/include/asm/uaccess_64.h
20838 +++ b/arch/x86/include/asm/uaccess_64.h
20839 @@ -10,6 +10,9 @@
20840 #include <asm/alternative.h>
20841 #include <asm/cpufeature.h>
20842 #include <asm/page.h>
20843 +#include <asm/pgtable.h>
20844 +
20845 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
20846
20847 /*
20848 * Copy To/From Userspace
20849 @@ -17,14 +20,14 @@
20850
20851 /* Handles exceptions in both to and from, but doesn't do access_ok */
20852 __must_check unsigned long
20853 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
20854 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
20855 __must_check unsigned long
20856 -copy_user_generic_string(void *to, const void *from, unsigned len);
20857 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
20858 __must_check unsigned long
20859 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
20860 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
20861
20862 static __always_inline __must_check unsigned long
20863 -copy_user_generic(void *to, const void *from, unsigned len)
20864 +copy_user_generic(void *to, const void *from, unsigned long len)
20865 {
20866 unsigned ret;
20867
20868 @@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
20869 }
20870
20871 __must_check unsigned long
20872 -copy_in_user(void __user *to, const void __user *from, unsigned len);
20873 +copy_in_user(void __user *to, const void __user *from, unsigned long len);
20874
20875 static __always_inline __must_check
20876 -int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
20877 +unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
20878 {
20879 - int ret = 0;
20880 + size_t sz = __compiletime_object_size(dst);
20881 + unsigned ret = 0;
20882 +
20883 + if (size > INT_MAX)
20884 + return size;
20885 +
20886 + check_object_size(dst, size, false);
20887 +
20888 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20889 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20890 + return size;
20891 +#endif
20892 +
20893 + if (unlikely(sz != (size_t)-1 && sz < size)) {
20894 + if(__builtin_constant_p(size))
20895 + copy_from_user_overflow();
20896 + else
20897 + __copy_from_user_overflow(sz, size);
20898 + return size;
20899 + }
20900
20901 if (!__builtin_constant_p(size))
20902 - return copy_user_generic(dst, (__force void *)src, size);
20903 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20904 switch (size) {
20905 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
20906 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
20907 ret, "b", "b", "=q", 1);
20908 return ret;
20909 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
20910 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
20911 ret, "w", "w", "=r", 2);
20912 return ret;
20913 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
20914 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
20915 ret, "l", "k", "=r", 4);
20916 return ret;
20917 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
20918 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20919 ret, "q", "", "=r", 8);
20920 return ret;
20921 case 10:
20922 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20923 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20924 ret, "q", "", "=r", 10);
20925 if (unlikely(ret))
20926 return ret;
20927 __get_user_asm(*(u16 *)(8 + (char *)dst),
20928 - (u16 __user *)(8 + (char __user *)src),
20929 + (const u16 __user *)(8 + (const char __user *)src),
20930 ret, "w", "w", "=r", 2);
20931 return ret;
20932 case 16:
20933 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20934 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20935 ret, "q", "", "=r", 16);
20936 if (unlikely(ret))
20937 return ret;
20938 __get_user_asm(*(u64 *)(8 + (char *)dst),
20939 - (u64 __user *)(8 + (char __user *)src),
20940 + (const u64 __user *)(8 + (const char __user *)src),
20941 ret, "q", "", "=r", 8);
20942 return ret;
20943 default:
20944 - return copy_user_generic(dst, (__force void *)src, size);
20945 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20946 }
20947 }
20948
20949 static __always_inline __must_check
20950 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
20951 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
20952 {
20953 might_fault();
20954 return __copy_from_user_nocheck(dst, src, size);
20955 }
20956
20957 static __always_inline __must_check
20958 -int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
20959 +unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
20960 {
20961 - int ret = 0;
20962 + size_t sz = __compiletime_object_size(src);
20963 + unsigned ret = 0;
20964 +
20965 + if (size > INT_MAX)
20966 + return size;
20967 +
20968 + check_object_size(src, size, true);
20969 +
20970 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20971 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20972 + return size;
20973 +#endif
20974 +
20975 + if (unlikely(sz != (size_t)-1 && sz < size)) {
20976 + if(__builtin_constant_p(size))
20977 + copy_to_user_overflow();
20978 + else
20979 + __copy_to_user_overflow(sz, size);
20980 + return size;
20981 + }
20982
20983 if (!__builtin_constant_p(size))
20984 - return copy_user_generic((__force void *)dst, src, size);
20985 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20986 switch (size) {
20987 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
20988 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
20989 ret, "b", "b", "iq", 1);
20990 return ret;
20991 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
20992 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
20993 ret, "w", "w", "ir", 2);
20994 return ret;
20995 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
20996 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
20997 ret, "l", "k", "ir", 4);
20998 return ret;
20999 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
21000 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
21001 ret, "q", "", "er", 8);
21002 return ret;
21003 case 10:
21004 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
21005 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
21006 ret, "q", "", "er", 10);
21007 if (unlikely(ret))
21008 return ret;
21009 asm("":::"memory");
21010 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
21011 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
21012 ret, "w", "w", "ir", 2);
21013 return ret;
21014 case 16:
21015 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
21016 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
21017 ret, "q", "", "er", 16);
21018 if (unlikely(ret))
21019 return ret;
21020 asm("":::"memory");
21021 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
21022 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
21023 ret, "q", "", "er", 8);
21024 return ret;
21025 default:
21026 - return copy_user_generic((__force void *)dst, src, size);
21027 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
21028 }
21029 }
21030
21031 static __always_inline __must_check
21032 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
21033 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
21034 {
21035 might_fault();
21036 return __copy_to_user_nocheck(dst, src, size);
21037 }
21038
21039 static __always_inline __must_check
21040 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
21041 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
21042 {
21043 - int ret = 0;
21044 + unsigned ret = 0;
21045
21046 might_fault();
21047 +
21048 + if (size > INT_MAX)
21049 + return size;
21050 +
21051 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21052 + if (!access_ok_noprefault(VERIFY_READ, src, size))
21053 + return size;
21054 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
21055 + return size;
21056 +#endif
21057 +
21058 if (!__builtin_constant_p(size))
21059 - return copy_user_generic((__force void *)dst,
21060 - (__force void *)src, size);
21061 + return copy_user_generic((__force_kernel void *)____m(dst),
21062 + (__force_kernel const void *)____m(src), size);
21063 switch (size) {
21064 case 1: {
21065 u8 tmp;
21066 - __get_user_asm(tmp, (u8 __user *)src,
21067 + __get_user_asm(tmp, (const u8 __user *)src,
21068 ret, "b", "b", "=q", 1);
21069 if (likely(!ret))
21070 __put_user_asm(tmp, (u8 __user *)dst,
21071 @@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
21072 }
21073 case 2: {
21074 u16 tmp;
21075 - __get_user_asm(tmp, (u16 __user *)src,
21076 + __get_user_asm(tmp, (const u16 __user *)src,
21077 ret, "w", "w", "=r", 2);
21078 if (likely(!ret))
21079 __put_user_asm(tmp, (u16 __user *)dst,
21080 @@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
21081
21082 case 4: {
21083 u32 tmp;
21084 - __get_user_asm(tmp, (u32 __user *)src,
21085 + __get_user_asm(tmp, (const u32 __user *)src,
21086 ret, "l", "k", "=r", 4);
21087 if (likely(!ret))
21088 __put_user_asm(tmp, (u32 __user *)dst,
21089 @@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
21090 }
21091 case 8: {
21092 u64 tmp;
21093 - __get_user_asm(tmp, (u64 __user *)src,
21094 + __get_user_asm(tmp, (const u64 __user *)src,
21095 ret, "q", "", "=r", 8);
21096 if (likely(!ret))
21097 __put_user_asm(tmp, (u64 __user *)dst,
21098 @@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
21099 return ret;
21100 }
21101 default:
21102 - return copy_user_generic((__force void *)dst,
21103 - (__force void *)src, size);
21104 + return copy_user_generic((__force_kernel void *)____m(dst),
21105 + (__force_kernel const void *)____m(src), size);
21106 }
21107 }
21108
21109 -static __must_check __always_inline int
21110 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
21111 +static __must_check __always_inline unsigned long
21112 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
21113 {
21114 return __copy_from_user_nocheck(dst, src, size);
21115 }
21116
21117 -static __must_check __always_inline int
21118 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
21119 +static __must_check __always_inline unsigned long
21120 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
21121 {
21122 return __copy_to_user_nocheck(dst, src, size);
21123 }
21124
21125 -extern long __copy_user_nocache(void *dst, const void __user *src,
21126 - unsigned size, int zerorest);
21127 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
21128 + unsigned long size, int zerorest);
21129
21130 -static inline int
21131 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
21132 +static inline unsigned long
21133 +__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
21134 {
21135 might_fault();
21136 +
21137 + if (size > INT_MAX)
21138 + return size;
21139 +
21140 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21141 + if (!access_ok_noprefault(VERIFY_READ, src, size))
21142 + return size;
21143 +#endif
21144 +
21145 return __copy_user_nocache(dst, src, size, 1);
21146 }
21147
21148 -static inline int
21149 +static inline unsigned long
21150 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
21151 - unsigned size)
21152 + unsigned long size)
21153 {
21154 + if (size > INT_MAX)
21155 + return size;
21156 +
21157 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21158 + if (!access_ok_noprefault(VERIFY_READ, src, size))
21159 + return size;
21160 +#endif
21161 +
21162 return __copy_user_nocache(dst, src, size, 0);
21163 }
21164
21165 unsigned long
21166 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
21167 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
21168
21169 #endif /* _ASM_X86_UACCESS_64_H */
21170 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
21171 index 5b238981..77fdd78 100644
21172 --- a/arch/x86/include/asm/word-at-a-time.h
21173 +++ b/arch/x86/include/asm/word-at-a-time.h
21174 @@ -11,7 +11,7 @@
21175 * and shift, for example.
21176 */
21177 struct word_at_a_time {
21178 - const unsigned long one_bits, high_bits;
21179 + unsigned long one_bits, high_bits;
21180 };
21181
21182 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
21183 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
21184 index e45e4da..44e8572 100644
21185 --- a/arch/x86/include/asm/x86_init.h
21186 +++ b/arch/x86/include/asm/x86_init.h
21187 @@ -129,7 +129,7 @@ struct x86_init_ops {
21188 struct x86_init_timers timers;
21189 struct x86_init_iommu iommu;
21190 struct x86_init_pci pci;
21191 -};
21192 +} __no_const;
21193
21194 /**
21195 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
21196 @@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
21197 void (*setup_percpu_clockev)(void);
21198 void (*early_percpu_clock_init)(void);
21199 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
21200 -};
21201 +} __no_const;
21202
21203 struct timespec;
21204
21205 @@ -168,7 +168,7 @@ struct x86_platform_ops {
21206 void (*save_sched_clock_state)(void);
21207 void (*restore_sched_clock_state)(void);
21208 void (*apic_post_init)(void);
21209 -};
21210 +} __no_const;
21211
21212 struct pci_dev;
21213 struct msi_msg;
21214 @@ -185,7 +185,7 @@ struct x86_msi_ops {
21215 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
21216 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
21217 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
21218 -};
21219 +} __no_const;
21220
21221 struct IO_APIC_route_entry;
21222 struct io_apic_irq_attr;
21223 @@ -206,7 +206,7 @@ struct x86_io_apic_ops {
21224 unsigned int destination, int vector,
21225 struct io_apic_irq_attr *attr);
21226 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
21227 -};
21228 +} __no_const;
21229
21230 extern struct x86_init_ops x86_init;
21231 extern struct x86_cpuinit_ops x86_cpuinit;
21232 diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
21233 index c949923..c22bfa4 100644
21234 --- a/arch/x86/include/asm/xen/page.h
21235 +++ b/arch/x86/include/asm/xen/page.h
21236 @@ -63,7 +63,7 @@ extern int m2p_remove_override(struct page *page,
21237 extern struct page *m2p_find_override(unsigned long mfn);
21238 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
21239
21240 -static inline unsigned long pfn_to_mfn(unsigned long pfn)
21241 +static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
21242 {
21243 unsigned long mfn;
21244
21245 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
21246 index 7e7a79a..0824666 100644
21247 --- a/arch/x86/include/asm/xsave.h
21248 +++ b/arch/x86/include/asm/xsave.h
21249 @@ -228,12 +228,16 @@ static inline int xsave_user(struct xsave_struct __user *buf)
21250 if (unlikely(err))
21251 return -EFAULT;
21252
21253 + pax_open_userland();
21254 __asm__ __volatile__(ASM_STAC "\n"
21255 - "1:"XSAVE"\n"
21256 + "1:"
21257 + __copyuser_seg
21258 + XSAVE"\n"
21259 "2: " ASM_CLAC "\n"
21260 xstate_fault
21261 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
21262 : "memory");
21263 + pax_close_userland();
21264 return err;
21265 }
21266
21267 @@ -243,16 +247,20 @@ static inline int xsave_user(struct xsave_struct __user *buf)
21268 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
21269 {
21270 int err = 0;
21271 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
21272 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
21273 u32 lmask = mask;
21274 u32 hmask = mask >> 32;
21275
21276 + pax_open_userland();
21277 __asm__ __volatile__(ASM_STAC "\n"
21278 - "1:"XRSTOR"\n"
21279 + "1:"
21280 + __copyuser_seg
21281 + XRSTOR"\n"
21282 "2: " ASM_CLAC "\n"
21283 xstate_fault
21284 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
21285 : "memory"); /* memory required? */
21286 + pax_close_userland();
21287 return err;
21288 }
21289
21290 diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
21291 index bbae024..e1528f9 100644
21292 --- a/arch/x86/include/uapi/asm/e820.h
21293 +++ b/arch/x86/include/uapi/asm/e820.h
21294 @@ -63,7 +63,7 @@ struct e820map {
21295 #define ISA_START_ADDRESS 0xa0000
21296 #define ISA_END_ADDRESS 0x100000
21297
21298 -#define BIOS_BEGIN 0x000a0000
21299 +#define BIOS_BEGIN 0x000c0000
21300 #define BIOS_END 0x00100000
21301
21302 #define BIOS_ROM_BASE 0xffe00000
21303 diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
21304 index 7b0a55a..ad115bf 100644
21305 --- a/arch/x86/include/uapi/asm/ptrace-abi.h
21306 +++ b/arch/x86/include/uapi/asm/ptrace-abi.h
21307 @@ -49,7 +49,6 @@
21308 #define EFLAGS 144
21309 #define RSP 152
21310 #define SS 160
21311 -#define ARGOFFSET R11
21312 #endif /* __ASSEMBLY__ */
21313
21314 /* top of stack page */
21315 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
21316 index ada2e2d..ca69e16 100644
21317 --- a/arch/x86/kernel/Makefile
21318 +++ b/arch/x86/kernel/Makefile
21319 @@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
21320 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
21321 obj-$(CONFIG_IRQ_WORK) += irq_work.o
21322 obj-y += probe_roms.o
21323 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
21324 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
21325 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
21326 obj-$(CONFIG_X86_64) += mcount_64.o
21327 obj-y += syscall_$(BITS).o vsyscall_gtod.o
21328 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
21329 index a142e77..6222cdd 100644
21330 --- a/arch/x86/kernel/acpi/boot.c
21331 +++ b/arch/x86/kernel/acpi/boot.c
21332 @@ -1276,7 +1276,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
21333 * If your system is blacklisted here, but you find that acpi=force
21334 * works for you, please contact linux-acpi@vger.kernel.org
21335 */
21336 -static struct dmi_system_id __initdata acpi_dmi_table[] = {
21337 +static const struct dmi_system_id __initconst acpi_dmi_table[] = {
21338 /*
21339 * Boxes that need ACPI disabled
21340 */
21341 @@ -1351,7 +1351,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
21342 };
21343
21344 /* second table for DMI checks that should run after early-quirks */
21345 -static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
21346 +static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
21347 /*
21348 * HP laptops which use a DSDT reporting as HP/SB400/10000,
21349 * which includes some code which overrides all temperature
21350 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
21351 index 3136820..e2c6577 100644
21352 --- a/arch/x86/kernel/acpi/sleep.c
21353 +++ b/arch/x86/kernel/acpi/sleep.c
21354 @@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
21355 #else /* CONFIG_64BIT */
21356 #ifdef CONFIG_SMP
21357 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
21358 +
21359 + pax_open_kernel();
21360 early_gdt_descr.address =
21361 (unsigned long)get_cpu_gdt_table(smp_processor_id());
21362 + pax_close_kernel();
21363 +
21364 initial_gs = per_cpu_offset(smp_processor_id());
21365 #endif
21366 initial_code = (unsigned long)wakeup_long64;
21367 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
21368 index 665c6b7..eae4d56 100644
21369 --- a/arch/x86/kernel/acpi/wakeup_32.S
21370 +++ b/arch/x86/kernel/acpi/wakeup_32.S
21371 @@ -29,13 +29,11 @@ wakeup_pmode_return:
21372 # and restore the stack ... but you need gdt for this to work
21373 movl saved_context_esp, %esp
21374
21375 - movl %cs:saved_magic, %eax
21376 - cmpl $0x12345678, %eax
21377 + cmpl $0x12345678, saved_magic
21378 jne bogus_magic
21379
21380 # jump to place where we left off
21381 - movl saved_eip, %eax
21382 - jmp *%eax
21383 + jmp *(saved_eip)
21384
21385 bogus_magic:
21386 jmp bogus_magic
21387 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
21388 index 703130f..27a155d 100644
21389 --- a/arch/x86/kernel/alternative.c
21390 +++ b/arch/x86/kernel/alternative.c
21391 @@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
21392 */
21393 for (a = start; a < end; a++) {
21394 instr = (u8 *)&a->instr_offset + a->instr_offset;
21395 +
21396 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21397 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
21398 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
21399 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
21400 +#endif
21401 +
21402 replacement = (u8 *)&a->repl_offset + a->repl_offset;
21403 BUG_ON(a->replacementlen > a->instrlen);
21404 BUG_ON(a->instrlen > sizeof(insnbuf));
21405 @@ -284,6 +291,11 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
21406 add_nops(insnbuf + a->replacementlen,
21407 a->instrlen - a->replacementlen);
21408
21409 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21410 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
21411 + instr = ktva_ktla(instr);
21412 +#endif
21413 +
21414 text_poke_early(instr, insnbuf, a->instrlen);
21415 }
21416 }
21417 @@ -299,10 +311,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
21418 for (poff = start; poff < end; poff++) {
21419 u8 *ptr = (u8 *)poff + *poff;
21420
21421 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21422 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
21423 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
21424 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
21425 +#endif
21426 +
21427 if (!*poff || ptr < text || ptr >= text_end)
21428 continue;
21429 /* turn DS segment override prefix into lock prefix */
21430 - if (*ptr == 0x3e)
21431 + if (*ktla_ktva(ptr) == 0x3e)
21432 text_poke(ptr, ((unsigned char []){0xf0}), 1);
21433 }
21434 mutex_unlock(&text_mutex);
21435 @@ -317,10 +335,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
21436 for (poff = start; poff < end; poff++) {
21437 u8 *ptr = (u8 *)poff + *poff;
21438
21439 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21440 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
21441 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
21442 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
21443 +#endif
21444 +
21445 if (!*poff || ptr < text || ptr >= text_end)
21446 continue;
21447 /* turn lock prefix into DS segment override prefix */
21448 - if (*ptr == 0xf0)
21449 + if (*ktla_ktva(ptr) == 0xf0)
21450 text_poke(ptr, ((unsigned char []){0x3E}), 1);
21451 }
21452 mutex_unlock(&text_mutex);
21453 @@ -457,7 +481,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
21454
21455 BUG_ON(p->len > MAX_PATCH_LEN);
21456 /* prep the buffer with the original instructions */
21457 - memcpy(insnbuf, p->instr, p->len);
21458 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
21459 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
21460 (unsigned long)p->instr, p->len);
21461
21462 @@ -504,7 +528,7 @@ void __init alternative_instructions(void)
21463 if (!uniproc_patched || num_possible_cpus() == 1)
21464 free_init_pages("SMP alternatives",
21465 (unsigned long)__smp_locks,
21466 - (unsigned long)__smp_locks_end);
21467 + PAGE_ALIGN((unsigned long)__smp_locks_end));
21468 #endif
21469
21470 apply_paravirt(__parainstructions, __parainstructions_end);
21471 @@ -524,13 +548,17 @@ void __init alternative_instructions(void)
21472 * instructions. And on the local CPU you need to be protected again NMI or MCE
21473 * handlers seeing an inconsistent instruction while you patch.
21474 */
21475 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
21476 +void *__kprobes text_poke_early(void *addr, const void *opcode,
21477 size_t len)
21478 {
21479 unsigned long flags;
21480 local_irq_save(flags);
21481 - memcpy(addr, opcode, len);
21482 +
21483 + pax_open_kernel();
21484 + memcpy(ktla_ktva(addr), opcode, len);
21485 sync_core();
21486 + pax_close_kernel();
21487 +
21488 local_irq_restore(flags);
21489 /* Could also do a CLFLUSH here to speed up CPU recovery; but
21490 that causes hangs on some VIA CPUs. */
21491 @@ -552,36 +580,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
21492 */
21493 void *text_poke(void *addr, const void *opcode, size_t len)
21494 {
21495 - unsigned long flags;
21496 - char *vaddr;
21497 + unsigned char *vaddr = ktla_ktva(addr);
21498 struct page *pages[2];
21499 - int i;
21500 + size_t i;
21501
21502 if (!core_kernel_text((unsigned long)addr)) {
21503 - pages[0] = vmalloc_to_page(addr);
21504 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
21505 + pages[0] = vmalloc_to_page(vaddr);
21506 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
21507 } else {
21508 - pages[0] = virt_to_page(addr);
21509 + pages[0] = virt_to_page(vaddr);
21510 WARN_ON(!PageReserved(pages[0]));
21511 - pages[1] = virt_to_page(addr + PAGE_SIZE);
21512 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
21513 }
21514 BUG_ON(!pages[0]);
21515 - local_irq_save(flags);
21516 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
21517 - if (pages[1])
21518 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
21519 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
21520 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
21521 - clear_fixmap(FIX_TEXT_POKE0);
21522 - if (pages[1])
21523 - clear_fixmap(FIX_TEXT_POKE1);
21524 - local_flush_tlb();
21525 - sync_core();
21526 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
21527 - that causes hangs on some VIA CPUs. */
21528 + text_poke_early(addr, opcode, len);
21529 for (i = 0; i < len; i++)
21530 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
21531 - local_irq_restore(flags);
21532 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
21533 return addr;
21534 }
21535
21536 @@ -601,7 +615,7 @@ int poke_int3_handler(struct pt_regs *regs)
21537 if (likely(!bp_patching_in_progress))
21538 return 0;
21539
21540 - if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
21541 + if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
21542 return 0;
21543
21544 /* set up the specified breakpoint handler */
21545 @@ -635,7 +649,7 @@ int poke_int3_handler(struct pt_regs *regs)
21546 */
21547 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
21548 {
21549 - unsigned char int3 = 0xcc;
21550 + const unsigned char int3 = 0xcc;
21551
21552 bp_int3_handler = handler;
21553 bp_int3_addr = (u8 *)addr + sizeof(int3);
21554 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
21555 index 24b5894..6d9701b 100644
21556 --- a/arch/x86/kernel/apic/apic.c
21557 +++ b/arch/x86/kernel/apic/apic.c
21558 @@ -201,7 +201,7 @@ int first_system_vector = 0xfe;
21559 /*
21560 * Debug level, exported for io_apic.c
21561 */
21562 -unsigned int apic_verbosity;
21563 +int apic_verbosity;
21564
21565 int pic_mode;
21566
21567 @@ -1989,7 +1989,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
21568 apic_write(APIC_ESR, 0);
21569 v = apic_read(APIC_ESR);
21570 ack_APIC_irq();
21571 - atomic_inc(&irq_err_count);
21572 + atomic_inc_unchecked(&irq_err_count);
21573
21574 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
21575 smp_processor_id(), v);
21576 diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
21577 index de918c4..32eed23 100644
21578 --- a/arch/x86/kernel/apic/apic_flat_64.c
21579 +++ b/arch/x86/kernel/apic/apic_flat_64.c
21580 @@ -154,7 +154,7 @@ static int flat_probe(void)
21581 return 1;
21582 }
21583
21584 -static struct apic apic_flat = {
21585 +static struct apic apic_flat __read_only = {
21586 .name = "flat",
21587 .probe = flat_probe,
21588 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
21589 @@ -260,7 +260,7 @@ static int physflat_probe(void)
21590 return 0;
21591 }
21592
21593 -static struct apic apic_physflat = {
21594 +static struct apic apic_physflat __read_only = {
21595
21596 .name = "physical flat",
21597 .probe = physflat_probe,
21598 diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
21599 index b205cdb..d8503ff 100644
21600 --- a/arch/x86/kernel/apic/apic_noop.c
21601 +++ b/arch/x86/kernel/apic/apic_noop.c
21602 @@ -108,7 +108,7 @@ static void noop_apic_write(u32 reg, u32 v)
21603 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
21604 }
21605
21606 -struct apic apic_noop = {
21607 +struct apic apic_noop __read_only = {
21608 .name = "noop",
21609 .probe = noop_probe,
21610 .acpi_madt_oem_check = NULL,
21611 diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
21612 index c4a8d63..fe893ac 100644
21613 --- a/arch/x86/kernel/apic/bigsmp_32.c
21614 +++ b/arch/x86/kernel/apic/bigsmp_32.c
21615 @@ -147,7 +147,7 @@ static int probe_bigsmp(void)
21616 return dmi_bigsmp;
21617 }
21618
21619 -static struct apic apic_bigsmp = {
21620 +static struct apic apic_bigsmp __read_only = {
21621
21622 .name = "bigsmp",
21623 .probe = probe_bigsmp,
21624 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
21625 index 337ce5a..c8d98b4 100644
21626 --- a/arch/x86/kernel/apic/io_apic.c
21627 +++ b/arch/x86/kernel/apic/io_apic.c
21628 @@ -1230,7 +1230,7 @@ out:
21629 }
21630 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
21631
21632 -void lock_vector_lock(void)
21633 +void lock_vector_lock(void) __acquires(vector_lock)
21634 {
21635 /* Used to the online set of cpus does not change
21636 * during assign_irq_vector.
21637 @@ -1238,7 +1238,7 @@ void lock_vector_lock(void)
21638 raw_spin_lock(&vector_lock);
21639 }
21640
21641 -void unlock_vector_lock(void)
21642 +void unlock_vector_lock(void) __releases(vector_lock)
21643 {
21644 raw_spin_unlock(&vector_lock);
21645 }
21646 @@ -2465,7 +2465,7 @@ static void ack_apic_edge(struct irq_data *data)
21647 ack_APIC_irq();
21648 }
21649
21650 -atomic_t irq_mis_count;
21651 +atomic_unchecked_t irq_mis_count;
21652
21653 #ifdef CONFIG_GENERIC_PENDING_IRQ
21654 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
21655 @@ -2606,7 +2606,7 @@ static void ack_apic_level(struct irq_data *data)
21656 * at the cpu.
21657 */
21658 if (!(v & (1 << (i & 0x1f)))) {
21659 - atomic_inc(&irq_mis_count);
21660 + atomic_inc_unchecked(&irq_mis_count);
21661
21662 eoi_ioapic_irq(irq, cfg);
21663 }
21664 diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
21665 index bda4886..f9c7195 100644
21666 --- a/arch/x86/kernel/apic/probe_32.c
21667 +++ b/arch/x86/kernel/apic/probe_32.c
21668 @@ -72,7 +72,7 @@ static int probe_default(void)
21669 return 1;
21670 }
21671
21672 -static struct apic apic_default = {
21673 +static struct apic apic_default __read_only = {
21674
21675 .name = "default",
21676 .probe = probe_default,
21677 diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
21678 index 6ce600f..cb44af8 100644
21679 --- a/arch/x86/kernel/apic/x2apic_cluster.c
21680 +++ b/arch/x86/kernel/apic/x2apic_cluster.c
21681 @@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
21682 return notifier_from_errno(err);
21683 }
21684
21685 -static struct notifier_block __refdata x2apic_cpu_notifier = {
21686 +static struct notifier_block x2apic_cpu_notifier = {
21687 .notifier_call = update_clusterinfo,
21688 };
21689
21690 @@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
21691 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
21692 }
21693
21694 -static struct apic apic_x2apic_cluster = {
21695 +static struct apic apic_x2apic_cluster __read_only = {
21696
21697 .name = "cluster x2apic",
21698 .probe = x2apic_cluster_probe,
21699 diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
21700 index 6fae733..5ca17af 100644
21701 --- a/arch/x86/kernel/apic/x2apic_phys.c
21702 +++ b/arch/x86/kernel/apic/x2apic_phys.c
21703 @@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
21704 return apic == &apic_x2apic_phys;
21705 }
21706
21707 -static struct apic apic_x2apic_phys = {
21708 +static struct apic apic_x2apic_phys __read_only = {
21709
21710 .name = "physical x2apic",
21711 .probe = x2apic_phys_probe,
21712 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
21713 index 004f017..8fbc8b5 100644
21714 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
21715 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
21716 @@ -350,7 +350,7 @@ static int uv_probe(void)
21717 return apic == &apic_x2apic_uv_x;
21718 }
21719
21720 -static struct apic __refdata apic_x2apic_uv_x = {
21721 +static struct apic apic_x2apic_uv_x __read_only = {
21722
21723 .name = "UV large system",
21724 .probe = uv_probe,
21725 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
21726 index 5848744..56cb598 100644
21727 --- a/arch/x86/kernel/apm_32.c
21728 +++ b/arch/x86/kernel/apm_32.c
21729 @@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
21730 * This is for buggy BIOS's that refer to (real mode) segment 0x40
21731 * even though they are called in protected mode.
21732 */
21733 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
21734 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
21735 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
21736
21737 static const char driver_version[] = "1.16ac"; /* no spaces */
21738 @@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
21739 BUG_ON(cpu != 0);
21740 gdt = get_cpu_gdt_table(cpu);
21741 save_desc_40 = gdt[0x40 / 8];
21742 +
21743 + pax_open_kernel();
21744 gdt[0x40 / 8] = bad_bios_desc;
21745 + pax_close_kernel();
21746
21747 apm_irq_save(flags);
21748 APM_DO_SAVE_SEGS;
21749 @@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
21750 &call->esi);
21751 APM_DO_RESTORE_SEGS;
21752 apm_irq_restore(flags);
21753 +
21754 + pax_open_kernel();
21755 gdt[0x40 / 8] = save_desc_40;
21756 + pax_close_kernel();
21757 +
21758 put_cpu();
21759
21760 return call->eax & 0xff;
21761 @@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
21762 BUG_ON(cpu != 0);
21763 gdt = get_cpu_gdt_table(cpu);
21764 save_desc_40 = gdt[0x40 / 8];
21765 +
21766 + pax_open_kernel();
21767 gdt[0x40 / 8] = bad_bios_desc;
21768 + pax_close_kernel();
21769
21770 apm_irq_save(flags);
21771 APM_DO_SAVE_SEGS;
21772 @@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
21773 &call->eax);
21774 APM_DO_RESTORE_SEGS;
21775 apm_irq_restore(flags);
21776 +
21777 + pax_open_kernel();
21778 gdt[0x40 / 8] = save_desc_40;
21779 + pax_close_kernel();
21780 +
21781 put_cpu();
21782 return error;
21783 }
21784 @@ -2350,12 +2364,15 @@ static int __init apm_init(void)
21785 * code to that CPU.
21786 */
21787 gdt = get_cpu_gdt_table(0);
21788 +
21789 + pax_open_kernel();
21790 set_desc_base(&gdt[APM_CS >> 3],
21791 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
21792 set_desc_base(&gdt[APM_CS_16 >> 3],
21793 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
21794 set_desc_base(&gdt[APM_DS >> 3],
21795 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
21796 + pax_close_kernel();
21797
21798 proc_create("apm", 0, NULL, &apm_file_ops);
21799
21800 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
21801 index 9f6b934..cf5ffb3 100644
21802 --- a/arch/x86/kernel/asm-offsets.c
21803 +++ b/arch/x86/kernel/asm-offsets.c
21804 @@ -32,6 +32,8 @@ void common(void) {
21805 OFFSET(TI_flags, thread_info, flags);
21806 OFFSET(TI_status, thread_info, status);
21807 OFFSET(TI_addr_limit, thread_info, addr_limit);
21808 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
21809 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
21810
21811 BLANK();
21812 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
21813 @@ -52,8 +54,26 @@ void common(void) {
21814 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
21815 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
21816 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
21817 +
21818 +#ifdef CONFIG_PAX_KERNEXEC
21819 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
21820 #endif
21821
21822 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21823 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
21824 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
21825 +#ifdef CONFIG_X86_64
21826 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
21827 +#endif
21828 +#endif
21829 +
21830 +#endif
21831 +
21832 + BLANK();
21833 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
21834 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
21835 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
21836 +
21837 #ifdef CONFIG_XEN
21838 BLANK();
21839 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
21840 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
21841 index e7c798b..2b2019b 100644
21842 --- a/arch/x86/kernel/asm-offsets_64.c
21843 +++ b/arch/x86/kernel/asm-offsets_64.c
21844 @@ -77,6 +77,7 @@ int main(void)
21845 BLANK();
21846 #undef ENTRY
21847
21848 + DEFINE(TSS_size, sizeof(struct tss_struct));
21849 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
21850 BLANK();
21851
21852 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
21853 index 7fd54f0..0691410 100644
21854 --- a/arch/x86/kernel/cpu/Makefile
21855 +++ b/arch/x86/kernel/cpu/Makefile
21856 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
21857 CFLAGS_REMOVE_perf_event.o = -pg
21858 endif
21859
21860 -# Make sure load_percpu_segment has no stackprotector
21861 -nostackp := $(call cc-option, -fno-stack-protector)
21862 -CFLAGS_common.o := $(nostackp)
21863 -
21864 obj-y := intel_cacheinfo.o scattered.o topology.o
21865 obj-y += proc.o capflags.o powerflags.o common.o
21866 obj-y += rdrand.o
21867 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
21868 index 60e5497..8efbd2f 100644
21869 --- a/arch/x86/kernel/cpu/amd.c
21870 +++ b/arch/x86/kernel/cpu/amd.c
21871 @@ -711,7 +711,7 @@ static void init_amd(struct cpuinfo_x86 *c)
21872 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
21873 {
21874 /* AMD errata T13 (order #21922) */
21875 - if ((c->x86 == 6)) {
21876 + if (c->x86 == 6) {
21877 /* Duron Rev A0 */
21878 if (c->x86_model == 3 && c->x86_mask == 0)
21879 size = 64;
21880 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
21881 index 3126558..a1028f6 100644
21882 --- a/arch/x86/kernel/cpu/common.c
21883 +++ b/arch/x86/kernel/cpu/common.c
21884 @@ -90,60 +90,6 @@ static const struct cpu_dev default_cpu = {
21885
21886 static const struct cpu_dev *this_cpu = &default_cpu;
21887
21888 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
21889 -#ifdef CONFIG_X86_64
21890 - /*
21891 - * We need valid kernel segments for data and code in long mode too
21892 - * IRET will check the segment types kkeil 2000/10/28
21893 - * Also sysret mandates a special GDT layout
21894 - *
21895 - * TLS descriptors are currently at a different place compared to i386.
21896 - * Hopefully nobody expects them at a fixed place (Wine?)
21897 - */
21898 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
21899 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
21900 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
21901 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
21902 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
21903 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
21904 -#else
21905 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
21906 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21907 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
21908 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
21909 - /*
21910 - * Segments used for calling PnP BIOS have byte granularity.
21911 - * They code segments and data segments have fixed 64k limits,
21912 - * the transfer segment sizes are set at run time.
21913 - */
21914 - /* 32-bit code */
21915 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21916 - /* 16-bit code */
21917 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21918 - /* 16-bit data */
21919 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
21920 - /* 16-bit data */
21921 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
21922 - /* 16-bit data */
21923 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
21924 - /*
21925 - * The APM segments have byte granularity and their bases
21926 - * are set at run time. All have 64k limits.
21927 - */
21928 - /* 32-bit code */
21929 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21930 - /* 16-bit code */
21931 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21932 - /* data */
21933 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
21934 -
21935 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21936 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21937 - GDT_STACK_CANARY_INIT
21938 -#endif
21939 -} };
21940 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
21941 -
21942 static int __init x86_xsave_setup(char *s)
21943 {
21944 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
21945 @@ -303,6 +249,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
21946 }
21947 }
21948
21949 +#ifdef CONFIG_X86_64
21950 +static __init int setup_disable_pcid(char *arg)
21951 +{
21952 + setup_clear_cpu_cap(X86_FEATURE_PCID);
21953 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
21954 +
21955 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21956 + if (clone_pgd_mask != ~(pgdval_t)0UL)
21957 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21958 +#endif
21959 +
21960 + return 1;
21961 +}
21962 +__setup("nopcid", setup_disable_pcid);
21963 +
21964 +static void setup_pcid(struct cpuinfo_x86 *c)
21965 +{
21966 + if (!cpu_has(c, X86_FEATURE_PCID)) {
21967 + clear_cpu_cap(c, X86_FEATURE_INVPCID);
21968 +
21969 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21970 + if (clone_pgd_mask != ~(pgdval_t)0UL) {
21971 + pax_open_kernel();
21972 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21973 + pax_close_kernel();
21974 + printk("PAX: slow and weak UDEREF enabled\n");
21975 + } else
21976 + printk("PAX: UDEREF disabled\n");
21977 +#endif
21978 +
21979 + return;
21980 + }
21981 +
21982 + printk("PAX: PCID detected\n");
21983 + set_in_cr4(X86_CR4_PCIDE);
21984 +
21985 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21986 + pax_open_kernel();
21987 + clone_pgd_mask = ~(pgdval_t)0UL;
21988 + pax_close_kernel();
21989 + if (pax_user_shadow_base)
21990 + printk("PAX: weak UDEREF enabled\n");
21991 + else {
21992 + set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
21993 + printk("PAX: strong UDEREF enabled\n");
21994 + }
21995 +#endif
21996 +
21997 + if (cpu_has(c, X86_FEATURE_INVPCID))
21998 + printk("PAX: INVPCID detected\n");
21999 +}
22000 +#endif
22001 +
22002 /*
22003 * Some CPU features depend on higher CPUID levels, which may not always
22004 * be available due to CPUID level capping or broken virtualization
22005 @@ -403,7 +402,7 @@ void switch_to_new_gdt(int cpu)
22006 {
22007 struct desc_ptr gdt_descr;
22008
22009 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
22010 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
22011 gdt_descr.size = GDT_SIZE - 1;
22012 load_gdt(&gdt_descr);
22013 /* Reload the per-cpu base */
22014 @@ -893,6 +892,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
22015 setup_smep(c);
22016 setup_smap(c);
22017
22018 +#ifdef CONFIG_X86_64
22019 + setup_pcid(c);
22020 +#endif
22021 +
22022 /*
22023 * The vendor-specific functions might have changed features.
22024 * Now we do "generic changes."
22025 @@ -901,6 +904,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
22026 /* Filter out anything that depends on CPUID levels we don't have */
22027 filter_cpuid_features(c, true);
22028
22029 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
22030 + setup_clear_cpu_cap(X86_FEATURE_SEP);
22031 +#endif
22032 +
22033 /* If the model name is still unset, do table lookup. */
22034 if (!c->x86_model_id[0]) {
22035 const char *p;
22036 @@ -981,7 +988,7 @@ static void syscall32_cpu_init(void)
22037 void enable_sep_cpu(void)
22038 {
22039 int cpu = get_cpu();
22040 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
22041 + struct tss_struct *tss = init_tss + cpu;
22042
22043 if (!boot_cpu_has(X86_FEATURE_SEP)) {
22044 put_cpu();
22045 @@ -1121,14 +1128,16 @@ static __init int setup_disablecpuid(char *arg)
22046 }
22047 __setup("clearcpuid=", setup_disablecpuid);
22048
22049 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
22050 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
22051 +
22052 DEFINE_PER_CPU(unsigned long, kernel_stack) =
22053 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
22054 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
22055 EXPORT_PER_CPU_SYMBOL(kernel_stack);
22056
22057 #ifdef CONFIG_X86_64
22058 -struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
22059 -struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
22060 - (unsigned long) debug_idt_table };
22061 +struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
22062 +const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
22063
22064 DEFINE_PER_CPU_FIRST(union irq_stack_union,
22065 irq_stack_union) __aligned(PAGE_SIZE) __visible;
22066 @@ -1291,7 +1300,7 @@ void cpu_init(void)
22067 load_ucode_ap();
22068
22069 cpu = stack_smp_processor_id();
22070 - t = &per_cpu(init_tss, cpu);
22071 + t = init_tss + cpu;
22072 oist = &per_cpu(orig_ist, cpu);
22073
22074 #ifdef CONFIG_NUMA
22075 @@ -1326,7 +1335,6 @@ void cpu_init(void)
22076 wrmsrl(MSR_KERNEL_GS_BASE, 0);
22077 barrier();
22078
22079 - x86_configure_nx();
22080 enable_x2apic();
22081
22082 /*
22083 @@ -1378,7 +1386,7 @@ void cpu_init(void)
22084 {
22085 int cpu = smp_processor_id();
22086 struct task_struct *curr = current;
22087 - struct tss_struct *t = &per_cpu(init_tss, cpu);
22088 + struct tss_struct *t = init_tss + cpu;
22089 struct thread_struct *thread = &curr->thread;
22090
22091 show_ucode_info_early();
22092 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
22093 index c703507..28535e3 100644
22094 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
22095 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
22096 @@ -1026,6 +1026,22 @@ static struct attribute *default_attrs[] = {
22097 };
22098
22099 #ifdef CONFIG_AMD_NB
22100 +static struct attribute *default_attrs_amd_nb[] = {
22101 + &type.attr,
22102 + &level.attr,
22103 + &coherency_line_size.attr,
22104 + &physical_line_partition.attr,
22105 + &ways_of_associativity.attr,
22106 + &number_of_sets.attr,
22107 + &size.attr,
22108 + &shared_cpu_map.attr,
22109 + &shared_cpu_list.attr,
22110 + NULL,
22111 + NULL,
22112 + NULL,
22113 + NULL
22114 +};
22115 +
22116 static struct attribute **amd_l3_attrs(void)
22117 {
22118 static struct attribute **attrs;
22119 @@ -1036,18 +1052,7 @@ static struct attribute **amd_l3_attrs(void)
22120
22121 n = ARRAY_SIZE(default_attrs);
22122
22123 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
22124 - n += 2;
22125 -
22126 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
22127 - n += 1;
22128 -
22129 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
22130 - if (attrs == NULL)
22131 - return attrs = default_attrs;
22132 -
22133 - for (n = 0; default_attrs[n]; n++)
22134 - attrs[n] = default_attrs[n];
22135 + attrs = default_attrs_amd_nb;
22136
22137 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
22138 attrs[n++] = &cache_disable_0.attr;
22139 @@ -1098,6 +1103,13 @@ static struct kobj_type ktype_cache = {
22140 .default_attrs = default_attrs,
22141 };
22142
22143 +#ifdef CONFIG_AMD_NB
22144 +static struct kobj_type ktype_cache_amd_nb = {
22145 + .sysfs_ops = &sysfs_ops,
22146 + .default_attrs = default_attrs_amd_nb,
22147 +};
22148 +#endif
22149 +
22150 static struct kobj_type ktype_percpu_entry = {
22151 .sysfs_ops = &sysfs_ops,
22152 };
22153 @@ -1163,20 +1175,26 @@ static int cache_add_dev(struct device *dev)
22154 return retval;
22155 }
22156
22157 +#ifdef CONFIG_AMD_NB
22158 + amd_l3_attrs();
22159 +#endif
22160 +
22161 for (i = 0; i < num_cache_leaves; i++) {
22162 + struct kobj_type *ktype;
22163 +
22164 this_object = INDEX_KOBJECT_PTR(cpu, i);
22165 this_object->cpu = cpu;
22166 this_object->index = i;
22167
22168 this_leaf = CPUID4_INFO_IDX(cpu, i);
22169
22170 - ktype_cache.default_attrs = default_attrs;
22171 + ktype = &ktype_cache;
22172 #ifdef CONFIG_AMD_NB
22173 if (this_leaf->base.nb)
22174 - ktype_cache.default_attrs = amd_l3_attrs();
22175 + ktype = &ktype_cache_amd_nb;
22176 #endif
22177 retval = kobject_init_and_add(&(this_object->kobj),
22178 - &ktype_cache,
22179 + ktype,
22180 per_cpu(ici_cache_kobject, cpu),
22181 "index%1lu", i);
22182 if (unlikely(retval)) {
22183 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
22184 index bd9ccda..38314e7 100644
22185 --- a/arch/x86/kernel/cpu/mcheck/mce.c
22186 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
22187 @@ -45,6 +45,7 @@
22188 #include <asm/processor.h>
22189 #include <asm/mce.h>
22190 #include <asm/msr.h>
22191 +#include <asm/local.h>
22192
22193 #include "mce-internal.h"
22194
22195 @@ -259,7 +260,7 @@ static void print_mce(struct mce *m)
22196 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
22197 m->cs, m->ip);
22198
22199 - if (m->cs == __KERNEL_CS)
22200 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
22201 print_symbol("{%s}", m->ip);
22202 pr_cont("\n");
22203 }
22204 @@ -292,10 +293,10 @@ static void print_mce(struct mce *m)
22205
22206 #define PANIC_TIMEOUT 5 /* 5 seconds */
22207
22208 -static atomic_t mce_paniced;
22209 +static atomic_unchecked_t mce_paniced;
22210
22211 static int fake_panic;
22212 -static atomic_t mce_fake_paniced;
22213 +static atomic_unchecked_t mce_fake_paniced;
22214
22215 /* Panic in progress. Enable interrupts and wait for final IPI */
22216 static void wait_for_panic(void)
22217 @@ -319,7 +320,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
22218 /*
22219 * Make sure only one CPU runs in machine check panic
22220 */
22221 - if (atomic_inc_return(&mce_paniced) > 1)
22222 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
22223 wait_for_panic();
22224 barrier();
22225
22226 @@ -327,7 +328,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
22227 console_verbose();
22228 } else {
22229 /* Don't log too much for fake panic */
22230 - if (atomic_inc_return(&mce_fake_paniced) > 1)
22231 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
22232 return;
22233 }
22234 /* First print corrected ones that are still unlogged */
22235 @@ -366,7 +367,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
22236 if (!fake_panic) {
22237 if (panic_timeout == 0)
22238 panic_timeout = mca_cfg.panic_timeout;
22239 - panic(msg);
22240 + panic("%s", msg);
22241 } else
22242 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
22243 }
22244 @@ -697,7 +698,7 @@ static int mce_timed_out(u64 *t)
22245 * might have been modified by someone else.
22246 */
22247 rmb();
22248 - if (atomic_read(&mce_paniced))
22249 + if (atomic_read_unchecked(&mce_paniced))
22250 wait_for_panic();
22251 if (!mca_cfg.monarch_timeout)
22252 goto out;
22253 @@ -1674,7 +1675,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
22254 }
22255
22256 /* Call the installed machine check handler for this CPU setup. */
22257 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
22258 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
22259 unexpected_machine_check;
22260
22261 /*
22262 @@ -1697,7 +1698,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
22263 return;
22264 }
22265
22266 + pax_open_kernel();
22267 machine_check_vector = do_machine_check;
22268 + pax_close_kernel();
22269
22270 __mcheck_cpu_init_generic();
22271 __mcheck_cpu_init_vendor(c);
22272 @@ -1711,7 +1714,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
22273 */
22274
22275 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
22276 -static int mce_chrdev_open_count; /* #times opened */
22277 +static local_t mce_chrdev_open_count; /* #times opened */
22278 static int mce_chrdev_open_exclu; /* already open exclusive? */
22279
22280 static int mce_chrdev_open(struct inode *inode, struct file *file)
22281 @@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
22282 spin_lock(&mce_chrdev_state_lock);
22283
22284 if (mce_chrdev_open_exclu ||
22285 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
22286 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
22287 spin_unlock(&mce_chrdev_state_lock);
22288
22289 return -EBUSY;
22290 @@ -1727,7 +1730,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
22291
22292 if (file->f_flags & O_EXCL)
22293 mce_chrdev_open_exclu = 1;
22294 - mce_chrdev_open_count++;
22295 + local_inc(&mce_chrdev_open_count);
22296
22297 spin_unlock(&mce_chrdev_state_lock);
22298
22299 @@ -1738,7 +1741,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
22300 {
22301 spin_lock(&mce_chrdev_state_lock);
22302
22303 - mce_chrdev_open_count--;
22304 + local_dec(&mce_chrdev_open_count);
22305 mce_chrdev_open_exclu = 0;
22306
22307 spin_unlock(&mce_chrdev_state_lock);
22308 @@ -2413,7 +2416,7 @@ static __init void mce_init_banks(void)
22309
22310 for (i = 0; i < mca_cfg.banks; i++) {
22311 struct mce_bank *b = &mce_banks[i];
22312 - struct device_attribute *a = &b->attr;
22313 + device_attribute_no_const *a = &b->attr;
22314
22315 sysfs_attr_init(&a->attr);
22316 a->attr.name = b->attrname;
22317 @@ -2520,7 +2523,7 @@ struct dentry *mce_get_debugfs_dir(void)
22318 static void mce_reset(void)
22319 {
22320 cpu_missing = 0;
22321 - atomic_set(&mce_fake_paniced, 0);
22322 + atomic_set_unchecked(&mce_fake_paniced, 0);
22323 atomic_set(&mce_executing, 0);
22324 atomic_set(&mce_callin, 0);
22325 atomic_set(&global_nwo, 0);
22326 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
22327 index a304298..49b6d06 100644
22328 --- a/arch/x86/kernel/cpu/mcheck/p5.c
22329 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
22330 @@ -10,6 +10,7 @@
22331 #include <asm/processor.h>
22332 #include <asm/mce.h>
22333 #include <asm/msr.h>
22334 +#include <asm/pgtable.h>
22335
22336 /* By default disabled */
22337 int mce_p5_enabled __read_mostly;
22338 @@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
22339 if (!cpu_has(c, X86_FEATURE_MCE))
22340 return;
22341
22342 + pax_open_kernel();
22343 machine_check_vector = pentium_machine_check;
22344 + pax_close_kernel();
22345 /* Make sure the vector pointer is visible before we enable MCEs: */
22346 wmb();
22347
22348 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
22349 index 7dc5564..1273569 100644
22350 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
22351 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
22352 @@ -9,6 +9,7 @@
22353 #include <asm/processor.h>
22354 #include <asm/mce.h>
22355 #include <asm/msr.h>
22356 +#include <asm/pgtable.h>
22357
22358 /* Machine check handler for WinChip C6: */
22359 static void winchip_machine_check(struct pt_regs *regs, long error_code)
22360 @@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
22361 {
22362 u32 lo, hi;
22363
22364 + pax_open_kernel();
22365 machine_check_vector = winchip_machine_check;
22366 + pax_close_kernel();
22367 /* Make sure the vector pointer is visible before we enable MCEs: */
22368 wmb();
22369
22370 diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
22371 index dd9d619..86e1d81 100644
22372 --- a/arch/x86/kernel/cpu/microcode/core.c
22373 +++ b/arch/x86/kernel/cpu/microcode/core.c
22374 @@ -516,7 +516,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
22375 return NOTIFY_OK;
22376 }
22377
22378 -static struct notifier_block __refdata mc_cpu_notifier = {
22379 +static struct notifier_block mc_cpu_notifier = {
22380 .notifier_call = mc_cpu_callback,
22381 };
22382
22383 diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
22384 index a276fa7..e66810f 100644
22385 --- a/arch/x86/kernel/cpu/microcode/intel.c
22386 +++ b/arch/x86/kernel/cpu/microcode/intel.c
22387 @@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
22388
22389 static int get_ucode_user(void *to, const void *from, size_t n)
22390 {
22391 - return copy_from_user(to, from, n);
22392 + return copy_from_user(to, (const void __force_user *)from, n);
22393 }
22394
22395 static enum ucode_state
22396 request_microcode_user(int cpu, const void __user *buf, size_t size)
22397 {
22398 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
22399 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
22400 }
22401
22402 static void microcode_fini_cpu(int cpu)
22403 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
22404 index f961de9..8a9d332 100644
22405 --- a/arch/x86/kernel/cpu/mtrr/main.c
22406 +++ b/arch/x86/kernel/cpu/mtrr/main.c
22407 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
22408 u64 size_or_mask, size_and_mask;
22409 static bool mtrr_aps_delayed_init;
22410
22411 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
22412 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
22413
22414 const struct mtrr_ops *mtrr_if;
22415
22416 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
22417 index df5e41f..816c719 100644
22418 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
22419 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
22420 @@ -25,7 +25,7 @@ struct mtrr_ops {
22421 int (*validate_add_page)(unsigned long base, unsigned long size,
22422 unsigned int type);
22423 int (*have_wrcomb)(void);
22424 -};
22425 +} __do_const;
22426
22427 extern int generic_get_free_region(unsigned long base, unsigned long size,
22428 int replace_reg);
22429 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
22430 index 2879ecd..bb8c80b 100644
22431 --- a/arch/x86/kernel/cpu/perf_event.c
22432 +++ b/arch/x86/kernel/cpu/perf_event.c
22433 @@ -1372,7 +1372,7 @@ static void __init pmu_check_apic(void)
22434
22435 }
22436
22437 -static struct attribute_group x86_pmu_format_group = {
22438 +static attribute_group_no_const x86_pmu_format_group = {
22439 .name = "format",
22440 .attrs = NULL,
22441 };
22442 @@ -1471,7 +1471,7 @@ static struct attribute *events_attr[] = {
22443 NULL,
22444 };
22445
22446 -static struct attribute_group x86_pmu_events_group = {
22447 +static attribute_group_no_const x86_pmu_events_group = {
22448 .name = "events",
22449 .attrs = events_attr,
22450 };
22451 @@ -1995,7 +1995,7 @@ static unsigned long get_segment_base(unsigned int segment)
22452 if (idx > GDT_ENTRIES)
22453 return 0;
22454
22455 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
22456 + desc = get_cpu_gdt_table(smp_processor_id());
22457 }
22458
22459 return get_desc_base(desc + idx);
22460 @@ -2085,7 +2085,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
22461 break;
22462
22463 perf_callchain_store(entry, frame.return_address);
22464 - fp = frame.next_frame;
22465 + fp = (const void __force_user *)frame.next_frame;
22466 }
22467 }
22468
22469 diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
22470 index 639d128..e92d7e5 100644
22471 --- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
22472 +++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
22473 @@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
22474 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
22475 {
22476 struct attribute **attrs;
22477 - struct attribute_group *attr_group;
22478 + attribute_group_no_const *attr_group;
22479 int i = 0, j;
22480
22481 while (amd_iommu_v2_event_descs[i].attr.attr.name)
22482 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
22483 index 2502d0d..e5cc05c 100644
22484 --- a/arch/x86/kernel/cpu/perf_event_intel.c
22485 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
22486 @@ -2353,10 +2353,10 @@ __init int intel_pmu_init(void)
22487 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
22488
22489 if (boot_cpu_has(X86_FEATURE_PDCM)) {
22490 - u64 capabilities;
22491 + u64 capabilities = x86_pmu.intel_cap.capabilities;
22492
22493 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
22494 - x86_pmu.intel_cap.capabilities = capabilities;
22495 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
22496 + x86_pmu.intel_cap.capabilities = capabilities;
22497 }
22498
22499 intel_ds_init();
22500 diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
22501 index 619f769..d510008 100644
22502 --- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
22503 +++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
22504 @@ -449,7 +449,7 @@ static struct attribute *rapl_events_hsw_attr[] = {
22505 NULL,
22506 };
22507
22508 -static struct attribute_group rapl_pmu_events_group = {
22509 +static attribute_group_no_const rapl_pmu_events_group __read_only = {
22510 .name = "events",
22511 .attrs = NULL, /* patched at runtime */
22512 };
22513 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
22514 index 0939f86..69730af 100644
22515 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
22516 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
22517 @@ -3691,7 +3691,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
22518 static int __init uncore_type_init(struct intel_uncore_type *type)
22519 {
22520 struct intel_uncore_pmu *pmus;
22521 - struct attribute_group *attr_group;
22522 + attribute_group_no_const *attr_group;
22523 struct attribute **attrs;
22524 int i, j;
22525
22526 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
22527 index 90236f0..54cb20d 100644
22528 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
22529 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
22530 @@ -503,7 +503,7 @@ struct intel_uncore_box {
22531 struct uncore_event_desc {
22532 struct kobj_attribute attr;
22533 const char *config;
22534 -};
22535 +} __do_const;
22536
22537 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
22538 { \
22539 diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
22540 index 3225ae6c..ee3c6db 100644
22541 --- a/arch/x86/kernel/cpuid.c
22542 +++ b/arch/x86/kernel/cpuid.c
22543 @@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
22544 return notifier_from_errno(err);
22545 }
22546
22547 -static struct notifier_block __refdata cpuid_class_cpu_notifier =
22548 +static struct notifier_block cpuid_class_cpu_notifier =
22549 {
22550 .notifier_call = cpuid_class_cpu_callback,
22551 };
22552 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
22553 index a618fcd..200e95b 100644
22554 --- a/arch/x86/kernel/crash.c
22555 +++ b/arch/x86/kernel/crash.c
22556 @@ -104,7 +104,7 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
22557 #ifdef CONFIG_X86_32
22558 struct pt_regs fixed_regs;
22559
22560 - if (!user_mode_vm(regs)) {
22561 + if (!user_mode(regs)) {
22562 crash_fixup_ss_esp(&fixed_regs, regs);
22563 regs = &fixed_regs;
22564 }
22565 diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
22566 index afa64ad..dce67dd 100644
22567 --- a/arch/x86/kernel/crash_dump_64.c
22568 +++ b/arch/x86/kernel/crash_dump_64.c
22569 @@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
22570 return -ENOMEM;
22571
22572 if (userbuf) {
22573 - if (copy_to_user(buf, vaddr + offset, csize)) {
22574 + if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
22575 iounmap(vaddr);
22576 return -EFAULT;
22577 }
22578 diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
22579 index f6dfd93..892ade4 100644
22580 --- a/arch/x86/kernel/doublefault.c
22581 +++ b/arch/x86/kernel/doublefault.c
22582 @@ -12,7 +12,7 @@
22583
22584 #define DOUBLEFAULT_STACKSIZE (1024)
22585 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
22586 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
22587 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
22588
22589 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
22590
22591 @@ -22,7 +22,7 @@ static void doublefault_fn(void)
22592 unsigned long gdt, tss;
22593
22594 native_store_gdt(&gdt_desc);
22595 - gdt = gdt_desc.address;
22596 + gdt = (unsigned long)gdt_desc.address;
22597
22598 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
22599
22600 @@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
22601 /* 0x2 bit is always set */
22602 .flags = X86_EFLAGS_SF | 0x2,
22603 .sp = STACK_START,
22604 - .es = __USER_DS,
22605 + .es = __KERNEL_DS,
22606 .cs = __KERNEL_CS,
22607 .ss = __KERNEL_DS,
22608 - .ds = __USER_DS,
22609 + .ds = __KERNEL_DS,
22610 .fs = __KERNEL_PERCPU,
22611
22612 .__cr3 = __pa_nodebug(swapper_pg_dir),
22613 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
22614 index b74ebc7..2c95874 100644
22615 --- a/arch/x86/kernel/dumpstack.c
22616 +++ b/arch/x86/kernel/dumpstack.c
22617 @@ -2,6 +2,9 @@
22618 * Copyright (C) 1991, 1992 Linus Torvalds
22619 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
22620 */
22621 +#ifdef CONFIG_GRKERNSEC_HIDESYM
22622 +#define __INCLUDED_BY_HIDESYM 1
22623 +#endif
22624 #include <linux/kallsyms.h>
22625 #include <linux/kprobes.h>
22626 #include <linux/uaccess.h>
22627 @@ -33,23 +36,21 @@ static void printk_stack_address(unsigned long address, int reliable)
22628
22629 void printk_address(unsigned long address)
22630 {
22631 - pr_cont(" [<%p>] %pS\n", (void *)address, (void *)address);
22632 + pr_cont(" [<%p>] %pA\n", (void *)address, (void *)address);
22633 }
22634
22635 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
22636 static void
22637 print_ftrace_graph_addr(unsigned long addr, void *data,
22638 const struct stacktrace_ops *ops,
22639 - struct thread_info *tinfo, int *graph)
22640 + struct task_struct *task, int *graph)
22641 {
22642 - struct task_struct *task;
22643 unsigned long ret_addr;
22644 int index;
22645
22646 if (addr != (unsigned long)return_to_handler)
22647 return;
22648
22649 - task = tinfo->task;
22650 index = task->curr_ret_stack;
22651
22652 if (!task->ret_stack || index < *graph)
22653 @@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
22654 static inline void
22655 print_ftrace_graph_addr(unsigned long addr, void *data,
22656 const struct stacktrace_ops *ops,
22657 - struct thread_info *tinfo, int *graph)
22658 + struct task_struct *task, int *graph)
22659 { }
22660 #endif
22661
22662 @@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
22663 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
22664 */
22665
22666 -static inline int valid_stack_ptr(struct thread_info *tinfo,
22667 - void *p, unsigned int size, void *end)
22668 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
22669 {
22670 - void *t = tinfo;
22671 if (end) {
22672 if (p < end && p >= (end-THREAD_SIZE))
22673 return 1;
22674 @@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
22675 }
22676
22677 unsigned long
22678 -print_context_stack(struct thread_info *tinfo,
22679 +print_context_stack(struct task_struct *task, void *stack_start,
22680 unsigned long *stack, unsigned long bp,
22681 const struct stacktrace_ops *ops, void *data,
22682 unsigned long *end, int *graph)
22683 {
22684 struct stack_frame *frame = (struct stack_frame *)bp;
22685
22686 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
22687 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
22688 unsigned long addr;
22689
22690 addr = *stack;
22691 @@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
22692 } else {
22693 ops->address(data, addr, 0);
22694 }
22695 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
22696 + print_ftrace_graph_addr(addr, data, ops, task, graph);
22697 }
22698 stack++;
22699 }
22700 @@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
22701 EXPORT_SYMBOL_GPL(print_context_stack);
22702
22703 unsigned long
22704 -print_context_stack_bp(struct thread_info *tinfo,
22705 +print_context_stack_bp(struct task_struct *task, void *stack_start,
22706 unsigned long *stack, unsigned long bp,
22707 const struct stacktrace_ops *ops, void *data,
22708 unsigned long *end, int *graph)
22709 @@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22710 struct stack_frame *frame = (struct stack_frame *)bp;
22711 unsigned long *ret_addr = &frame->return_address;
22712
22713 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
22714 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
22715 unsigned long addr = *ret_addr;
22716
22717 if (!__kernel_text_address(addr))
22718 @@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22719 ops->address(data, addr, 1);
22720 frame = frame->next_frame;
22721 ret_addr = &frame->return_address;
22722 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
22723 + print_ftrace_graph_addr(addr, data, ops, task, graph);
22724 }
22725
22726 return (unsigned long)frame;
22727 @@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
22728 static void print_trace_address(void *data, unsigned long addr, int reliable)
22729 {
22730 touch_nmi_watchdog();
22731 - printk(data);
22732 + printk("%s", (char *)data);
22733 printk_stack_address(addr, reliable);
22734 }
22735
22736 @@ -225,6 +224,8 @@ unsigned long oops_begin(void)
22737 EXPORT_SYMBOL_GPL(oops_begin);
22738 NOKPROBE_SYMBOL(oops_begin);
22739
22740 +extern void gr_handle_kernel_exploit(void);
22741 +
22742 void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22743 {
22744 if (regs && kexec_should_crash(current))
22745 @@ -246,7 +247,10 @@ void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22746 panic("Fatal exception in interrupt");
22747 if (panic_on_oops)
22748 panic("Fatal exception");
22749 - do_exit(signr);
22750 +
22751 + gr_handle_kernel_exploit();
22752 +
22753 + do_group_exit(signr);
22754 }
22755 NOKPROBE_SYMBOL(oops_end);
22756
22757 @@ -275,7 +279,7 @@ int __die(const char *str, struct pt_regs *regs, long err)
22758 print_modules();
22759 show_regs(regs);
22760 #ifdef CONFIG_X86_32
22761 - if (user_mode_vm(regs)) {
22762 + if (user_mode(regs)) {
22763 sp = regs->sp;
22764 ss = regs->ss & 0xffff;
22765 } else {
22766 @@ -304,7 +308,7 @@ void die(const char *str, struct pt_regs *regs, long err)
22767 unsigned long flags = oops_begin();
22768 int sig = SIGSEGV;
22769
22770 - if (!user_mode_vm(regs))
22771 + if (!user_mode(regs))
22772 report_bug(regs->ip, regs);
22773
22774 if (__die(str, regs, err))
22775 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
22776 index 5abd4cd..c65733b 100644
22777 --- a/arch/x86/kernel/dumpstack_32.c
22778 +++ b/arch/x86/kernel/dumpstack_32.c
22779 @@ -61,15 +61,14 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22780 bp = stack_frame(task, regs);
22781
22782 for (;;) {
22783 - struct thread_info *context;
22784 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22785 void *end_stack;
22786
22787 end_stack = is_hardirq_stack(stack, cpu);
22788 if (!end_stack)
22789 end_stack = is_softirq_stack(stack, cpu);
22790
22791 - context = task_thread_info(task);
22792 - bp = ops->walk_stack(context, stack, bp, ops, data,
22793 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data,
22794 end_stack, &graph);
22795
22796 /* Stop if not on irq stack */
22797 @@ -123,27 +122,28 @@ void show_regs(struct pt_regs *regs)
22798 int i;
22799
22800 show_regs_print_info(KERN_EMERG);
22801 - __show_regs(regs, !user_mode_vm(regs));
22802 + __show_regs(regs, !user_mode(regs));
22803
22804 /*
22805 * When in-kernel, we also print out the stack and code at the
22806 * time of the fault..
22807 */
22808 - if (!user_mode_vm(regs)) {
22809 + if (!user_mode(regs)) {
22810 unsigned int code_prologue = code_bytes * 43 / 64;
22811 unsigned int code_len = code_bytes;
22812 unsigned char c;
22813 u8 *ip;
22814 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
22815
22816 pr_emerg("Stack:\n");
22817 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
22818
22819 pr_emerg("Code:");
22820
22821 - ip = (u8 *)regs->ip - code_prologue;
22822 + ip = (u8 *)regs->ip - code_prologue + cs_base;
22823 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
22824 /* try starting at IP */
22825 - ip = (u8 *)regs->ip;
22826 + ip = (u8 *)regs->ip + cs_base;
22827 code_len = code_len - code_prologue + 1;
22828 }
22829 for (i = 0; i < code_len; i++, ip++) {
22830 @@ -152,7 +152,7 @@ void show_regs(struct pt_regs *regs)
22831 pr_cont(" Bad EIP value.");
22832 break;
22833 }
22834 - if (ip == (u8 *)regs->ip)
22835 + if (ip == (u8 *)regs->ip + cs_base)
22836 pr_cont(" <%02x>", c);
22837 else
22838 pr_cont(" %02x", c);
22839 @@ -165,6 +165,7 @@ int is_valid_bugaddr(unsigned long ip)
22840 {
22841 unsigned short ud2;
22842
22843 + ip = ktla_ktva(ip);
22844 if (ip < PAGE_OFFSET)
22845 return 0;
22846 if (probe_kernel_address((unsigned short *)ip, ud2))
22847 @@ -172,3 +173,15 @@ int is_valid_bugaddr(unsigned long ip)
22848
22849 return ud2 == 0x0b0f;
22850 }
22851 +
22852 +#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22853 +void pax_check_alloca(unsigned long size)
22854 +{
22855 + unsigned long sp = (unsigned long)&sp, stack_left;
22856 +
22857 + /* all kernel stacks are of the same size */
22858 + stack_left = sp & (THREAD_SIZE - 1);
22859 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22860 +}
22861 +EXPORT_SYMBOL(pax_check_alloca);
22862 +#endif
22863 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
22864 index 1abcb50..6c8d702 100644
22865 --- a/arch/x86/kernel/dumpstack_64.c
22866 +++ b/arch/x86/kernel/dumpstack_64.c
22867 @@ -154,12 +154,12 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22868 const struct stacktrace_ops *ops, void *data)
22869 {
22870 const unsigned cpu = get_cpu();
22871 - struct thread_info *tinfo;
22872 unsigned long *irq_stack = (unsigned long *)per_cpu(irq_stack_ptr, cpu);
22873 unsigned long dummy;
22874 unsigned used = 0;
22875 int graph = 0;
22876 int done = 0;
22877 + void *stack_start;
22878
22879 if (!task)
22880 task = current;
22881 @@ -180,7 +180,6 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22882 * current stack address. If the stacks consist of nested
22883 * exceptions
22884 */
22885 - tinfo = task_thread_info(task);
22886 while (!done) {
22887 unsigned long *stack_end;
22888 enum stack_type stype;
22889 @@ -203,7 +202,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22890 if (ops->stack(data, id) < 0)
22891 break;
22892
22893 - bp = ops->walk_stack(tinfo, stack, bp, ops,
22894 + bp = ops->walk_stack(task, stack_end - EXCEPTION_STKSZ, stack, bp, ops,
22895 data, stack_end, &graph);
22896 ops->stack(data, "<EOE>");
22897 /*
22898 @@ -211,6 +210,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22899 * second-to-last pointer (index -2 to end) in the
22900 * exception stack:
22901 */
22902 + if ((u16)stack_end[-1] != __KERNEL_DS)
22903 + goto out;
22904 stack = (unsigned long *) stack_end[-2];
22905 done = 0;
22906 break;
22907 @@ -219,7 +220,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22908
22909 if (ops->stack(data, "IRQ") < 0)
22910 break;
22911 - bp = ops->walk_stack(tinfo, stack, bp,
22912 + bp = ops->walk_stack(task, irq_stack, stack, bp,
22913 ops, data, stack_end, &graph);
22914 /*
22915 * We link to the next stack (which would be
22916 @@ -241,7 +242,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22917 /*
22918 * This handles the process stack:
22919 */
22920 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
22921 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22922 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
22923 +out:
22924 put_cpu();
22925 }
22926 EXPORT_SYMBOL(dump_trace);
22927 @@ -350,3 +353,50 @@ int is_valid_bugaddr(unsigned long ip)
22928
22929 return ud2 == 0x0b0f;
22930 }
22931 +
22932 +#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22933 +void pax_check_alloca(unsigned long size)
22934 +{
22935 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
22936 + unsigned cpu, used;
22937 + char *id;
22938 +
22939 + /* check the process stack first */
22940 + stack_start = (unsigned long)task_stack_page(current);
22941 + stack_end = stack_start + THREAD_SIZE;
22942 + if (likely(stack_start <= sp && sp < stack_end)) {
22943 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
22944 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22945 + return;
22946 + }
22947 +
22948 + cpu = get_cpu();
22949 +
22950 + /* check the irq stacks */
22951 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
22952 + stack_start = stack_end - IRQ_STACK_SIZE;
22953 + if (stack_start <= sp && sp < stack_end) {
22954 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
22955 + put_cpu();
22956 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22957 + return;
22958 + }
22959 +
22960 + /* check the exception stacks */
22961 + used = 0;
22962 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
22963 + stack_start = stack_end - EXCEPTION_STKSZ;
22964 + if (stack_end && stack_start <= sp && sp < stack_end) {
22965 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
22966 + put_cpu();
22967 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22968 + return;
22969 + }
22970 +
22971 + put_cpu();
22972 +
22973 + /* unknown stack */
22974 + BUG();
22975 +}
22976 +EXPORT_SYMBOL(pax_check_alloca);
22977 +#endif
22978 diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
22979 index 988c00a..4f673b6 100644
22980 --- a/arch/x86/kernel/e820.c
22981 +++ b/arch/x86/kernel/e820.c
22982 @@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
22983
22984 static void early_panic(char *msg)
22985 {
22986 - early_printk(msg);
22987 - panic(msg);
22988 + early_printk("%s", msg);
22989 + panic("%s", msg);
22990 }
22991
22992 static int userdef __initdata;
22993 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
22994 index 01d1c18..8073693 100644
22995 --- a/arch/x86/kernel/early_printk.c
22996 +++ b/arch/x86/kernel/early_printk.c
22997 @@ -7,6 +7,7 @@
22998 #include <linux/pci_regs.h>
22999 #include <linux/pci_ids.h>
23000 #include <linux/errno.h>
23001 +#include <linux/sched.h>
23002 #include <asm/io.h>
23003 #include <asm/processor.h>
23004 #include <asm/fcntl.h>
23005 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
23006 index 4b0e1df..884b67e 100644
23007 --- a/arch/x86/kernel/entry_32.S
23008 +++ b/arch/x86/kernel/entry_32.S
23009 @@ -177,13 +177,153 @@
23010 /*CFI_REL_OFFSET gs, PT_GS*/
23011 .endm
23012 .macro SET_KERNEL_GS reg
23013 +
23014 +#ifdef CONFIG_CC_STACKPROTECTOR
23015 movl $(__KERNEL_STACK_CANARY), \reg
23016 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
23017 + movl $(__USER_DS), \reg
23018 +#else
23019 + xorl \reg, \reg
23020 +#endif
23021 +
23022 movl \reg, %gs
23023 .endm
23024
23025 #endif /* CONFIG_X86_32_LAZY_GS */
23026
23027 -.macro SAVE_ALL
23028 +.macro pax_enter_kernel
23029 +#ifdef CONFIG_PAX_KERNEXEC
23030 + call pax_enter_kernel
23031 +#endif
23032 +.endm
23033 +
23034 +.macro pax_exit_kernel
23035 +#ifdef CONFIG_PAX_KERNEXEC
23036 + call pax_exit_kernel
23037 +#endif
23038 +.endm
23039 +
23040 +#ifdef CONFIG_PAX_KERNEXEC
23041 +ENTRY(pax_enter_kernel)
23042 +#ifdef CONFIG_PARAVIRT
23043 + pushl %eax
23044 + pushl %ecx
23045 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
23046 + mov %eax, %esi
23047 +#else
23048 + mov %cr0, %esi
23049 +#endif
23050 + bts $16, %esi
23051 + jnc 1f
23052 + mov %cs, %esi
23053 + cmp $__KERNEL_CS, %esi
23054 + jz 3f
23055 + ljmp $__KERNEL_CS, $3f
23056 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
23057 +2:
23058 +#ifdef CONFIG_PARAVIRT
23059 + mov %esi, %eax
23060 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
23061 +#else
23062 + mov %esi, %cr0
23063 +#endif
23064 +3:
23065 +#ifdef CONFIG_PARAVIRT
23066 + popl %ecx
23067 + popl %eax
23068 +#endif
23069 + ret
23070 +ENDPROC(pax_enter_kernel)
23071 +
23072 +ENTRY(pax_exit_kernel)
23073 +#ifdef CONFIG_PARAVIRT
23074 + pushl %eax
23075 + pushl %ecx
23076 +#endif
23077 + mov %cs, %esi
23078 + cmp $__KERNEXEC_KERNEL_CS, %esi
23079 + jnz 2f
23080 +#ifdef CONFIG_PARAVIRT
23081 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
23082 + mov %eax, %esi
23083 +#else
23084 + mov %cr0, %esi
23085 +#endif
23086 + btr $16, %esi
23087 + ljmp $__KERNEL_CS, $1f
23088 +1:
23089 +#ifdef CONFIG_PARAVIRT
23090 + mov %esi, %eax
23091 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
23092 +#else
23093 + mov %esi, %cr0
23094 +#endif
23095 +2:
23096 +#ifdef CONFIG_PARAVIRT
23097 + popl %ecx
23098 + popl %eax
23099 +#endif
23100 + ret
23101 +ENDPROC(pax_exit_kernel)
23102 +#endif
23103 +
23104 + .macro pax_erase_kstack
23105 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23106 + call pax_erase_kstack
23107 +#endif
23108 + .endm
23109 +
23110 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23111 +/*
23112 + * ebp: thread_info
23113 + */
23114 +ENTRY(pax_erase_kstack)
23115 + pushl %edi
23116 + pushl %ecx
23117 + pushl %eax
23118 +
23119 + mov TI_lowest_stack(%ebp), %edi
23120 + mov $-0xBEEF, %eax
23121 + std
23122 +
23123 +1: mov %edi, %ecx
23124 + and $THREAD_SIZE_asm - 1, %ecx
23125 + shr $2, %ecx
23126 + repne scasl
23127 + jecxz 2f
23128 +
23129 + cmp $2*16, %ecx
23130 + jc 2f
23131 +
23132 + mov $2*16, %ecx
23133 + repe scasl
23134 + jecxz 2f
23135 + jne 1b
23136 +
23137 +2: cld
23138 + mov %esp, %ecx
23139 + sub %edi, %ecx
23140 +
23141 + cmp $THREAD_SIZE_asm, %ecx
23142 + jb 3f
23143 + ud2
23144 +3:
23145 +
23146 + shr $2, %ecx
23147 + rep stosl
23148 +
23149 + mov TI_task_thread_sp0(%ebp), %edi
23150 + sub $128, %edi
23151 + mov %edi, TI_lowest_stack(%ebp)
23152 +
23153 + popl %eax
23154 + popl %ecx
23155 + popl %edi
23156 + ret
23157 +ENDPROC(pax_erase_kstack)
23158 +#endif
23159 +
23160 +.macro __SAVE_ALL _DS
23161 cld
23162 PUSH_GS
23163 pushl_cfi %fs
23164 @@ -206,7 +346,7 @@
23165 CFI_REL_OFFSET ecx, 0
23166 pushl_cfi %ebx
23167 CFI_REL_OFFSET ebx, 0
23168 - movl $(__USER_DS), %edx
23169 + movl $\_DS, %edx
23170 movl %edx, %ds
23171 movl %edx, %es
23172 movl $(__KERNEL_PERCPU), %edx
23173 @@ -214,6 +354,15 @@
23174 SET_KERNEL_GS %edx
23175 .endm
23176
23177 +.macro SAVE_ALL
23178 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23179 + __SAVE_ALL __KERNEL_DS
23180 + pax_enter_kernel
23181 +#else
23182 + __SAVE_ALL __USER_DS
23183 +#endif
23184 +.endm
23185 +
23186 .macro RESTORE_INT_REGS
23187 popl_cfi %ebx
23188 CFI_RESTORE ebx
23189 @@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
23190 popfl_cfi
23191 jmp syscall_exit
23192 CFI_ENDPROC
23193 -END(ret_from_fork)
23194 +ENDPROC(ret_from_fork)
23195
23196 ENTRY(ret_from_kernel_thread)
23197 CFI_STARTPROC
23198 @@ -340,7 +489,15 @@ ret_from_intr:
23199 andl $SEGMENT_RPL_MASK, %eax
23200 #endif
23201 cmpl $USER_RPL, %eax
23202 +
23203 +#ifdef CONFIG_PAX_KERNEXEC
23204 + jae resume_userspace
23205 +
23206 + pax_exit_kernel
23207 + jmp resume_kernel
23208 +#else
23209 jb resume_kernel # not returning to v8086 or userspace
23210 +#endif
23211
23212 ENTRY(resume_userspace)
23213 LOCKDEP_SYS_EXIT
23214 @@ -352,8 +509,8 @@ ENTRY(resume_userspace)
23215 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
23216 # int/exception return?
23217 jne work_pending
23218 - jmp restore_all
23219 -END(ret_from_exception)
23220 + jmp restore_all_pax
23221 +ENDPROC(ret_from_exception)
23222
23223 #ifdef CONFIG_PREEMPT
23224 ENTRY(resume_kernel)
23225 @@ -365,7 +522,7 @@ need_resched:
23226 jz restore_all
23227 call preempt_schedule_irq
23228 jmp need_resched
23229 -END(resume_kernel)
23230 +ENDPROC(resume_kernel)
23231 #endif
23232 CFI_ENDPROC
23233
23234 @@ -395,30 +552,45 @@ sysenter_past_esp:
23235 /*CFI_REL_OFFSET cs, 0*/
23236 /*
23237 * Push current_thread_info()->sysenter_return to the stack.
23238 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
23239 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
23240 */
23241 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
23242 + pushl_cfi $0
23243 CFI_REL_OFFSET eip, 0
23244
23245 pushl_cfi %eax
23246 SAVE_ALL
23247 + GET_THREAD_INFO(%ebp)
23248 + movl TI_sysenter_return(%ebp),%ebp
23249 + movl %ebp,PT_EIP(%esp)
23250 ENABLE_INTERRUPTS(CLBR_NONE)
23251
23252 /*
23253 * Load the potential sixth argument from user stack.
23254 * Careful about security.
23255 */
23256 + movl PT_OLDESP(%esp),%ebp
23257 +
23258 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23259 + mov PT_OLDSS(%esp),%ds
23260 +1: movl %ds:(%ebp),%ebp
23261 + push %ss
23262 + pop %ds
23263 +#else
23264 cmpl $__PAGE_OFFSET-3,%ebp
23265 jae syscall_fault
23266 ASM_STAC
23267 1: movl (%ebp),%ebp
23268 ASM_CLAC
23269 +#endif
23270 +
23271 movl %ebp,PT_EBP(%esp)
23272 _ASM_EXTABLE(1b,syscall_fault)
23273
23274 GET_THREAD_INFO(%ebp)
23275
23276 +#ifdef CONFIG_PAX_RANDKSTACK
23277 + pax_erase_kstack
23278 +#endif
23279 +
23280 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
23281 jnz sysenter_audit
23282 sysenter_do_call:
23283 @@ -434,12 +606,24 @@ sysenter_after_call:
23284 testl $_TIF_ALLWORK_MASK, %ecx
23285 jne sysexit_audit
23286 sysenter_exit:
23287 +
23288 +#ifdef CONFIG_PAX_RANDKSTACK
23289 + pushl_cfi %eax
23290 + movl %esp, %eax
23291 + call pax_randomize_kstack
23292 + popl_cfi %eax
23293 +#endif
23294 +
23295 + pax_erase_kstack
23296 +
23297 /* if something modifies registers it must also disable sysexit */
23298 movl PT_EIP(%esp), %edx
23299 movl PT_OLDESP(%esp), %ecx
23300 xorl %ebp,%ebp
23301 TRACE_IRQS_ON
23302 1: mov PT_FS(%esp), %fs
23303 +2: mov PT_DS(%esp), %ds
23304 +3: mov PT_ES(%esp), %es
23305 PTGS_TO_GS
23306 ENABLE_INTERRUPTS_SYSEXIT
23307
23308 @@ -456,6 +640,9 @@ sysenter_audit:
23309 movl %eax,%edx /* 2nd arg: syscall number */
23310 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
23311 call __audit_syscall_entry
23312 +
23313 + pax_erase_kstack
23314 +
23315 pushl_cfi %ebx
23316 movl PT_EAX(%esp),%eax /* reload syscall number */
23317 jmp sysenter_do_call
23318 @@ -481,10 +668,16 @@ sysexit_audit:
23319
23320 CFI_ENDPROC
23321 .pushsection .fixup,"ax"
23322 -2: movl $0,PT_FS(%esp)
23323 +4: movl $0,PT_FS(%esp)
23324 + jmp 1b
23325 +5: movl $0,PT_DS(%esp)
23326 + jmp 1b
23327 +6: movl $0,PT_ES(%esp)
23328 jmp 1b
23329 .popsection
23330 - _ASM_EXTABLE(1b,2b)
23331 + _ASM_EXTABLE(1b,4b)
23332 + _ASM_EXTABLE(2b,5b)
23333 + _ASM_EXTABLE(3b,6b)
23334 PTGS_TO_GS_EX
23335 ENDPROC(ia32_sysenter_target)
23336
23337 @@ -495,6 +688,11 @@ ENTRY(system_call)
23338 pushl_cfi %eax # save orig_eax
23339 SAVE_ALL
23340 GET_THREAD_INFO(%ebp)
23341 +
23342 +#ifdef CONFIG_PAX_RANDKSTACK
23343 + pax_erase_kstack
23344 +#endif
23345 +
23346 # system call tracing in operation / emulation
23347 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
23348 jnz syscall_trace_entry
23349 @@ -514,6 +712,15 @@ syscall_exit:
23350 testl $_TIF_ALLWORK_MASK, %ecx # current->work
23351 jne syscall_exit_work
23352
23353 +restore_all_pax:
23354 +
23355 +#ifdef CONFIG_PAX_RANDKSTACK
23356 + movl %esp, %eax
23357 + call pax_randomize_kstack
23358 +#endif
23359 +
23360 + pax_erase_kstack
23361 +
23362 restore_all:
23363 TRACE_IRQS_IRET
23364 restore_all_notrace:
23365 @@ -568,14 +775,34 @@ ldt_ss:
23366 * compensating for the offset by changing to the ESPFIX segment with
23367 * a base address that matches for the difference.
23368 */
23369 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
23370 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
23371 mov %esp, %edx /* load kernel esp */
23372 mov PT_OLDESP(%esp), %eax /* load userspace esp */
23373 mov %dx, %ax /* eax: new kernel esp */
23374 sub %eax, %edx /* offset (low word is 0) */
23375 +#ifdef CONFIG_SMP
23376 + movl PER_CPU_VAR(cpu_number), %ebx
23377 + shll $PAGE_SHIFT_asm, %ebx
23378 + addl $cpu_gdt_table, %ebx
23379 +#else
23380 + movl $cpu_gdt_table, %ebx
23381 +#endif
23382 shr $16, %edx
23383 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
23384 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
23385 +
23386 +#ifdef CONFIG_PAX_KERNEXEC
23387 + mov %cr0, %esi
23388 + btr $16, %esi
23389 + mov %esi, %cr0
23390 +#endif
23391 +
23392 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
23393 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
23394 +
23395 +#ifdef CONFIG_PAX_KERNEXEC
23396 + bts $16, %esi
23397 + mov %esi, %cr0
23398 +#endif
23399 +
23400 pushl_cfi $__ESPFIX_SS
23401 pushl_cfi %eax /* new kernel esp */
23402 /* Disable interrupts, but do not irqtrace this section: we
23403 @@ -605,20 +832,18 @@ work_resched:
23404 movl TI_flags(%ebp), %ecx
23405 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
23406 # than syscall tracing?
23407 - jz restore_all
23408 + jz restore_all_pax
23409 testb $_TIF_NEED_RESCHED, %cl
23410 jnz work_resched
23411
23412 work_notifysig: # deal with pending signals and
23413 # notify-resume requests
23414 + movl %esp, %eax
23415 #ifdef CONFIG_VM86
23416 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
23417 - movl %esp, %eax
23418 jne work_notifysig_v86 # returning to kernel-space or
23419 # vm86-space
23420 1:
23421 -#else
23422 - movl %esp, %eax
23423 #endif
23424 TRACE_IRQS_ON
23425 ENABLE_INTERRUPTS(CLBR_NONE)
23426 @@ -639,7 +864,7 @@ work_notifysig_v86:
23427 movl %eax, %esp
23428 jmp 1b
23429 #endif
23430 -END(work_pending)
23431 +ENDPROC(work_pending)
23432
23433 # perform syscall exit tracing
23434 ALIGN
23435 @@ -647,11 +872,14 @@ syscall_trace_entry:
23436 movl $-ENOSYS,PT_EAX(%esp)
23437 movl %esp, %eax
23438 call syscall_trace_enter
23439 +
23440 + pax_erase_kstack
23441 +
23442 /* What it returned is what we'll actually use. */
23443 cmpl $(NR_syscalls), %eax
23444 jnae syscall_call
23445 jmp syscall_exit
23446 -END(syscall_trace_entry)
23447 +ENDPROC(syscall_trace_entry)
23448
23449 # perform syscall exit tracing
23450 ALIGN
23451 @@ -664,26 +892,30 @@ syscall_exit_work:
23452 movl %esp, %eax
23453 call syscall_trace_leave
23454 jmp resume_userspace
23455 -END(syscall_exit_work)
23456 +ENDPROC(syscall_exit_work)
23457 CFI_ENDPROC
23458
23459 RING0_INT_FRAME # can't unwind into user space anyway
23460 syscall_fault:
23461 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23462 + push %ss
23463 + pop %ds
23464 +#endif
23465 ASM_CLAC
23466 GET_THREAD_INFO(%ebp)
23467 movl $-EFAULT,PT_EAX(%esp)
23468 jmp resume_userspace
23469 -END(syscall_fault)
23470 +ENDPROC(syscall_fault)
23471
23472 syscall_badsys:
23473 movl $-ENOSYS,%eax
23474 jmp syscall_after_call
23475 -END(syscall_badsys)
23476 +ENDPROC(syscall_badsys)
23477
23478 sysenter_badsys:
23479 movl $-ENOSYS,%eax
23480 jmp sysenter_after_call
23481 -END(sysenter_badsys)
23482 +ENDPROC(sysenter_badsys)
23483 CFI_ENDPROC
23484
23485 .macro FIXUP_ESPFIX_STACK
23486 @@ -696,8 +928,15 @@ END(sysenter_badsys)
23487 */
23488 #ifdef CONFIG_X86_ESPFIX32
23489 /* fixup the stack */
23490 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
23491 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
23492 +#ifdef CONFIG_SMP
23493 + movl PER_CPU_VAR(cpu_number), %ebx
23494 + shll $PAGE_SHIFT_asm, %ebx
23495 + addl $cpu_gdt_table, %ebx
23496 +#else
23497 + movl $cpu_gdt_table, %ebx
23498 +#endif
23499 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
23500 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
23501 shl $16, %eax
23502 addl %esp, %eax /* the adjusted stack pointer */
23503 pushl_cfi $__KERNEL_DS
23504 @@ -753,7 +992,7 @@ vector=vector+1
23505 .endr
23506 2: jmp common_interrupt
23507 .endr
23508 -END(irq_entries_start)
23509 +ENDPROC(irq_entries_start)
23510
23511 .previous
23512 END(interrupt)
23513 @@ -810,7 +1049,7 @@ ENTRY(coprocessor_error)
23514 pushl_cfi $do_coprocessor_error
23515 jmp error_code
23516 CFI_ENDPROC
23517 -END(coprocessor_error)
23518 +ENDPROC(coprocessor_error)
23519
23520 ENTRY(simd_coprocessor_error)
23521 RING0_INT_FRAME
23522 @@ -823,7 +1062,7 @@ ENTRY(simd_coprocessor_error)
23523 .section .altinstructions,"a"
23524 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
23525 .previous
23526 -.section .altinstr_replacement,"ax"
23527 +.section .altinstr_replacement,"a"
23528 663: pushl $do_simd_coprocessor_error
23529 664:
23530 .previous
23531 @@ -832,7 +1071,7 @@ ENTRY(simd_coprocessor_error)
23532 #endif
23533 jmp error_code
23534 CFI_ENDPROC
23535 -END(simd_coprocessor_error)
23536 +ENDPROC(simd_coprocessor_error)
23537
23538 ENTRY(device_not_available)
23539 RING0_INT_FRAME
23540 @@ -841,18 +1080,18 @@ ENTRY(device_not_available)
23541 pushl_cfi $do_device_not_available
23542 jmp error_code
23543 CFI_ENDPROC
23544 -END(device_not_available)
23545 +ENDPROC(device_not_available)
23546
23547 #ifdef CONFIG_PARAVIRT
23548 ENTRY(native_iret)
23549 iret
23550 _ASM_EXTABLE(native_iret, iret_exc)
23551 -END(native_iret)
23552 +ENDPROC(native_iret)
23553
23554 ENTRY(native_irq_enable_sysexit)
23555 sti
23556 sysexit
23557 -END(native_irq_enable_sysexit)
23558 +ENDPROC(native_irq_enable_sysexit)
23559 #endif
23560
23561 ENTRY(overflow)
23562 @@ -862,7 +1101,7 @@ ENTRY(overflow)
23563 pushl_cfi $do_overflow
23564 jmp error_code
23565 CFI_ENDPROC
23566 -END(overflow)
23567 +ENDPROC(overflow)
23568
23569 ENTRY(bounds)
23570 RING0_INT_FRAME
23571 @@ -871,7 +1110,7 @@ ENTRY(bounds)
23572 pushl_cfi $do_bounds
23573 jmp error_code
23574 CFI_ENDPROC
23575 -END(bounds)
23576 +ENDPROC(bounds)
23577
23578 ENTRY(invalid_op)
23579 RING0_INT_FRAME
23580 @@ -880,7 +1119,7 @@ ENTRY(invalid_op)
23581 pushl_cfi $do_invalid_op
23582 jmp error_code
23583 CFI_ENDPROC
23584 -END(invalid_op)
23585 +ENDPROC(invalid_op)
23586
23587 ENTRY(coprocessor_segment_overrun)
23588 RING0_INT_FRAME
23589 @@ -889,7 +1128,7 @@ ENTRY(coprocessor_segment_overrun)
23590 pushl_cfi $do_coprocessor_segment_overrun
23591 jmp error_code
23592 CFI_ENDPROC
23593 -END(coprocessor_segment_overrun)
23594 +ENDPROC(coprocessor_segment_overrun)
23595
23596 ENTRY(invalid_TSS)
23597 RING0_EC_FRAME
23598 @@ -897,7 +1136,7 @@ ENTRY(invalid_TSS)
23599 pushl_cfi $do_invalid_TSS
23600 jmp error_code
23601 CFI_ENDPROC
23602 -END(invalid_TSS)
23603 +ENDPROC(invalid_TSS)
23604
23605 ENTRY(segment_not_present)
23606 RING0_EC_FRAME
23607 @@ -905,7 +1144,7 @@ ENTRY(segment_not_present)
23608 pushl_cfi $do_segment_not_present
23609 jmp error_code
23610 CFI_ENDPROC
23611 -END(segment_not_present)
23612 +ENDPROC(segment_not_present)
23613
23614 ENTRY(stack_segment)
23615 RING0_EC_FRAME
23616 @@ -913,7 +1152,7 @@ ENTRY(stack_segment)
23617 pushl_cfi $do_stack_segment
23618 jmp error_code
23619 CFI_ENDPROC
23620 -END(stack_segment)
23621 +ENDPROC(stack_segment)
23622
23623 ENTRY(alignment_check)
23624 RING0_EC_FRAME
23625 @@ -921,7 +1160,7 @@ ENTRY(alignment_check)
23626 pushl_cfi $do_alignment_check
23627 jmp error_code
23628 CFI_ENDPROC
23629 -END(alignment_check)
23630 +ENDPROC(alignment_check)
23631
23632 ENTRY(divide_error)
23633 RING0_INT_FRAME
23634 @@ -930,7 +1169,7 @@ ENTRY(divide_error)
23635 pushl_cfi $do_divide_error
23636 jmp error_code
23637 CFI_ENDPROC
23638 -END(divide_error)
23639 +ENDPROC(divide_error)
23640
23641 #ifdef CONFIG_X86_MCE
23642 ENTRY(machine_check)
23643 @@ -940,7 +1179,7 @@ ENTRY(machine_check)
23644 pushl_cfi machine_check_vector
23645 jmp error_code
23646 CFI_ENDPROC
23647 -END(machine_check)
23648 +ENDPROC(machine_check)
23649 #endif
23650
23651 ENTRY(spurious_interrupt_bug)
23652 @@ -950,7 +1189,7 @@ ENTRY(spurious_interrupt_bug)
23653 pushl_cfi $do_spurious_interrupt_bug
23654 jmp error_code
23655 CFI_ENDPROC
23656 -END(spurious_interrupt_bug)
23657 +ENDPROC(spurious_interrupt_bug)
23658
23659 #ifdef CONFIG_XEN
23660 /* Xen doesn't set %esp to be precisely what the normal sysenter
23661 @@ -1056,7 +1295,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
23662
23663 ENTRY(mcount)
23664 ret
23665 -END(mcount)
23666 +ENDPROC(mcount)
23667
23668 ENTRY(ftrace_caller)
23669 pushl %eax
23670 @@ -1086,7 +1325,7 @@ ftrace_graph_call:
23671 .globl ftrace_stub
23672 ftrace_stub:
23673 ret
23674 -END(ftrace_caller)
23675 +ENDPROC(ftrace_caller)
23676
23677 ENTRY(ftrace_regs_caller)
23678 pushf /* push flags before compare (in cs location) */
23679 @@ -1184,7 +1423,7 @@ trace:
23680 popl %ecx
23681 popl %eax
23682 jmp ftrace_stub
23683 -END(mcount)
23684 +ENDPROC(mcount)
23685 #endif /* CONFIG_DYNAMIC_FTRACE */
23686 #endif /* CONFIG_FUNCTION_TRACER */
23687
23688 @@ -1202,7 +1441,7 @@ ENTRY(ftrace_graph_caller)
23689 popl %ecx
23690 popl %eax
23691 ret
23692 -END(ftrace_graph_caller)
23693 +ENDPROC(ftrace_graph_caller)
23694
23695 .globl return_to_handler
23696 return_to_handler:
23697 @@ -1263,15 +1502,18 @@ error_code:
23698 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
23699 REG_TO_PTGS %ecx
23700 SET_KERNEL_GS %ecx
23701 - movl $(__USER_DS), %ecx
23702 + movl $(__KERNEL_DS), %ecx
23703 movl %ecx, %ds
23704 movl %ecx, %es
23705 +
23706 + pax_enter_kernel
23707 +
23708 TRACE_IRQS_OFF
23709 movl %esp,%eax # pt_regs pointer
23710 call *%edi
23711 jmp ret_from_exception
23712 CFI_ENDPROC
23713 -END(page_fault)
23714 +ENDPROC(page_fault)
23715
23716 /*
23717 * Debug traps and NMI can happen at the one SYSENTER instruction
23718 @@ -1314,7 +1556,7 @@ debug_stack_correct:
23719 call do_debug
23720 jmp ret_from_exception
23721 CFI_ENDPROC
23722 -END(debug)
23723 +ENDPROC(debug)
23724
23725 /*
23726 * NMI is doubly nasty. It can happen _while_ we're handling
23727 @@ -1354,6 +1596,9 @@ nmi_stack_correct:
23728 xorl %edx,%edx # zero error code
23729 movl %esp,%eax # pt_regs pointer
23730 call do_nmi
23731 +
23732 + pax_exit_kernel
23733 +
23734 jmp restore_all_notrace
23735 CFI_ENDPROC
23736
23737 @@ -1391,13 +1636,16 @@ nmi_espfix_stack:
23738 FIXUP_ESPFIX_STACK # %eax == %esp
23739 xorl %edx,%edx # zero error code
23740 call do_nmi
23741 +
23742 + pax_exit_kernel
23743 +
23744 RESTORE_REGS
23745 lss 12+4(%esp), %esp # back to espfix stack
23746 CFI_ADJUST_CFA_OFFSET -24
23747 jmp irq_return
23748 #endif
23749 CFI_ENDPROC
23750 -END(nmi)
23751 +ENDPROC(nmi)
23752
23753 ENTRY(int3)
23754 RING0_INT_FRAME
23755 @@ -1410,14 +1658,14 @@ ENTRY(int3)
23756 call do_int3
23757 jmp ret_from_exception
23758 CFI_ENDPROC
23759 -END(int3)
23760 +ENDPROC(int3)
23761
23762 ENTRY(general_protection)
23763 RING0_EC_FRAME
23764 pushl_cfi $do_general_protection
23765 jmp error_code
23766 CFI_ENDPROC
23767 -END(general_protection)
23768 +ENDPROC(general_protection)
23769
23770 #ifdef CONFIG_KVM_GUEST
23771 ENTRY(async_page_fault)
23772 @@ -1426,6 +1674,6 @@ ENTRY(async_page_fault)
23773 pushl_cfi $do_async_page_fault
23774 jmp error_code
23775 CFI_ENDPROC
23776 -END(async_page_fault)
23777 +ENDPROC(async_page_fault)
23778 #endif
23779
23780 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
23781 index 2fac134..b020fca 100644
23782 --- a/arch/x86/kernel/entry_64.S
23783 +++ b/arch/x86/kernel/entry_64.S
23784 @@ -59,6 +59,8 @@
23785 #include <asm/smap.h>
23786 #include <asm/pgtable_types.h>
23787 #include <linux/err.h>
23788 +#include <asm/pgtable.h>
23789 +#include <asm/alternative-asm.h>
23790
23791 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
23792 #include <linux/elf-em.h>
23793 @@ -81,6 +83,430 @@ ENTRY(native_usergs_sysret64)
23794 ENDPROC(native_usergs_sysret64)
23795 #endif /* CONFIG_PARAVIRT */
23796
23797 + .macro ljmpq sel, off
23798 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
23799 + .byte 0x48; ljmp *1234f(%rip)
23800 + .pushsection .rodata
23801 + .align 16
23802 + 1234: .quad \off; .word \sel
23803 + .popsection
23804 +#else
23805 + pushq $\sel
23806 + pushq $\off
23807 + lretq
23808 +#endif
23809 + .endm
23810 +
23811 + .macro pax_enter_kernel
23812 + pax_set_fptr_mask
23813 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23814 + call pax_enter_kernel
23815 +#endif
23816 + .endm
23817 +
23818 + .macro pax_exit_kernel
23819 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23820 + call pax_exit_kernel
23821 +#endif
23822 +
23823 + .endm
23824 +
23825 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23826 +ENTRY(pax_enter_kernel)
23827 + pushq %rdi
23828 +
23829 +#ifdef CONFIG_PARAVIRT
23830 + PV_SAVE_REGS(CLBR_RDI)
23831 +#endif
23832 +
23833 +#ifdef CONFIG_PAX_KERNEXEC
23834 + GET_CR0_INTO_RDI
23835 + bts $16,%rdi
23836 + jnc 3f
23837 + mov %cs,%edi
23838 + cmp $__KERNEL_CS,%edi
23839 + jnz 2f
23840 +1:
23841 +#endif
23842 +
23843 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23844 + 661: jmp 111f
23845 + .pushsection .altinstr_replacement, "a"
23846 + 662: ASM_NOP2
23847 + .popsection
23848 + .pushsection .altinstructions, "a"
23849 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23850 + .popsection
23851 + GET_CR3_INTO_RDI
23852 + cmp $0,%dil
23853 + jnz 112f
23854 + mov $__KERNEL_DS,%edi
23855 + mov %edi,%ss
23856 + jmp 111f
23857 +112: cmp $1,%dil
23858 + jz 113f
23859 + ud2
23860 +113: sub $4097,%rdi
23861 + bts $63,%rdi
23862 + SET_RDI_INTO_CR3
23863 + mov $__UDEREF_KERNEL_DS,%edi
23864 + mov %edi,%ss
23865 +111:
23866 +#endif
23867 +
23868 +#ifdef CONFIG_PARAVIRT
23869 + PV_RESTORE_REGS(CLBR_RDI)
23870 +#endif
23871 +
23872 + popq %rdi
23873 + pax_force_retaddr
23874 + retq
23875 +
23876 +#ifdef CONFIG_PAX_KERNEXEC
23877 +2: ljmpq __KERNEL_CS,1b
23878 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
23879 +4: SET_RDI_INTO_CR0
23880 + jmp 1b
23881 +#endif
23882 +ENDPROC(pax_enter_kernel)
23883 +
23884 +ENTRY(pax_exit_kernel)
23885 + pushq %rdi
23886 +
23887 +#ifdef CONFIG_PARAVIRT
23888 + PV_SAVE_REGS(CLBR_RDI)
23889 +#endif
23890 +
23891 +#ifdef CONFIG_PAX_KERNEXEC
23892 + mov %cs,%rdi
23893 + cmp $__KERNEXEC_KERNEL_CS,%edi
23894 + jz 2f
23895 + GET_CR0_INTO_RDI
23896 + bts $16,%rdi
23897 + jnc 4f
23898 +1:
23899 +#endif
23900 +
23901 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23902 + 661: jmp 111f
23903 + .pushsection .altinstr_replacement, "a"
23904 + 662: ASM_NOP2
23905 + .popsection
23906 + .pushsection .altinstructions, "a"
23907 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23908 + .popsection
23909 + mov %ss,%edi
23910 + cmp $__UDEREF_KERNEL_DS,%edi
23911 + jnz 111f
23912 + GET_CR3_INTO_RDI
23913 + cmp $0,%dil
23914 + jz 112f
23915 + ud2
23916 +112: add $4097,%rdi
23917 + bts $63,%rdi
23918 + SET_RDI_INTO_CR3
23919 + mov $__KERNEL_DS,%edi
23920 + mov %edi,%ss
23921 +111:
23922 +#endif
23923 +
23924 +#ifdef CONFIG_PARAVIRT
23925 + PV_RESTORE_REGS(CLBR_RDI);
23926 +#endif
23927 +
23928 + popq %rdi
23929 + pax_force_retaddr
23930 + retq
23931 +
23932 +#ifdef CONFIG_PAX_KERNEXEC
23933 +2: GET_CR0_INTO_RDI
23934 + btr $16,%rdi
23935 + jnc 4f
23936 + ljmpq __KERNEL_CS,3f
23937 +3: SET_RDI_INTO_CR0
23938 + jmp 1b
23939 +4: ud2
23940 + jmp 4b
23941 +#endif
23942 +ENDPROC(pax_exit_kernel)
23943 +#endif
23944 +
23945 + .macro pax_enter_kernel_user
23946 + pax_set_fptr_mask
23947 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23948 + call pax_enter_kernel_user
23949 +#endif
23950 + .endm
23951 +
23952 + .macro pax_exit_kernel_user
23953 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23954 + call pax_exit_kernel_user
23955 +#endif
23956 +#ifdef CONFIG_PAX_RANDKSTACK
23957 + pushq %rax
23958 + pushq %r11
23959 + call pax_randomize_kstack
23960 + popq %r11
23961 + popq %rax
23962 +#endif
23963 + .endm
23964 +
23965 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23966 +ENTRY(pax_enter_kernel_user)
23967 + pushq %rdi
23968 + pushq %rbx
23969 +
23970 +#ifdef CONFIG_PARAVIRT
23971 + PV_SAVE_REGS(CLBR_RDI)
23972 +#endif
23973 +
23974 + 661: jmp 111f
23975 + .pushsection .altinstr_replacement, "a"
23976 + 662: ASM_NOP2
23977 + .popsection
23978 + .pushsection .altinstructions, "a"
23979 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23980 + .popsection
23981 + GET_CR3_INTO_RDI
23982 + cmp $1,%dil
23983 + jnz 4f
23984 + sub $4097,%rdi
23985 + bts $63,%rdi
23986 + SET_RDI_INTO_CR3
23987 + jmp 3f
23988 +111:
23989 +
23990 + GET_CR3_INTO_RDI
23991 + mov %rdi,%rbx
23992 + add $__START_KERNEL_map,%rbx
23993 + sub phys_base(%rip),%rbx
23994 +
23995 +#ifdef CONFIG_PARAVIRT
23996 + cmpl $0, pv_info+PARAVIRT_enabled
23997 + jz 1f
23998 + pushq %rdi
23999 + i = 0
24000 + .rept USER_PGD_PTRS
24001 + mov i*8(%rbx),%rsi
24002 + mov $0,%sil
24003 + lea i*8(%rbx),%rdi
24004 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
24005 + i = i + 1
24006 + .endr
24007 + popq %rdi
24008 + jmp 2f
24009 +1:
24010 +#endif
24011 +
24012 + i = 0
24013 + .rept USER_PGD_PTRS
24014 + movb $0,i*8(%rbx)
24015 + i = i + 1
24016 + .endr
24017 +
24018 +2: SET_RDI_INTO_CR3
24019 +
24020 +#ifdef CONFIG_PAX_KERNEXEC
24021 + GET_CR0_INTO_RDI
24022 + bts $16,%rdi
24023 + SET_RDI_INTO_CR0
24024 +#endif
24025 +
24026 +3:
24027 +
24028 +#ifdef CONFIG_PARAVIRT
24029 + PV_RESTORE_REGS(CLBR_RDI)
24030 +#endif
24031 +
24032 + popq %rbx
24033 + popq %rdi
24034 + pax_force_retaddr
24035 + retq
24036 +4: ud2
24037 +ENDPROC(pax_enter_kernel_user)
24038 +
24039 +ENTRY(pax_exit_kernel_user)
24040 + pushq %rdi
24041 + pushq %rbx
24042 +
24043 +#ifdef CONFIG_PARAVIRT
24044 + PV_SAVE_REGS(CLBR_RDI)
24045 +#endif
24046 +
24047 + GET_CR3_INTO_RDI
24048 + 661: jmp 1f
24049 + .pushsection .altinstr_replacement, "a"
24050 + 662: ASM_NOP2
24051 + .popsection
24052 + .pushsection .altinstructions, "a"
24053 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
24054 + .popsection
24055 + cmp $0,%dil
24056 + jnz 3f
24057 + add $4097,%rdi
24058 + bts $63,%rdi
24059 + SET_RDI_INTO_CR3
24060 + jmp 2f
24061 +1:
24062 +
24063 + mov %rdi,%rbx
24064 +
24065 +#ifdef CONFIG_PAX_KERNEXEC
24066 + GET_CR0_INTO_RDI
24067 + btr $16,%rdi
24068 + jnc 3f
24069 + SET_RDI_INTO_CR0
24070 +#endif
24071 +
24072 + add $__START_KERNEL_map,%rbx
24073 + sub phys_base(%rip),%rbx
24074 +
24075 +#ifdef CONFIG_PARAVIRT
24076 + cmpl $0, pv_info+PARAVIRT_enabled
24077 + jz 1f
24078 + i = 0
24079 + .rept USER_PGD_PTRS
24080 + mov i*8(%rbx),%rsi
24081 + mov $0x67,%sil
24082 + lea i*8(%rbx),%rdi
24083 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
24084 + i = i + 1
24085 + .endr
24086 + jmp 2f
24087 +1:
24088 +#endif
24089 +
24090 + i = 0
24091 + .rept USER_PGD_PTRS
24092 + movb $0x67,i*8(%rbx)
24093 + i = i + 1
24094 + .endr
24095 +2:
24096 +
24097 +#ifdef CONFIG_PARAVIRT
24098 + PV_RESTORE_REGS(CLBR_RDI)
24099 +#endif
24100 +
24101 + popq %rbx
24102 + popq %rdi
24103 + pax_force_retaddr
24104 + retq
24105 +3: ud2
24106 +ENDPROC(pax_exit_kernel_user)
24107 +#endif
24108 +
24109 + .macro pax_enter_kernel_nmi
24110 + pax_set_fptr_mask
24111 +
24112 +#ifdef CONFIG_PAX_KERNEXEC
24113 + GET_CR0_INTO_RDI
24114 + bts $16,%rdi
24115 + jc 110f
24116 + SET_RDI_INTO_CR0
24117 + or $2,%ebx
24118 +110:
24119 +#endif
24120 +
24121 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24122 + 661: jmp 111f
24123 + .pushsection .altinstr_replacement, "a"
24124 + 662: ASM_NOP2
24125 + .popsection
24126 + .pushsection .altinstructions, "a"
24127 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
24128 + .popsection
24129 + GET_CR3_INTO_RDI
24130 + cmp $0,%dil
24131 + jz 111f
24132 + sub $4097,%rdi
24133 + or $4,%ebx
24134 + bts $63,%rdi
24135 + SET_RDI_INTO_CR3
24136 + mov $__UDEREF_KERNEL_DS,%edi
24137 + mov %edi,%ss
24138 +111:
24139 +#endif
24140 + .endm
24141 +
24142 + .macro pax_exit_kernel_nmi
24143 +#ifdef CONFIG_PAX_KERNEXEC
24144 + btr $1,%ebx
24145 + jnc 110f
24146 + GET_CR0_INTO_RDI
24147 + btr $16,%rdi
24148 + SET_RDI_INTO_CR0
24149 +110:
24150 +#endif
24151 +
24152 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24153 + btr $2,%ebx
24154 + jnc 111f
24155 + GET_CR3_INTO_RDI
24156 + add $4097,%rdi
24157 + bts $63,%rdi
24158 + SET_RDI_INTO_CR3
24159 + mov $__KERNEL_DS,%edi
24160 + mov %edi,%ss
24161 +111:
24162 +#endif
24163 + .endm
24164 +
24165 + .macro pax_erase_kstack
24166 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
24167 + call pax_erase_kstack
24168 +#endif
24169 + .endm
24170 +
24171 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
24172 +ENTRY(pax_erase_kstack)
24173 + pushq %rdi
24174 + pushq %rcx
24175 + pushq %rax
24176 + pushq %r11
24177 +
24178 + GET_THREAD_INFO(%r11)
24179 + mov TI_lowest_stack(%r11), %rdi
24180 + mov $-0xBEEF, %rax
24181 + std
24182 +
24183 +1: mov %edi, %ecx
24184 + and $THREAD_SIZE_asm - 1, %ecx
24185 + shr $3, %ecx
24186 + repne scasq
24187 + jecxz 2f
24188 +
24189 + cmp $2*8, %ecx
24190 + jc 2f
24191 +
24192 + mov $2*8, %ecx
24193 + repe scasq
24194 + jecxz 2f
24195 + jne 1b
24196 +
24197 +2: cld
24198 + mov %esp, %ecx
24199 + sub %edi, %ecx
24200 +
24201 + cmp $THREAD_SIZE_asm, %rcx
24202 + jb 3f
24203 + ud2
24204 +3:
24205 +
24206 + shr $3, %ecx
24207 + rep stosq
24208 +
24209 + mov TI_task_thread_sp0(%r11), %rdi
24210 + sub $256, %rdi
24211 + mov %rdi, TI_lowest_stack(%r11)
24212 +
24213 + popq %r11
24214 + popq %rax
24215 + popq %rcx
24216 + popq %rdi
24217 + pax_force_retaddr
24218 + ret
24219 +ENDPROC(pax_erase_kstack)
24220 +#endif
24221
24222 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
24223 #ifdef CONFIG_TRACE_IRQFLAGS
24224 @@ -117,7 +543,7 @@ ENDPROC(native_usergs_sysret64)
24225 .endm
24226
24227 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
24228 - bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
24229 + bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
24230 jnc 1f
24231 TRACE_IRQS_ON_DEBUG
24232 1:
24233 @@ -155,27 +581,6 @@ ENDPROC(native_usergs_sysret64)
24234 movq \tmp,R11+\offset(%rsp)
24235 .endm
24236
24237 - .macro FAKE_STACK_FRAME child_rip
24238 - /* push in order ss, rsp, eflags, cs, rip */
24239 - xorl %eax, %eax
24240 - pushq_cfi $__KERNEL_DS /* ss */
24241 - /*CFI_REL_OFFSET ss,0*/
24242 - pushq_cfi %rax /* rsp */
24243 - CFI_REL_OFFSET rsp,0
24244 - pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
24245 - /*CFI_REL_OFFSET rflags,0*/
24246 - pushq_cfi $__KERNEL_CS /* cs */
24247 - /*CFI_REL_OFFSET cs,0*/
24248 - pushq_cfi \child_rip /* rip */
24249 - CFI_REL_OFFSET rip,0
24250 - pushq_cfi %rax /* orig rax */
24251 - .endm
24252 -
24253 - .macro UNFAKE_STACK_FRAME
24254 - addq $8*6, %rsp
24255 - CFI_ADJUST_CFA_OFFSET -(6*8)
24256 - .endm
24257 -
24258 /*
24259 * initial frame state for interrupts (and exceptions without error code)
24260 */
24261 @@ -241,25 +646,26 @@ ENDPROC(native_usergs_sysret64)
24262 /* save partial stack frame */
24263 .macro SAVE_ARGS_IRQ
24264 cld
24265 - /* start from rbp in pt_regs and jump over */
24266 - movq_cfi rdi, (RDI-RBP)
24267 - movq_cfi rsi, (RSI-RBP)
24268 - movq_cfi rdx, (RDX-RBP)
24269 - movq_cfi rcx, (RCX-RBP)
24270 - movq_cfi rax, (RAX-RBP)
24271 - movq_cfi r8, (R8-RBP)
24272 - movq_cfi r9, (R9-RBP)
24273 - movq_cfi r10, (R10-RBP)
24274 - movq_cfi r11, (R11-RBP)
24275 + /* start from r15 in pt_regs and jump over */
24276 + movq_cfi rdi, RDI
24277 + movq_cfi rsi, RSI
24278 + movq_cfi rdx, RDX
24279 + movq_cfi rcx, RCX
24280 + movq_cfi rax, RAX
24281 + movq_cfi r8, R8
24282 + movq_cfi r9, R9
24283 + movq_cfi r10, R10
24284 + movq_cfi r11, R11
24285 + movq_cfi r12, R12
24286
24287 /* Save rbp so that we can unwind from get_irq_regs() */
24288 - movq_cfi rbp, 0
24289 + movq_cfi rbp, RBP
24290
24291 /* Save previous stack value */
24292 movq %rsp, %rsi
24293
24294 - leaq -RBP(%rsp),%rdi /* arg1 for handler */
24295 - testl $3, CS-RBP(%rsi)
24296 + movq %rsp,%rdi /* arg1 for handler */
24297 + testb $3, CS(%rsi)
24298 je 1f
24299 SWAPGS
24300 /*
24301 @@ -279,6 +685,18 @@ ENDPROC(native_usergs_sysret64)
24302 0x06 /* DW_OP_deref */, \
24303 0x08 /* DW_OP_const1u */, SS+8-RBP, \
24304 0x22 /* DW_OP_plus */
24305 +
24306 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24307 + testb $3, CS(%rdi)
24308 + jnz 1f
24309 + pax_enter_kernel
24310 + jmp 2f
24311 +1: pax_enter_kernel_user
24312 +2:
24313 +#else
24314 + pax_enter_kernel
24315 +#endif
24316 +
24317 /* We entered an interrupt context - irqs are off: */
24318 TRACE_IRQS_OFF
24319 .endm
24320 @@ -308,9 +726,52 @@ ENTRY(save_paranoid)
24321 js 1f /* negative -> in kernel */
24322 SWAPGS
24323 xorl %ebx,%ebx
24324 -1: ret
24325 +1:
24326 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24327 + testb $3, CS+8(%rsp)
24328 + jnz 1f
24329 + pax_enter_kernel
24330 + jmp 2f
24331 +1: pax_enter_kernel_user
24332 +2:
24333 +#else
24334 + pax_enter_kernel
24335 +#endif
24336 + pax_force_retaddr
24337 + ret
24338 CFI_ENDPROC
24339 -END(save_paranoid)
24340 +ENDPROC(save_paranoid)
24341 +
24342 +ENTRY(save_paranoid_nmi)
24343 + XCPT_FRAME 1 RDI+8
24344 + cld
24345 + movq_cfi rdi, RDI+8
24346 + movq_cfi rsi, RSI+8
24347 + movq_cfi rdx, RDX+8
24348 + movq_cfi rcx, RCX+8
24349 + movq_cfi rax, RAX+8
24350 + movq_cfi r8, R8+8
24351 + movq_cfi r9, R9+8
24352 + movq_cfi r10, R10+8
24353 + movq_cfi r11, R11+8
24354 + movq_cfi rbx, RBX+8
24355 + movq_cfi rbp, RBP+8
24356 + movq_cfi r12, R12+8
24357 + movq_cfi r13, R13+8
24358 + movq_cfi r14, R14+8
24359 + movq_cfi r15, R15+8
24360 + movl $1,%ebx
24361 + movl $MSR_GS_BASE,%ecx
24362 + rdmsr
24363 + testl %edx,%edx
24364 + js 1f /* negative -> in kernel */
24365 + SWAPGS
24366 + xorl %ebx,%ebx
24367 +1: pax_enter_kernel_nmi
24368 + pax_force_retaddr
24369 + ret
24370 + CFI_ENDPROC
24371 +ENDPROC(save_paranoid_nmi)
24372
24373 /*
24374 * A newly forked process directly context switches into this address.
24375 @@ -331,7 +792,7 @@ ENTRY(ret_from_fork)
24376
24377 RESTORE_REST
24378
24379 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
24380 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
24381 jz 1f
24382
24383 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
24384 @@ -341,15 +802,13 @@ ENTRY(ret_from_fork)
24385 jmp ret_from_sys_call # go to the SYSRET fastpath
24386
24387 1:
24388 - subq $REST_SKIP, %rsp # leave space for volatiles
24389 - CFI_ADJUST_CFA_OFFSET REST_SKIP
24390 movq %rbp, %rdi
24391 call *%rbx
24392 movl $0, RAX(%rsp)
24393 RESTORE_REST
24394 jmp int_ret_from_sys_call
24395 CFI_ENDPROC
24396 -END(ret_from_fork)
24397 +ENDPROC(ret_from_fork)
24398
24399 /*
24400 * System call entry. Up to 6 arguments in registers are supported.
24401 @@ -386,7 +845,7 @@ END(ret_from_fork)
24402 ENTRY(system_call)
24403 CFI_STARTPROC simple
24404 CFI_SIGNAL_FRAME
24405 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
24406 + CFI_DEF_CFA rsp,0
24407 CFI_REGISTER rip,rcx
24408 /*CFI_REGISTER rflags,r11*/
24409 SWAPGS_UNSAFE_STACK
24410 @@ -399,16 +858,23 @@ GLOBAL(system_call_after_swapgs)
24411
24412 movq %rsp,PER_CPU_VAR(old_rsp)
24413 movq PER_CPU_VAR(kernel_stack),%rsp
24414 + SAVE_ARGS 8*6,0
24415 + pax_enter_kernel_user
24416 +
24417 +#ifdef CONFIG_PAX_RANDKSTACK
24418 + pax_erase_kstack
24419 +#endif
24420 +
24421 /*
24422 * No need to follow this irqs off/on section - it's straight
24423 * and short:
24424 */
24425 ENABLE_INTERRUPTS(CLBR_NONE)
24426 - SAVE_ARGS 8,0
24427 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
24428 movq %rcx,RIP-ARGOFFSET(%rsp)
24429 CFI_REL_OFFSET rip,RIP-ARGOFFSET
24430 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
24431 + GET_THREAD_INFO(%rcx)
24432 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
24433 jnz tracesys
24434 system_call_fastpath:
24435 #if __SYSCALL_MASK == ~0
24436 @@ -432,10 +898,13 @@ sysret_check:
24437 LOCKDEP_SYS_EXIT
24438 DISABLE_INTERRUPTS(CLBR_NONE)
24439 TRACE_IRQS_OFF
24440 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
24441 + GET_THREAD_INFO(%rcx)
24442 + movl TI_flags(%rcx),%edx
24443 andl %edi,%edx
24444 jnz sysret_careful
24445 CFI_REMEMBER_STATE
24446 + pax_exit_kernel_user
24447 + pax_erase_kstack
24448 /*
24449 * sysretq will re-enable interrupts:
24450 */
24451 @@ -494,6 +963,9 @@ auditsys:
24452 movq %rax,%rsi /* 2nd arg: syscall number */
24453 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
24454 call __audit_syscall_entry
24455 +
24456 + pax_erase_kstack
24457 +
24458 LOAD_ARGS 0 /* reload call-clobbered registers */
24459 jmp system_call_fastpath
24460
24461 @@ -515,7 +987,7 @@ sysret_audit:
24462 /* Do syscall tracing */
24463 tracesys:
24464 #ifdef CONFIG_AUDITSYSCALL
24465 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
24466 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
24467 jz auditsys
24468 #endif
24469 SAVE_REST
24470 @@ -523,12 +995,15 @@ tracesys:
24471 FIXUP_TOP_OF_STACK %rdi
24472 movq %rsp,%rdi
24473 call syscall_trace_enter
24474 +
24475 + pax_erase_kstack
24476 +
24477 /*
24478 * Reload arg registers from stack in case ptrace changed them.
24479 * We don't reload %rax because syscall_trace_enter() returned
24480 * the value it wants us to use in the table lookup.
24481 */
24482 - LOAD_ARGS ARGOFFSET, 1
24483 + LOAD_ARGS 1
24484 RESTORE_REST
24485 #if __SYSCALL_MASK == ~0
24486 cmpq $__NR_syscall_max,%rax
24487 @@ -558,7 +1033,9 @@ GLOBAL(int_with_check)
24488 andl %edi,%edx
24489 jnz int_careful
24490 andl $~TS_COMPAT,TI_status(%rcx)
24491 - jmp retint_swapgs
24492 + pax_exit_kernel_user
24493 + pax_erase_kstack
24494 + jmp retint_swapgs_pax
24495
24496 /* Either reschedule or signal or syscall exit tracking needed. */
24497 /* First do a reschedule test. */
24498 @@ -604,7 +1081,7 @@ int_restore_rest:
24499 TRACE_IRQS_OFF
24500 jmp int_with_check
24501 CFI_ENDPROC
24502 -END(system_call)
24503 +ENDPROC(system_call)
24504
24505 .macro FORK_LIKE func
24506 ENTRY(stub_\func)
24507 @@ -617,9 +1094,10 @@ ENTRY(stub_\func)
24508 DEFAULT_FRAME 0 8 /* offset 8: return address */
24509 call sys_\func
24510 RESTORE_TOP_OF_STACK %r11, 8
24511 - ret $REST_SKIP /* pop extended registers */
24512 + pax_force_retaddr
24513 + ret
24514 CFI_ENDPROC
24515 -END(stub_\func)
24516 +ENDPROC(stub_\func)
24517 .endm
24518
24519 .macro FIXED_FRAME label,func
24520 @@ -629,9 +1107,10 @@ ENTRY(\label)
24521 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
24522 call \func
24523 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
24524 + pax_force_retaddr
24525 ret
24526 CFI_ENDPROC
24527 -END(\label)
24528 +ENDPROC(\label)
24529 .endm
24530
24531 FORK_LIKE clone
24532 @@ -639,19 +1118,6 @@ END(\label)
24533 FORK_LIKE vfork
24534 FIXED_FRAME stub_iopl, sys_iopl
24535
24536 -ENTRY(ptregscall_common)
24537 - DEFAULT_FRAME 1 8 /* offset 8: return address */
24538 - RESTORE_TOP_OF_STACK %r11, 8
24539 - movq_cfi_restore R15+8, r15
24540 - movq_cfi_restore R14+8, r14
24541 - movq_cfi_restore R13+8, r13
24542 - movq_cfi_restore R12+8, r12
24543 - movq_cfi_restore RBP+8, rbp
24544 - movq_cfi_restore RBX+8, rbx
24545 - ret $REST_SKIP /* pop extended registers */
24546 - CFI_ENDPROC
24547 -END(ptregscall_common)
24548 -
24549 ENTRY(stub_execve)
24550 CFI_STARTPROC
24551 addq $8, %rsp
24552 @@ -663,7 +1129,7 @@ ENTRY(stub_execve)
24553 RESTORE_REST
24554 jmp int_ret_from_sys_call
24555 CFI_ENDPROC
24556 -END(stub_execve)
24557 +ENDPROC(stub_execve)
24558
24559 /*
24560 * sigreturn is special because it needs to restore all registers on return.
24561 @@ -680,7 +1146,7 @@ ENTRY(stub_rt_sigreturn)
24562 RESTORE_REST
24563 jmp int_ret_from_sys_call
24564 CFI_ENDPROC
24565 -END(stub_rt_sigreturn)
24566 +ENDPROC(stub_rt_sigreturn)
24567
24568 #ifdef CONFIG_X86_X32_ABI
24569 ENTRY(stub_x32_rt_sigreturn)
24570 @@ -694,7 +1160,7 @@ ENTRY(stub_x32_rt_sigreturn)
24571 RESTORE_REST
24572 jmp int_ret_from_sys_call
24573 CFI_ENDPROC
24574 -END(stub_x32_rt_sigreturn)
24575 +ENDPROC(stub_x32_rt_sigreturn)
24576
24577 ENTRY(stub_x32_execve)
24578 CFI_STARTPROC
24579 @@ -708,7 +1174,7 @@ ENTRY(stub_x32_execve)
24580 RESTORE_REST
24581 jmp int_ret_from_sys_call
24582 CFI_ENDPROC
24583 -END(stub_x32_execve)
24584 +ENDPROC(stub_x32_execve)
24585
24586 #endif
24587
24588 @@ -745,7 +1211,7 @@ vector=vector+1
24589 2: jmp common_interrupt
24590 .endr
24591 CFI_ENDPROC
24592 -END(irq_entries_start)
24593 +ENDPROC(irq_entries_start)
24594
24595 .previous
24596 END(interrupt)
24597 @@ -762,8 +1228,8 @@ END(interrupt)
24598 /* 0(%rsp): ~(interrupt number) */
24599 .macro interrupt func
24600 /* reserve pt_regs for scratch regs and rbp */
24601 - subq $ORIG_RAX-RBP, %rsp
24602 - CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
24603 + subq $ORIG_RAX, %rsp
24604 + CFI_ADJUST_CFA_OFFSET ORIG_RAX
24605 SAVE_ARGS_IRQ
24606 call \func
24607 .endm
24608 @@ -786,14 +1252,14 @@ ret_from_intr:
24609
24610 /* Restore saved previous stack */
24611 popq %rsi
24612 - CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
24613 - leaq ARGOFFSET-RBP(%rsi), %rsp
24614 + CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
24615 + movq %rsi, %rsp
24616 CFI_DEF_CFA_REGISTER rsp
24617 - CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
24618 + CFI_ADJUST_CFA_OFFSET -ARGOFFSET
24619
24620 exit_intr:
24621 GET_THREAD_INFO(%rcx)
24622 - testl $3,CS-ARGOFFSET(%rsp)
24623 + testb $3,CS-ARGOFFSET(%rsp)
24624 je retint_kernel
24625
24626 /* Interrupt came from user space */
24627 @@ -815,12 +1281,35 @@ retint_swapgs: /* return to user-space */
24628 * The iretq could re-enable interrupts:
24629 */
24630 DISABLE_INTERRUPTS(CLBR_ANY)
24631 + pax_exit_kernel_user
24632 +retint_swapgs_pax:
24633 TRACE_IRQS_IRETQ
24634 SWAPGS
24635 jmp restore_args
24636
24637 retint_restore_args: /* return to kernel space */
24638 DISABLE_INTERRUPTS(CLBR_ANY)
24639 + pax_exit_kernel
24640 +
24641 +#if defined(CONFIG_EFI) && defined(CONFIG_PAX_KERNEXEC)
24642 + /* This is a quirk to allow IRQs/NMIs/MCEs during early EFI setup,
24643 + * namely calling EFI runtime services with a phys mapping. We're
24644 + * starting off with NOPs and patch in the real instrumentation
24645 + * (BTS/OR) before starting any userland process; even before starting
24646 + * up the APs.
24647 + */
24648 + .pushsection .altinstr_replacement, "a"
24649 + 601: pax_force_retaddr (RIP-ARGOFFSET)
24650 + 602:
24651 + .popsection
24652 + 603: .fill 602b-601b, 1, 0x90
24653 + .pushsection .altinstructions, "a"
24654 + altinstruction_entry 603b, 601b, X86_FEATURE_ALWAYS, 602b-601b, 602b-601b
24655 + .popsection
24656 +#else
24657 + pax_force_retaddr (RIP-ARGOFFSET)
24658 +#endif
24659 +
24660 /*
24661 * The iretq could re-enable interrupts:
24662 */
24663 @@ -933,7 +1422,7 @@ ENTRY(retint_kernel)
24664 jmp exit_intr
24665 #endif
24666 CFI_ENDPROC
24667 -END(common_interrupt)
24668 +ENDPROC(common_interrupt)
24669
24670 /*
24671 * If IRET takes a fault on the espfix stack, then we
24672 @@ -955,13 +1444,13 @@ __do_double_fault:
24673 cmpq $native_irq_return_iret,%rax
24674 jne do_double_fault /* This shouldn't happen... */
24675 movq PER_CPU_VAR(kernel_stack),%rax
24676 - subq $(6*8-KERNEL_STACK_OFFSET),%rax /* Reset to original stack */
24677 + subq $(6*8),%rax /* Reset to original stack */
24678 movq %rax,RSP(%rdi)
24679 movq $0,(%rax) /* Missing (lost) #GP error code */
24680 movq $general_protection,RIP(%rdi)
24681 retq
24682 CFI_ENDPROC
24683 -END(__do_double_fault)
24684 +ENDPROC(__do_double_fault)
24685 #else
24686 # define __do_double_fault do_double_fault
24687 #endif
24688 @@ -978,7 +1467,7 @@ ENTRY(\sym)
24689 interrupt \do_sym
24690 jmp ret_from_intr
24691 CFI_ENDPROC
24692 -END(\sym)
24693 +ENDPROC(\sym)
24694 .endm
24695
24696 #ifdef CONFIG_TRACING
24697 @@ -1051,7 +1540,7 @@ apicinterrupt IRQ_WORK_VECTOR \
24698 /*
24699 * Exception entry points.
24700 */
24701 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
24702 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
24703
24704 .macro idtentry sym do_sym has_error_code:req paranoid=0 shift_ist=-1
24705 ENTRY(\sym)
24706 @@ -1102,6 +1591,12 @@ ENTRY(\sym)
24707 .endif
24708
24709 .if \shift_ist != -1
24710 +#ifdef CONFIG_SMP
24711 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
24712 + lea init_tss(%r13), %r13
24713 +#else
24714 + lea init_tss(%rip), %r13
24715 +#endif
24716 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\shift_ist)
24717 .endif
24718
24719 @@ -1118,7 +1613,7 @@ ENTRY(\sym)
24720 .endif
24721
24722 CFI_ENDPROC
24723 -END(\sym)
24724 +ENDPROC(\sym)
24725 .endm
24726
24727 #ifdef CONFIG_TRACING
24728 @@ -1159,9 +1654,10 @@ gs_change:
24729 2: mfence /* workaround */
24730 SWAPGS
24731 popfq_cfi
24732 + pax_force_retaddr
24733 ret
24734 CFI_ENDPROC
24735 -END(native_load_gs_index)
24736 +ENDPROC(native_load_gs_index)
24737
24738 _ASM_EXTABLE(gs_change,bad_gs)
24739 .section .fixup,"ax"
24740 @@ -1189,9 +1685,10 @@ ENTRY(do_softirq_own_stack)
24741 CFI_DEF_CFA_REGISTER rsp
24742 CFI_ADJUST_CFA_OFFSET -8
24743 decl PER_CPU_VAR(irq_count)
24744 + pax_force_retaddr
24745 ret
24746 CFI_ENDPROC
24747 -END(do_softirq_own_stack)
24748 +ENDPROC(do_softirq_own_stack)
24749
24750 #ifdef CONFIG_XEN
24751 idtentry xen_hypervisor_callback xen_do_hypervisor_callback has_error_code=0
24752 @@ -1229,7 +1726,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
24753 decl PER_CPU_VAR(irq_count)
24754 jmp error_exit
24755 CFI_ENDPROC
24756 -END(xen_do_hypervisor_callback)
24757 +ENDPROC(xen_do_hypervisor_callback)
24758
24759 /*
24760 * Hypervisor uses this for application faults while it executes.
24761 @@ -1288,7 +1785,7 @@ ENTRY(xen_failsafe_callback)
24762 SAVE_ALL
24763 jmp error_exit
24764 CFI_ENDPROC
24765 -END(xen_failsafe_callback)
24766 +ENDPROC(xen_failsafe_callback)
24767
24768 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
24769 xen_hvm_callback_vector xen_evtchn_do_upcall
24770 @@ -1335,18 +1832,33 @@ ENTRY(paranoid_exit)
24771 DEFAULT_FRAME
24772 DISABLE_INTERRUPTS(CLBR_NONE)
24773 TRACE_IRQS_OFF_DEBUG
24774 - testl %ebx,%ebx /* swapgs needed? */
24775 + testl $1,%ebx /* swapgs needed? */
24776 jnz paranoid_restore
24777 - testl $3,CS(%rsp)
24778 + testb $3,CS(%rsp)
24779 jnz paranoid_userspace
24780 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24781 + pax_exit_kernel
24782 + TRACE_IRQS_IRETQ 0
24783 + SWAPGS_UNSAFE_STACK
24784 + RESTORE_ALL 8
24785 + pax_force_retaddr_bts
24786 + jmp irq_return
24787 +#endif
24788 paranoid_swapgs:
24789 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24790 + pax_exit_kernel_user
24791 +#else
24792 + pax_exit_kernel
24793 +#endif
24794 TRACE_IRQS_IRETQ 0
24795 SWAPGS_UNSAFE_STACK
24796 RESTORE_ALL 8
24797 jmp irq_return
24798 paranoid_restore:
24799 + pax_exit_kernel
24800 TRACE_IRQS_IRETQ_DEBUG 0
24801 RESTORE_ALL 8
24802 + pax_force_retaddr_bts
24803 jmp irq_return
24804 paranoid_userspace:
24805 GET_THREAD_INFO(%rcx)
24806 @@ -1375,7 +1887,7 @@ paranoid_schedule:
24807 TRACE_IRQS_OFF
24808 jmp paranoid_userspace
24809 CFI_ENDPROC
24810 -END(paranoid_exit)
24811 +ENDPROC(paranoid_exit)
24812
24813 /*
24814 * Exception entry point. This expects an error code/orig_rax on the stack.
24815 @@ -1402,12 +1914,23 @@ ENTRY(error_entry)
24816 movq %r14, R14+8(%rsp)
24817 movq %r15, R15+8(%rsp)
24818 xorl %ebx,%ebx
24819 - testl $3,CS+8(%rsp)
24820 + testb $3,CS+8(%rsp)
24821 je error_kernelspace
24822 error_swapgs:
24823 SWAPGS
24824 error_sti:
24825 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24826 + testb $3, CS+8(%rsp)
24827 + jnz 1f
24828 + pax_enter_kernel
24829 + jmp 2f
24830 +1: pax_enter_kernel_user
24831 +2:
24832 +#else
24833 + pax_enter_kernel
24834 +#endif
24835 TRACE_IRQS_OFF
24836 + pax_force_retaddr
24837 ret
24838
24839 /*
24840 @@ -1435,7 +1958,7 @@ bstep_iret:
24841 movq %rcx,RIP+8(%rsp)
24842 jmp error_swapgs
24843 CFI_ENDPROC
24844 -END(error_entry)
24845 +ENDPROC(error_entry)
24846
24847
24848 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
24849 @@ -1446,7 +1969,7 @@ ENTRY(error_exit)
24850 DISABLE_INTERRUPTS(CLBR_NONE)
24851 TRACE_IRQS_OFF
24852 GET_THREAD_INFO(%rcx)
24853 - testl %eax,%eax
24854 + testl $1,%eax
24855 jne retint_kernel
24856 LOCKDEP_SYS_EXIT_IRQ
24857 movl TI_flags(%rcx),%edx
24858 @@ -1455,7 +1978,7 @@ ENTRY(error_exit)
24859 jnz retint_careful
24860 jmp retint_swapgs
24861 CFI_ENDPROC
24862 -END(error_exit)
24863 +ENDPROC(error_exit)
24864
24865 /*
24866 * Test if a given stack is an NMI stack or not.
24867 @@ -1513,9 +2036,11 @@ ENTRY(nmi)
24868 * If %cs was not the kernel segment, then the NMI triggered in user
24869 * space, which means it is definitely not nested.
24870 */
24871 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
24872 + je 1f
24873 cmpl $__KERNEL_CS, 16(%rsp)
24874 jne first_nmi
24875 -
24876 +1:
24877 /*
24878 * Check the special variable on the stack to see if NMIs are
24879 * executing.
24880 @@ -1549,8 +2074,7 @@ nested_nmi:
24881
24882 1:
24883 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
24884 - leaq -1*8(%rsp), %rdx
24885 - movq %rdx, %rsp
24886 + subq $8, %rsp
24887 CFI_ADJUST_CFA_OFFSET 1*8
24888 leaq -10*8(%rsp), %rdx
24889 pushq_cfi $__KERNEL_DS
24890 @@ -1568,6 +2092,7 @@ nested_nmi_out:
24891 CFI_RESTORE rdx
24892
24893 /* No need to check faults here */
24894 +# pax_force_retaddr_bts
24895 INTERRUPT_RETURN
24896
24897 CFI_RESTORE_STATE
24898 @@ -1664,13 +2189,13 @@ end_repeat_nmi:
24899 subq $ORIG_RAX-R15, %rsp
24900 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
24901 /*
24902 - * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
24903 + * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
24904 * as we should not be calling schedule in NMI context.
24905 * Even with normal interrupts enabled. An NMI should not be
24906 * setting NEED_RESCHED or anything that normal interrupts and
24907 * exceptions might do.
24908 */
24909 - call save_paranoid
24910 + call save_paranoid_nmi
24911 DEFAULT_FRAME 0
24912
24913 /*
24914 @@ -1680,9 +2205,9 @@ end_repeat_nmi:
24915 * NMI itself takes a page fault, the page fault that was preempted
24916 * will read the information from the NMI page fault and not the
24917 * origin fault. Save it off and restore it if it changes.
24918 - * Use the r12 callee-saved register.
24919 + * Use the r13 callee-saved register.
24920 */
24921 - movq %cr2, %r12
24922 + movq %cr2, %r13
24923
24924 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
24925 movq %rsp,%rdi
24926 @@ -1691,29 +2216,34 @@ end_repeat_nmi:
24927
24928 /* Did the NMI take a page fault? Restore cr2 if it did */
24929 movq %cr2, %rcx
24930 - cmpq %rcx, %r12
24931 + cmpq %rcx, %r13
24932 je 1f
24933 - movq %r12, %cr2
24934 + movq %r13, %cr2
24935 1:
24936
24937 - testl %ebx,%ebx /* swapgs needed? */
24938 + testl $1,%ebx /* swapgs needed? */
24939 jnz nmi_restore
24940 nmi_swapgs:
24941 SWAPGS_UNSAFE_STACK
24942 nmi_restore:
24943 + pax_exit_kernel_nmi
24944 /* Pop the extra iret frame at once */
24945 RESTORE_ALL 6*8
24946 + testb $3, 8(%rsp)
24947 + jnz 1f
24948 + pax_force_retaddr_bts
24949 +1:
24950
24951 /* Clear the NMI executing stack variable */
24952 movq $0, 5*8(%rsp)
24953 jmp irq_return
24954 CFI_ENDPROC
24955 -END(nmi)
24956 +ENDPROC(nmi)
24957
24958 ENTRY(ignore_sysret)
24959 CFI_STARTPROC
24960 mov $-ENOSYS,%eax
24961 sysret
24962 CFI_ENDPROC
24963 -END(ignore_sysret)
24964 +ENDPROC(ignore_sysret)
24965
24966 diff --git a/arch/x86/kernel/espfix_64.c b/arch/x86/kernel/espfix_64.c
24967 index 94d857f..bf1f0bf 100644
24968 --- a/arch/x86/kernel/espfix_64.c
24969 +++ b/arch/x86/kernel/espfix_64.c
24970 @@ -197,7 +197,7 @@ void init_espfix_ap(void)
24971 set_pte(&pte_p[n*PTE_STRIDE], pte);
24972
24973 /* Job is done for this CPU and any CPU which shares this page */
24974 - ACCESS_ONCE(espfix_pages[page]) = stack_page;
24975 + ACCESS_ONCE_RW(espfix_pages[page]) = stack_page;
24976
24977 unlock_done:
24978 mutex_unlock(&espfix_init_mutex);
24979 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
24980 index 3386dc9..28bdf81 100644
24981 --- a/arch/x86/kernel/ftrace.c
24982 +++ b/arch/x86/kernel/ftrace.c
24983 @@ -88,7 +88,7 @@ static unsigned long text_ip_addr(unsigned long ip)
24984 * kernel identity mapping to modify code.
24985 */
24986 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
24987 - ip = (unsigned long)__va(__pa_symbol(ip));
24988 + ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
24989
24990 return ip;
24991 }
24992 @@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
24993 {
24994 unsigned char replaced[MCOUNT_INSN_SIZE];
24995
24996 + ip = ktla_ktva(ip);
24997 +
24998 /*
24999 * Note: Due to modules and __init, code can
25000 * disappear and change, we need to protect against faulting
25001 @@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
25002 unsigned char old[MCOUNT_INSN_SIZE];
25003 int ret;
25004
25005 - memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
25006 + memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
25007
25008 ftrace_update_func = ip;
25009 /* Make sure the breakpoints see the ftrace_update_func update */
25010 @@ -310,7 +312,7 @@ static int add_break(unsigned long ip, const char *old)
25011 unsigned char replaced[MCOUNT_INSN_SIZE];
25012 unsigned char brk = BREAKPOINT_INSTRUCTION;
25013
25014 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
25015 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
25016 return -EFAULT;
25017
25018 /* Make sure it is what we expect it to be */
25019 diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
25020 index eda1a86..8f6df48 100644
25021 --- a/arch/x86/kernel/head64.c
25022 +++ b/arch/x86/kernel/head64.c
25023 @@ -67,12 +67,12 @@ again:
25024 pgd = *pgd_p;
25025
25026 /*
25027 - * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
25028 - * critical -- __PAGE_OFFSET would point us back into the dynamic
25029 + * The use of __early_va rather than __va here is critical:
25030 + * __va would point us back into the dynamic
25031 * range and we might end up looping forever...
25032 */
25033 if (pgd)
25034 - pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
25035 + pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
25036 else {
25037 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
25038 reset_early_page_tables();
25039 @@ -82,13 +82,13 @@ again:
25040 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
25041 for (i = 0; i < PTRS_PER_PUD; i++)
25042 pud_p[i] = 0;
25043 - *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
25044 + *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
25045 }
25046 pud_p += pud_index(address);
25047 pud = *pud_p;
25048
25049 if (pud)
25050 - pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
25051 + pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
25052 else {
25053 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
25054 reset_early_page_tables();
25055 @@ -98,7 +98,7 @@ again:
25056 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
25057 for (i = 0; i < PTRS_PER_PMD; i++)
25058 pmd_p[i] = 0;
25059 - *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
25060 + *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
25061 }
25062 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
25063 pmd_p[pmd_index(address)] = pmd;
25064 @@ -175,7 +175,6 @@ asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data)
25065 if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG)
25066 early_printk("Kernel alive\n");
25067
25068 - clear_page(init_level4_pgt);
25069 /* set init_level4_pgt kernel high mapping*/
25070 init_level4_pgt[511] = early_level4_pgt[511];
25071
25072 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
25073 index f36bd42..0ab4474 100644
25074 --- a/arch/x86/kernel/head_32.S
25075 +++ b/arch/x86/kernel/head_32.S
25076 @@ -26,6 +26,12 @@
25077 /* Physical address */
25078 #define pa(X) ((X) - __PAGE_OFFSET)
25079
25080 +#ifdef CONFIG_PAX_KERNEXEC
25081 +#define ta(X) (X)
25082 +#else
25083 +#define ta(X) ((X) - __PAGE_OFFSET)
25084 +#endif
25085 +
25086 /*
25087 * References to members of the new_cpu_data structure.
25088 */
25089 @@ -55,11 +61,7 @@
25090 * and small than max_low_pfn, otherwise will waste some page table entries
25091 */
25092
25093 -#if PTRS_PER_PMD > 1
25094 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
25095 -#else
25096 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
25097 -#endif
25098 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
25099
25100 /* Number of possible pages in the lowmem region */
25101 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
25102 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
25103 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
25104
25105 /*
25106 + * Real beginning of normal "text" segment
25107 + */
25108 +ENTRY(stext)
25109 +ENTRY(_stext)
25110 +
25111 +/*
25112 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
25113 * %esi points to the real-mode code as a 32-bit pointer.
25114 * CS and DS must be 4 GB flat segments, but we don't depend on
25115 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
25116 * can.
25117 */
25118 __HEAD
25119 +
25120 +#ifdef CONFIG_PAX_KERNEXEC
25121 + jmp startup_32
25122 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
25123 +.fill PAGE_SIZE-5,1,0xcc
25124 +#endif
25125 +
25126 ENTRY(startup_32)
25127 movl pa(stack_start),%ecx
25128
25129 @@ -106,6 +121,59 @@ ENTRY(startup_32)
25130 2:
25131 leal -__PAGE_OFFSET(%ecx),%esp
25132
25133 +#ifdef CONFIG_SMP
25134 + movl $pa(cpu_gdt_table),%edi
25135 + movl $__per_cpu_load,%eax
25136 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
25137 + rorl $16,%eax
25138 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
25139 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
25140 + movl $__per_cpu_end - 1,%eax
25141 + subl $__per_cpu_start,%eax
25142 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
25143 +#endif
25144 +
25145 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25146 + movl $NR_CPUS,%ecx
25147 + movl $pa(cpu_gdt_table),%edi
25148 +1:
25149 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
25150 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
25151 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
25152 + addl $PAGE_SIZE_asm,%edi
25153 + loop 1b
25154 +#endif
25155 +
25156 +#ifdef CONFIG_PAX_KERNEXEC
25157 + movl $pa(boot_gdt),%edi
25158 + movl $__LOAD_PHYSICAL_ADDR,%eax
25159 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
25160 + rorl $16,%eax
25161 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
25162 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
25163 + rorl $16,%eax
25164 +
25165 + ljmp $(__BOOT_CS),$1f
25166 +1:
25167 +
25168 + movl $NR_CPUS,%ecx
25169 + movl $pa(cpu_gdt_table),%edi
25170 + addl $__PAGE_OFFSET,%eax
25171 +1:
25172 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
25173 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
25174 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
25175 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
25176 + rorl $16,%eax
25177 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
25178 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
25179 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
25180 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
25181 + rorl $16,%eax
25182 + addl $PAGE_SIZE_asm,%edi
25183 + loop 1b
25184 +#endif
25185 +
25186 /*
25187 * Clear BSS first so that there are no surprises...
25188 */
25189 @@ -201,8 +269,11 @@ ENTRY(startup_32)
25190 movl %eax, pa(max_pfn_mapped)
25191
25192 /* Do early initialization of the fixmap area */
25193 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
25194 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
25195 +#ifdef CONFIG_COMPAT_VDSO
25196 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
25197 +#else
25198 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
25199 +#endif
25200 #else /* Not PAE */
25201
25202 page_pde_offset = (__PAGE_OFFSET >> 20);
25203 @@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
25204 movl %eax, pa(max_pfn_mapped)
25205
25206 /* Do early initialization of the fixmap area */
25207 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
25208 - movl %eax,pa(initial_page_table+0xffc)
25209 +#ifdef CONFIG_COMPAT_VDSO
25210 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
25211 +#else
25212 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
25213 +#endif
25214 #endif
25215
25216 #ifdef CONFIG_PARAVIRT
25217 @@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
25218 cmpl $num_subarch_entries, %eax
25219 jae bad_subarch
25220
25221 - movl pa(subarch_entries)(,%eax,4), %eax
25222 - subl $__PAGE_OFFSET, %eax
25223 - jmp *%eax
25224 + jmp *pa(subarch_entries)(,%eax,4)
25225
25226 bad_subarch:
25227 WEAK(lguest_entry)
25228 @@ -261,10 +333,10 @@ WEAK(xen_entry)
25229 __INITDATA
25230
25231 subarch_entries:
25232 - .long default_entry /* normal x86/PC */
25233 - .long lguest_entry /* lguest hypervisor */
25234 - .long xen_entry /* Xen hypervisor */
25235 - .long default_entry /* Moorestown MID */
25236 + .long ta(default_entry) /* normal x86/PC */
25237 + .long ta(lguest_entry) /* lguest hypervisor */
25238 + .long ta(xen_entry) /* Xen hypervisor */
25239 + .long ta(default_entry) /* Moorestown MID */
25240 num_subarch_entries = (. - subarch_entries) / 4
25241 .previous
25242 #else
25243 @@ -354,6 +426,7 @@ default_entry:
25244 movl pa(mmu_cr4_features),%eax
25245 movl %eax,%cr4
25246
25247 +#ifdef CONFIG_X86_PAE
25248 testb $X86_CR4_PAE, %al # check if PAE is enabled
25249 jz enable_paging
25250
25251 @@ -382,6 +455,9 @@ default_entry:
25252 /* Make changes effective */
25253 wrmsr
25254
25255 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
25256 +#endif
25257 +
25258 enable_paging:
25259
25260 /*
25261 @@ -449,14 +525,20 @@ is486:
25262 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
25263 movl %eax,%ss # after changing gdt.
25264
25265 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
25266 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
25267 movl %eax,%ds
25268 movl %eax,%es
25269
25270 movl $(__KERNEL_PERCPU), %eax
25271 movl %eax,%fs # set this cpu's percpu
25272
25273 +#ifdef CONFIG_CC_STACKPROTECTOR
25274 movl $(__KERNEL_STACK_CANARY),%eax
25275 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
25276 + movl $(__USER_DS),%eax
25277 +#else
25278 + xorl %eax,%eax
25279 +#endif
25280 movl %eax,%gs
25281
25282 xorl %eax,%eax # Clear LDT
25283 @@ -512,8 +594,11 @@ setup_once:
25284 * relocation. Manually set base address in stack canary
25285 * segment descriptor.
25286 */
25287 - movl $gdt_page,%eax
25288 + movl $cpu_gdt_table,%eax
25289 movl $stack_canary,%ecx
25290 +#ifdef CONFIG_SMP
25291 + addl $__per_cpu_load,%ecx
25292 +#endif
25293 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
25294 shrl $16, %ecx
25295 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
25296 @@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
25297 cmpl $2,(%esp) # X86_TRAP_NMI
25298 je is_nmi # Ignore NMI
25299
25300 - cmpl $2,%ss:early_recursion_flag
25301 + cmpl $1,%ss:early_recursion_flag
25302 je hlt_loop
25303 incl %ss:early_recursion_flag
25304
25305 @@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
25306 pushl (20+6*4)(%esp) /* trapno */
25307 pushl $fault_msg
25308 call printk
25309 -#endif
25310 call dump_stack
25311 +#endif
25312 hlt_loop:
25313 hlt
25314 jmp hlt_loop
25315 @@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
25316 /* This is the default interrupt "handler" :-) */
25317 ALIGN
25318 ignore_int:
25319 - cld
25320 #ifdef CONFIG_PRINTK
25321 + cmpl $2,%ss:early_recursion_flag
25322 + je hlt_loop
25323 + incl %ss:early_recursion_flag
25324 + cld
25325 pushl %eax
25326 pushl %ecx
25327 pushl %edx
25328 @@ -617,9 +705,6 @@ ignore_int:
25329 movl $(__KERNEL_DS),%eax
25330 movl %eax,%ds
25331 movl %eax,%es
25332 - cmpl $2,early_recursion_flag
25333 - je hlt_loop
25334 - incl early_recursion_flag
25335 pushl 16(%esp)
25336 pushl 24(%esp)
25337 pushl 32(%esp)
25338 @@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
25339 /*
25340 * BSS section
25341 */
25342 -__PAGE_ALIGNED_BSS
25343 - .align PAGE_SIZE
25344 #ifdef CONFIG_X86_PAE
25345 +.section .initial_pg_pmd,"a",@progbits
25346 initial_pg_pmd:
25347 .fill 1024*KPMDS,4,0
25348 #else
25349 +.section .initial_page_table,"a",@progbits
25350 ENTRY(initial_page_table)
25351 .fill 1024,4,0
25352 #endif
25353 +.section .initial_pg_fixmap,"a",@progbits
25354 initial_pg_fixmap:
25355 .fill 1024,4,0
25356 +.section .empty_zero_page,"a",@progbits
25357 ENTRY(empty_zero_page)
25358 .fill 4096,1,0
25359 +.section .swapper_pg_dir,"a",@progbits
25360 ENTRY(swapper_pg_dir)
25361 +#ifdef CONFIG_X86_PAE
25362 + .fill 4,8,0
25363 +#else
25364 .fill 1024,4,0
25365 +#endif
25366
25367 /*
25368 * This starts the data section.
25369 */
25370 #ifdef CONFIG_X86_PAE
25371 -__PAGE_ALIGNED_DATA
25372 - /* Page-aligned for the benefit of paravirt? */
25373 - .align PAGE_SIZE
25374 +.section .initial_page_table,"a",@progbits
25375 ENTRY(initial_page_table)
25376 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
25377 # if KPMDS == 3
25378 @@ -694,12 +784,20 @@ ENTRY(initial_page_table)
25379 # error "Kernel PMDs should be 1, 2 or 3"
25380 # endif
25381 .align PAGE_SIZE /* needs to be page-sized too */
25382 +
25383 +#ifdef CONFIG_PAX_PER_CPU_PGD
25384 +ENTRY(cpu_pgd)
25385 + .rept 2*NR_CPUS
25386 + .fill 4,8,0
25387 + .endr
25388 +#endif
25389 +
25390 #endif
25391
25392 .data
25393 .balign 4
25394 ENTRY(stack_start)
25395 - .long init_thread_union+THREAD_SIZE
25396 + .long init_thread_union+THREAD_SIZE-8
25397
25398 __INITRODATA
25399 int_msg:
25400 @@ -727,7 +825,7 @@ fault_msg:
25401 * segment size, and 32-bit linear address value:
25402 */
25403
25404 - .data
25405 +.section .rodata,"a",@progbits
25406 .globl boot_gdt_descr
25407 .globl idt_descr
25408
25409 @@ -736,7 +834,7 @@ fault_msg:
25410 .word 0 # 32 bit align gdt_desc.address
25411 boot_gdt_descr:
25412 .word __BOOT_DS+7
25413 - .long boot_gdt - __PAGE_OFFSET
25414 + .long pa(boot_gdt)
25415
25416 .word 0 # 32-bit align idt_desc.address
25417 idt_descr:
25418 @@ -747,7 +845,7 @@ idt_descr:
25419 .word 0 # 32 bit align gdt_desc.address
25420 ENTRY(early_gdt_descr)
25421 .word GDT_ENTRIES*8-1
25422 - .long gdt_page /* Overwritten for secondary CPUs */
25423 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
25424
25425 /*
25426 * The boot_gdt must mirror the equivalent in setup.S and is
25427 @@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
25428 .align L1_CACHE_BYTES
25429 ENTRY(boot_gdt)
25430 .fill GDT_ENTRY_BOOT_CS,8,0
25431 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
25432 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
25433 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
25434 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
25435 +
25436 + .align PAGE_SIZE_asm
25437 +ENTRY(cpu_gdt_table)
25438 + .rept NR_CPUS
25439 + .quad 0x0000000000000000 /* NULL descriptor */
25440 + .quad 0x0000000000000000 /* 0x0b reserved */
25441 + .quad 0x0000000000000000 /* 0x13 reserved */
25442 + .quad 0x0000000000000000 /* 0x1b reserved */
25443 +
25444 +#ifdef CONFIG_PAX_KERNEXEC
25445 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
25446 +#else
25447 + .quad 0x0000000000000000 /* 0x20 unused */
25448 +#endif
25449 +
25450 + .quad 0x0000000000000000 /* 0x28 unused */
25451 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
25452 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
25453 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
25454 + .quad 0x0000000000000000 /* 0x4b reserved */
25455 + .quad 0x0000000000000000 /* 0x53 reserved */
25456 + .quad 0x0000000000000000 /* 0x5b reserved */
25457 +
25458 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
25459 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
25460 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
25461 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
25462 +
25463 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
25464 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
25465 +
25466 + /*
25467 + * Segments used for calling PnP BIOS have byte granularity.
25468 + * The code segments and data segments have fixed 64k limits,
25469 + * the transfer segment sizes are set at run time.
25470 + */
25471 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
25472 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
25473 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
25474 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
25475 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
25476 +
25477 + /*
25478 + * The APM segments have byte granularity and their bases
25479 + * are set at run time. All have 64k limits.
25480 + */
25481 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
25482 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
25483 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
25484 +
25485 + .quad 0x00c093000000ffff /* 0xd0 - ESPFIX SS */
25486 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
25487 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
25488 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
25489 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
25490 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
25491 +
25492 + /* Be sure this is zeroed to avoid false validations in Xen */
25493 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
25494 + .endr
25495 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
25496 index a468c0a..8b5a879 100644
25497 --- a/arch/x86/kernel/head_64.S
25498 +++ b/arch/x86/kernel/head_64.S
25499 @@ -20,6 +20,8 @@
25500 #include <asm/processor-flags.h>
25501 #include <asm/percpu.h>
25502 #include <asm/nops.h>
25503 +#include <asm/cpufeature.h>
25504 +#include <asm/alternative-asm.h>
25505
25506 #ifdef CONFIG_PARAVIRT
25507 #include <asm/asm-offsets.h>
25508 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
25509 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
25510 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
25511 L3_START_KERNEL = pud_index(__START_KERNEL_map)
25512 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
25513 +L3_VMALLOC_START = pud_index(VMALLOC_START)
25514 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
25515 +L3_VMALLOC_END = pud_index(VMALLOC_END)
25516 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
25517 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
25518
25519 .text
25520 __HEAD
25521 @@ -89,11 +97,24 @@ startup_64:
25522 * Fixup the physical addresses in the page table
25523 */
25524 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
25525 + addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
25526 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
25527 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
25528 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
25529 + addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
25530
25531 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
25532 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
25533 + addq %rbp, level3_ident_pgt + (0*8)(%rip)
25534 +#ifndef CONFIG_XEN
25535 + addq %rbp, level3_ident_pgt + (1*8)(%rip)
25536 +#endif
25537 +
25538 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
25539 +
25540 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
25541 + addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
25542
25543 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
25544 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
25545
25546 /*
25547 * Set up the identity mapping for the switchover. These
25548 @@ -174,11 +195,12 @@ ENTRY(secondary_startup_64)
25549 * after the boot processor executes this code.
25550 */
25551
25552 + orq $-1, %rbp
25553 movq $(init_level4_pgt - __START_KERNEL_map), %rax
25554 1:
25555
25556 - /* Enable PAE mode and PGE */
25557 - movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
25558 + /* Enable PAE mode and PSE/PGE */
25559 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
25560 movq %rcx, %cr4
25561
25562 /* Setup early boot stage 4 level pagetables. */
25563 @@ -199,10 +221,19 @@ ENTRY(secondary_startup_64)
25564 movl $MSR_EFER, %ecx
25565 rdmsr
25566 btsl $_EFER_SCE, %eax /* Enable System Call */
25567 - btl $20,%edi /* No Execute supported? */
25568 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
25569 jnc 1f
25570 btsl $_EFER_NX, %eax
25571 + cmpq $-1, %rbp
25572 + je 1f
25573 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
25574 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
25575 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
25576 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
25577 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
25578 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
25579 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
25580 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
25581 1: wrmsr /* Make changes effective */
25582
25583 /* Setup cr0 */
25584 @@ -282,6 +313,7 @@ ENTRY(secondary_startup_64)
25585 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
25586 * address given in m16:64.
25587 */
25588 + pax_set_fptr_mask
25589 movq initial_code(%rip),%rax
25590 pushq $0 # fake return address to stop unwinder
25591 pushq $__KERNEL_CS # set correct cs
25592 @@ -313,7 +345,7 @@ ENDPROC(start_cpu0)
25593 .quad INIT_PER_CPU_VAR(irq_stack_union)
25594
25595 GLOBAL(stack_start)
25596 - .quad init_thread_union+THREAD_SIZE-8
25597 + .quad init_thread_union+THREAD_SIZE-16
25598 .word 0
25599 __FINITDATA
25600
25601 @@ -391,7 +423,7 @@ ENTRY(early_idt_handler)
25602 call dump_stack
25603 #ifdef CONFIG_KALLSYMS
25604 leaq early_idt_ripmsg(%rip),%rdi
25605 - movq 40(%rsp),%rsi # %rip again
25606 + movq 88(%rsp),%rsi # %rip again
25607 call __print_symbol
25608 #endif
25609 #endif /* EARLY_PRINTK */
25610 @@ -420,6 +452,7 @@ ENDPROC(early_idt_handler)
25611 early_recursion_flag:
25612 .long 0
25613
25614 + .section .rodata,"a",@progbits
25615 #ifdef CONFIG_EARLY_PRINTK
25616 early_idt_msg:
25617 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
25618 @@ -447,29 +480,52 @@ NEXT_PAGE(early_level4_pgt)
25619 NEXT_PAGE(early_dynamic_pgts)
25620 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
25621
25622 - .data
25623 + .section .rodata,"a",@progbits
25624
25625 -#ifndef CONFIG_XEN
25626 NEXT_PAGE(init_level4_pgt)
25627 - .fill 512,8,0
25628 -#else
25629 -NEXT_PAGE(init_level4_pgt)
25630 - .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25631 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
25632 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25633 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
25634 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
25635 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
25636 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
25637 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
25638 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
25639 .org init_level4_pgt + L4_START_KERNEL*8, 0
25640 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
25641 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
25642
25643 +#ifdef CONFIG_PAX_PER_CPU_PGD
25644 +NEXT_PAGE(cpu_pgd)
25645 + .rept 2*NR_CPUS
25646 + .fill 512,8,0
25647 + .endr
25648 +#endif
25649 +
25650 NEXT_PAGE(level3_ident_pgt)
25651 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25652 +#ifdef CONFIG_XEN
25653 .fill 511, 8, 0
25654 +#else
25655 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
25656 + .fill 510,8,0
25657 +#endif
25658 +
25659 +NEXT_PAGE(level3_vmalloc_start_pgt)
25660 + .fill 512,8,0
25661 +
25662 +NEXT_PAGE(level3_vmalloc_end_pgt)
25663 + .fill 512,8,0
25664 +
25665 +NEXT_PAGE(level3_vmemmap_pgt)
25666 + .fill L3_VMEMMAP_START,8,0
25667 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
25668 +
25669 NEXT_PAGE(level2_ident_pgt)
25670 - /* Since I easily can, map the first 1G.
25671 + /* Since I easily can, map the first 2G.
25672 * Don't set NX because code runs from these pages.
25673 */
25674 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
25675 -#endif
25676 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
25677
25678 NEXT_PAGE(level3_kernel_pgt)
25679 .fill L3_START_KERNEL,8,0
25680 @@ -477,6 +533,9 @@ NEXT_PAGE(level3_kernel_pgt)
25681 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
25682 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25683
25684 +NEXT_PAGE(level2_vmemmap_pgt)
25685 + .fill 512,8,0
25686 +
25687 NEXT_PAGE(level2_kernel_pgt)
25688 /*
25689 * 512 MB kernel mapping. We spend a full page on this pagetable
25690 @@ -494,28 +553,64 @@ NEXT_PAGE(level2_kernel_pgt)
25691 NEXT_PAGE(level2_fixmap_pgt)
25692 .fill 506,8,0
25693 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25694 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
25695 - .fill 5,8,0
25696 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
25697 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
25698 + .fill 4,8,0
25699
25700 NEXT_PAGE(level1_fixmap_pgt)
25701 .fill 512,8,0
25702
25703 +NEXT_PAGE(level1_vsyscall_pgt)
25704 + .fill 512,8,0
25705 +
25706 #undef PMDS
25707
25708 - .data
25709 + .align PAGE_SIZE
25710 +ENTRY(cpu_gdt_table)
25711 + .rept NR_CPUS
25712 + .quad 0x0000000000000000 /* NULL descriptor */
25713 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
25714 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
25715 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
25716 + .quad 0x00cffb000000ffff /* __USER32_CS */
25717 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
25718 + .quad 0x00affb000000ffff /* __USER_CS */
25719 +
25720 +#ifdef CONFIG_PAX_KERNEXEC
25721 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
25722 +#else
25723 + .quad 0x0 /* unused */
25724 +#endif
25725 +
25726 + .quad 0,0 /* TSS */
25727 + .quad 0,0 /* LDT */
25728 + .quad 0,0,0 /* three TLS descriptors */
25729 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
25730 + /* asm/segment.h:GDT_ENTRIES must match this */
25731 +
25732 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25733 + .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
25734 +#else
25735 + .quad 0x0 /* unused */
25736 +#endif
25737 +
25738 + /* zero the remaining page */
25739 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
25740 + .endr
25741 +
25742 .align 16
25743 .globl early_gdt_descr
25744 early_gdt_descr:
25745 .word GDT_ENTRIES*8-1
25746 early_gdt_descr_base:
25747 - .quad INIT_PER_CPU_VAR(gdt_page)
25748 + .quad cpu_gdt_table
25749
25750 ENTRY(phys_base)
25751 /* This must match the first entry in level2_kernel_pgt */
25752 .quad 0x0000000000000000
25753
25754 #include "../../x86/xen/xen-head.S"
25755 -
25756 - __PAGE_ALIGNED_BSS
25757 +
25758 + .section .rodata,"a",@progbits
25759 NEXT_PAGE(empty_zero_page)
25760 .skip PAGE_SIZE
25761 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
25762 index 05fd74f..c3548b1 100644
25763 --- a/arch/x86/kernel/i386_ksyms_32.c
25764 +++ b/arch/x86/kernel/i386_ksyms_32.c
25765 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
25766 EXPORT_SYMBOL(cmpxchg8b_emu);
25767 #endif
25768
25769 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
25770 +
25771 /* Networking helper routines. */
25772 EXPORT_SYMBOL(csum_partial_copy_generic);
25773 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
25774 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
25775
25776 EXPORT_SYMBOL(__get_user_1);
25777 EXPORT_SYMBOL(__get_user_2);
25778 @@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
25779 EXPORT_SYMBOL(___preempt_schedule_context);
25780 #endif
25781 #endif
25782 +
25783 +#ifdef CONFIG_PAX_KERNEXEC
25784 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
25785 +#endif
25786 +
25787 +#ifdef CONFIG_PAX_PER_CPU_PGD
25788 +EXPORT_SYMBOL(cpu_pgd);
25789 +#endif
25790 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
25791 index a9a4229..6f4d476 100644
25792 --- a/arch/x86/kernel/i387.c
25793 +++ b/arch/x86/kernel/i387.c
25794 @@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
25795 static inline bool interrupted_user_mode(void)
25796 {
25797 struct pt_regs *regs = get_irq_regs();
25798 - return regs && user_mode_vm(regs);
25799 + return regs && user_mode(regs);
25800 }
25801
25802 /*
25803 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
25804 index 8af8171..f8c1169 100644
25805 --- a/arch/x86/kernel/i8259.c
25806 +++ b/arch/x86/kernel/i8259.c
25807 @@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
25808 static void make_8259A_irq(unsigned int irq)
25809 {
25810 disable_irq_nosync(irq);
25811 - io_apic_irqs &= ~(1<<irq);
25812 + io_apic_irqs &= ~(1UL<<irq);
25813 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
25814 i8259A_chip.name);
25815 enable_irq(irq);
25816 @@ -209,7 +209,7 @@ spurious_8259A_irq:
25817 "spurious 8259A interrupt: IRQ%d.\n", irq);
25818 spurious_irq_mask |= irqmask;
25819 }
25820 - atomic_inc(&irq_err_count);
25821 + atomic_inc_unchecked(&irq_err_count);
25822 /*
25823 * Theoretically we do not have to handle this IRQ,
25824 * but in Linux this does not cause problems and is
25825 @@ -350,14 +350,16 @@ static void init_8259A(int auto_eoi)
25826 /* (slave's support for AEOI in flat mode is to be investigated) */
25827 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
25828
25829 + pax_open_kernel();
25830 if (auto_eoi)
25831 /*
25832 * In AEOI mode we just have to mask the interrupt
25833 * when acking.
25834 */
25835 - i8259A_chip.irq_mask_ack = disable_8259A_irq;
25836 + *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
25837 else
25838 - i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25839 + *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25840 + pax_close_kernel();
25841
25842 udelay(100); /* wait for 8259A to initialize */
25843
25844 diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
25845 index a979b5b..1d6db75 100644
25846 --- a/arch/x86/kernel/io_delay.c
25847 +++ b/arch/x86/kernel/io_delay.c
25848 @@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
25849 * Quirk table for systems that misbehave (lock up, etc.) if port
25850 * 0x80 is used:
25851 */
25852 -static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
25853 +static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
25854 {
25855 .callback = dmi_io_delay_0xed_port,
25856 .ident = "Compaq Presario V6000",
25857 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
25858 index 4ddaf66..49d5c18 100644
25859 --- a/arch/x86/kernel/ioport.c
25860 +++ b/arch/x86/kernel/ioport.c
25861 @@ -6,6 +6,7 @@
25862 #include <linux/sched.h>
25863 #include <linux/kernel.h>
25864 #include <linux/capability.h>
25865 +#include <linux/security.h>
25866 #include <linux/errno.h>
25867 #include <linux/types.h>
25868 #include <linux/ioport.h>
25869 @@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25870 return -EINVAL;
25871 if (turn_on && !capable(CAP_SYS_RAWIO))
25872 return -EPERM;
25873 +#ifdef CONFIG_GRKERNSEC_IO
25874 + if (turn_on && grsec_disable_privio) {
25875 + gr_handle_ioperm();
25876 + return -ENODEV;
25877 + }
25878 +#endif
25879
25880 /*
25881 * If it's the first ioperm() call in this thread's lifetime, set the
25882 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25883 * because the ->io_bitmap_max value must match the bitmap
25884 * contents:
25885 */
25886 - tss = &per_cpu(init_tss, get_cpu());
25887 + tss = init_tss + get_cpu();
25888
25889 if (turn_on)
25890 bitmap_clear(t->io_bitmap_ptr, from, num);
25891 @@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
25892 if (level > old) {
25893 if (!capable(CAP_SYS_RAWIO))
25894 return -EPERM;
25895 +#ifdef CONFIG_GRKERNSEC_IO
25896 + if (grsec_disable_privio) {
25897 + gr_handle_iopl();
25898 + return -ENODEV;
25899 + }
25900 +#endif
25901 }
25902 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
25903 t->iopl = level << 12;
25904 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
25905 index 922d285..6d20692 100644
25906 --- a/arch/x86/kernel/irq.c
25907 +++ b/arch/x86/kernel/irq.c
25908 @@ -22,7 +22,7 @@
25909 #define CREATE_TRACE_POINTS
25910 #include <asm/trace/irq_vectors.h>
25911
25912 -atomic_t irq_err_count;
25913 +atomic_unchecked_t irq_err_count;
25914
25915 /* Function pointer for generic interrupt vector handling */
25916 void (*x86_platform_ipi_callback)(void) = NULL;
25917 @@ -132,9 +132,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
25918 seq_printf(p, "%10u ", irq_stats(j)->irq_hv_callback_count);
25919 seq_printf(p, " Hypervisor callback interrupts\n");
25920 #endif
25921 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
25922 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
25923 #if defined(CONFIG_X86_IO_APIC)
25924 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
25925 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
25926 #endif
25927 return 0;
25928 }
25929 @@ -174,7 +174,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
25930
25931 u64 arch_irq_stat(void)
25932 {
25933 - u64 sum = atomic_read(&irq_err_count);
25934 + u64 sum = atomic_read_unchecked(&irq_err_count);
25935 return sum;
25936 }
25937
25938 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
25939 index 63ce838..2ea3e06 100644
25940 --- a/arch/x86/kernel/irq_32.c
25941 +++ b/arch/x86/kernel/irq_32.c
25942 @@ -29,6 +29,8 @@ EXPORT_PER_CPU_SYMBOL(irq_regs);
25943
25944 #ifdef CONFIG_DEBUG_STACKOVERFLOW
25945
25946 +extern void gr_handle_kernel_exploit(void);
25947 +
25948 int sysctl_panic_on_stackoverflow __read_mostly;
25949
25950 /* Debugging check for stack overflow: is there less than 1KB free? */
25951 @@ -39,13 +41,14 @@ static int check_stack_overflow(void)
25952 __asm__ __volatile__("andl %%esp,%0" :
25953 "=r" (sp) : "0" (THREAD_SIZE - 1));
25954
25955 - return sp < (sizeof(struct thread_info) + STACK_WARN);
25956 + return sp < STACK_WARN;
25957 }
25958
25959 static void print_stack_overflow(void)
25960 {
25961 printk(KERN_WARNING "low stack detected by irq handler\n");
25962 dump_stack();
25963 + gr_handle_kernel_exploit();
25964 if (sysctl_panic_on_stackoverflow)
25965 panic("low stack detected by irq handler - check messages\n");
25966 }
25967 @@ -84,10 +87,9 @@ static inline void *current_stack(void)
25968 static inline int
25969 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25970 {
25971 - struct irq_stack *curstk, *irqstk;
25972 + struct irq_stack *irqstk;
25973 u32 *isp, *prev_esp, arg1, arg2;
25974
25975 - curstk = (struct irq_stack *) current_stack();
25976 irqstk = __this_cpu_read(hardirq_stack);
25977
25978 /*
25979 @@ -96,15 +98,19 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25980 * handler) we can't do that and just have to keep using the
25981 * current stack (which is the irq stack already after all)
25982 */
25983 - if (unlikely(curstk == irqstk))
25984 + if (unlikely((void *)current_stack_pointer - (void *)irqstk < THREAD_SIZE))
25985 return 0;
25986
25987 - isp = (u32 *) ((char *)irqstk + sizeof(*irqstk));
25988 + isp = (u32 *) ((char *)irqstk + sizeof(*irqstk) - 8);
25989
25990 /* Save the next esp at the bottom of the stack */
25991 prev_esp = (u32 *)irqstk;
25992 *prev_esp = current_stack_pointer;
25993
25994 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25995 + __set_fs(MAKE_MM_SEG(0));
25996 +#endif
25997 +
25998 if (unlikely(overflow))
25999 call_on_stack(print_stack_overflow, isp);
26000
26001 @@ -115,6 +121,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
26002 : "0" (irq), "1" (desc), "2" (isp),
26003 "D" (desc->handle_irq)
26004 : "memory", "cc", "ecx");
26005 +
26006 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26007 + __set_fs(current_thread_info()->addr_limit);
26008 +#endif
26009 +
26010 return 1;
26011 }
26012
26013 @@ -123,32 +134,18 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
26014 */
26015 void irq_ctx_init(int cpu)
26016 {
26017 - struct irq_stack *irqstk;
26018 -
26019 if (per_cpu(hardirq_stack, cpu))
26020 return;
26021
26022 - irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
26023 - THREADINFO_GFP,
26024 - THREAD_SIZE_ORDER));
26025 - per_cpu(hardirq_stack, cpu) = irqstk;
26026 -
26027 - irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
26028 - THREADINFO_GFP,
26029 - THREAD_SIZE_ORDER));
26030 - per_cpu(softirq_stack, cpu) = irqstk;
26031 -
26032 - printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
26033 - cpu, per_cpu(hardirq_stack, cpu), per_cpu(softirq_stack, cpu));
26034 + per_cpu(hardirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
26035 + per_cpu(softirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
26036 }
26037
26038 void do_softirq_own_stack(void)
26039 {
26040 - struct thread_info *curstk;
26041 struct irq_stack *irqstk;
26042 u32 *isp, *prev_esp;
26043
26044 - curstk = current_stack();
26045 irqstk = __this_cpu_read(softirq_stack);
26046
26047 /* build the stack frame on the softirq stack */
26048 @@ -158,7 +155,16 @@ void do_softirq_own_stack(void)
26049 prev_esp = (u32 *)irqstk;
26050 *prev_esp = current_stack_pointer;
26051
26052 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26053 + __set_fs(MAKE_MM_SEG(0));
26054 +#endif
26055 +
26056 call_on_stack(__do_softirq, isp);
26057 +
26058 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26059 + __set_fs(current_thread_info()->addr_limit);
26060 +#endif
26061 +
26062 }
26063
26064 bool handle_irq(unsigned irq, struct pt_regs *regs)
26065 @@ -172,7 +178,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
26066 if (unlikely(!desc))
26067 return false;
26068
26069 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
26070 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
26071 if (unlikely(overflow))
26072 print_stack_overflow();
26073 desc->handle_irq(irq, desc);
26074 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
26075 index 4d1c746..55a22d6 100644
26076 --- a/arch/x86/kernel/irq_64.c
26077 +++ b/arch/x86/kernel/irq_64.c
26078 @@ -26,6 +26,8 @@ EXPORT_PER_CPU_SYMBOL(irq_stat);
26079 DEFINE_PER_CPU(struct pt_regs *, irq_regs);
26080 EXPORT_PER_CPU_SYMBOL(irq_regs);
26081
26082 +extern void gr_handle_kernel_exploit(void);
26083 +
26084 int sysctl_panic_on_stackoverflow;
26085
26086 /*
26087 @@ -44,7 +46,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
26088 u64 estack_top, estack_bottom;
26089 u64 curbase = (u64)task_stack_page(current);
26090
26091 - if (user_mode_vm(regs))
26092 + if (user_mode(regs))
26093 return;
26094
26095 if (regs->sp >= curbase + sizeof(struct thread_info) +
26096 @@ -69,6 +71,8 @@ static inline void stack_overflow_check(struct pt_regs *regs)
26097 irq_stack_top, irq_stack_bottom,
26098 estack_top, estack_bottom);
26099
26100 + gr_handle_kernel_exploit();
26101 +
26102 if (sysctl_panic_on_stackoverflow)
26103 panic("low stack detected by irq handler - check messages\n");
26104 #endif
26105 diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
26106 index 26d5a55..a01160a 100644
26107 --- a/arch/x86/kernel/jump_label.c
26108 +++ b/arch/x86/kernel/jump_label.c
26109 @@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
26110 * Jump label is enabled for the first time.
26111 * So we expect a default_nop...
26112 */
26113 - if (unlikely(memcmp((void *)entry->code, default_nop, 5)
26114 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
26115 != 0))
26116 bug_at((void *)entry->code, __LINE__);
26117 } else {
26118 @@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
26119 * ...otherwise expect an ideal_nop. Otherwise
26120 * something went horribly wrong.
26121 */
26122 - if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
26123 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
26124 != 0))
26125 bug_at((void *)entry->code, __LINE__);
26126 }
26127 @@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
26128 * are converting the default nop to the ideal nop.
26129 */
26130 if (init) {
26131 - if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
26132 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
26133 bug_at((void *)entry->code, __LINE__);
26134 } else {
26135 code.jump = 0xe9;
26136 code.offset = entry->target -
26137 (entry->code + JUMP_LABEL_NOP_SIZE);
26138 - if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
26139 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
26140 bug_at((void *)entry->code, __LINE__);
26141 }
26142 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
26143 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
26144 index 7ec1d5f..5a7d130 100644
26145 --- a/arch/x86/kernel/kgdb.c
26146 +++ b/arch/x86/kernel/kgdb.c
26147 @@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
26148 #ifdef CONFIG_X86_32
26149 switch (regno) {
26150 case GDB_SS:
26151 - if (!user_mode_vm(regs))
26152 + if (!user_mode(regs))
26153 *(unsigned long *)mem = __KERNEL_DS;
26154 break;
26155 case GDB_SP:
26156 - if (!user_mode_vm(regs))
26157 + if (!user_mode(regs))
26158 *(unsigned long *)mem = kernel_stack_pointer(regs);
26159 break;
26160 case GDB_GS:
26161 @@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
26162 bp->attr.bp_addr = breakinfo[breakno].addr;
26163 bp->attr.bp_len = breakinfo[breakno].len;
26164 bp->attr.bp_type = breakinfo[breakno].type;
26165 - info->address = breakinfo[breakno].addr;
26166 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
26167 + info->address = ktla_ktva(breakinfo[breakno].addr);
26168 + else
26169 + info->address = breakinfo[breakno].addr;
26170 info->len = breakinfo[breakno].len;
26171 info->type = breakinfo[breakno].type;
26172 val = arch_install_hw_breakpoint(bp);
26173 @@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
26174 case 'k':
26175 /* clear the trace bit */
26176 linux_regs->flags &= ~X86_EFLAGS_TF;
26177 - atomic_set(&kgdb_cpu_doing_single_step, -1);
26178 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
26179
26180 /* set the trace bit if we're stepping */
26181 if (remcomInBuffer[0] == 's') {
26182 linux_regs->flags |= X86_EFLAGS_TF;
26183 - atomic_set(&kgdb_cpu_doing_single_step,
26184 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
26185 raw_smp_processor_id());
26186 }
26187
26188 @@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
26189
26190 switch (cmd) {
26191 case DIE_DEBUG:
26192 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
26193 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
26194 if (user_mode(regs))
26195 return single_step_cont(regs, args);
26196 break;
26197 @@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
26198 #endif /* CONFIG_DEBUG_RODATA */
26199
26200 bpt->type = BP_BREAKPOINT;
26201 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
26202 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
26203 BREAK_INSTR_SIZE);
26204 if (err)
26205 return err;
26206 - err = probe_kernel_write((char *)bpt->bpt_addr,
26207 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
26208 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
26209 #ifdef CONFIG_DEBUG_RODATA
26210 if (!err)
26211 @@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
26212 return -EBUSY;
26213 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
26214 BREAK_INSTR_SIZE);
26215 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
26216 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
26217 if (err)
26218 return err;
26219 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
26220 @@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
26221 if (mutex_is_locked(&text_mutex))
26222 goto knl_write;
26223 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
26224 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
26225 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
26226 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
26227 goto knl_write;
26228 return err;
26229 knl_write:
26230 #endif /* CONFIG_DEBUG_RODATA */
26231 - return probe_kernel_write((char *)bpt->bpt_addr,
26232 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
26233 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
26234 }
26235
26236 diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
26237 index 67e6d19..731ed28 100644
26238 --- a/arch/x86/kernel/kprobes/core.c
26239 +++ b/arch/x86/kernel/kprobes/core.c
26240 @@ -120,9 +120,12 @@ __synthesize_relative_insn(void *from, void *to, u8 op)
26241 s32 raddr;
26242 } __packed *insn;
26243
26244 - insn = (struct __arch_relative_insn *)from;
26245 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
26246 +
26247 + pax_open_kernel();
26248 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
26249 insn->op = op;
26250 + pax_close_kernel();
26251 }
26252
26253 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
26254 @@ -168,7 +171,7 @@ int can_boost(kprobe_opcode_t *opcodes)
26255 kprobe_opcode_t opcode;
26256 kprobe_opcode_t *orig_opcodes = opcodes;
26257
26258 - if (search_exception_tables((unsigned long)opcodes))
26259 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
26260 return 0; /* Page fault may occur on this address. */
26261
26262 retry:
26263 @@ -242,9 +245,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
26264 * for the first byte, we can recover the original instruction
26265 * from it and kp->opcode.
26266 */
26267 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
26268 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
26269 buf[0] = kp->opcode;
26270 - return (unsigned long)buf;
26271 + return ktva_ktla((unsigned long)buf);
26272 }
26273
26274 /*
26275 @@ -336,7 +339,9 @@ int __copy_instruction(u8 *dest, u8 *src)
26276 /* Another subsystem puts a breakpoint, failed to recover */
26277 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
26278 return 0;
26279 + pax_open_kernel();
26280 memcpy(dest, insn.kaddr, insn.length);
26281 + pax_close_kernel();
26282
26283 #ifdef CONFIG_X86_64
26284 if (insn_rip_relative(&insn)) {
26285 @@ -363,7 +368,9 @@ int __copy_instruction(u8 *dest, u8 *src)
26286 return 0;
26287 }
26288 disp = (u8 *) dest + insn_offset_displacement(&insn);
26289 + pax_open_kernel();
26290 *(s32 *) disp = (s32) newdisp;
26291 + pax_close_kernel();
26292 }
26293 #endif
26294 return insn.length;
26295 @@ -505,7 +512,7 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
26296 * nor set current_kprobe, because it doesn't use single
26297 * stepping.
26298 */
26299 - regs->ip = (unsigned long)p->ainsn.insn;
26300 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
26301 preempt_enable_no_resched();
26302 return;
26303 }
26304 @@ -522,9 +529,9 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
26305 regs->flags &= ~X86_EFLAGS_IF;
26306 /* single step inline if the instruction is an int3 */
26307 if (p->opcode == BREAKPOINT_INSTRUCTION)
26308 - regs->ip = (unsigned long)p->addr;
26309 + regs->ip = ktla_ktva((unsigned long)p->addr);
26310 else
26311 - regs->ip = (unsigned long)p->ainsn.insn;
26312 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
26313 }
26314 NOKPROBE_SYMBOL(setup_singlestep);
26315
26316 @@ -574,7 +581,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
26317 struct kprobe *p;
26318 struct kprobe_ctlblk *kcb;
26319
26320 - if (user_mode_vm(regs))
26321 + if (user_mode(regs))
26322 return 0;
26323
26324 addr = (kprobe_opcode_t *)(regs->ip - sizeof(kprobe_opcode_t));
26325 @@ -609,7 +616,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
26326 setup_singlestep(p, regs, kcb, 0);
26327 return 1;
26328 }
26329 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
26330 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
26331 /*
26332 * The breakpoint instruction was removed right
26333 * after we hit it. Another cpu has removed
26334 @@ -656,6 +663,9 @@ static void __used kretprobe_trampoline_holder(void)
26335 " movq %rax, 152(%rsp)\n"
26336 RESTORE_REGS_STRING
26337 " popfq\n"
26338 +#ifdef KERNEXEC_PLUGIN
26339 + " btsq $63,(%rsp)\n"
26340 +#endif
26341 #else
26342 " pushf\n"
26343 SAVE_REGS_STRING
26344 @@ -796,7 +806,7 @@ static void resume_execution(struct kprobe *p, struct pt_regs *regs,
26345 struct kprobe_ctlblk *kcb)
26346 {
26347 unsigned long *tos = stack_addr(regs);
26348 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
26349 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
26350 unsigned long orig_ip = (unsigned long)p->addr;
26351 kprobe_opcode_t *insn = p->ainsn.insn;
26352
26353 @@ -979,7 +989,7 @@ int kprobe_exceptions_notify(struct notifier_block *self, unsigned long val,
26354 struct die_args *args = data;
26355 int ret = NOTIFY_DONE;
26356
26357 - if (args->regs && user_mode_vm(args->regs))
26358 + if (args->regs && user_mode(args->regs))
26359 return ret;
26360
26361 if (val == DIE_GPF) {
26362 diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
26363 index f1314d0..15f3154 100644
26364 --- a/arch/x86/kernel/kprobes/opt.c
26365 +++ b/arch/x86/kernel/kprobes/opt.c
26366 @@ -79,6 +79,7 @@ found:
26367 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
26368 static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
26369 {
26370 + pax_open_kernel();
26371 #ifdef CONFIG_X86_64
26372 *addr++ = 0x48;
26373 *addr++ = 0xbf;
26374 @@ -86,6 +87,7 @@ static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
26375 *addr++ = 0xb8;
26376 #endif
26377 *(unsigned long *)addr = val;
26378 + pax_close_kernel();
26379 }
26380
26381 asm (
26382 @@ -337,7 +339,7 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
26383 * Verify if the address gap is in 2GB range, because this uses
26384 * a relative jump.
26385 */
26386 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
26387 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
26388 if (abs(rel) > 0x7fffffff) {
26389 __arch_remove_optimized_kprobe(op, 0);
26390 return -ERANGE;
26391 @@ -354,16 +356,18 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
26392 op->optinsn.size = ret;
26393
26394 /* Copy arch-dep-instance from template */
26395 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
26396 + pax_open_kernel();
26397 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
26398 + pax_close_kernel();
26399
26400 /* Set probe information */
26401 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
26402
26403 /* Set probe function call */
26404 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
26405 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
26406
26407 /* Set returning jmp instruction at the tail of out-of-line buffer */
26408 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
26409 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
26410 (u8 *)op->kp.addr + op->optinsn.size);
26411
26412 flush_icache_range((unsigned long) buf,
26413 @@ -388,7 +392,7 @@ void arch_optimize_kprobes(struct list_head *oplist)
26414 WARN_ON(kprobe_disabled(&op->kp));
26415
26416 /* Backup instructions which will be replaced by jump address */
26417 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
26418 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
26419 RELATIVE_ADDR_SIZE);
26420
26421 insn_buf[0] = RELATIVEJUMP_OPCODE;
26422 @@ -436,7 +440,7 @@ int setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
26423 /* This kprobe is really able to run optimized path. */
26424 op = container_of(p, struct optimized_kprobe, kp);
26425 /* Detour through copied instructions */
26426 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
26427 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
26428 if (!reenter)
26429 reset_current_kprobe();
26430 preempt_enable_no_resched();
26431 diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
26432 index c2bedae..25e7ab60 100644
26433 --- a/arch/x86/kernel/ksysfs.c
26434 +++ b/arch/x86/kernel/ksysfs.c
26435 @@ -184,7 +184,7 @@ out:
26436
26437 static struct kobj_attribute type_attr = __ATTR_RO(type);
26438
26439 -static struct bin_attribute data_attr = {
26440 +static bin_attribute_no_const data_attr __read_only = {
26441 .attr = {
26442 .name = "data",
26443 .mode = S_IRUGO,
26444 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
26445 index c37886d..d851d32 100644
26446 --- a/arch/x86/kernel/ldt.c
26447 +++ b/arch/x86/kernel/ldt.c
26448 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
26449 if (reload) {
26450 #ifdef CONFIG_SMP
26451 preempt_disable();
26452 - load_LDT(pc);
26453 + load_LDT_nolock(pc);
26454 if (!cpumask_equal(mm_cpumask(current->mm),
26455 cpumask_of(smp_processor_id())))
26456 smp_call_function(flush_ldt, current->mm, 1);
26457 preempt_enable();
26458 #else
26459 - load_LDT(pc);
26460 + load_LDT_nolock(pc);
26461 #endif
26462 }
26463 if (oldsize) {
26464 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
26465 return err;
26466
26467 for (i = 0; i < old->size; i++)
26468 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
26469 + write_ldt_entry(new->ldt, i, old->ldt + i);
26470 return 0;
26471 }
26472
26473 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
26474 retval = copy_ldt(&mm->context, &old_mm->context);
26475 mutex_unlock(&old_mm->context.lock);
26476 }
26477 +
26478 + if (tsk == current) {
26479 + mm->context.vdso = 0;
26480 +
26481 +#ifdef CONFIG_X86_32
26482 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26483 + mm->context.user_cs_base = 0UL;
26484 + mm->context.user_cs_limit = ~0UL;
26485 +
26486 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
26487 + cpus_clear(mm->context.cpu_user_cs_mask);
26488 +#endif
26489 +
26490 +#endif
26491 +#endif
26492 +
26493 + }
26494 +
26495 return retval;
26496 }
26497
26498 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
26499 }
26500 }
26501
26502 +#ifdef CONFIG_PAX_SEGMEXEC
26503 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
26504 + error = -EINVAL;
26505 + goto out_unlock;
26506 + }
26507 +#endif
26508 +
26509 if (!IS_ENABLED(CONFIG_X86_16BIT) && !ldt_info.seg_32bit) {
26510 error = -EINVAL;
26511 goto out_unlock;
26512 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
26513 index 1667b1d..16492c5 100644
26514 --- a/arch/x86/kernel/machine_kexec_32.c
26515 +++ b/arch/x86/kernel/machine_kexec_32.c
26516 @@ -25,7 +25,7 @@
26517 #include <asm/cacheflush.h>
26518 #include <asm/debugreg.h>
26519
26520 -static void set_idt(void *newidt, __u16 limit)
26521 +static void set_idt(struct desc_struct *newidt, __u16 limit)
26522 {
26523 struct desc_ptr curidt;
26524
26525 @@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
26526 }
26527
26528
26529 -static void set_gdt(void *newgdt, __u16 limit)
26530 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
26531 {
26532 struct desc_ptr curgdt;
26533
26534 @@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
26535 }
26536
26537 control_page = page_address(image->control_code_page);
26538 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
26539 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
26540
26541 relocate_kernel_ptr = control_page;
26542 page_list[PA_CONTROL_PAGE] = __pa(control_page);
26543 diff --git a/arch/x86/kernel/mcount_64.S b/arch/x86/kernel/mcount_64.S
26544 index c73aecf..4c63630 100644
26545 --- a/arch/x86/kernel/mcount_64.S
26546 +++ b/arch/x86/kernel/mcount_64.S
26547 @@ -7,7 +7,7 @@
26548 #include <linux/linkage.h>
26549 #include <asm/ptrace.h>
26550 #include <asm/ftrace.h>
26551 -
26552 +#include <asm/alternative-asm.h>
26553
26554 .code64
26555 .section .entry.text, "ax"
26556 @@ -24,8 +24,9 @@
26557 #ifdef CONFIG_DYNAMIC_FTRACE
26558
26559 ENTRY(function_hook)
26560 + pax_force_retaddr
26561 retq
26562 -END(function_hook)
26563 +ENDPROC(function_hook)
26564
26565 /* skip is set if stack has been adjusted */
26566 .macro ftrace_caller_setup skip=0
26567 @@ -62,8 +63,9 @@ GLOBAL(ftrace_graph_call)
26568 #endif
26569
26570 GLOBAL(ftrace_stub)
26571 + pax_force_retaddr
26572 retq
26573 -END(ftrace_caller)
26574 +ENDPROC(ftrace_caller)
26575
26576 ENTRY(ftrace_regs_caller)
26577 /* Save the current flags before compare (in SS location)*/
26578 @@ -127,7 +129,7 @@ GLOBAL(ftrace_regs_call)
26579 popfq
26580 jmp ftrace_stub
26581
26582 -END(ftrace_regs_caller)
26583 +ENDPROC(ftrace_regs_caller)
26584
26585
26586 #else /* ! CONFIG_DYNAMIC_FTRACE */
26587 @@ -145,6 +147,7 @@ ENTRY(function_hook)
26588 #endif
26589
26590 GLOBAL(ftrace_stub)
26591 + pax_force_retaddr
26592 retq
26593
26594 trace:
26595 @@ -158,12 +161,13 @@ trace:
26596 #endif
26597 subq $MCOUNT_INSN_SIZE, %rdi
26598
26599 + pax_force_fptr ftrace_trace_function
26600 call *ftrace_trace_function
26601
26602 MCOUNT_RESTORE_FRAME
26603
26604 jmp ftrace_stub
26605 -END(function_hook)
26606 +ENDPROC(function_hook)
26607 #endif /* CONFIG_DYNAMIC_FTRACE */
26608 #endif /* CONFIG_FUNCTION_TRACER */
26609
26610 @@ -185,8 +189,9 @@ ENTRY(ftrace_graph_caller)
26611
26612 MCOUNT_RESTORE_FRAME
26613
26614 + pax_force_retaddr
26615 retq
26616 -END(ftrace_graph_caller)
26617 +ENDPROC(ftrace_graph_caller)
26618
26619 GLOBAL(return_to_handler)
26620 subq $24, %rsp
26621 @@ -202,5 +207,7 @@ GLOBAL(return_to_handler)
26622 movq 8(%rsp), %rdx
26623 movq (%rsp), %rax
26624 addq $24, %rsp
26625 + pax_force_fptr %rdi
26626 jmp *%rdi
26627 +ENDPROC(return_to_handler)
26628 #endif
26629 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
26630 index e69f988..da078ea 100644
26631 --- a/arch/x86/kernel/module.c
26632 +++ b/arch/x86/kernel/module.c
26633 @@ -81,17 +81,62 @@ static unsigned long int get_module_load_offset(void)
26634 }
26635 #endif
26636
26637 -void *module_alloc(unsigned long size)
26638 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
26639 {
26640 - if (PAGE_ALIGN(size) > MODULES_LEN)
26641 + if (!size || PAGE_ALIGN(size) > MODULES_LEN)
26642 return NULL;
26643 return __vmalloc_node_range(size, 1,
26644 MODULES_VADDR + get_module_load_offset(),
26645 - MODULES_END, GFP_KERNEL | __GFP_HIGHMEM,
26646 - PAGE_KERNEL_EXEC, NUMA_NO_NODE,
26647 + MODULES_END, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
26648 + prot, NUMA_NO_NODE,
26649 __builtin_return_address(0));
26650 }
26651
26652 +void *module_alloc(unsigned long size)
26653 +{
26654 +
26655 +#ifdef CONFIG_PAX_KERNEXEC
26656 + return __module_alloc(size, PAGE_KERNEL);
26657 +#else
26658 + return __module_alloc(size, PAGE_KERNEL_EXEC);
26659 +#endif
26660 +
26661 +}
26662 +
26663 +#ifdef CONFIG_PAX_KERNEXEC
26664 +#ifdef CONFIG_X86_32
26665 +void *module_alloc_exec(unsigned long size)
26666 +{
26667 + struct vm_struct *area;
26668 +
26669 + if (size == 0)
26670 + return NULL;
26671 +
26672 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
26673 +return area ? area->addr : NULL;
26674 +}
26675 +EXPORT_SYMBOL(module_alloc_exec);
26676 +
26677 +void module_free_exec(struct module *mod, void *module_region)
26678 +{
26679 + vunmap(module_region);
26680 +}
26681 +EXPORT_SYMBOL(module_free_exec);
26682 +#else
26683 +void module_free_exec(struct module *mod, void *module_region)
26684 +{
26685 + module_free(mod, module_region);
26686 +}
26687 +EXPORT_SYMBOL(module_free_exec);
26688 +
26689 +void *module_alloc_exec(unsigned long size)
26690 +{
26691 + return __module_alloc(size, PAGE_KERNEL_RX);
26692 +}
26693 +EXPORT_SYMBOL(module_alloc_exec);
26694 +#endif
26695 +#endif
26696 +
26697 #ifdef CONFIG_X86_32
26698 int apply_relocate(Elf32_Shdr *sechdrs,
26699 const char *strtab,
26700 @@ -102,14 +147,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26701 unsigned int i;
26702 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
26703 Elf32_Sym *sym;
26704 - uint32_t *location;
26705 + uint32_t *plocation, location;
26706
26707 DEBUGP("Applying relocate section %u to %u\n",
26708 relsec, sechdrs[relsec].sh_info);
26709 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
26710 /* This is where to make the change */
26711 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
26712 - + rel[i].r_offset;
26713 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
26714 + location = (uint32_t)plocation;
26715 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
26716 + plocation = ktla_ktva((void *)plocation);
26717 /* This is the symbol it is referring to. Note that all
26718 undefined symbols have been resolved. */
26719 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
26720 @@ -118,11 +165,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26721 switch (ELF32_R_TYPE(rel[i].r_info)) {
26722 case R_386_32:
26723 /* We add the value into the location given */
26724 - *location += sym->st_value;
26725 + pax_open_kernel();
26726 + *plocation += sym->st_value;
26727 + pax_close_kernel();
26728 break;
26729 case R_386_PC32:
26730 /* Add the value, subtract its position */
26731 - *location += sym->st_value - (uint32_t)location;
26732 + pax_open_kernel();
26733 + *plocation += sym->st_value - location;
26734 + pax_close_kernel();
26735 break;
26736 default:
26737 pr_err("%s: Unknown relocation: %u\n",
26738 @@ -167,21 +218,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
26739 case R_X86_64_NONE:
26740 break;
26741 case R_X86_64_64:
26742 + pax_open_kernel();
26743 *(u64 *)loc = val;
26744 + pax_close_kernel();
26745 break;
26746 case R_X86_64_32:
26747 + pax_open_kernel();
26748 *(u32 *)loc = val;
26749 + pax_close_kernel();
26750 if (val != *(u32 *)loc)
26751 goto overflow;
26752 break;
26753 case R_X86_64_32S:
26754 + pax_open_kernel();
26755 *(s32 *)loc = val;
26756 + pax_close_kernel();
26757 if ((s64)val != *(s32 *)loc)
26758 goto overflow;
26759 break;
26760 case R_X86_64_PC32:
26761 val -= (u64)loc;
26762 + pax_open_kernel();
26763 *(u32 *)loc = val;
26764 + pax_close_kernel();
26765 +
26766 #if 0
26767 if ((s64)val != *(s32 *)loc)
26768 goto overflow;
26769 diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
26770 index c9603ac..9f88728 100644
26771 --- a/arch/x86/kernel/msr.c
26772 +++ b/arch/x86/kernel/msr.c
26773 @@ -37,6 +37,7 @@
26774 #include <linux/notifier.h>
26775 #include <linux/uaccess.h>
26776 #include <linux/gfp.h>
26777 +#include <linux/grsecurity.h>
26778
26779 #include <asm/processor.h>
26780 #include <asm/msr.h>
26781 @@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
26782 int err = 0;
26783 ssize_t bytes = 0;
26784
26785 +#ifdef CONFIG_GRKERNSEC_KMEM
26786 + gr_handle_msr_write();
26787 + return -EPERM;
26788 +#endif
26789 +
26790 if (count % 8)
26791 return -EINVAL; /* Invalid chunk size */
26792
26793 @@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
26794 err = -EBADF;
26795 break;
26796 }
26797 +#ifdef CONFIG_GRKERNSEC_KMEM
26798 + gr_handle_msr_write();
26799 + return -EPERM;
26800 +#endif
26801 if (copy_from_user(&regs, uregs, sizeof regs)) {
26802 err = -EFAULT;
26803 break;
26804 @@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
26805 return notifier_from_errno(err);
26806 }
26807
26808 -static struct notifier_block __refdata msr_class_cpu_notifier = {
26809 +static struct notifier_block msr_class_cpu_notifier = {
26810 .notifier_call = msr_class_cpu_callback,
26811 };
26812
26813 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
26814 index c3e985d..110a36a 100644
26815 --- a/arch/x86/kernel/nmi.c
26816 +++ b/arch/x86/kernel/nmi.c
26817 @@ -98,16 +98,16 @@ fs_initcall(nmi_warning_debugfs);
26818
26819 static void nmi_max_handler(struct irq_work *w)
26820 {
26821 - struct nmiaction *a = container_of(w, struct nmiaction, irq_work);
26822 + struct nmiwork *n = container_of(w, struct nmiwork, irq_work);
26823 int remainder_ns, decimal_msecs;
26824 - u64 whole_msecs = ACCESS_ONCE(a->max_duration);
26825 + u64 whole_msecs = ACCESS_ONCE(n->max_duration);
26826
26827 remainder_ns = do_div(whole_msecs, (1000 * 1000));
26828 decimal_msecs = remainder_ns / 1000;
26829
26830 printk_ratelimited(KERN_INFO
26831 "INFO: NMI handler (%ps) took too long to run: %lld.%03d msecs\n",
26832 - a->handler, whole_msecs, decimal_msecs);
26833 + n->action->handler, whole_msecs, decimal_msecs);
26834 }
26835
26836 static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26837 @@ -134,11 +134,11 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26838 delta = sched_clock() - delta;
26839 trace_nmi_handler(a->handler, (int)delta, thishandled);
26840
26841 - if (delta < nmi_longest_ns || delta < a->max_duration)
26842 + if (delta < nmi_longest_ns || delta < a->work->max_duration)
26843 continue;
26844
26845 - a->max_duration = delta;
26846 - irq_work_queue(&a->irq_work);
26847 + a->work->max_duration = delta;
26848 + irq_work_queue(&a->work->irq_work);
26849 }
26850
26851 rcu_read_unlock();
26852 @@ -148,7 +148,7 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26853 }
26854 NOKPROBE_SYMBOL(nmi_handle);
26855
26856 -int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26857 +int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
26858 {
26859 struct nmi_desc *desc = nmi_to_desc(type);
26860 unsigned long flags;
26861 @@ -156,7 +156,8 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26862 if (!action->handler)
26863 return -EINVAL;
26864
26865 - init_irq_work(&action->irq_work, nmi_max_handler);
26866 + action->work->action = action;
26867 + init_irq_work(&action->work->irq_work, nmi_max_handler);
26868
26869 spin_lock_irqsave(&desc->lock, flags);
26870
26871 @@ -174,9 +175,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26872 * event confuses some handlers (kdump uses this flag)
26873 */
26874 if (action->flags & NMI_FLAG_FIRST)
26875 - list_add_rcu(&action->list, &desc->head);
26876 + pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
26877 else
26878 - list_add_tail_rcu(&action->list, &desc->head);
26879 + pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
26880
26881 spin_unlock_irqrestore(&desc->lock, flags);
26882 return 0;
26883 @@ -199,7 +200,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
26884 if (!strcmp(n->name, name)) {
26885 WARN(in_nmi(),
26886 "Trying to free NMI (%s) from NMI context!\n", n->name);
26887 - list_del_rcu(&n->list);
26888 + pax_list_del_rcu((struct list_head *)&n->list);
26889 break;
26890 }
26891 }
26892 @@ -528,6 +529,17 @@ static inline void nmi_nesting_postprocess(void)
26893 dotraplinkage notrace void
26894 do_nmi(struct pt_regs *regs, long error_code)
26895 {
26896 +
26897 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26898 + if (!user_mode(regs)) {
26899 + unsigned long cs = regs->cs & 0xFFFF;
26900 + unsigned long ip = ktva_ktla(regs->ip);
26901 +
26902 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
26903 + regs->ip = ip;
26904 + }
26905 +#endif
26906 +
26907 nmi_nesting_preprocess(regs);
26908
26909 nmi_enter();
26910 diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
26911 index 6d9582e..f746287 100644
26912 --- a/arch/x86/kernel/nmi_selftest.c
26913 +++ b/arch/x86/kernel/nmi_selftest.c
26914 @@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
26915 {
26916 /* trap all the unknown NMIs we may generate */
26917 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
26918 - __initdata);
26919 + __initconst);
26920 }
26921
26922 static void __init cleanup_nmi_testsuite(void)
26923 @@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
26924 unsigned long timeout;
26925
26926 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
26927 - NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
26928 + NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
26929 nmi_fail = FAILURE;
26930 return;
26931 }
26932 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
26933 index bbb6c73..24a58ef 100644
26934 --- a/arch/x86/kernel/paravirt-spinlocks.c
26935 +++ b/arch/x86/kernel/paravirt-spinlocks.c
26936 @@ -8,7 +8,7 @@
26937
26938 #include <asm/paravirt.h>
26939
26940 -struct pv_lock_ops pv_lock_ops = {
26941 +struct pv_lock_ops pv_lock_ops __read_only = {
26942 #ifdef CONFIG_SMP
26943 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
26944 .unlock_kick = paravirt_nop,
26945 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
26946 index 548d25f..f8fb99c 100644
26947 --- a/arch/x86/kernel/paravirt.c
26948 +++ b/arch/x86/kernel/paravirt.c
26949 @@ -56,6 +56,9 @@ u64 _paravirt_ident_64(u64 x)
26950 {
26951 return x;
26952 }
26953 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26954 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
26955 +#endif
26956
26957 void __init default_banner(void)
26958 {
26959 @@ -142,16 +145,20 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
26960
26961 if (opfunc == NULL)
26962 /* If there's no function, patch it with a ud2a (BUG) */
26963 - ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
26964 - else if (opfunc == _paravirt_nop)
26965 + ret = paravirt_patch_insns(insnbuf, len, ktva_ktla(ud2a), ud2a+sizeof(ud2a));
26966 + else if (opfunc == (void *)_paravirt_nop)
26967 /* If the operation is a nop, then nop the callsite */
26968 ret = paravirt_patch_nop();
26969
26970 /* identity functions just return their single argument */
26971 - else if (opfunc == _paravirt_ident_32)
26972 + else if (opfunc == (void *)_paravirt_ident_32)
26973 ret = paravirt_patch_ident_32(insnbuf, len);
26974 - else if (opfunc == _paravirt_ident_64)
26975 + else if (opfunc == (void *)_paravirt_ident_64)
26976 ret = paravirt_patch_ident_64(insnbuf, len);
26977 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26978 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
26979 + ret = paravirt_patch_ident_64(insnbuf, len);
26980 +#endif
26981
26982 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
26983 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
26984 @@ -176,7 +183,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
26985 if (insn_len > len || start == NULL)
26986 insn_len = len;
26987 else
26988 - memcpy(insnbuf, start, insn_len);
26989 + memcpy(insnbuf, ktla_ktva(start), insn_len);
26990
26991 return insn_len;
26992 }
26993 @@ -300,7 +307,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
26994 return this_cpu_read(paravirt_lazy_mode);
26995 }
26996
26997 -struct pv_info pv_info = {
26998 +struct pv_info pv_info __read_only = {
26999 .name = "bare hardware",
27000 .paravirt_enabled = 0,
27001 .kernel_rpl = 0,
27002 @@ -311,16 +318,16 @@ struct pv_info pv_info = {
27003 #endif
27004 };
27005
27006 -struct pv_init_ops pv_init_ops = {
27007 +struct pv_init_ops pv_init_ops __read_only = {
27008 .patch = native_patch,
27009 };
27010
27011 -struct pv_time_ops pv_time_ops = {
27012 +struct pv_time_ops pv_time_ops __read_only = {
27013 .sched_clock = native_sched_clock,
27014 .steal_clock = native_steal_clock,
27015 };
27016
27017 -__visible struct pv_irq_ops pv_irq_ops = {
27018 +__visible struct pv_irq_ops pv_irq_ops __read_only = {
27019 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
27020 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
27021 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
27022 @@ -332,7 +339,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
27023 #endif
27024 };
27025
27026 -__visible struct pv_cpu_ops pv_cpu_ops = {
27027 +__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
27028 .cpuid = native_cpuid,
27029 .get_debugreg = native_get_debugreg,
27030 .set_debugreg = native_set_debugreg,
27031 @@ -395,21 +402,26 @@ NOKPROBE_SYMBOL(native_get_debugreg);
27032 NOKPROBE_SYMBOL(native_set_debugreg);
27033 NOKPROBE_SYMBOL(native_load_idt);
27034
27035 -struct pv_apic_ops pv_apic_ops = {
27036 +struct pv_apic_ops pv_apic_ops __read_only= {
27037 #ifdef CONFIG_X86_LOCAL_APIC
27038 .startup_ipi_hook = paravirt_nop,
27039 #endif
27040 };
27041
27042 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
27043 +#ifdef CONFIG_X86_32
27044 +#ifdef CONFIG_X86_PAE
27045 +/* 64-bit pagetable entries */
27046 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
27047 +#else
27048 /* 32-bit pagetable entries */
27049 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
27050 +#endif
27051 #else
27052 /* 64-bit pagetable entries */
27053 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
27054 #endif
27055
27056 -struct pv_mmu_ops pv_mmu_ops = {
27057 +struct pv_mmu_ops pv_mmu_ops __read_only = {
27058
27059 .read_cr2 = native_read_cr2,
27060 .write_cr2 = native_write_cr2,
27061 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
27062 .make_pud = PTE_IDENT,
27063
27064 .set_pgd = native_set_pgd,
27065 + .set_pgd_batched = native_set_pgd_batched,
27066 #endif
27067 #endif /* PAGETABLE_LEVELS >= 3 */
27068
27069 @@ -479,6 +492,12 @@ struct pv_mmu_ops pv_mmu_ops = {
27070 },
27071
27072 .set_fixmap = native_set_fixmap,
27073 +
27074 +#ifdef CONFIG_PAX_KERNEXEC
27075 + .pax_open_kernel = native_pax_open_kernel,
27076 + .pax_close_kernel = native_pax_close_kernel,
27077 +#endif
27078 +
27079 };
27080
27081 EXPORT_SYMBOL_GPL(pv_time_ops);
27082 diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
27083 index 0497f71..7186c0d 100644
27084 --- a/arch/x86/kernel/pci-calgary_64.c
27085 +++ b/arch/x86/kernel/pci-calgary_64.c
27086 @@ -1347,7 +1347,7 @@ static void __init get_tce_space_from_tar(void)
27087 tce_space = be64_to_cpu(readq(target));
27088 tce_space = tce_space & TAR_SW_BITS;
27089
27090 - tce_space = tce_space & (~specified_table_size);
27091 + tce_space = tce_space & (~(unsigned long)specified_table_size);
27092 info->tce_space = (u64 *)__va(tce_space);
27093 }
27094 }
27095 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
27096 index 35ccf75..7a15747 100644
27097 --- a/arch/x86/kernel/pci-iommu_table.c
27098 +++ b/arch/x86/kernel/pci-iommu_table.c
27099 @@ -2,7 +2,7 @@
27100 #include <asm/iommu_table.h>
27101 #include <linux/string.h>
27102 #include <linux/kallsyms.h>
27103 -
27104 +#include <linux/sched.h>
27105
27106 #define DEBUG 1
27107
27108 diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
27109 index 77dd0ad..9ec4723 100644
27110 --- a/arch/x86/kernel/pci-swiotlb.c
27111 +++ b/arch/x86/kernel/pci-swiotlb.c
27112 @@ -33,7 +33,7 @@ void x86_swiotlb_free_coherent(struct device *dev, size_t size,
27113 struct dma_attrs *attrs)
27114 {
27115 if (is_swiotlb_buffer(dma_to_phys(dev, dma_addr)))
27116 - swiotlb_free_coherent(dev, size, vaddr, dma_addr);
27117 + swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
27118 else
27119 dma_generic_free_coherent(dev, size, vaddr, dma_addr, attrs);
27120 }
27121 diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
27122 index ca7f0d5..8996469 100644
27123 --- a/arch/x86/kernel/preempt.S
27124 +++ b/arch/x86/kernel/preempt.S
27125 @@ -3,12 +3,14 @@
27126 #include <asm/dwarf2.h>
27127 #include <asm/asm.h>
27128 #include <asm/calling.h>
27129 +#include <asm/alternative-asm.h>
27130
27131 ENTRY(___preempt_schedule)
27132 CFI_STARTPROC
27133 SAVE_ALL
27134 call preempt_schedule
27135 RESTORE_ALL
27136 + pax_force_retaddr
27137 ret
27138 CFI_ENDPROC
27139
27140 @@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
27141 SAVE_ALL
27142 call preempt_schedule_context
27143 RESTORE_ALL
27144 + pax_force_retaddr
27145 ret
27146 CFI_ENDPROC
27147
27148 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
27149 index f804dc9..7c62095 100644
27150 --- a/arch/x86/kernel/process.c
27151 +++ b/arch/x86/kernel/process.c
27152 @@ -36,7 +36,8 @@
27153 * section. Since TSS's are completely CPU-local, we want them
27154 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
27155 */
27156 -__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
27157 +struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
27158 +EXPORT_SYMBOL(init_tss);
27159
27160 #ifdef CONFIG_X86_64
27161 static DEFINE_PER_CPU(unsigned char, is_idle);
27162 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
27163 task_xstate_cachep =
27164 kmem_cache_create("task_xstate", xstate_size,
27165 __alignof__(union thread_xstate),
27166 - SLAB_PANIC | SLAB_NOTRACK, NULL);
27167 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
27168 setup_xstate_comp();
27169 }
27170
27171 @@ -106,7 +107,7 @@ void exit_thread(void)
27172 unsigned long *bp = t->io_bitmap_ptr;
27173
27174 if (bp) {
27175 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
27176 + struct tss_struct *tss = init_tss + get_cpu();
27177
27178 t->io_bitmap_ptr = NULL;
27179 clear_thread_flag(TIF_IO_BITMAP);
27180 @@ -126,6 +127,9 @@ void flush_thread(void)
27181 {
27182 struct task_struct *tsk = current;
27183
27184 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
27185 + loadsegment(gs, 0);
27186 +#endif
27187 flush_ptrace_hw_breakpoint(tsk);
27188 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
27189 drop_init_fpu(tsk);
27190 @@ -272,7 +276,7 @@ static void __exit_idle(void)
27191 void exit_idle(void)
27192 {
27193 /* idle loop has pid 0 */
27194 - if (current->pid)
27195 + if (task_pid_nr(current))
27196 return;
27197 __exit_idle();
27198 }
27199 @@ -325,7 +329,7 @@ bool xen_set_default_idle(void)
27200 return ret;
27201 }
27202 #endif
27203 -void stop_this_cpu(void *dummy)
27204 +__noreturn void stop_this_cpu(void *dummy)
27205 {
27206 local_irq_disable();
27207 /*
27208 @@ -454,16 +458,37 @@ static int __init idle_setup(char *str)
27209 }
27210 early_param("idle", idle_setup);
27211
27212 -unsigned long arch_align_stack(unsigned long sp)
27213 +#ifdef CONFIG_PAX_RANDKSTACK
27214 +void pax_randomize_kstack(struct pt_regs *regs)
27215 {
27216 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
27217 - sp -= get_random_int() % 8192;
27218 - return sp & ~0xf;
27219 -}
27220 + struct thread_struct *thread = &current->thread;
27221 + unsigned long time;
27222
27223 -unsigned long arch_randomize_brk(struct mm_struct *mm)
27224 -{
27225 - unsigned long range_end = mm->brk + 0x02000000;
27226 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
27227 -}
27228 + if (!randomize_va_space)
27229 + return;
27230 +
27231 + if (v8086_mode(regs))
27232 + return;
27233
27234 + rdtscl(time);
27235 +
27236 + /* P4 seems to return a 0 LSB, ignore it */
27237 +#ifdef CONFIG_MPENTIUM4
27238 + time &= 0x3EUL;
27239 + time <<= 2;
27240 +#elif defined(CONFIG_X86_64)
27241 + time &= 0xFUL;
27242 + time <<= 4;
27243 +#else
27244 + time &= 0x1FUL;
27245 + time <<= 3;
27246 +#endif
27247 +
27248 + thread->sp0 ^= time;
27249 + load_sp0(init_tss + smp_processor_id(), thread);
27250 +
27251 +#ifdef CONFIG_X86_64
27252 + this_cpu_write(kernel_stack, thread->sp0);
27253 +#endif
27254 +}
27255 +#endif
27256 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
27257 index 7bc86bb..0ea06e8 100644
27258 --- a/arch/x86/kernel/process_32.c
27259 +++ b/arch/x86/kernel/process_32.c
27260 @@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
27261 unsigned long thread_saved_pc(struct task_struct *tsk)
27262 {
27263 return ((unsigned long *)tsk->thread.sp)[3];
27264 +//XXX return tsk->thread.eip;
27265 }
27266
27267 void __show_regs(struct pt_regs *regs, int all)
27268 @@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
27269 unsigned long sp;
27270 unsigned short ss, gs;
27271
27272 - if (user_mode_vm(regs)) {
27273 + if (user_mode(regs)) {
27274 sp = regs->sp;
27275 ss = regs->ss & 0xffff;
27276 - gs = get_user_gs(regs);
27277 } else {
27278 sp = kernel_stack_pointer(regs);
27279 savesegment(ss, ss);
27280 - savesegment(gs, gs);
27281 }
27282 + gs = get_user_gs(regs);
27283
27284 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
27285 (u16)regs->cs, regs->ip, regs->flags,
27286 - smp_processor_id());
27287 + raw_smp_processor_id());
27288 print_symbol("EIP is at %s\n", regs->ip);
27289
27290 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
27291 @@ -132,20 +132,21 @@ void release_thread(struct task_struct *dead_task)
27292 int copy_thread(unsigned long clone_flags, unsigned long sp,
27293 unsigned long arg, struct task_struct *p)
27294 {
27295 - struct pt_regs *childregs = task_pt_regs(p);
27296 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
27297 struct task_struct *tsk;
27298 int err;
27299
27300 p->thread.sp = (unsigned long) childregs;
27301 p->thread.sp0 = (unsigned long) (childregs+1);
27302 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
27303
27304 if (unlikely(p->flags & PF_KTHREAD)) {
27305 /* kernel thread */
27306 memset(childregs, 0, sizeof(struct pt_regs));
27307 p->thread.ip = (unsigned long) ret_from_kernel_thread;
27308 - task_user_gs(p) = __KERNEL_STACK_CANARY;
27309 - childregs->ds = __USER_DS;
27310 - childregs->es = __USER_DS;
27311 + savesegment(gs, childregs->gs);
27312 + childregs->ds = __KERNEL_DS;
27313 + childregs->es = __KERNEL_DS;
27314 childregs->fs = __KERNEL_PERCPU;
27315 childregs->bx = sp; /* function */
27316 childregs->bp = arg;
27317 @@ -252,7 +253,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27318 struct thread_struct *prev = &prev_p->thread,
27319 *next = &next_p->thread;
27320 int cpu = smp_processor_id();
27321 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
27322 + struct tss_struct *tss = init_tss + cpu;
27323 fpu_switch_t fpu;
27324
27325 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
27326 @@ -276,6 +277,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27327 */
27328 lazy_save_gs(prev->gs);
27329
27330 +#ifdef CONFIG_PAX_MEMORY_UDEREF
27331 + __set_fs(task_thread_info(next_p)->addr_limit);
27332 +#endif
27333 +
27334 /*
27335 * Load the per-thread Thread-Local Storage descriptor.
27336 */
27337 @@ -314,9 +319,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27338 */
27339 arch_end_context_switch(next_p);
27340
27341 - this_cpu_write(kernel_stack,
27342 - (unsigned long)task_stack_page(next_p) +
27343 - THREAD_SIZE - KERNEL_STACK_OFFSET);
27344 + this_cpu_write(current_task, next_p);
27345 + this_cpu_write(current_tinfo, &next_p->tinfo);
27346 + this_cpu_write(kernel_stack, next->sp0);
27347
27348 /*
27349 * Restore %gs if needed (which is common)
27350 @@ -326,8 +331,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27351
27352 switch_fpu_finish(next_p, fpu);
27353
27354 - this_cpu_write(current_task, next_p);
27355 -
27356 return prev_p;
27357 }
27358
27359 @@ -357,4 +360,3 @@ unsigned long get_wchan(struct task_struct *p)
27360 } while (count++ < 16);
27361 return 0;
27362 }
27363 -
27364 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
27365 index ca5b02d..c0b2f6a 100644
27366 --- a/arch/x86/kernel/process_64.c
27367 +++ b/arch/x86/kernel/process_64.c
27368 @@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
27369 struct pt_regs *childregs;
27370 struct task_struct *me = current;
27371
27372 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
27373 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
27374 childregs = task_pt_regs(p);
27375 p->thread.sp = (unsigned long) childregs;
27376 p->thread.usersp = me->thread.usersp;
27377 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
27378 set_tsk_thread_flag(p, TIF_FORK);
27379 p->thread.fpu_counter = 0;
27380 p->thread.io_bitmap_ptr = NULL;
27381 @@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
27382 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
27383 savesegment(es, p->thread.es);
27384 savesegment(ds, p->thread.ds);
27385 + savesegment(ss, p->thread.ss);
27386 + BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
27387 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
27388
27389 if (unlikely(p->flags & PF_KTHREAD)) {
27390 @@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27391 struct thread_struct *prev = &prev_p->thread;
27392 struct thread_struct *next = &next_p->thread;
27393 int cpu = smp_processor_id();
27394 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
27395 + struct tss_struct *tss = init_tss + cpu;
27396 unsigned fsindex, gsindex;
27397 fpu_switch_t fpu;
27398
27399 @@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27400 if (unlikely(next->ds | prev->ds))
27401 loadsegment(ds, next->ds);
27402
27403 + savesegment(ss, prev->ss);
27404 + if (unlikely(next->ss != prev->ss))
27405 + loadsegment(ss, next->ss);
27406
27407 /* We must save %fs and %gs before load_TLS() because
27408 * %fs and %gs may be cleared by load_TLS().
27409 @@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27410 prev->usersp = this_cpu_read(old_rsp);
27411 this_cpu_write(old_rsp, next->usersp);
27412 this_cpu_write(current_task, next_p);
27413 + this_cpu_write(current_tinfo, &next_p->tinfo);
27414
27415 /*
27416 * If it were not for PREEMPT_ACTIVE we could guarantee that the
27417 @@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27418 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
27419 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
27420
27421 - this_cpu_write(kernel_stack,
27422 - (unsigned long)task_stack_page(next_p) +
27423 - THREAD_SIZE - KERNEL_STACK_OFFSET);
27424 + this_cpu_write(kernel_stack, next->sp0);
27425
27426 /*
27427 * Now maybe reload the debug registers and handle I/O bitmaps
27428 @@ -443,12 +448,11 @@ unsigned long get_wchan(struct task_struct *p)
27429 if (!p || p == current || p->state == TASK_RUNNING)
27430 return 0;
27431 stack = (unsigned long)task_stack_page(p);
27432 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
27433 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
27434 return 0;
27435 fp = *(u64 *)(p->thread.sp);
27436 do {
27437 - if (fp < (unsigned long)stack ||
27438 - fp >= (unsigned long)stack+THREAD_SIZE)
27439 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
27440 return 0;
27441 ip = *(u64 *)(fp+8);
27442 if (!in_sched_functions(ip))
27443 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
27444 index b1a5dfa..ed94526 100644
27445 --- a/arch/x86/kernel/ptrace.c
27446 +++ b/arch/x86/kernel/ptrace.c
27447 @@ -186,10 +186,10 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
27448 unsigned long sp = (unsigned long)&regs->sp;
27449 u32 *prev_esp;
27450
27451 - if (context == (sp & ~(THREAD_SIZE - 1)))
27452 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
27453 return sp;
27454
27455 - prev_esp = (u32 *)(context);
27456 + prev_esp = *(u32 **)(context);
27457 if (prev_esp)
27458 return (unsigned long)prev_esp;
27459
27460 @@ -452,6 +452,20 @@ static int putreg(struct task_struct *child,
27461 if (child->thread.gs != value)
27462 return do_arch_prctl(child, ARCH_SET_GS, value);
27463 return 0;
27464 +
27465 + case offsetof(struct user_regs_struct,ip):
27466 + /*
27467 + * Protect against any attempt to set ip to an
27468 + * impossible address. There are dragons lurking if the
27469 + * address is noncanonical. (This explicitly allows
27470 + * setting ip to TASK_SIZE_MAX, because user code can do
27471 + * that all by itself by running off the end of its
27472 + * address space.
27473 + */
27474 + if (value > TASK_SIZE_MAX)
27475 + return -EIO;
27476 + break;
27477 +
27478 #endif
27479 }
27480
27481 @@ -588,7 +602,7 @@ static void ptrace_triggered(struct perf_event *bp,
27482 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
27483 {
27484 int i;
27485 - int dr7 = 0;
27486 + unsigned long dr7 = 0;
27487 struct arch_hw_breakpoint *info;
27488
27489 for (i = 0; i < HBP_NUM; i++) {
27490 @@ -822,7 +836,7 @@ long arch_ptrace(struct task_struct *child, long request,
27491 unsigned long addr, unsigned long data)
27492 {
27493 int ret;
27494 - unsigned long __user *datap = (unsigned long __user *)data;
27495 + unsigned long __user *datap = (__force unsigned long __user *)data;
27496
27497 switch (request) {
27498 /* read the word at location addr in the USER area. */
27499 @@ -907,14 +921,14 @@ long arch_ptrace(struct task_struct *child, long request,
27500 if ((int) addr < 0)
27501 return -EIO;
27502 ret = do_get_thread_area(child, addr,
27503 - (struct user_desc __user *)data);
27504 + (__force struct user_desc __user *) data);
27505 break;
27506
27507 case PTRACE_SET_THREAD_AREA:
27508 if ((int) addr < 0)
27509 return -EIO;
27510 ret = do_set_thread_area(child, addr,
27511 - (struct user_desc __user *)data, 0);
27512 + (__force struct user_desc __user *) data, 0);
27513 break;
27514 #endif
27515
27516 @@ -1292,7 +1306,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
27517
27518 #ifdef CONFIG_X86_64
27519
27520 -static struct user_regset x86_64_regsets[] __read_mostly = {
27521 +static user_regset_no_const x86_64_regsets[] __read_only = {
27522 [REGSET_GENERAL] = {
27523 .core_note_type = NT_PRSTATUS,
27524 .n = sizeof(struct user_regs_struct) / sizeof(long),
27525 @@ -1333,7 +1347,7 @@ static const struct user_regset_view user_x86_64_view = {
27526 #endif /* CONFIG_X86_64 */
27527
27528 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
27529 -static struct user_regset x86_32_regsets[] __read_mostly = {
27530 +static user_regset_no_const x86_32_regsets[] __read_only = {
27531 [REGSET_GENERAL] = {
27532 .core_note_type = NT_PRSTATUS,
27533 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
27534 @@ -1386,7 +1400,7 @@ static const struct user_regset_view user_x86_32_view = {
27535 */
27536 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
27537
27538 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
27539 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
27540 {
27541 #ifdef CONFIG_X86_64
27542 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
27543 @@ -1421,7 +1435,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
27544 memset(info, 0, sizeof(*info));
27545 info->si_signo = SIGTRAP;
27546 info->si_code = si_code;
27547 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
27548 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
27549 }
27550
27551 void user_single_step_siginfo(struct task_struct *tsk,
27552 @@ -1441,6 +1455,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
27553 force_sig_info(SIGTRAP, &info, tsk);
27554 }
27555
27556 +#ifdef CONFIG_GRKERNSEC_SETXID
27557 +extern void gr_delayed_cred_worker(void);
27558 +#endif
27559 +
27560 /*
27561 * We must return the syscall number to actually look up in the table.
27562 * This can be -1L to skip running any syscall at all.
27563 @@ -1451,6 +1469,11 @@ long syscall_trace_enter(struct pt_regs *regs)
27564
27565 user_exit();
27566
27567 +#ifdef CONFIG_GRKERNSEC_SETXID
27568 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
27569 + gr_delayed_cred_worker();
27570 +#endif
27571 +
27572 /*
27573 * If we stepped into a sysenter/syscall insn, it trapped in
27574 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
27575 @@ -1506,6 +1529,11 @@ void syscall_trace_leave(struct pt_regs *regs)
27576 */
27577 user_exit();
27578
27579 +#ifdef CONFIG_GRKERNSEC_SETXID
27580 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
27581 + gr_delayed_cred_worker();
27582 +#endif
27583 +
27584 audit_syscall_exit(regs);
27585
27586 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
27587 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
27588 index 2f355d2..e75ed0a 100644
27589 --- a/arch/x86/kernel/pvclock.c
27590 +++ b/arch/x86/kernel/pvclock.c
27591 @@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
27592 reset_hung_task_detector();
27593 }
27594
27595 -static atomic64_t last_value = ATOMIC64_INIT(0);
27596 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
27597
27598 void pvclock_resume(void)
27599 {
27600 - atomic64_set(&last_value, 0);
27601 + atomic64_set_unchecked(&last_value, 0);
27602 }
27603
27604 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
27605 @@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
27606 * updating at the same time, and one of them could be slightly behind,
27607 * making the assumption that last_value always go forward fail to hold.
27608 */
27609 - last = atomic64_read(&last_value);
27610 + last = atomic64_read_unchecked(&last_value);
27611 do {
27612 if (ret < last)
27613 return last;
27614 - last = atomic64_cmpxchg(&last_value, last, ret);
27615 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
27616 } while (unlikely(last != ret));
27617
27618 return ret;
27619 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
27620 index 17962e6..47f55db 100644
27621 --- a/arch/x86/kernel/reboot.c
27622 +++ b/arch/x86/kernel/reboot.c
27623 @@ -69,6 +69,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
27624
27625 void __noreturn machine_real_restart(unsigned int type)
27626 {
27627 +
27628 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
27629 + struct desc_struct *gdt;
27630 +#endif
27631 +
27632 local_irq_disable();
27633
27634 /*
27635 @@ -96,7 +101,29 @@ void __noreturn machine_real_restart(unsigned int type)
27636
27637 /* Jump to the identity-mapped low memory code */
27638 #ifdef CONFIG_X86_32
27639 - asm volatile("jmpl *%0" : :
27640 +
27641 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
27642 + gdt = get_cpu_gdt_table(smp_processor_id());
27643 + pax_open_kernel();
27644 +#ifdef CONFIG_PAX_MEMORY_UDEREF
27645 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
27646 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
27647 + loadsegment(ds, __KERNEL_DS);
27648 + loadsegment(es, __KERNEL_DS);
27649 + loadsegment(ss, __KERNEL_DS);
27650 +#endif
27651 +#ifdef CONFIG_PAX_KERNEXEC
27652 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
27653 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
27654 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
27655 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
27656 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
27657 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
27658 +#endif
27659 + pax_close_kernel();
27660 +#endif
27661 +
27662 + asm volatile("ljmpl *%0" : :
27663 "rm" (real_mode_header->machine_real_restart_asm),
27664 "a" (type));
27665 #else
27666 @@ -500,7 +527,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
27667 * This means that this function can never return, it can misbehave
27668 * by not rebooting properly and hanging.
27669 */
27670 -static void native_machine_emergency_restart(void)
27671 +static void __noreturn native_machine_emergency_restart(void)
27672 {
27673 int i;
27674 int attempt = 0;
27675 @@ -620,13 +647,13 @@ void native_machine_shutdown(void)
27676 #endif
27677 }
27678
27679 -static void __machine_emergency_restart(int emergency)
27680 +static void __noreturn __machine_emergency_restart(int emergency)
27681 {
27682 reboot_emergency = emergency;
27683 machine_ops.emergency_restart();
27684 }
27685
27686 -static void native_machine_restart(char *__unused)
27687 +static void __noreturn native_machine_restart(char *__unused)
27688 {
27689 pr_notice("machine restart\n");
27690
27691 @@ -635,7 +662,7 @@ static void native_machine_restart(char *__unused)
27692 __machine_emergency_restart(0);
27693 }
27694
27695 -static void native_machine_halt(void)
27696 +static void __noreturn native_machine_halt(void)
27697 {
27698 /* Stop other cpus and apics */
27699 machine_shutdown();
27700 @@ -645,7 +672,7 @@ static void native_machine_halt(void)
27701 stop_this_cpu(NULL);
27702 }
27703
27704 -static void native_machine_power_off(void)
27705 +static void __noreturn native_machine_power_off(void)
27706 {
27707 if (pm_power_off) {
27708 if (!reboot_force)
27709 @@ -654,9 +681,10 @@ static void native_machine_power_off(void)
27710 }
27711 /* A fallback in case there is no PM info available */
27712 tboot_shutdown(TB_SHUTDOWN_HALT);
27713 + unreachable();
27714 }
27715
27716 -struct machine_ops machine_ops = {
27717 +struct machine_ops machine_ops __read_only = {
27718 .power_off = native_machine_power_off,
27719 .shutdown = native_machine_shutdown,
27720 .emergency_restart = native_machine_emergency_restart,
27721 diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
27722 index c8e41e9..64049ef 100644
27723 --- a/arch/x86/kernel/reboot_fixups_32.c
27724 +++ b/arch/x86/kernel/reboot_fixups_32.c
27725 @@ -57,7 +57,7 @@ struct device_fixup {
27726 unsigned int vendor;
27727 unsigned int device;
27728 void (*reboot_fixup)(struct pci_dev *);
27729 -};
27730 +} __do_const;
27731
27732 /*
27733 * PCI ids solely used for fixups_table go here
27734 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
27735 index 3fd2c69..a444264 100644
27736 --- a/arch/x86/kernel/relocate_kernel_64.S
27737 +++ b/arch/x86/kernel/relocate_kernel_64.S
27738 @@ -96,8 +96,7 @@ relocate_kernel:
27739
27740 /* jump to identity mapped page */
27741 addq $(identity_mapped - relocate_kernel), %r8
27742 - pushq %r8
27743 - ret
27744 + jmp *%r8
27745
27746 identity_mapped:
27747 /* set return address to 0 if not preserving context */
27748 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
27749 index 41ead8d..7ccde23 100644
27750 --- a/arch/x86/kernel/setup.c
27751 +++ b/arch/x86/kernel/setup.c
27752 @@ -110,6 +110,7 @@
27753 #include <asm/mce.h>
27754 #include <asm/alternative.h>
27755 #include <asm/prom.h>
27756 +#include <asm/boot.h>
27757
27758 /*
27759 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
27760 @@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
27761 #endif
27762
27763
27764 -#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
27765 -__visible unsigned long mmu_cr4_features;
27766 +#ifdef CONFIG_X86_64
27767 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
27768 +#elif defined(CONFIG_X86_PAE)
27769 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
27770 #else
27771 -__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
27772 +__visible unsigned long mmu_cr4_features __read_only;
27773 #endif
27774
27775 +void set_in_cr4(unsigned long mask)
27776 +{
27777 + unsigned long cr4 = read_cr4();
27778 +
27779 + if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
27780 + return;
27781 +
27782 + pax_open_kernel();
27783 + mmu_cr4_features |= mask;
27784 + pax_close_kernel();
27785 +
27786 + if (trampoline_cr4_features)
27787 + *trampoline_cr4_features = mmu_cr4_features;
27788 + cr4 |= mask;
27789 + write_cr4(cr4);
27790 +}
27791 +EXPORT_SYMBOL(set_in_cr4);
27792 +
27793 +void clear_in_cr4(unsigned long mask)
27794 +{
27795 + unsigned long cr4 = read_cr4();
27796 +
27797 + if (!(cr4 & mask) && cr4 == mmu_cr4_features)
27798 + return;
27799 +
27800 + pax_open_kernel();
27801 + mmu_cr4_features &= ~mask;
27802 + pax_close_kernel();
27803 +
27804 + if (trampoline_cr4_features)
27805 + *trampoline_cr4_features = mmu_cr4_features;
27806 + cr4 &= ~mask;
27807 + write_cr4(cr4);
27808 +}
27809 +EXPORT_SYMBOL(clear_in_cr4);
27810 +
27811 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
27812 int bootloader_type, bootloader_version;
27813
27814 @@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
27815 * area (640->1Mb) as ram even though it is not.
27816 * take them out.
27817 */
27818 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
27819 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
27820
27821 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
27822 }
27823 @@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
27824 /* called before trim_bios_range() to spare extra sanitize */
27825 static void __init e820_add_kernel_range(void)
27826 {
27827 - u64 start = __pa_symbol(_text);
27828 + u64 start = __pa_symbol(ktla_ktva(_text));
27829 u64 size = __pa_symbol(_end) - start;
27830
27831 /*
27832 @@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
27833
27834 void __init setup_arch(char **cmdline_p)
27835 {
27836 +#ifdef CONFIG_X86_32
27837 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
27838 +#else
27839 memblock_reserve(__pa_symbol(_text),
27840 (unsigned long)__bss_stop - (unsigned long)_text);
27841 +#endif
27842
27843 early_reserve_initrd();
27844
27845 @@ -946,14 +989,14 @@ void __init setup_arch(char **cmdline_p)
27846
27847 if (!boot_params.hdr.root_flags)
27848 root_mountflags &= ~MS_RDONLY;
27849 - init_mm.start_code = (unsigned long) _text;
27850 - init_mm.end_code = (unsigned long) _etext;
27851 + init_mm.start_code = ktla_ktva((unsigned long) _text);
27852 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
27853 init_mm.end_data = (unsigned long) _edata;
27854 init_mm.brk = _brk_end;
27855
27856 - code_resource.start = __pa_symbol(_text);
27857 - code_resource.end = __pa_symbol(_etext)-1;
27858 - data_resource.start = __pa_symbol(_etext);
27859 + code_resource.start = __pa_symbol(ktla_ktva(_text));
27860 + code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
27861 + data_resource.start = __pa_symbol(_sdata);
27862 data_resource.end = __pa_symbol(_edata)-1;
27863 bss_resource.start = __pa_symbol(__bss_start);
27864 bss_resource.end = __pa_symbol(__bss_stop)-1;
27865 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
27866 index 5cdff03..80fa283 100644
27867 --- a/arch/x86/kernel/setup_percpu.c
27868 +++ b/arch/x86/kernel/setup_percpu.c
27869 @@ -21,19 +21,17 @@
27870 #include <asm/cpu.h>
27871 #include <asm/stackprotector.h>
27872
27873 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
27874 +#ifdef CONFIG_SMP
27875 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
27876 EXPORT_PER_CPU_SYMBOL(cpu_number);
27877 +#endif
27878
27879 -#ifdef CONFIG_X86_64
27880 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
27881 -#else
27882 -#define BOOT_PERCPU_OFFSET 0
27883 -#endif
27884
27885 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
27886 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
27887
27888 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
27889 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
27890 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
27891 };
27892 EXPORT_SYMBOL(__per_cpu_offset);
27893 @@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
27894 {
27895 #ifdef CONFIG_NEED_MULTIPLE_NODES
27896 pg_data_t *last = NULL;
27897 - unsigned int cpu;
27898 + int cpu;
27899
27900 for_each_possible_cpu(cpu) {
27901 int node = early_cpu_to_node(cpu);
27902 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
27903 {
27904 #ifdef CONFIG_X86_32
27905 struct desc_struct gdt;
27906 + unsigned long base = per_cpu_offset(cpu);
27907
27908 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
27909 - 0x2 | DESCTYPE_S, 0x8);
27910 - gdt.s = 1;
27911 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
27912 + 0x83 | DESCTYPE_S, 0xC);
27913 write_gdt_entry(get_cpu_gdt_table(cpu),
27914 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
27915 #endif
27916 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
27917 /* alrighty, percpu areas up and running */
27918 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
27919 for_each_possible_cpu(cpu) {
27920 +#ifdef CONFIG_CC_STACKPROTECTOR
27921 +#ifdef CONFIG_X86_32
27922 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
27923 +#endif
27924 +#endif
27925 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
27926 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
27927 per_cpu(cpu_number, cpu) = cpu;
27928 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
27929 */
27930 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
27931 #endif
27932 +#ifdef CONFIG_CC_STACKPROTECTOR
27933 +#ifdef CONFIG_X86_32
27934 + if (!cpu)
27935 + per_cpu(stack_canary.canary, cpu) = canary;
27936 +#endif
27937 +#endif
27938 /*
27939 * Up to this point, the boot CPU has been using .init.data
27940 * area. Reload any changed state for the boot CPU.
27941 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
27942 index ed37a76..39f936e 100644
27943 --- a/arch/x86/kernel/signal.c
27944 +++ b/arch/x86/kernel/signal.c
27945 @@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
27946 * Align the stack pointer according to the i386 ABI,
27947 * i.e. so that on function entry ((sp + 4) & 15) == 0.
27948 */
27949 - sp = ((sp + 4) & -16ul) - 4;
27950 + sp = ((sp - 12) & -16ul) - 4;
27951 #else /* !CONFIG_X86_32 */
27952 sp = round_down(sp, 16) - 8;
27953 #endif
27954 @@ -298,10 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27955 }
27956
27957 if (current->mm->context.vdso)
27958 - restorer = current->mm->context.vdso +
27959 - selected_vdso32->sym___kernel_sigreturn;
27960 + restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_sigreturn);
27961 else
27962 - restorer = &frame->retcode;
27963 + restorer = (void __user *)&frame->retcode;
27964 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27965 restorer = ksig->ka.sa.sa_restorer;
27966
27967 @@ -315,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27968 * reasons and because gdb uses it as a signature to notice
27969 * signal handler stack frames.
27970 */
27971 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
27972 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
27973
27974 if (err)
27975 return -EFAULT;
27976 @@ -362,8 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27977 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
27978
27979 /* Set up to return from userspace. */
27980 - restorer = current->mm->context.vdso +
27981 - selected_vdso32->sym___kernel_rt_sigreturn;
27982 + if (current->mm->context.vdso)
27983 + restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_rt_sigreturn);
27984 + else
27985 + restorer = (void __user *)&frame->retcode;
27986 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27987 restorer = ksig->ka.sa.sa_restorer;
27988 put_user_ex(restorer, &frame->pretcode);
27989 @@ -375,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27990 * reasons and because gdb uses it as a signature to notice
27991 * signal handler stack frames.
27992 */
27993 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
27994 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
27995 } put_user_catch(err);
27996
27997 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
27998 @@ -611,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27999 {
28000 int usig = signr_convert(ksig->sig);
28001 sigset_t *set = sigmask_to_save();
28002 - compat_sigset_t *cset = (compat_sigset_t *) set;
28003 + sigset_t sigcopy;
28004 + compat_sigset_t *cset;
28005 +
28006 + sigcopy = *set;
28007 +
28008 + cset = (compat_sigset_t *) &sigcopy;
28009
28010 /* Set up the stack frame */
28011 if (is_ia32_frame()) {
28012 @@ -622,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
28013 } else if (is_x32_frame()) {
28014 return x32_setup_rt_frame(ksig, cset, regs);
28015 } else {
28016 - return __setup_rt_frame(ksig->sig, ksig, set, regs);
28017 + return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
28018 }
28019 }
28020
28021 diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
28022 index be8e1bd..a3d93fa 100644
28023 --- a/arch/x86/kernel/smp.c
28024 +++ b/arch/x86/kernel/smp.c
28025 @@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
28026
28027 __setup("nonmi_ipi", nonmi_ipi_setup);
28028
28029 -struct smp_ops smp_ops = {
28030 +struct smp_ops smp_ops __read_only = {
28031 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
28032 .smp_prepare_cpus = native_smp_prepare_cpus,
28033 .smp_cpus_done = native_smp_cpus_done,
28034 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
28035 index 42a2dca..35a07aa 100644
28036 --- a/arch/x86/kernel/smpboot.c
28037 +++ b/arch/x86/kernel/smpboot.c
28038 @@ -226,14 +226,17 @@ static void notrace start_secondary(void *unused)
28039
28040 enable_start_cpu0 = 0;
28041
28042 -#ifdef CONFIG_X86_32
28043 + /* otherwise gcc will move up smp_processor_id before the cpu_init */
28044 + barrier();
28045 +
28046 /* switch away from the initial page table */
28047 +#ifdef CONFIG_PAX_PER_CPU_PGD
28048 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
28049 +#else
28050 load_cr3(swapper_pg_dir);
28051 +#endif
28052 __flush_tlb_all();
28053 -#endif
28054
28055 - /* otherwise gcc will move up smp_processor_id before the cpu_init */
28056 - barrier();
28057 /*
28058 * Check TSC synchronization with the BP:
28059 */
28060 @@ -760,8 +763,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
28061 alternatives_enable_smp();
28062
28063 idle->thread.sp = (unsigned long) (((struct pt_regs *)
28064 - (THREAD_SIZE + task_stack_page(idle))) - 1);
28065 + (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
28066 per_cpu(current_task, cpu) = idle;
28067 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
28068
28069 #ifdef CONFIG_X86_32
28070 /* Stack for startup_32 can be just as for start_secondary onwards */
28071 @@ -770,10 +774,10 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
28072 clear_tsk_thread_flag(idle, TIF_FORK);
28073 initial_gs = per_cpu_offset(cpu);
28074 #endif
28075 - per_cpu(kernel_stack, cpu) =
28076 - (unsigned long)task_stack_page(idle) -
28077 - KERNEL_STACK_OFFSET + THREAD_SIZE;
28078 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
28079 + pax_open_kernel();
28080 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
28081 + pax_close_kernel();
28082 initial_code = (unsigned long)start_secondary;
28083 stack_start = idle->thread.sp;
28084
28085 @@ -919,6 +923,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
28086 /* the FPU context is blank, nobody can own it */
28087 __cpu_disable_lazy_restore(cpu);
28088
28089 +#ifdef CONFIG_PAX_PER_CPU_PGD
28090 + clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
28091 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28092 + KERNEL_PGD_PTRS);
28093 + clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
28094 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28095 + KERNEL_PGD_PTRS);
28096 +#endif
28097 +
28098 err = do_boot_cpu(apicid, cpu, tidle);
28099 if (err) {
28100 pr_err("do_boot_cpu failed(%d) to wakeup CPU#%u\n", err, cpu);
28101 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
28102 index 9b4d51d..5d28b58 100644
28103 --- a/arch/x86/kernel/step.c
28104 +++ b/arch/x86/kernel/step.c
28105 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
28106 struct desc_struct *desc;
28107 unsigned long base;
28108
28109 - seg &= ~7UL;
28110 + seg >>= 3;
28111
28112 mutex_lock(&child->mm->context.lock);
28113 - if (unlikely((seg >> 3) >= child->mm->context.size))
28114 + if (unlikely(seg >= child->mm->context.size))
28115 addr = -1L; /* bogus selector, access would fault */
28116 else {
28117 desc = child->mm->context.ldt + seg;
28118 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
28119 addr += base;
28120 }
28121 mutex_unlock(&child->mm->context.lock);
28122 - }
28123 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
28124 + addr = ktla_ktva(addr);
28125
28126 return addr;
28127 }
28128 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
28129 unsigned char opcode[15];
28130 unsigned long addr = convert_ip_to_linear(child, regs);
28131
28132 + if (addr == -EINVAL)
28133 + return 0;
28134 +
28135 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
28136 for (i = 0; i < copied; i++) {
28137 switch (opcode[i]) {
28138 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
28139 new file mode 100644
28140 index 0000000..5877189
28141 --- /dev/null
28142 +++ b/arch/x86/kernel/sys_i386_32.c
28143 @@ -0,0 +1,189 @@
28144 +/*
28145 + * This file contains various random system calls that
28146 + * have a non-standard calling sequence on the Linux/i386
28147 + * platform.
28148 + */
28149 +
28150 +#include <linux/errno.h>
28151 +#include <linux/sched.h>
28152 +#include <linux/mm.h>
28153 +#include <linux/fs.h>
28154 +#include <linux/smp.h>
28155 +#include <linux/sem.h>
28156 +#include <linux/msg.h>
28157 +#include <linux/shm.h>
28158 +#include <linux/stat.h>
28159 +#include <linux/syscalls.h>
28160 +#include <linux/mman.h>
28161 +#include <linux/file.h>
28162 +#include <linux/utsname.h>
28163 +#include <linux/ipc.h>
28164 +#include <linux/elf.h>
28165 +
28166 +#include <linux/uaccess.h>
28167 +#include <linux/unistd.h>
28168 +
28169 +#include <asm/syscalls.h>
28170 +
28171 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
28172 +{
28173 + unsigned long pax_task_size = TASK_SIZE;
28174 +
28175 +#ifdef CONFIG_PAX_SEGMEXEC
28176 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
28177 + pax_task_size = SEGMEXEC_TASK_SIZE;
28178 +#endif
28179 +
28180 + if (flags & MAP_FIXED)
28181 + if (len > pax_task_size || addr > pax_task_size - len)
28182 + return -EINVAL;
28183 +
28184 + return 0;
28185 +}
28186 +
28187 +/*
28188 + * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
28189 + */
28190 +static unsigned long get_align_mask(void)
28191 +{
28192 + if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
28193 + return 0;
28194 +
28195 + if (!(current->flags & PF_RANDOMIZE))
28196 + return 0;
28197 +
28198 + return va_align.mask;
28199 +}
28200 +
28201 +unsigned long
28202 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
28203 + unsigned long len, unsigned long pgoff, unsigned long flags)
28204 +{
28205 + struct mm_struct *mm = current->mm;
28206 + struct vm_area_struct *vma;
28207 + unsigned long pax_task_size = TASK_SIZE;
28208 + struct vm_unmapped_area_info info;
28209 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
28210 +
28211 +#ifdef CONFIG_PAX_SEGMEXEC
28212 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
28213 + pax_task_size = SEGMEXEC_TASK_SIZE;
28214 +#endif
28215 +
28216 + pax_task_size -= PAGE_SIZE;
28217 +
28218 + if (len > pax_task_size)
28219 + return -ENOMEM;
28220 +
28221 + if (flags & MAP_FIXED)
28222 + return addr;
28223 +
28224 +#ifdef CONFIG_PAX_RANDMMAP
28225 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
28226 +#endif
28227 +
28228 + if (addr) {
28229 + addr = PAGE_ALIGN(addr);
28230 + if (pax_task_size - len >= addr) {
28231 + vma = find_vma(mm, addr);
28232 + if (check_heap_stack_gap(vma, addr, len, offset))
28233 + return addr;
28234 + }
28235 + }
28236 +
28237 + info.flags = 0;
28238 + info.length = len;
28239 + info.align_mask = filp ? get_align_mask() : 0;
28240 + info.align_offset = pgoff << PAGE_SHIFT;
28241 + info.threadstack_offset = offset;
28242 +
28243 +#ifdef CONFIG_PAX_PAGEEXEC
28244 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
28245 + info.low_limit = 0x00110000UL;
28246 + info.high_limit = mm->start_code;
28247 +
28248 +#ifdef CONFIG_PAX_RANDMMAP
28249 + if (mm->pax_flags & MF_PAX_RANDMMAP)
28250 + info.low_limit += mm->delta_mmap & 0x03FFF000UL;
28251 +#endif
28252 +
28253 + if (info.low_limit < info.high_limit) {
28254 + addr = vm_unmapped_area(&info);
28255 + if (!IS_ERR_VALUE(addr))
28256 + return addr;
28257 + }
28258 + } else
28259 +#endif
28260 +
28261 + info.low_limit = mm->mmap_base;
28262 + info.high_limit = pax_task_size;
28263 +
28264 + return vm_unmapped_area(&info);
28265 +}
28266 +
28267 +unsigned long
28268 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
28269 + const unsigned long len, const unsigned long pgoff,
28270 + const unsigned long flags)
28271 +{
28272 + struct vm_area_struct *vma;
28273 + struct mm_struct *mm = current->mm;
28274 + unsigned long addr = addr0, pax_task_size = TASK_SIZE;
28275 + struct vm_unmapped_area_info info;
28276 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
28277 +
28278 +#ifdef CONFIG_PAX_SEGMEXEC
28279 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
28280 + pax_task_size = SEGMEXEC_TASK_SIZE;
28281 +#endif
28282 +
28283 + pax_task_size -= PAGE_SIZE;
28284 +
28285 + /* requested length too big for entire address space */
28286 + if (len > pax_task_size)
28287 + return -ENOMEM;
28288 +
28289 + if (flags & MAP_FIXED)
28290 + return addr;
28291 +
28292 +#ifdef CONFIG_PAX_PAGEEXEC
28293 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
28294 + goto bottomup;
28295 +#endif
28296 +
28297 +#ifdef CONFIG_PAX_RANDMMAP
28298 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
28299 +#endif
28300 +
28301 + /* requesting a specific address */
28302 + if (addr) {
28303 + addr = PAGE_ALIGN(addr);
28304 + if (pax_task_size - len >= addr) {
28305 + vma = find_vma(mm, addr);
28306 + if (check_heap_stack_gap(vma, addr, len, offset))
28307 + return addr;
28308 + }
28309 + }
28310 +
28311 + info.flags = VM_UNMAPPED_AREA_TOPDOWN;
28312 + info.length = len;
28313 + info.low_limit = PAGE_SIZE;
28314 + info.high_limit = mm->mmap_base;
28315 + info.align_mask = filp ? get_align_mask() : 0;
28316 + info.align_offset = pgoff << PAGE_SHIFT;
28317 + info.threadstack_offset = offset;
28318 +
28319 + addr = vm_unmapped_area(&info);
28320 + if (!(addr & ~PAGE_MASK))
28321 + return addr;
28322 + VM_BUG_ON(addr != -ENOMEM);
28323 +
28324 +bottomup:
28325 + /*
28326 + * A failed mmap() very likely causes application failure,
28327 + * so fall back to the bottom-up function here. This scenario
28328 + * can happen with large stack limits and large mmap()
28329 + * allocations.
28330 + */
28331 + return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
28332 +}
28333 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
28334 index 30277e2..5664a29 100644
28335 --- a/arch/x86/kernel/sys_x86_64.c
28336 +++ b/arch/x86/kernel/sys_x86_64.c
28337 @@ -81,8 +81,8 @@ out:
28338 return error;
28339 }
28340
28341 -static void find_start_end(unsigned long flags, unsigned long *begin,
28342 - unsigned long *end)
28343 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
28344 + unsigned long *begin, unsigned long *end)
28345 {
28346 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
28347 unsigned long new_begin;
28348 @@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
28349 *begin = new_begin;
28350 }
28351 } else {
28352 - *begin = current->mm->mmap_legacy_base;
28353 + *begin = mm->mmap_legacy_base;
28354 *end = TASK_SIZE;
28355 }
28356 }
28357 @@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
28358 struct vm_area_struct *vma;
28359 struct vm_unmapped_area_info info;
28360 unsigned long begin, end;
28361 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
28362
28363 if (flags & MAP_FIXED)
28364 return addr;
28365
28366 - find_start_end(flags, &begin, &end);
28367 + find_start_end(mm, flags, &begin, &end);
28368
28369 if (len > end)
28370 return -ENOMEM;
28371
28372 +#ifdef CONFIG_PAX_RANDMMAP
28373 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
28374 +#endif
28375 +
28376 if (addr) {
28377 addr = PAGE_ALIGN(addr);
28378 vma = find_vma(mm, addr);
28379 - if (end - len >= addr &&
28380 - (!vma || addr + len <= vma->vm_start))
28381 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
28382 return addr;
28383 }
28384
28385 @@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
28386 info.high_limit = end;
28387 info.align_mask = filp ? get_align_mask() : 0;
28388 info.align_offset = pgoff << PAGE_SHIFT;
28389 + info.threadstack_offset = offset;
28390 return vm_unmapped_area(&info);
28391 }
28392
28393 @@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
28394 struct mm_struct *mm = current->mm;
28395 unsigned long addr = addr0;
28396 struct vm_unmapped_area_info info;
28397 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
28398
28399 /* requested length too big for entire address space */
28400 if (len > TASK_SIZE)
28401 @@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
28402 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
28403 goto bottomup;
28404
28405 +#ifdef CONFIG_PAX_RANDMMAP
28406 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
28407 +#endif
28408 +
28409 /* requesting a specific address */
28410 if (addr) {
28411 addr = PAGE_ALIGN(addr);
28412 vma = find_vma(mm, addr);
28413 - if (TASK_SIZE - len >= addr &&
28414 - (!vma || addr + len <= vma->vm_start))
28415 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
28416 return addr;
28417 }
28418
28419 @@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
28420 info.high_limit = mm->mmap_base;
28421 info.align_mask = filp ? get_align_mask() : 0;
28422 info.align_offset = pgoff << PAGE_SHIFT;
28423 + info.threadstack_offset = offset;
28424 addr = vm_unmapped_area(&info);
28425 if (!(addr & ~PAGE_MASK))
28426 return addr;
28427 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
28428 index 91a4496..bb87552 100644
28429 --- a/arch/x86/kernel/tboot.c
28430 +++ b/arch/x86/kernel/tboot.c
28431 @@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
28432
28433 void tboot_shutdown(u32 shutdown_type)
28434 {
28435 - void (*shutdown)(void);
28436 + void (* __noreturn shutdown)(void);
28437
28438 if (!tboot_enabled())
28439 return;
28440 @@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
28441
28442 switch_to_tboot_pt();
28443
28444 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
28445 + shutdown = (void *)(unsigned long)tboot->shutdown_entry;
28446 shutdown();
28447
28448 /* should not reach here */
28449 @@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
28450 return -ENODEV;
28451 }
28452
28453 -static atomic_t ap_wfs_count;
28454 +static atomic_unchecked_t ap_wfs_count;
28455
28456 static int tboot_wait_for_aps(int num_aps)
28457 {
28458 @@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
28459 {
28460 switch (action) {
28461 case CPU_DYING:
28462 - atomic_inc(&ap_wfs_count);
28463 + atomic_inc_unchecked(&ap_wfs_count);
28464 if (num_online_cpus() == 1)
28465 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
28466 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
28467 return NOTIFY_BAD;
28468 break;
28469 }
28470 @@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
28471
28472 tboot_create_trampoline();
28473
28474 - atomic_set(&ap_wfs_count, 0);
28475 + atomic_set_unchecked(&ap_wfs_count, 0);
28476 register_hotcpu_notifier(&tboot_cpu_notifier);
28477
28478 #ifdef CONFIG_DEBUG_FS
28479 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
28480 index 0fa2960..91eabbe 100644
28481 --- a/arch/x86/kernel/time.c
28482 +++ b/arch/x86/kernel/time.c
28483 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
28484 {
28485 unsigned long pc = instruction_pointer(regs);
28486
28487 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
28488 + if (!user_mode(regs) && in_lock_functions(pc)) {
28489 #ifdef CONFIG_FRAME_POINTER
28490 - return *(unsigned long *)(regs->bp + sizeof(long));
28491 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
28492 #else
28493 unsigned long *sp =
28494 (unsigned long *)kernel_stack_pointer(regs);
28495 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
28496 * or above a saved flags. Eflags has bits 22-31 zero,
28497 * kernel addresses don't.
28498 */
28499 +
28500 +#ifdef CONFIG_PAX_KERNEXEC
28501 + return ktla_ktva(sp[0]);
28502 +#else
28503 if (sp[0] >> 22)
28504 return sp[0];
28505 if (sp[1] >> 22)
28506 return sp[1];
28507 #endif
28508 +
28509 +#endif
28510 }
28511 return pc;
28512 }
28513 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
28514 index f7fec09..9991981 100644
28515 --- a/arch/x86/kernel/tls.c
28516 +++ b/arch/x86/kernel/tls.c
28517 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
28518 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
28519 return -EINVAL;
28520
28521 +#ifdef CONFIG_PAX_SEGMEXEC
28522 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
28523 + return -EINVAL;
28524 +#endif
28525 +
28526 set_tls_desc(p, idx, &info, 1);
28527
28528 return 0;
28529 @@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
28530
28531 if (kbuf)
28532 info = kbuf;
28533 - else if (__copy_from_user(infobuf, ubuf, count))
28534 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
28535 return -EFAULT;
28536 else
28537 info = infobuf;
28538 diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
28539 index 1c113db..287b42e 100644
28540 --- a/arch/x86/kernel/tracepoint.c
28541 +++ b/arch/x86/kernel/tracepoint.c
28542 @@ -9,11 +9,11 @@
28543 #include <linux/atomic.h>
28544
28545 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
28546 -struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
28547 +const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
28548 (unsigned long) trace_idt_table };
28549
28550 /* No need to be aligned, but done to keep all IDTs defined the same way. */
28551 -gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
28552 +gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
28553
28554 static int trace_irq_vector_refcount;
28555 static DEFINE_MUTEX(irq_vector_mutex);
28556 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
28557 index 0d0e922..0886373 100644
28558 --- a/arch/x86/kernel/traps.c
28559 +++ b/arch/x86/kernel/traps.c
28560 @@ -67,7 +67,7 @@
28561 #include <asm/proto.h>
28562
28563 /* No need to be aligned, but done to keep all IDTs defined the same way. */
28564 -gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
28565 +gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
28566 #else
28567 #include <asm/processor-flags.h>
28568 #include <asm/setup.h>
28569 @@ -76,7 +76,7 @@ asmlinkage int system_call(void);
28570 #endif
28571
28572 /* Must be page-aligned because the real IDT is used in a fixmap. */
28573 -gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
28574 +gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
28575
28576 DECLARE_BITMAP(used_vectors, NR_VECTORS);
28577 EXPORT_SYMBOL_GPL(used_vectors);
28578 @@ -108,11 +108,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
28579 }
28580
28581 static nokprobe_inline int
28582 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
28583 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
28584 struct pt_regs *regs, long error_code)
28585 {
28586 #ifdef CONFIG_X86_32
28587 - if (regs->flags & X86_VM_MASK) {
28588 + if (v8086_mode(regs)) {
28589 /*
28590 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
28591 * On nmi (interrupt 2), do_trap should not be called.
28592 @@ -125,12 +125,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
28593 return -1;
28594 }
28595 #endif
28596 - if (!user_mode(regs)) {
28597 + if (!user_mode_novm(regs)) {
28598 if (!fixup_exception(regs)) {
28599 tsk->thread.error_code = error_code;
28600 tsk->thread.trap_nr = trapnr;
28601 +
28602 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28603 + if (trapnr == X86_TRAP_SS && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
28604 + str = "PAX: suspicious stack segment fault";
28605 +#endif
28606 +
28607 die(str, regs, error_code);
28608 }
28609 +
28610 +#ifdef CONFIG_PAX_REFCOUNT
28611 + if (trapnr == X86_TRAP_OF)
28612 + pax_report_refcount_overflow(regs);
28613 +#endif
28614 +
28615 return 0;
28616 }
28617
28618 @@ -169,7 +181,7 @@ static siginfo_t *fill_trap_info(struct pt_regs *regs, int signr, int trapnr,
28619 }
28620
28621 static void
28622 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
28623 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
28624 long error_code, siginfo_t *info)
28625 {
28626 struct task_struct *tsk = current;
28627 @@ -193,7 +205,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
28628 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
28629 printk_ratelimit()) {
28630 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
28631 - tsk->comm, tsk->pid, str,
28632 + tsk->comm, task_pid_nr(tsk), str,
28633 regs->ip, regs->sp, error_code);
28634 print_vma_addr(" in ", regs->ip);
28635 pr_cont("\n");
28636 @@ -266,6 +278,11 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
28637 tsk->thread.error_code = error_code;
28638 tsk->thread.trap_nr = X86_TRAP_DF;
28639
28640 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
28641 + if ((unsigned long)tsk->stack - regs->sp <= PAGE_SIZE)
28642 + die("grsec: kernel stack overflow detected", regs, error_code);
28643 +#endif
28644 +
28645 #ifdef CONFIG_DOUBLEFAULT
28646 df_debug(regs, error_code);
28647 #endif
28648 @@ -288,7 +305,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
28649 conditional_sti(regs);
28650
28651 #ifdef CONFIG_X86_32
28652 - if (regs->flags & X86_VM_MASK) {
28653 + if (v8086_mode(regs)) {
28654 local_irq_enable();
28655 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
28656 goto exit;
28657 @@ -296,18 +313,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
28658 #endif
28659
28660 tsk = current;
28661 - if (!user_mode(regs)) {
28662 + if (!user_mode_novm(regs)) {
28663 if (fixup_exception(regs))
28664 goto exit;
28665
28666 tsk->thread.error_code = error_code;
28667 tsk->thread.trap_nr = X86_TRAP_GP;
28668 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
28669 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
28670 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
28671 +
28672 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28673 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
28674 + die("PAX: suspicious general protection fault", regs, error_code);
28675 + else
28676 +#endif
28677 +
28678 die("general protection fault", regs, error_code);
28679 + }
28680 goto exit;
28681 }
28682
28683 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
28684 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
28685 + struct mm_struct *mm = tsk->mm;
28686 + unsigned long limit;
28687 +
28688 + down_write(&mm->mmap_sem);
28689 + limit = mm->context.user_cs_limit;
28690 + if (limit < TASK_SIZE) {
28691 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
28692 + up_write(&mm->mmap_sem);
28693 + return;
28694 + }
28695 + up_write(&mm->mmap_sem);
28696 + }
28697 +#endif
28698 +
28699 tsk->thread.error_code = error_code;
28700 tsk->thread.trap_nr = X86_TRAP_GP;
28701
28702 @@ -481,7 +522,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28703 /* It's safe to allow irq's after DR6 has been saved */
28704 preempt_conditional_sti(regs);
28705
28706 - if (regs->flags & X86_VM_MASK) {
28707 + if (v8086_mode(regs)) {
28708 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
28709 X86_TRAP_DB);
28710 preempt_conditional_cli(regs);
28711 @@ -496,7 +537,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28712 * We already checked v86 mode above, so we can check for kernel mode
28713 * by just checking the CPL of CS.
28714 */
28715 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
28716 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
28717 tsk->thread.debugreg6 &= ~DR_STEP;
28718 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
28719 regs->flags &= ~X86_EFLAGS_TF;
28720 @@ -529,7 +570,7 @@ static void math_error(struct pt_regs *regs, int error_code, int trapnr)
28721 return;
28722 conditional_sti(regs);
28723
28724 - if (!user_mode_vm(regs))
28725 + if (!user_mode(regs))
28726 {
28727 if (!fixup_exception(regs)) {
28728 task->thread.error_code = error_code;
28729 diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
28730 index b7e50bb..f4a93ae 100644
28731 --- a/arch/x86/kernel/tsc.c
28732 +++ b/arch/x86/kernel/tsc.c
28733 @@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
28734 */
28735 smp_wmb();
28736
28737 - ACCESS_ONCE(c2n->head) = data;
28738 + ACCESS_ONCE_RW(c2n->head) = data;
28739 }
28740
28741 /*
28742 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
28743 index 5d1cbfe..2a21feb 100644
28744 --- a/arch/x86/kernel/uprobes.c
28745 +++ b/arch/x86/kernel/uprobes.c
28746 @@ -845,7 +845,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
28747 int ret = NOTIFY_DONE;
28748
28749 /* We are only interested in userspace traps */
28750 - if (regs && !user_mode_vm(regs))
28751 + if (regs && !user_mode(regs))
28752 return NOTIFY_DONE;
28753
28754 switch (val) {
28755 @@ -919,7 +919,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
28756
28757 if (nleft != rasize) {
28758 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
28759 - "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
28760 + "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
28761
28762 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
28763 }
28764 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
28765 index b9242ba..50c5edd 100644
28766 --- a/arch/x86/kernel/verify_cpu.S
28767 +++ b/arch/x86/kernel/verify_cpu.S
28768 @@ -20,6 +20,7 @@
28769 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
28770 * arch/x86/kernel/trampoline_64.S: secondary processor verification
28771 * arch/x86/kernel/head_32.S: processor startup
28772 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
28773 *
28774 * verify_cpu, returns the status of longmode and SSE in register %eax.
28775 * 0: Success 1: Failure
28776 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
28777 index e8edcf5..27f9344 100644
28778 --- a/arch/x86/kernel/vm86_32.c
28779 +++ b/arch/x86/kernel/vm86_32.c
28780 @@ -44,6 +44,7 @@
28781 #include <linux/ptrace.h>
28782 #include <linux/audit.h>
28783 #include <linux/stddef.h>
28784 +#include <linux/grsecurity.h>
28785
28786 #include <asm/uaccess.h>
28787 #include <asm/io.h>
28788 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
28789 do_exit(SIGSEGV);
28790 }
28791
28792 - tss = &per_cpu(init_tss, get_cpu());
28793 + tss = init_tss + get_cpu();
28794 current->thread.sp0 = current->thread.saved_sp0;
28795 current->thread.sysenter_cs = __KERNEL_CS;
28796 load_sp0(tss, &current->thread);
28797 @@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
28798
28799 if (tsk->thread.saved_sp0)
28800 return -EPERM;
28801 +
28802 +#ifdef CONFIG_GRKERNSEC_VM86
28803 + if (!capable(CAP_SYS_RAWIO)) {
28804 + gr_handle_vm86();
28805 + return -EPERM;
28806 + }
28807 +#endif
28808 +
28809 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
28810 offsetof(struct kernel_vm86_struct, vm86plus) -
28811 sizeof(info.regs));
28812 @@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
28813 int tmp;
28814 struct vm86plus_struct __user *v86;
28815
28816 +#ifdef CONFIG_GRKERNSEC_VM86
28817 + if (!capable(CAP_SYS_RAWIO)) {
28818 + gr_handle_vm86();
28819 + return -EPERM;
28820 + }
28821 +#endif
28822 +
28823 tsk = current;
28824 switch (cmd) {
28825 case VM86_REQUEST_IRQ:
28826 @@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
28827 tsk->thread.saved_fs = info->regs32->fs;
28828 tsk->thread.saved_gs = get_user_gs(info->regs32);
28829
28830 - tss = &per_cpu(init_tss, get_cpu());
28831 + tss = init_tss + get_cpu();
28832 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
28833 if (cpu_has_sep)
28834 tsk->thread.sysenter_cs = 0;
28835 @@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
28836 goto cannot_handle;
28837 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
28838 goto cannot_handle;
28839 - intr_ptr = (unsigned long __user *) (i << 2);
28840 + intr_ptr = (__force unsigned long __user *) (i << 2);
28841 if (get_user(segoffs, intr_ptr))
28842 goto cannot_handle;
28843 if ((segoffs >> 16) == BIOSSEG)
28844 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
28845 index 49edf2d..c0d1362 100644
28846 --- a/arch/x86/kernel/vmlinux.lds.S
28847 +++ b/arch/x86/kernel/vmlinux.lds.S
28848 @@ -26,6 +26,13 @@
28849 #include <asm/page_types.h>
28850 #include <asm/cache.h>
28851 #include <asm/boot.h>
28852 +#include <asm/segment.h>
28853 +
28854 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28855 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
28856 +#else
28857 +#define __KERNEL_TEXT_OFFSET 0
28858 +#endif
28859
28860 #undef i386 /* in case the preprocessor is a 32bit one */
28861
28862 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
28863
28864 PHDRS {
28865 text PT_LOAD FLAGS(5); /* R_E */
28866 +#ifdef CONFIG_X86_32
28867 + module PT_LOAD FLAGS(5); /* R_E */
28868 +#endif
28869 +#ifdef CONFIG_XEN
28870 + rodata PT_LOAD FLAGS(5); /* R_E */
28871 +#else
28872 + rodata PT_LOAD FLAGS(4); /* R__ */
28873 +#endif
28874 data PT_LOAD FLAGS(6); /* RW_ */
28875 -#ifdef CONFIG_X86_64
28876 + init.begin PT_LOAD FLAGS(6); /* RW_ */
28877 #ifdef CONFIG_SMP
28878 percpu PT_LOAD FLAGS(6); /* RW_ */
28879 #endif
28880 + text.init PT_LOAD FLAGS(5); /* R_E */
28881 + text.exit PT_LOAD FLAGS(5); /* R_E */
28882 init PT_LOAD FLAGS(7); /* RWE */
28883 -#endif
28884 note PT_NOTE FLAGS(0); /* ___ */
28885 }
28886
28887 SECTIONS
28888 {
28889 #ifdef CONFIG_X86_32
28890 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
28891 - phys_startup_32 = startup_32 - LOAD_OFFSET;
28892 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
28893 #else
28894 - . = __START_KERNEL;
28895 - phys_startup_64 = startup_64 - LOAD_OFFSET;
28896 + . = __START_KERNEL;
28897 #endif
28898
28899 /* Text and read-only data */
28900 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
28901 - _text = .;
28902 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28903 /* bootstrapping code */
28904 +#ifdef CONFIG_X86_32
28905 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28906 +#else
28907 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28908 +#endif
28909 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28910 + _text = .;
28911 HEAD_TEXT
28912 . = ALIGN(8);
28913 _stext = .;
28914 @@ -104,13 +124,47 @@ SECTIONS
28915 IRQENTRY_TEXT
28916 *(.fixup)
28917 *(.gnu.warning)
28918 - /* End of text section */
28919 - _etext = .;
28920 } :text = 0x9090
28921
28922 - NOTES :text :note
28923 + . += __KERNEL_TEXT_OFFSET;
28924
28925 - EXCEPTION_TABLE(16) :text = 0x9090
28926 +#ifdef CONFIG_X86_32
28927 + . = ALIGN(PAGE_SIZE);
28928 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
28929 +
28930 +#ifdef CONFIG_PAX_KERNEXEC
28931 + MODULES_EXEC_VADDR = .;
28932 + BYTE(0)
28933 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
28934 + . = ALIGN(HPAGE_SIZE) - 1;
28935 + MODULES_EXEC_END = .;
28936 +#endif
28937 +
28938 + } :module
28939 +#endif
28940 +
28941 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
28942 + /* End of text section */
28943 + BYTE(0)
28944 + _etext = . - __KERNEL_TEXT_OFFSET;
28945 + }
28946 +
28947 +#ifdef CONFIG_X86_32
28948 + . = ALIGN(PAGE_SIZE);
28949 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
28950 + . = ALIGN(PAGE_SIZE);
28951 + *(.empty_zero_page)
28952 + *(.initial_pg_fixmap)
28953 + *(.initial_pg_pmd)
28954 + *(.initial_page_table)
28955 + *(.swapper_pg_dir)
28956 + } :rodata
28957 +#endif
28958 +
28959 + . = ALIGN(PAGE_SIZE);
28960 + NOTES :rodata :note
28961 +
28962 + EXCEPTION_TABLE(16) :rodata
28963
28964 #if defined(CONFIG_DEBUG_RODATA)
28965 /* .text should occupy whole number of pages */
28966 @@ -122,16 +176,20 @@ SECTIONS
28967
28968 /* Data */
28969 .data : AT(ADDR(.data) - LOAD_OFFSET) {
28970 +
28971 +#ifdef CONFIG_PAX_KERNEXEC
28972 + . = ALIGN(HPAGE_SIZE);
28973 +#else
28974 + . = ALIGN(PAGE_SIZE);
28975 +#endif
28976 +
28977 /* Start of data section */
28978 _sdata = .;
28979
28980 /* init_task */
28981 INIT_TASK_DATA(THREAD_SIZE)
28982
28983 -#ifdef CONFIG_X86_32
28984 - /* 32 bit has nosave before _edata */
28985 NOSAVE_DATA
28986 -#endif
28987
28988 PAGE_ALIGNED_DATA(PAGE_SIZE)
28989
28990 @@ -174,12 +232,19 @@ SECTIONS
28991 . = ALIGN(__vvar_page + PAGE_SIZE, PAGE_SIZE);
28992
28993 /* Init code and data - will be freed after init */
28994 - . = ALIGN(PAGE_SIZE);
28995 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
28996 + BYTE(0)
28997 +
28998 +#ifdef CONFIG_PAX_KERNEXEC
28999 + . = ALIGN(HPAGE_SIZE);
29000 +#else
29001 + . = ALIGN(PAGE_SIZE);
29002 +#endif
29003 +
29004 __init_begin = .; /* paired with __init_end */
29005 - }
29006 + } :init.begin
29007
29008 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
29009 +#ifdef CONFIG_SMP
29010 /*
29011 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
29012 * output PHDR, so the next output section - .init.text - should
29013 @@ -188,12 +253,27 @@ SECTIONS
29014 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
29015 #endif
29016
29017 - INIT_TEXT_SECTION(PAGE_SIZE)
29018 -#ifdef CONFIG_X86_64
29019 - :init
29020 -#endif
29021 + . = ALIGN(PAGE_SIZE);
29022 + init_begin = .;
29023 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
29024 + VMLINUX_SYMBOL(_sinittext) = .;
29025 + INIT_TEXT
29026 + VMLINUX_SYMBOL(_einittext) = .;
29027 + . = ALIGN(PAGE_SIZE);
29028 + } :text.init
29029
29030 - INIT_DATA_SECTION(16)
29031 + /*
29032 + * .exit.text is discard at runtime, not link time, to deal with
29033 + * references from .altinstructions and .eh_frame
29034 + */
29035 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
29036 + EXIT_TEXT
29037 + . = ALIGN(16);
29038 + } :text.exit
29039 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
29040 +
29041 + . = ALIGN(PAGE_SIZE);
29042 + INIT_DATA_SECTION(16) :init
29043
29044 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
29045 __x86_cpu_dev_start = .;
29046 @@ -264,19 +344,12 @@ SECTIONS
29047 }
29048
29049 . = ALIGN(8);
29050 - /*
29051 - * .exit.text is discard at runtime, not link time, to deal with
29052 - * references from .altinstructions and .eh_frame
29053 - */
29054 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
29055 - EXIT_TEXT
29056 - }
29057
29058 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
29059 EXIT_DATA
29060 }
29061
29062 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
29063 +#ifndef CONFIG_SMP
29064 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
29065 #endif
29066
29067 @@ -295,16 +368,10 @@ SECTIONS
29068 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
29069 __smp_locks = .;
29070 *(.smp_locks)
29071 - . = ALIGN(PAGE_SIZE);
29072 __smp_locks_end = .;
29073 + . = ALIGN(PAGE_SIZE);
29074 }
29075
29076 -#ifdef CONFIG_X86_64
29077 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
29078 - NOSAVE_DATA
29079 - }
29080 -#endif
29081 -
29082 /* BSS */
29083 . = ALIGN(PAGE_SIZE);
29084 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
29085 @@ -320,6 +387,7 @@ SECTIONS
29086 __brk_base = .;
29087 . += 64 * 1024; /* 64k alignment slop space */
29088 *(.brk_reservation) /* areas brk users have reserved */
29089 + . = ALIGN(HPAGE_SIZE);
29090 __brk_limit = .;
29091 }
29092
29093 @@ -346,13 +414,12 @@ SECTIONS
29094 * for the boot processor.
29095 */
29096 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
29097 -INIT_PER_CPU(gdt_page);
29098 INIT_PER_CPU(irq_stack_union);
29099
29100 /*
29101 * Build-time check on the image size:
29102 */
29103 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
29104 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
29105 "kernel image bigger than KERNEL_IMAGE_SIZE");
29106
29107 #ifdef CONFIG_SMP
29108 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
29109 index e1e1e80..1400089 100644
29110 --- a/arch/x86/kernel/vsyscall_64.c
29111 +++ b/arch/x86/kernel/vsyscall_64.c
29112 @@ -54,15 +54,13 @@
29113
29114 DEFINE_VVAR(int, vgetcpu_mode);
29115
29116 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
29117 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
29118
29119 static int __init vsyscall_setup(char *str)
29120 {
29121 if (str) {
29122 if (!strcmp("emulate", str))
29123 vsyscall_mode = EMULATE;
29124 - else if (!strcmp("native", str))
29125 - vsyscall_mode = NATIVE;
29126 else if (!strcmp("none", str))
29127 vsyscall_mode = NONE;
29128 else
29129 @@ -279,8 +277,7 @@ do_ret:
29130 return true;
29131
29132 sigsegv:
29133 - force_sig(SIGSEGV, current);
29134 - return true;
29135 + do_group_exit(SIGKILL);
29136 }
29137
29138 /*
29139 @@ -331,10 +328,7 @@ void __init map_vsyscall(void)
29140 extern char __vsyscall_page;
29141 unsigned long physaddr_vsyscall = __pa_symbol(&__vsyscall_page);
29142
29143 - __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall,
29144 - vsyscall_mode == NATIVE
29145 - ? PAGE_KERNEL_VSYSCALL
29146 - : PAGE_KERNEL_VVAR);
29147 + __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
29148 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_PAGE) !=
29149 (unsigned long)VSYSCALL_ADDR);
29150 }
29151 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
29152 index 04068192..4d75aa6 100644
29153 --- a/arch/x86/kernel/x8664_ksyms_64.c
29154 +++ b/arch/x86/kernel/x8664_ksyms_64.c
29155 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
29156 EXPORT_SYMBOL(copy_user_generic_unrolled);
29157 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
29158 EXPORT_SYMBOL(__copy_user_nocache);
29159 -EXPORT_SYMBOL(_copy_from_user);
29160 -EXPORT_SYMBOL(_copy_to_user);
29161
29162 EXPORT_SYMBOL(copy_page);
29163 EXPORT_SYMBOL(clear_page);
29164 @@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
29165 EXPORT_SYMBOL(___preempt_schedule_context);
29166 #endif
29167 #endif
29168 +
29169 +#ifdef CONFIG_PAX_PER_CPU_PGD
29170 +EXPORT_SYMBOL(cpu_pgd);
29171 +#endif
29172 diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
29173 index e48b674..a451dd9 100644
29174 --- a/arch/x86/kernel/x86_init.c
29175 +++ b/arch/x86/kernel/x86_init.c
29176 @@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
29177 static void default_nmi_init(void) { };
29178 static int default_i8042_detect(void) { return 1; };
29179
29180 -struct x86_platform_ops x86_platform = {
29181 +struct x86_platform_ops x86_platform __read_only = {
29182 .calibrate_tsc = native_calibrate_tsc,
29183 .get_wallclock = mach_get_cmos_time,
29184 .set_wallclock = mach_set_rtc_mmss,
29185 @@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
29186 EXPORT_SYMBOL_GPL(x86_platform);
29187
29188 #if defined(CONFIG_PCI_MSI)
29189 -struct x86_msi_ops x86_msi = {
29190 +struct x86_msi_ops x86_msi __read_only = {
29191 .setup_msi_irqs = native_setup_msi_irqs,
29192 .compose_msi_msg = native_compose_msi_msg,
29193 .teardown_msi_irq = native_teardown_msi_irq,
29194 @@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
29195 }
29196 #endif
29197
29198 -struct x86_io_apic_ops x86_io_apic_ops = {
29199 +struct x86_io_apic_ops x86_io_apic_ops __read_only = {
29200 .init = native_io_apic_init_mappings,
29201 .read = native_io_apic_read,
29202 .write = native_io_apic_write,
29203 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
29204 index 4c540c4..0b985b0 100644
29205 --- a/arch/x86/kernel/xsave.c
29206 +++ b/arch/x86/kernel/xsave.c
29207 @@ -167,18 +167,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
29208
29209 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
29210 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
29211 - err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
29212 + err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
29213
29214 if (!use_xsave())
29215 return err;
29216
29217 - err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
29218 + err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
29219
29220 /*
29221 * Read the xstate_bv which we copied (directly from the cpu or
29222 * from the state in task struct) to the user buffers.
29223 */
29224 - err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
29225 + err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
29226
29227 /*
29228 * For legacy compatible, we always set FP/SSE bits in the bit
29229 @@ -193,7 +193,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
29230 */
29231 xstate_bv |= XSTATE_FPSSE;
29232
29233 - err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
29234 + err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
29235
29236 return err;
29237 }
29238 @@ -202,6 +202,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
29239 {
29240 int err;
29241
29242 + buf = (struct xsave_struct __user *)____m(buf);
29243 if (use_xsave())
29244 err = xsave_user(buf);
29245 else if (use_fxsr())
29246 @@ -312,6 +313,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
29247 */
29248 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
29249 {
29250 + buf = (void __user *)____m(buf);
29251 if (use_xsave()) {
29252 if ((unsigned long)buf % 64 || fx_only) {
29253 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
29254 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
29255 index 38a0afe..94421a9 100644
29256 --- a/arch/x86/kvm/cpuid.c
29257 +++ b/arch/x86/kvm/cpuid.c
29258 @@ -166,15 +166,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
29259 struct kvm_cpuid2 *cpuid,
29260 struct kvm_cpuid_entry2 __user *entries)
29261 {
29262 - int r;
29263 + int r, i;
29264
29265 r = -E2BIG;
29266 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
29267 goto out;
29268 r = -EFAULT;
29269 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
29270 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
29271 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
29272 goto out;
29273 + for (i = 0; i < cpuid->nent; ++i) {
29274 + struct kvm_cpuid_entry2 cpuid_entry;
29275 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
29276 + goto out;
29277 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
29278 + }
29279 vcpu->arch.cpuid_nent = cpuid->nent;
29280 kvm_apic_set_version(vcpu);
29281 kvm_x86_ops->cpuid_update(vcpu);
29282 @@ -189,15 +194,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
29283 struct kvm_cpuid2 *cpuid,
29284 struct kvm_cpuid_entry2 __user *entries)
29285 {
29286 - int r;
29287 + int r, i;
29288
29289 r = -E2BIG;
29290 if (cpuid->nent < vcpu->arch.cpuid_nent)
29291 goto out;
29292 r = -EFAULT;
29293 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
29294 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
29295 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
29296 goto out;
29297 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
29298 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
29299 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
29300 + goto out;
29301 + }
29302 return 0;
29303
29304 out:
29305 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
29306 index 08e8a89..0e9183e 100644
29307 --- a/arch/x86/kvm/lapic.c
29308 +++ b/arch/x86/kvm/lapic.c
29309 @@ -55,7 +55,7 @@
29310 #define APIC_BUS_CYCLE_NS 1
29311
29312 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
29313 -#define apic_debug(fmt, arg...)
29314 +#define apic_debug(fmt, arg...) do {} while (0)
29315
29316 #define APIC_LVT_NUM 6
29317 /* 14 is the version for Xeon and Pentium 8.4.8*/
29318 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
29319 index 4107765..d9eb358 100644
29320 --- a/arch/x86/kvm/paging_tmpl.h
29321 +++ b/arch/x86/kvm/paging_tmpl.h
29322 @@ -331,7 +331,7 @@ retry_walk:
29323 if (unlikely(kvm_is_error_hva(host_addr)))
29324 goto error;
29325
29326 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
29327 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
29328 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
29329 goto error;
29330 walker->ptep_user[walker->level - 1] = ptep_user;
29331 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
29332 index 78dadc3..fd84599 100644
29333 --- a/arch/x86/kvm/svm.c
29334 +++ b/arch/x86/kvm/svm.c
29335 @@ -3547,7 +3547,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
29336 int cpu = raw_smp_processor_id();
29337
29338 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
29339 +
29340 + pax_open_kernel();
29341 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
29342 + pax_close_kernel();
29343 +
29344 load_TR_desc();
29345 }
29346
29347 @@ -3948,6 +3952,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
29348 #endif
29349 #endif
29350
29351 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29352 + __set_fs(current_thread_info()->addr_limit);
29353 +#endif
29354 +
29355 reload_tss(vcpu);
29356
29357 local_irq_disable();
29358 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
29359 index 41a5426..c0b3c00 100644
29360 --- a/arch/x86/kvm/vmx.c
29361 +++ b/arch/x86/kvm/vmx.c
29362 @@ -1341,12 +1341,12 @@ static void vmcs_write64(unsigned long field, u64 value)
29363 #endif
29364 }
29365
29366 -static void vmcs_clear_bits(unsigned long field, u32 mask)
29367 +static void vmcs_clear_bits(unsigned long field, unsigned long mask)
29368 {
29369 vmcs_writel(field, vmcs_readl(field) & ~mask);
29370 }
29371
29372 -static void vmcs_set_bits(unsigned long field, u32 mask)
29373 +static void vmcs_set_bits(unsigned long field, unsigned long mask)
29374 {
29375 vmcs_writel(field, vmcs_readl(field) | mask);
29376 }
29377 @@ -1606,7 +1606,11 @@ static void reload_tss(void)
29378 struct desc_struct *descs;
29379
29380 descs = (void *)gdt->address;
29381 +
29382 + pax_open_kernel();
29383 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
29384 + pax_close_kernel();
29385 +
29386 load_TR_desc();
29387 }
29388
29389 @@ -1834,6 +1838,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
29390 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
29391 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
29392
29393 +#ifdef CONFIG_PAX_PER_CPU_PGD
29394 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
29395 +#endif
29396 +
29397 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
29398 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
29399 vmx->loaded_vmcs->cpu = cpu;
29400 @@ -2123,7 +2131,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
29401 * reads and returns guest's timestamp counter "register"
29402 * guest_tsc = host_tsc + tsc_offset -- 21.3
29403 */
29404 -static u64 guest_read_tsc(void)
29405 +static u64 __intentional_overflow(-1) guest_read_tsc(void)
29406 {
29407 u64 host_tsc, tsc_offset;
29408
29409 @@ -3114,8 +3122,11 @@ static __init int hardware_setup(void)
29410 if (!cpu_has_vmx_flexpriority())
29411 flexpriority_enabled = 0;
29412
29413 - if (!cpu_has_vmx_tpr_shadow())
29414 - kvm_x86_ops->update_cr8_intercept = NULL;
29415 + if (!cpu_has_vmx_tpr_shadow()) {
29416 + pax_open_kernel();
29417 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
29418 + pax_close_kernel();
29419 + }
29420
29421 if (enable_ept && !cpu_has_vmx_ept_2m_page())
29422 kvm_disable_largepages();
29423 @@ -3126,13 +3137,15 @@ static __init int hardware_setup(void)
29424 if (!cpu_has_vmx_apicv())
29425 enable_apicv = 0;
29426
29427 + pax_open_kernel();
29428 if (enable_apicv)
29429 - kvm_x86_ops->update_cr8_intercept = NULL;
29430 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
29431 else {
29432 - kvm_x86_ops->hwapic_irr_update = NULL;
29433 - kvm_x86_ops->deliver_posted_interrupt = NULL;
29434 - kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
29435 + *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
29436 + *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
29437 + *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
29438 }
29439 + pax_close_kernel();
29440
29441 if (nested)
29442 nested_vmx_setup_ctls_msrs();
29443 @@ -4242,7 +4255,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
29444 unsigned long cr4;
29445
29446 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
29447 +
29448 +#ifndef CONFIG_PAX_PER_CPU_PGD
29449 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
29450 +#endif
29451
29452 /* Save the most likely value for this task's CR4 in the VMCS. */
29453 cr4 = read_cr4();
29454 @@ -4269,7 +4285,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
29455 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
29456 vmx->host_idt_base = dt.address;
29457
29458 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
29459 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
29460
29461 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
29462 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
29463 @@ -7475,6 +7491,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
29464 "jmp 2f \n\t"
29465 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
29466 "2: "
29467 +
29468 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29469 + "ljmp %[cs],$3f\n\t"
29470 + "3: "
29471 +#endif
29472 +
29473 /* Save guest registers, load host registers, keep flags */
29474 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
29475 "pop %0 \n\t"
29476 @@ -7527,6 +7549,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
29477 #endif
29478 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
29479 [wordsize]"i"(sizeof(ulong))
29480 +
29481 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29482 + ,[cs]"i"(__KERNEL_CS)
29483 +#endif
29484 +
29485 : "cc", "memory"
29486 #ifdef CONFIG_X86_64
29487 , "rax", "rbx", "rdi", "rsi"
29488 @@ -7540,7 +7567,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
29489 if (debugctlmsr)
29490 update_debugctlmsr(debugctlmsr);
29491
29492 -#ifndef CONFIG_X86_64
29493 +#ifdef CONFIG_X86_32
29494 /*
29495 * The sysexit path does not restore ds/es, so we must set them to
29496 * a reasonable value ourselves.
29497 @@ -7549,8 +7576,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
29498 * may be executed in interrupt context, which saves and restore segments
29499 * around it, nullifying its effect.
29500 */
29501 - loadsegment(ds, __USER_DS);
29502 - loadsegment(es, __USER_DS);
29503 + loadsegment(ds, __KERNEL_DS);
29504 + loadsegment(es, __KERNEL_DS);
29505 + loadsegment(ss, __KERNEL_DS);
29506 +
29507 +#ifdef CONFIG_PAX_KERNEXEC
29508 + loadsegment(fs, __KERNEL_PERCPU);
29509 +#endif
29510 +
29511 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29512 + __set_fs(current_thread_info()->addr_limit);
29513 +#endif
29514 +
29515 #endif
29516
29517 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
29518 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
29519 index d6aeccf..cea125a 100644
29520 --- a/arch/x86/kvm/x86.c
29521 +++ b/arch/x86/kvm/x86.c
29522 @@ -1857,8 +1857,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
29523 {
29524 struct kvm *kvm = vcpu->kvm;
29525 int lm = is_long_mode(vcpu);
29526 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
29527 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
29528 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
29529 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
29530 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
29531 : kvm->arch.xen_hvm_config.blob_size_32;
29532 u32 page_num = data & ~PAGE_MASK;
29533 @@ -2779,6 +2779,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
29534 if (n < msr_list.nmsrs)
29535 goto out;
29536 r = -EFAULT;
29537 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
29538 + goto out;
29539 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
29540 num_msrs_to_save * sizeof(u32)))
29541 goto out;
29542 @@ -5639,7 +5641,7 @@ static struct notifier_block pvclock_gtod_notifier = {
29543 };
29544 #endif
29545
29546 -int kvm_arch_init(void *opaque)
29547 +int kvm_arch_init(const void *opaque)
29548 {
29549 int r;
29550 struct kvm_x86_ops *ops = opaque;
29551 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
29552 index aae9413..d11e829 100644
29553 --- a/arch/x86/lguest/boot.c
29554 +++ b/arch/x86/lguest/boot.c
29555 @@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
29556 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
29557 * Launcher to reboot us.
29558 */
29559 -static void lguest_restart(char *reason)
29560 +static __noreturn void lguest_restart(char *reason)
29561 {
29562 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
29563 + BUG();
29564 }
29565
29566 /*G:050
29567 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
29568 index 00933d5..3a64af9 100644
29569 --- a/arch/x86/lib/atomic64_386_32.S
29570 +++ b/arch/x86/lib/atomic64_386_32.S
29571 @@ -48,6 +48,10 @@ BEGIN(read)
29572 movl (v), %eax
29573 movl 4(v), %edx
29574 RET_ENDP
29575 +BEGIN(read_unchecked)
29576 + movl (v), %eax
29577 + movl 4(v), %edx
29578 +RET_ENDP
29579 #undef v
29580
29581 #define v %esi
29582 @@ -55,6 +59,10 @@ BEGIN(set)
29583 movl %ebx, (v)
29584 movl %ecx, 4(v)
29585 RET_ENDP
29586 +BEGIN(set_unchecked)
29587 + movl %ebx, (v)
29588 + movl %ecx, 4(v)
29589 +RET_ENDP
29590 #undef v
29591
29592 #define v %esi
29593 @@ -70,6 +78,20 @@ RET_ENDP
29594 BEGIN(add)
29595 addl %eax, (v)
29596 adcl %edx, 4(v)
29597 +
29598 +#ifdef CONFIG_PAX_REFCOUNT
29599 + jno 0f
29600 + subl %eax, (v)
29601 + sbbl %edx, 4(v)
29602 + int $4
29603 +0:
29604 + _ASM_EXTABLE(0b, 0b)
29605 +#endif
29606 +
29607 +RET_ENDP
29608 +BEGIN(add_unchecked)
29609 + addl %eax, (v)
29610 + adcl %edx, 4(v)
29611 RET_ENDP
29612 #undef v
29613
29614 @@ -77,6 +99,24 @@ RET_ENDP
29615 BEGIN(add_return)
29616 addl (v), %eax
29617 adcl 4(v), %edx
29618 +
29619 +#ifdef CONFIG_PAX_REFCOUNT
29620 + into
29621 +1234:
29622 + _ASM_EXTABLE(1234b, 2f)
29623 +#endif
29624 +
29625 + movl %eax, (v)
29626 + movl %edx, 4(v)
29627 +
29628 +#ifdef CONFIG_PAX_REFCOUNT
29629 +2:
29630 +#endif
29631 +
29632 +RET_ENDP
29633 +BEGIN(add_return_unchecked)
29634 + addl (v), %eax
29635 + adcl 4(v), %edx
29636 movl %eax, (v)
29637 movl %edx, 4(v)
29638 RET_ENDP
29639 @@ -86,6 +126,20 @@ RET_ENDP
29640 BEGIN(sub)
29641 subl %eax, (v)
29642 sbbl %edx, 4(v)
29643 +
29644 +#ifdef CONFIG_PAX_REFCOUNT
29645 + jno 0f
29646 + addl %eax, (v)
29647 + adcl %edx, 4(v)
29648 + int $4
29649 +0:
29650 + _ASM_EXTABLE(0b, 0b)
29651 +#endif
29652 +
29653 +RET_ENDP
29654 +BEGIN(sub_unchecked)
29655 + subl %eax, (v)
29656 + sbbl %edx, 4(v)
29657 RET_ENDP
29658 #undef v
29659
29660 @@ -96,6 +150,27 @@ BEGIN(sub_return)
29661 sbbl $0, %edx
29662 addl (v), %eax
29663 adcl 4(v), %edx
29664 +
29665 +#ifdef CONFIG_PAX_REFCOUNT
29666 + into
29667 +1234:
29668 + _ASM_EXTABLE(1234b, 2f)
29669 +#endif
29670 +
29671 + movl %eax, (v)
29672 + movl %edx, 4(v)
29673 +
29674 +#ifdef CONFIG_PAX_REFCOUNT
29675 +2:
29676 +#endif
29677 +
29678 +RET_ENDP
29679 +BEGIN(sub_return_unchecked)
29680 + negl %edx
29681 + negl %eax
29682 + sbbl $0, %edx
29683 + addl (v), %eax
29684 + adcl 4(v), %edx
29685 movl %eax, (v)
29686 movl %edx, 4(v)
29687 RET_ENDP
29688 @@ -105,6 +180,20 @@ RET_ENDP
29689 BEGIN(inc)
29690 addl $1, (v)
29691 adcl $0, 4(v)
29692 +
29693 +#ifdef CONFIG_PAX_REFCOUNT
29694 + jno 0f
29695 + subl $1, (v)
29696 + sbbl $0, 4(v)
29697 + int $4
29698 +0:
29699 + _ASM_EXTABLE(0b, 0b)
29700 +#endif
29701 +
29702 +RET_ENDP
29703 +BEGIN(inc_unchecked)
29704 + addl $1, (v)
29705 + adcl $0, 4(v)
29706 RET_ENDP
29707 #undef v
29708
29709 @@ -114,6 +203,26 @@ BEGIN(inc_return)
29710 movl 4(v), %edx
29711 addl $1, %eax
29712 adcl $0, %edx
29713 +
29714 +#ifdef CONFIG_PAX_REFCOUNT
29715 + into
29716 +1234:
29717 + _ASM_EXTABLE(1234b, 2f)
29718 +#endif
29719 +
29720 + movl %eax, (v)
29721 + movl %edx, 4(v)
29722 +
29723 +#ifdef CONFIG_PAX_REFCOUNT
29724 +2:
29725 +#endif
29726 +
29727 +RET_ENDP
29728 +BEGIN(inc_return_unchecked)
29729 + movl (v), %eax
29730 + movl 4(v), %edx
29731 + addl $1, %eax
29732 + adcl $0, %edx
29733 movl %eax, (v)
29734 movl %edx, 4(v)
29735 RET_ENDP
29736 @@ -123,6 +232,20 @@ RET_ENDP
29737 BEGIN(dec)
29738 subl $1, (v)
29739 sbbl $0, 4(v)
29740 +
29741 +#ifdef CONFIG_PAX_REFCOUNT
29742 + jno 0f
29743 + addl $1, (v)
29744 + adcl $0, 4(v)
29745 + int $4
29746 +0:
29747 + _ASM_EXTABLE(0b, 0b)
29748 +#endif
29749 +
29750 +RET_ENDP
29751 +BEGIN(dec_unchecked)
29752 + subl $1, (v)
29753 + sbbl $0, 4(v)
29754 RET_ENDP
29755 #undef v
29756
29757 @@ -132,6 +255,26 @@ BEGIN(dec_return)
29758 movl 4(v), %edx
29759 subl $1, %eax
29760 sbbl $0, %edx
29761 +
29762 +#ifdef CONFIG_PAX_REFCOUNT
29763 + into
29764 +1234:
29765 + _ASM_EXTABLE(1234b, 2f)
29766 +#endif
29767 +
29768 + movl %eax, (v)
29769 + movl %edx, 4(v)
29770 +
29771 +#ifdef CONFIG_PAX_REFCOUNT
29772 +2:
29773 +#endif
29774 +
29775 +RET_ENDP
29776 +BEGIN(dec_return_unchecked)
29777 + movl (v), %eax
29778 + movl 4(v), %edx
29779 + subl $1, %eax
29780 + sbbl $0, %edx
29781 movl %eax, (v)
29782 movl %edx, 4(v)
29783 RET_ENDP
29784 @@ -143,6 +286,13 @@ BEGIN(add_unless)
29785 adcl %edx, %edi
29786 addl (v), %eax
29787 adcl 4(v), %edx
29788 +
29789 +#ifdef CONFIG_PAX_REFCOUNT
29790 + into
29791 +1234:
29792 + _ASM_EXTABLE(1234b, 2f)
29793 +#endif
29794 +
29795 cmpl %eax, %ecx
29796 je 3f
29797 1:
29798 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
29799 1:
29800 addl $1, %eax
29801 adcl $0, %edx
29802 +
29803 +#ifdef CONFIG_PAX_REFCOUNT
29804 + into
29805 +1234:
29806 + _ASM_EXTABLE(1234b, 2f)
29807 +#endif
29808 +
29809 movl %eax, (v)
29810 movl %edx, 4(v)
29811 movl $1, %eax
29812 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
29813 movl 4(v), %edx
29814 subl $1, %eax
29815 sbbl $0, %edx
29816 +
29817 +#ifdef CONFIG_PAX_REFCOUNT
29818 + into
29819 +1234:
29820 + _ASM_EXTABLE(1234b, 1f)
29821 +#endif
29822 +
29823 js 1f
29824 movl %eax, (v)
29825 movl %edx, 4(v)
29826 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
29827 index f5cc9eb..51fa319 100644
29828 --- a/arch/x86/lib/atomic64_cx8_32.S
29829 +++ b/arch/x86/lib/atomic64_cx8_32.S
29830 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
29831 CFI_STARTPROC
29832
29833 read64 %ecx
29834 + pax_force_retaddr
29835 ret
29836 CFI_ENDPROC
29837 ENDPROC(atomic64_read_cx8)
29838
29839 +ENTRY(atomic64_read_unchecked_cx8)
29840 + CFI_STARTPROC
29841 +
29842 + read64 %ecx
29843 + pax_force_retaddr
29844 + ret
29845 + CFI_ENDPROC
29846 +ENDPROC(atomic64_read_unchecked_cx8)
29847 +
29848 ENTRY(atomic64_set_cx8)
29849 CFI_STARTPROC
29850
29851 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
29852 cmpxchg8b (%esi)
29853 jne 1b
29854
29855 + pax_force_retaddr
29856 ret
29857 CFI_ENDPROC
29858 ENDPROC(atomic64_set_cx8)
29859
29860 +ENTRY(atomic64_set_unchecked_cx8)
29861 + CFI_STARTPROC
29862 +
29863 +1:
29864 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
29865 + * are atomic on 586 and newer */
29866 + cmpxchg8b (%esi)
29867 + jne 1b
29868 +
29869 + pax_force_retaddr
29870 + ret
29871 + CFI_ENDPROC
29872 +ENDPROC(atomic64_set_unchecked_cx8)
29873 +
29874 ENTRY(atomic64_xchg_cx8)
29875 CFI_STARTPROC
29876
29877 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
29878 cmpxchg8b (%esi)
29879 jne 1b
29880
29881 + pax_force_retaddr
29882 ret
29883 CFI_ENDPROC
29884 ENDPROC(atomic64_xchg_cx8)
29885
29886 -.macro addsub_return func ins insc
29887 -ENTRY(atomic64_\func\()_return_cx8)
29888 +.macro addsub_return func ins insc unchecked=""
29889 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29890 CFI_STARTPROC
29891 SAVE ebp
29892 SAVE ebx
29893 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
29894 movl %edx, %ecx
29895 \ins\()l %esi, %ebx
29896 \insc\()l %edi, %ecx
29897 +
29898 +.ifb \unchecked
29899 +#ifdef CONFIG_PAX_REFCOUNT
29900 + into
29901 +2:
29902 + _ASM_EXTABLE(2b, 3f)
29903 +#endif
29904 +.endif
29905 +
29906 LOCK_PREFIX
29907 cmpxchg8b (%ebp)
29908 jne 1b
29909 -
29910 -10:
29911 movl %ebx, %eax
29912 movl %ecx, %edx
29913 +
29914 +.ifb \unchecked
29915 +#ifdef CONFIG_PAX_REFCOUNT
29916 +3:
29917 +#endif
29918 +.endif
29919 +
29920 RESTORE edi
29921 RESTORE esi
29922 RESTORE ebx
29923 RESTORE ebp
29924 + pax_force_retaddr
29925 ret
29926 CFI_ENDPROC
29927 -ENDPROC(atomic64_\func\()_return_cx8)
29928 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29929 .endm
29930
29931 addsub_return add add adc
29932 addsub_return sub sub sbb
29933 +addsub_return add add adc _unchecked
29934 +addsub_return sub sub sbb _unchecked
29935
29936 -.macro incdec_return func ins insc
29937 -ENTRY(atomic64_\func\()_return_cx8)
29938 +.macro incdec_return func ins insc unchecked=""
29939 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29940 CFI_STARTPROC
29941 SAVE ebx
29942
29943 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
29944 movl %edx, %ecx
29945 \ins\()l $1, %ebx
29946 \insc\()l $0, %ecx
29947 +
29948 +.ifb \unchecked
29949 +#ifdef CONFIG_PAX_REFCOUNT
29950 + into
29951 +2:
29952 + _ASM_EXTABLE(2b, 3f)
29953 +#endif
29954 +.endif
29955 +
29956 LOCK_PREFIX
29957 cmpxchg8b (%esi)
29958 jne 1b
29959
29960 -10:
29961 movl %ebx, %eax
29962 movl %ecx, %edx
29963 +
29964 +.ifb \unchecked
29965 +#ifdef CONFIG_PAX_REFCOUNT
29966 +3:
29967 +#endif
29968 +.endif
29969 +
29970 RESTORE ebx
29971 + pax_force_retaddr
29972 ret
29973 CFI_ENDPROC
29974 -ENDPROC(atomic64_\func\()_return_cx8)
29975 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29976 .endm
29977
29978 incdec_return inc add adc
29979 incdec_return dec sub sbb
29980 +incdec_return inc add adc _unchecked
29981 +incdec_return dec sub sbb _unchecked
29982
29983 ENTRY(atomic64_dec_if_positive_cx8)
29984 CFI_STARTPROC
29985 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
29986 movl %edx, %ecx
29987 subl $1, %ebx
29988 sbb $0, %ecx
29989 +
29990 +#ifdef CONFIG_PAX_REFCOUNT
29991 + into
29992 +1234:
29993 + _ASM_EXTABLE(1234b, 2f)
29994 +#endif
29995 +
29996 js 2f
29997 LOCK_PREFIX
29998 cmpxchg8b (%esi)
29999 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
30000 movl %ebx, %eax
30001 movl %ecx, %edx
30002 RESTORE ebx
30003 + pax_force_retaddr
30004 ret
30005 CFI_ENDPROC
30006 ENDPROC(atomic64_dec_if_positive_cx8)
30007 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
30008 movl %edx, %ecx
30009 addl %ebp, %ebx
30010 adcl %edi, %ecx
30011 +
30012 +#ifdef CONFIG_PAX_REFCOUNT
30013 + into
30014 +1234:
30015 + _ASM_EXTABLE(1234b, 3f)
30016 +#endif
30017 +
30018 LOCK_PREFIX
30019 cmpxchg8b (%esi)
30020 jne 1b
30021 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
30022 CFI_ADJUST_CFA_OFFSET -8
30023 RESTORE ebx
30024 RESTORE ebp
30025 + pax_force_retaddr
30026 ret
30027 4:
30028 cmpl %edx, 4(%esp)
30029 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
30030 xorl %ecx, %ecx
30031 addl $1, %ebx
30032 adcl %edx, %ecx
30033 +
30034 +#ifdef CONFIG_PAX_REFCOUNT
30035 + into
30036 +1234:
30037 + _ASM_EXTABLE(1234b, 3f)
30038 +#endif
30039 +
30040 LOCK_PREFIX
30041 cmpxchg8b (%esi)
30042 jne 1b
30043 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
30044 movl $1, %eax
30045 3:
30046 RESTORE ebx
30047 + pax_force_retaddr
30048 ret
30049 CFI_ENDPROC
30050 ENDPROC(atomic64_inc_not_zero_cx8)
30051 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
30052 index e78b8eee..7e173a8 100644
30053 --- a/arch/x86/lib/checksum_32.S
30054 +++ b/arch/x86/lib/checksum_32.S
30055 @@ -29,7 +29,8 @@
30056 #include <asm/dwarf2.h>
30057 #include <asm/errno.h>
30058 #include <asm/asm.h>
30059 -
30060 +#include <asm/segment.h>
30061 +
30062 /*
30063 * computes a partial checksum, e.g. for TCP/UDP fragments
30064 */
30065 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
30066
30067 #define ARGBASE 16
30068 #define FP 12
30069 -
30070 -ENTRY(csum_partial_copy_generic)
30071 +
30072 +ENTRY(csum_partial_copy_generic_to_user)
30073 CFI_STARTPROC
30074 +
30075 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30076 + pushl_cfi %gs
30077 + popl_cfi %es
30078 + jmp csum_partial_copy_generic
30079 +#endif
30080 +
30081 +ENTRY(csum_partial_copy_generic_from_user)
30082 +
30083 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30084 + pushl_cfi %gs
30085 + popl_cfi %ds
30086 +#endif
30087 +
30088 +ENTRY(csum_partial_copy_generic)
30089 subl $4,%esp
30090 CFI_ADJUST_CFA_OFFSET 4
30091 pushl_cfi %edi
30092 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
30093 jmp 4f
30094 SRC(1: movw (%esi), %bx )
30095 addl $2, %esi
30096 -DST( movw %bx, (%edi) )
30097 +DST( movw %bx, %es:(%edi) )
30098 addl $2, %edi
30099 addw %bx, %ax
30100 adcl $0, %eax
30101 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
30102 SRC(1: movl (%esi), %ebx )
30103 SRC( movl 4(%esi), %edx )
30104 adcl %ebx, %eax
30105 -DST( movl %ebx, (%edi) )
30106 +DST( movl %ebx, %es:(%edi) )
30107 adcl %edx, %eax
30108 -DST( movl %edx, 4(%edi) )
30109 +DST( movl %edx, %es:4(%edi) )
30110
30111 SRC( movl 8(%esi), %ebx )
30112 SRC( movl 12(%esi), %edx )
30113 adcl %ebx, %eax
30114 -DST( movl %ebx, 8(%edi) )
30115 +DST( movl %ebx, %es:8(%edi) )
30116 adcl %edx, %eax
30117 -DST( movl %edx, 12(%edi) )
30118 +DST( movl %edx, %es:12(%edi) )
30119
30120 SRC( movl 16(%esi), %ebx )
30121 SRC( movl 20(%esi), %edx )
30122 adcl %ebx, %eax
30123 -DST( movl %ebx, 16(%edi) )
30124 +DST( movl %ebx, %es:16(%edi) )
30125 adcl %edx, %eax
30126 -DST( movl %edx, 20(%edi) )
30127 +DST( movl %edx, %es:20(%edi) )
30128
30129 SRC( movl 24(%esi), %ebx )
30130 SRC( movl 28(%esi), %edx )
30131 adcl %ebx, %eax
30132 -DST( movl %ebx, 24(%edi) )
30133 +DST( movl %ebx, %es:24(%edi) )
30134 adcl %edx, %eax
30135 -DST( movl %edx, 28(%edi) )
30136 +DST( movl %edx, %es:28(%edi) )
30137
30138 lea 32(%esi), %esi
30139 lea 32(%edi), %edi
30140 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
30141 shrl $2, %edx # This clears CF
30142 SRC(3: movl (%esi), %ebx )
30143 adcl %ebx, %eax
30144 -DST( movl %ebx, (%edi) )
30145 +DST( movl %ebx, %es:(%edi) )
30146 lea 4(%esi), %esi
30147 lea 4(%edi), %edi
30148 dec %edx
30149 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
30150 jb 5f
30151 SRC( movw (%esi), %cx )
30152 leal 2(%esi), %esi
30153 -DST( movw %cx, (%edi) )
30154 +DST( movw %cx, %es:(%edi) )
30155 leal 2(%edi), %edi
30156 je 6f
30157 shll $16,%ecx
30158 SRC(5: movb (%esi), %cl )
30159 -DST( movb %cl, (%edi) )
30160 +DST( movb %cl, %es:(%edi) )
30161 6: addl %ecx, %eax
30162 adcl $0, %eax
30163 7:
30164 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
30165
30166 6001:
30167 movl ARGBASE+20(%esp), %ebx # src_err_ptr
30168 - movl $-EFAULT, (%ebx)
30169 + movl $-EFAULT, %ss:(%ebx)
30170
30171 # zero the complete destination - computing the rest
30172 # is too much work
30173 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
30174
30175 6002:
30176 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
30177 - movl $-EFAULT,(%ebx)
30178 + movl $-EFAULT,%ss:(%ebx)
30179 jmp 5000b
30180
30181 .previous
30182
30183 + pushl_cfi %ss
30184 + popl_cfi %ds
30185 + pushl_cfi %ss
30186 + popl_cfi %es
30187 popl_cfi %ebx
30188 CFI_RESTORE ebx
30189 popl_cfi %esi
30190 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
30191 popl_cfi %ecx # equivalent to addl $4,%esp
30192 ret
30193 CFI_ENDPROC
30194 -ENDPROC(csum_partial_copy_generic)
30195 +ENDPROC(csum_partial_copy_generic_to_user)
30196
30197 #else
30198
30199 /* Version for PentiumII/PPro */
30200
30201 #define ROUND1(x) \
30202 + nop; nop; nop; \
30203 SRC(movl x(%esi), %ebx ) ; \
30204 addl %ebx, %eax ; \
30205 - DST(movl %ebx, x(%edi) ) ;
30206 + DST(movl %ebx, %es:x(%edi)) ;
30207
30208 #define ROUND(x) \
30209 + nop; nop; nop; \
30210 SRC(movl x(%esi), %ebx ) ; \
30211 adcl %ebx, %eax ; \
30212 - DST(movl %ebx, x(%edi) ) ;
30213 + DST(movl %ebx, %es:x(%edi)) ;
30214
30215 #define ARGBASE 12
30216 -
30217 -ENTRY(csum_partial_copy_generic)
30218 +
30219 +ENTRY(csum_partial_copy_generic_to_user)
30220 CFI_STARTPROC
30221 +
30222 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30223 + pushl_cfi %gs
30224 + popl_cfi %es
30225 + jmp csum_partial_copy_generic
30226 +#endif
30227 +
30228 +ENTRY(csum_partial_copy_generic_from_user)
30229 +
30230 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30231 + pushl_cfi %gs
30232 + popl_cfi %ds
30233 +#endif
30234 +
30235 +ENTRY(csum_partial_copy_generic)
30236 pushl_cfi %ebx
30237 CFI_REL_OFFSET ebx, 0
30238 pushl_cfi %edi
30239 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
30240 subl %ebx, %edi
30241 lea -1(%esi),%edx
30242 andl $-32,%edx
30243 - lea 3f(%ebx,%ebx), %ebx
30244 + lea 3f(%ebx,%ebx,2), %ebx
30245 testl %esi, %esi
30246 jmp *%ebx
30247 1: addl $64,%esi
30248 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
30249 jb 5f
30250 SRC( movw (%esi), %dx )
30251 leal 2(%esi), %esi
30252 -DST( movw %dx, (%edi) )
30253 +DST( movw %dx, %es:(%edi) )
30254 leal 2(%edi), %edi
30255 je 6f
30256 shll $16,%edx
30257 5:
30258 SRC( movb (%esi), %dl )
30259 -DST( movb %dl, (%edi) )
30260 +DST( movb %dl, %es:(%edi) )
30261 6: addl %edx, %eax
30262 adcl $0, %eax
30263 7:
30264 .section .fixup, "ax"
30265 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
30266 - movl $-EFAULT, (%ebx)
30267 + movl $-EFAULT, %ss:(%ebx)
30268 # zero the complete destination (computing the rest is too much work)
30269 movl ARGBASE+8(%esp),%edi # dst
30270 movl ARGBASE+12(%esp),%ecx # len
30271 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
30272 rep; stosb
30273 jmp 7b
30274 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
30275 - movl $-EFAULT, (%ebx)
30276 + movl $-EFAULT, %ss:(%ebx)
30277 jmp 7b
30278 .previous
30279
30280 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30281 + pushl_cfi %ss
30282 + popl_cfi %ds
30283 + pushl_cfi %ss
30284 + popl_cfi %es
30285 +#endif
30286 +
30287 popl_cfi %esi
30288 CFI_RESTORE esi
30289 popl_cfi %edi
30290 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
30291 CFI_RESTORE ebx
30292 ret
30293 CFI_ENDPROC
30294 -ENDPROC(csum_partial_copy_generic)
30295 +ENDPROC(csum_partial_copy_generic_to_user)
30296
30297 #undef ROUND
30298 #undef ROUND1
30299 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
30300 index f2145cf..cea889d 100644
30301 --- a/arch/x86/lib/clear_page_64.S
30302 +++ b/arch/x86/lib/clear_page_64.S
30303 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
30304 movl $4096/8,%ecx
30305 xorl %eax,%eax
30306 rep stosq
30307 + pax_force_retaddr
30308 ret
30309 CFI_ENDPROC
30310 ENDPROC(clear_page_c)
30311 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
30312 movl $4096,%ecx
30313 xorl %eax,%eax
30314 rep stosb
30315 + pax_force_retaddr
30316 ret
30317 CFI_ENDPROC
30318 ENDPROC(clear_page_c_e)
30319 @@ -43,6 +45,7 @@ ENTRY(clear_page)
30320 leaq 64(%rdi),%rdi
30321 jnz .Lloop
30322 nop
30323 + pax_force_retaddr
30324 ret
30325 CFI_ENDPROC
30326 .Lclear_page_end:
30327 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
30328
30329 #include <asm/cpufeature.h>
30330
30331 - .section .altinstr_replacement,"ax"
30332 + .section .altinstr_replacement,"a"
30333 1: .byte 0xeb /* jmp <disp8> */
30334 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
30335 2: .byte 0xeb /* jmp <disp8> */
30336 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
30337 index 1e572c5..2a162cd 100644
30338 --- a/arch/x86/lib/cmpxchg16b_emu.S
30339 +++ b/arch/x86/lib/cmpxchg16b_emu.S
30340 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
30341
30342 popf
30343 mov $1, %al
30344 + pax_force_retaddr
30345 ret
30346
30347 not_same:
30348 popf
30349 xor %al,%al
30350 + pax_force_retaddr
30351 ret
30352
30353 CFI_ENDPROC
30354 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
30355 index 176cca6..e0d658e 100644
30356 --- a/arch/x86/lib/copy_page_64.S
30357 +++ b/arch/x86/lib/copy_page_64.S
30358 @@ -9,6 +9,7 @@ copy_page_rep:
30359 CFI_STARTPROC
30360 movl $4096/8, %ecx
30361 rep movsq
30362 + pax_force_retaddr
30363 ret
30364 CFI_ENDPROC
30365 ENDPROC(copy_page_rep)
30366 @@ -24,8 +25,8 @@ ENTRY(copy_page)
30367 CFI_ADJUST_CFA_OFFSET 2*8
30368 movq %rbx, (%rsp)
30369 CFI_REL_OFFSET rbx, 0
30370 - movq %r12, 1*8(%rsp)
30371 - CFI_REL_OFFSET r12, 1*8
30372 + movq %r13, 1*8(%rsp)
30373 + CFI_REL_OFFSET r13, 1*8
30374
30375 movl $(4096/64)-5, %ecx
30376 .p2align 4
30377 @@ -38,7 +39,7 @@ ENTRY(copy_page)
30378 movq 0x8*4(%rsi), %r9
30379 movq 0x8*5(%rsi), %r10
30380 movq 0x8*6(%rsi), %r11
30381 - movq 0x8*7(%rsi), %r12
30382 + movq 0x8*7(%rsi), %r13
30383
30384 prefetcht0 5*64(%rsi)
30385
30386 @@ -49,7 +50,7 @@ ENTRY(copy_page)
30387 movq %r9, 0x8*4(%rdi)
30388 movq %r10, 0x8*5(%rdi)
30389 movq %r11, 0x8*6(%rdi)
30390 - movq %r12, 0x8*7(%rdi)
30391 + movq %r13, 0x8*7(%rdi)
30392
30393 leaq 64 (%rsi), %rsi
30394 leaq 64 (%rdi), %rdi
30395 @@ -68,7 +69,7 @@ ENTRY(copy_page)
30396 movq 0x8*4(%rsi), %r9
30397 movq 0x8*5(%rsi), %r10
30398 movq 0x8*6(%rsi), %r11
30399 - movq 0x8*7(%rsi), %r12
30400 + movq 0x8*7(%rsi), %r13
30401
30402 movq %rax, 0x8*0(%rdi)
30403 movq %rbx, 0x8*1(%rdi)
30404 @@ -77,7 +78,7 @@ ENTRY(copy_page)
30405 movq %r9, 0x8*4(%rdi)
30406 movq %r10, 0x8*5(%rdi)
30407 movq %r11, 0x8*6(%rdi)
30408 - movq %r12, 0x8*7(%rdi)
30409 + movq %r13, 0x8*7(%rdi)
30410
30411 leaq 64(%rdi), %rdi
30412 leaq 64(%rsi), %rsi
30413 @@ -85,10 +86,11 @@ ENTRY(copy_page)
30414
30415 movq (%rsp), %rbx
30416 CFI_RESTORE rbx
30417 - movq 1*8(%rsp), %r12
30418 - CFI_RESTORE r12
30419 + movq 1*8(%rsp), %r13
30420 + CFI_RESTORE r13
30421 addq $2*8, %rsp
30422 CFI_ADJUST_CFA_OFFSET -2*8
30423 + pax_force_retaddr
30424 ret
30425 .Lcopy_page_end:
30426 CFI_ENDPROC
30427 @@ -99,7 +101,7 @@ ENDPROC(copy_page)
30428
30429 #include <asm/cpufeature.h>
30430
30431 - .section .altinstr_replacement,"ax"
30432 + .section .altinstr_replacement,"a"
30433 1: .byte 0xeb /* jmp <disp8> */
30434 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
30435 2:
30436 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
30437 index dee945d..a84067b 100644
30438 --- a/arch/x86/lib/copy_user_64.S
30439 +++ b/arch/x86/lib/copy_user_64.S
30440 @@ -18,31 +18,7 @@
30441 #include <asm/alternative-asm.h>
30442 #include <asm/asm.h>
30443 #include <asm/smap.h>
30444 -
30445 -/*
30446 - * By placing feature2 after feature1 in altinstructions section, we logically
30447 - * implement:
30448 - * If CPU has feature2, jmp to alt2 is used
30449 - * else if CPU has feature1, jmp to alt1 is used
30450 - * else jmp to orig is used.
30451 - */
30452 - .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
30453 -0:
30454 - .byte 0xe9 /* 32bit jump */
30455 - .long \orig-1f /* by default jump to orig */
30456 -1:
30457 - .section .altinstr_replacement,"ax"
30458 -2: .byte 0xe9 /* near jump with 32bit immediate */
30459 - .long \alt1-1b /* offset */ /* or alternatively to alt1 */
30460 -3: .byte 0xe9 /* near jump with 32bit immediate */
30461 - .long \alt2-1b /* offset */ /* or alternatively to alt2 */
30462 - .previous
30463 -
30464 - .section .altinstructions,"a"
30465 - altinstruction_entry 0b,2b,\feature1,5,5
30466 - altinstruction_entry 0b,3b,\feature2,5,5
30467 - .previous
30468 - .endm
30469 +#include <asm/pgtable.h>
30470
30471 .macro ALIGN_DESTINATION
30472 #ifdef FIX_ALIGNMENT
30473 @@ -70,52 +46,6 @@
30474 #endif
30475 .endm
30476
30477 -/* Standard copy_to_user with segment limit checking */
30478 -ENTRY(_copy_to_user)
30479 - CFI_STARTPROC
30480 - GET_THREAD_INFO(%rax)
30481 - movq %rdi,%rcx
30482 - addq %rdx,%rcx
30483 - jc bad_to_user
30484 - cmpq TI_addr_limit(%rax),%rcx
30485 - ja bad_to_user
30486 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
30487 - copy_user_generic_unrolled,copy_user_generic_string, \
30488 - copy_user_enhanced_fast_string
30489 - CFI_ENDPROC
30490 -ENDPROC(_copy_to_user)
30491 -
30492 -/* Standard copy_from_user with segment limit checking */
30493 -ENTRY(_copy_from_user)
30494 - CFI_STARTPROC
30495 - GET_THREAD_INFO(%rax)
30496 - movq %rsi,%rcx
30497 - addq %rdx,%rcx
30498 - jc bad_from_user
30499 - cmpq TI_addr_limit(%rax),%rcx
30500 - ja bad_from_user
30501 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
30502 - copy_user_generic_unrolled,copy_user_generic_string, \
30503 - copy_user_enhanced_fast_string
30504 - CFI_ENDPROC
30505 -ENDPROC(_copy_from_user)
30506 -
30507 - .section .fixup,"ax"
30508 - /* must zero dest */
30509 -ENTRY(bad_from_user)
30510 -bad_from_user:
30511 - CFI_STARTPROC
30512 - movl %edx,%ecx
30513 - xorl %eax,%eax
30514 - rep
30515 - stosb
30516 -bad_to_user:
30517 - movl %edx,%eax
30518 - ret
30519 - CFI_ENDPROC
30520 -ENDPROC(bad_from_user)
30521 - .previous
30522 -
30523 /*
30524 * copy_user_generic_unrolled - memory copy with exception handling.
30525 * This version is for CPUs like P4 that don't have efficient micro
30526 @@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
30527 */
30528 ENTRY(copy_user_generic_unrolled)
30529 CFI_STARTPROC
30530 + ASM_PAX_OPEN_USERLAND
30531 ASM_STAC
30532 cmpl $8,%edx
30533 jb 20f /* less then 8 bytes, go to byte copy loop */
30534 @@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
30535 jnz 21b
30536 23: xor %eax,%eax
30537 ASM_CLAC
30538 + ASM_PAX_CLOSE_USERLAND
30539 + pax_force_retaddr
30540 ret
30541
30542 .section .fixup,"ax"
30543 @@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
30544 */
30545 ENTRY(copy_user_generic_string)
30546 CFI_STARTPROC
30547 + ASM_PAX_OPEN_USERLAND
30548 ASM_STAC
30549 cmpl $8,%edx
30550 jb 2f /* less than 8 bytes, go to byte copy loop */
30551 @@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
30552 movsb
30553 xorl %eax,%eax
30554 ASM_CLAC
30555 + ASM_PAX_CLOSE_USERLAND
30556 + pax_force_retaddr
30557 ret
30558
30559 .section .fixup,"ax"
30560 @@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
30561 */
30562 ENTRY(copy_user_enhanced_fast_string)
30563 CFI_STARTPROC
30564 + ASM_PAX_OPEN_USERLAND
30565 ASM_STAC
30566 movl %edx,%ecx
30567 1: rep
30568 movsb
30569 xorl %eax,%eax
30570 ASM_CLAC
30571 + ASM_PAX_CLOSE_USERLAND
30572 + pax_force_retaddr
30573 ret
30574
30575 .section .fixup,"ax"
30576 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
30577 index 6a4f43c..c70fb52 100644
30578 --- a/arch/x86/lib/copy_user_nocache_64.S
30579 +++ b/arch/x86/lib/copy_user_nocache_64.S
30580 @@ -8,6 +8,7 @@
30581
30582 #include <linux/linkage.h>
30583 #include <asm/dwarf2.h>
30584 +#include <asm/alternative-asm.h>
30585
30586 #define FIX_ALIGNMENT 1
30587
30588 @@ -16,6 +17,7 @@
30589 #include <asm/thread_info.h>
30590 #include <asm/asm.h>
30591 #include <asm/smap.h>
30592 +#include <asm/pgtable.h>
30593
30594 .macro ALIGN_DESTINATION
30595 #ifdef FIX_ALIGNMENT
30596 @@ -49,6 +51,16 @@
30597 */
30598 ENTRY(__copy_user_nocache)
30599 CFI_STARTPROC
30600 +
30601 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30602 + mov pax_user_shadow_base,%rcx
30603 + cmp %rcx,%rsi
30604 + jae 1f
30605 + add %rcx,%rsi
30606 +1:
30607 +#endif
30608 +
30609 + ASM_PAX_OPEN_USERLAND
30610 ASM_STAC
30611 cmpl $8,%edx
30612 jb 20f /* less then 8 bytes, go to byte copy loop */
30613 @@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
30614 jnz 21b
30615 23: xorl %eax,%eax
30616 ASM_CLAC
30617 + ASM_PAX_CLOSE_USERLAND
30618 sfence
30619 + pax_force_retaddr
30620 ret
30621
30622 .section .fixup,"ax"
30623 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
30624 index 2419d5f..fe52d0e 100644
30625 --- a/arch/x86/lib/csum-copy_64.S
30626 +++ b/arch/x86/lib/csum-copy_64.S
30627 @@ -9,6 +9,7 @@
30628 #include <asm/dwarf2.h>
30629 #include <asm/errno.h>
30630 #include <asm/asm.h>
30631 +#include <asm/alternative-asm.h>
30632
30633 /*
30634 * Checksum copy with exception handling.
30635 @@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
30636 CFI_ADJUST_CFA_OFFSET 7*8
30637 movq %rbx, 2*8(%rsp)
30638 CFI_REL_OFFSET rbx, 2*8
30639 - movq %r12, 3*8(%rsp)
30640 - CFI_REL_OFFSET r12, 3*8
30641 + movq %r15, 3*8(%rsp)
30642 + CFI_REL_OFFSET r15, 3*8
30643 movq %r14, 4*8(%rsp)
30644 CFI_REL_OFFSET r14, 4*8
30645 movq %r13, 5*8(%rsp)
30646 @@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
30647 movl %edx, %ecx
30648
30649 xorl %r9d, %r9d
30650 - movq %rcx, %r12
30651 + movq %rcx, %r15
30652
30653 - shrq $6, %r12
30654 + shrq $6, %r15
30655 jz .Lhandle_tail /* < 64 */
30656
30657 clc
30658
30659 /* main loop. clear in 64 byte blocks */
30660 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
30661 - /* r11: temp3, rdx: temp4, r12 loopcnt */
30662 + /* r11: temp3, rdx: temp4, r15 loopcnt */
30663 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
30664 .p2align 4
30665 .Lloop:
30666 @@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
30667 adcq %r14, %rax
30668 adcq %r13, %rax
30669
30670 - decl %r12d
30671 + decl %r15d
30672
30673 dest
30674 movq %rbx, (%rsi)
30675 @@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
30676 .Lende:
30677 movq 2*8(%rsp), %rbx
30678 CFI_RESTORE rbx
30679 - movq 3*8(%rsp), %r12
30680 - CFI_RESTORE r12
30681 + movq 3*8(%rsp), %r15
30682 + CFI_RESTORE r15
30683 movq 4*8(%rsp), %r14
30684 CFI_RESTORE r14
30685 movq 5*8(%rsp), %r13
30686 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
30687 CFI_RESTORE rbp
30688 addq $7*8, %rsp
30689 CFI_ADJUST_CFA_OFFSET -7*8
30690 + pax_force_retaddr
30691 ret
30692 CFI_RESTORE_STATE
30693
30694 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
30695 index 7609e0e..b449b98 100644
30696 --- a/arch/x86/lib/csum-wrappers_64.c
30697 +++ b/arch/x86/lib/csum-wrappers_64.c
30698 @@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
30699 len -= 2;
30700 }
30701 }
30702 + pax_open_userland();
30703 stac();
30704 - isum = csum_partial_copy_generic((__force const void *)src,
30705 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
30706 dst, len, isum, errp, NULL);
30707 clac();
30708 + pax_close_userland();
30709 if (unlikely(*errp))
30710 goto out_err;
30711
30712 @@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
30713 }
30714
30715 *errp = 0;
30716 + pax_open_userland();
30717 stac();
30718 - ret = csum_partial_copy_generic(src, (void __force *)dst,
30719 + ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
30720 len, isum, NULL, errp);
30721 clac();
30722 + pax_close_userland();
30723 return ret;
30724 }
30725 EXPORT_SYMBOL(csum_partial_copy_to_user);
30726 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
30727 index a451235..1daa956 100644
30728 --- a/arch/x86/lib/getuser.S
30729 +++ b/arch/x86/lib/getuser.S
30730 @@ -33,17 +33,40 @@
30731 #include <asm/thread_info.h>
30732 #include <asm/asm.h>
30733 #include <asm/smap.h>
30734 +#include <asm/segment.h>
30735 +#include <asm/pgtable.h>
30736 +#include <asm/alternative-asm.h>
30737 +
30738 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30739 +#define __copyuser_seg gs;
30740 +#else
30741 +#define __copyuser_seg
30742 +#endif
30743
30744 .text
30745 ENTRY(__get_user_1)
30746 CFI_STARTPROC
30747 +
30748 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30749 GET_THREAD_INFO(%_ASM_DX)
30750 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30751 jae bad_get_user
30752 ASM_STAC
30753 -1: movzbl (%_ASM_AX),%edx
30754 +
30755 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30756 + mov pax_user_shadow_base,%_ASM_DX
30757 + cmp %_ASM_DX,%_ASM_AX
30758 + jae 1234f
30759 + add %_ASM_DX,%_ASM_AX
30760 +1234:
30761 +#endif
30762 +
30763 +#endif
30764 +
30765 +1: __copyuser_seg movzbl (%_ASM_AX),%edx
30766 xor %eax,%eax
30767 ASM_CLAC
30768 + pax_force_retaddr
30769 ret
30770 CFI_ENDPROC
30771 ENDPROC(__get_user_1)
30772 @@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
30773 ENTRY(__get_user_2)
30774 CFI_STARTPROC
30775 add $1,%_ASM_AX
30776 +
30777 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30778 jc bad_get_user
30779 GET_THREAD_INFO(%_ASM_DX)
30780 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30781 jae bad_get_user
30782 ASM_STAC
30783 -2: movzwl -1(%_ASM_AX),%edx
30784 +
30785 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30786 + mov pax_user_shadow_base,%_ASM_DX
30787 + cmp %_ASM_DX,%_ASM_AX
30788 + jae 1234f
30789 + add %_ASM_DX,%_ASM_AX
30790 +1234:
30791 +#endif
30792 +
30793 +#endif
30794 +
30795 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
30796 xor %eax,%eax
30797 ASM_CLAC
30798 + pax_force_retaddr
30799 ret
30800 CFI_ENDPROC
30801 ENDPROC(__get_user_2)
30802 @@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
30803 ENTRY(__get_user_4)
30804 CFI_STARTPROC
30805 add $3,%_ASM_AX
30806 +
30807 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30808 jc bad_get_user
30809 GET_THREAD_INFO(%_ASM_DX)
30810 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30811 jae bad_get_user
30812 ASM_STAC
30813 -3: movl -3(%_ASM_AX),%edx
30814 +
30815 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30816 + mov pax_user_shadow_base,%_ASM_DX
30817 + cmp %_ASM_DX,%_ASM_AX
30818 + jae 1234f
30819 + add %_ASM_DX,%_ASM_AX
30820 +1234:
30821 +#endif
30822 +
30823 +#endif
30824 +
30825 +3: __copyuser_seg movl -3(%_ASM_AX),%edx
30826 xor %eax,%eax
30827 ASM_CLAC
30828 + pax_force_retaddr
30829 ret
30830 CFI_ENDPROC
30831 ENDPROC(__get_user_4)
30832 @@ -86,10 +137,20 @@ ENTRY(__get_user_8)
30833 GET_THREAD_INFO(%_ASM_DX)
30834 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30835 jae bad_get_user
30836 +
30837 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30838 + mov pax_user_shadow_base,%_ASM_DX
30839 + cmp %_ASM_DX,%_ASM_AX
30840 + jae 1234f
30841 + add %_ASM_DX,%_ASM_AX
30842 +1234:
30843 +#endif
30844 +
30845 ASM_STAC
30846 4: movq -7(%_ASM_AX),%rdx
30847 xor %eax,%eax
30848 ASM_CLAC
30849 + pax_force_retaddr
30850 ret
30851 #else
30852 add $7,%_ASM_AX
30853 @@ -98,10 +159,11 @@ ENTRY(__get_user_8)
30854 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30855 jae bad_get_user_8
30856 ASM_STAC
30857 -4: movl -7(%_ASM_AX),%edx
30858 -5: movl -3(%_ASM_AX),%ecx
30859 +4: __copyuser_seg movl -7(%_ASM_AX),%edx
30860 +5: __copyuser_seg movl -3(%_ASM_AX),%ecx
30861 xor %eax,%eax
30862 ASM_CLAC
30863 + pax_force_retaddr
30864 ret
30865 #endif
30866 CFI_ENDPROC
30867 @@ -113,6 +175,7 @@ bad_get_user:
30868 xor %edx,%edx
30869 mov $(-EFAULT),%_ASM_AX
30870 ASM_CLAC
30871 + pax_force_retaddr
30872 ret
30873 CFI_ENDPROC
30874 END(bad_get_user)
30875 @@ -124,6 +187,7 @@ bad_get_user_8:
30876 xor %ecx,%ecx
30877 mov $(-EFAULT),%_ASM_AX
30878 ASM_CLAC
30879 + pax_force_retaddr
30880 ret
30881 CFI_ENDPROC
30882 END(bad_get_user_8)
30883 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
30884 index 54fcffe..7be149e 100644
30885 --- a/arch/x86/lib/insn.c
30886 +++ b/arch/x86/lib/insn.c
30887 @@ -20,8 +20,10 @@
30888
30889 #ifdef __KERNEL__
30890 #include <linux/string.h>
30891 +#include <asm/pgtable_types.h>
30892 #else
30893 #include <string.h>
30894 +#define ktla_ktva(addr) addr
30895 #endif
30896 #include <asm/inat.h>
30897 #include <asm/insn.h>
30898 @@ -53,8 +55,8 @@
30899 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
30900 {
30901 memset(insn, 0, sizeof(*insn));
30902 - insn->kaddr = kaddr;
30903 - insn->next_byte = kaddr;
30904 + insn->kaddr = ktla_ktva(kaddr);
30905 + insn->next_byte = ktla_ktva(kaddr);
30906 insn->x86_64 = x86_64 ? 1 : 0;
30907 insn->opnd_bytes = 4;
30908 if (x86_64)
30909 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
30910 index 05a95e7..326f2fa 100644
30911 --- a/arch/x86/lib/iomap_copy_64.S
30912 +++ b/arch/x86/lib/iomap_copy_64.S
30913 @@ -17,6 +17,7 @@
30914
30915 #include <linux/linkage.h>
30916 #include <asm/dwarf2.h>
30917 +#include <asm/alternative-asm.h>
30918
30919 /*
30920 * override generic version in lib/iomap_copy.c
30921 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
30922 CFI_STARTPROC
30923 movl %edx,%ecx
30924 rep movsd
30925 + pax_force_retaddr
30926 ret
30927 CFI_ENDPROC
30928 ENDPROC(__iowrite32_copy)
30929 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
30930 index 56313a3..0db417e 100644
30931 --- a/arch/x86/lib/memcpy_64.S
30932 +++ b/arch/x86/lib/memcpy_64.S
30933 @@ -24,7 +24,7 @@
30934 * This gets patched over the unrolled variant (below) via the
30935 * alternative instructions framework:
30936 */
30937 - .section .altinstr_replacement, "ax", @progbits
30938 + .section .altinstr_replacement, "a", @progbits
30939 .Lmemcpy_c:
30940 movq %rdi, %rax
30941 movq %rdx, %rcx
30942 @@ -33,6 +33,7 @@
30943 rep movsq
30944 movl %edx, %ecx
30945 rep movsb
30946 + pax_force_retaddr
30947 ret
30948 .Lmemcpy_e:
30949 .previous
30950 @@ -44,11 +45,12 @@
30951 * This gets patched over the unrolled variant (below) via the
30952 * alternative instructions framework:
30953 */
30954 - .section .altinstr_replacement, "ax", @progbits
30955 + .section .altinstr_replacement, "a", @progbits
30956 .Lmemcpy_c_e:
30957 movq %rdi, %rax
30958 movq %rdx, %rcx
30959 rep movsb
30960 + pax_force_retaddr
30961 ret
30962 .Lmemcpy_e_e:
30963 .previous
30964 @@ -136,6 +138,7 @@ ENTRY(memcpy)
30965 movq %r9, 1*8(%rdi)
30966 movq %r10, -2*8(%rdi, %rdx)
30967 movq %r11, -1*8(%rdi, %rdx)
30968 + pax_force_retaddr
30969 retq
30970 .p2align 4
30971 .Lless_16bytes:
30972 @@ -148,6 +151,7 @@ ENTRY(memcpy)
30973 movq -1*8(%rsi, %rdx), %r9
30974 movq %r8, 0*8(%rdi)
30975 movq %r9, -1*8(%rdi, %rdx)
30976 + pax_force_retaddr
30977 retq
30978 .p2align 4
30979 .Lless_8bytes:
30980 @@ -161,6 +165,7 @@ ENTRY(memcpy)
30981 movl -4(%rsi, %rdx), %r8d
30982 movl %ecx, (%rdi)
30983 movl %r8d, -4(%rdi, %rdx)
30984 + pax_force_retaddr
30985 retq
30986 .p2align 4
30987 .Lless_3bytes:
30988 @@ -179,6 +184,7 @@ ENTRY(memcpy)
30989 movb %cl, (%rdi)
30990
30991 .Lend:
30992 + pax_force_retaddr
30993 retq
30994 CFI_ENDPROC
30995 ENDPROC(memcpy)
30996 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
30997 index 65268a6..dd1de11 100644
30998 --- a/arch/x86/lib/memmove_64.S
30999 +++ b/arch/x86/lib/memmove_64.S
31000 @@ -202,14 +202,16 @@ ENTRY(memmove)
31001 movb (%rsi), %r11b
31002 movb %r11b, (%rdi)
31003 13:
31004 + pax_force_retaddr
31005 retq
31006 CFI_ENDPROC
31007
31008 - .section .altinstr_replacement,"ax"
31009 + .section .altinstr_replacement,"a"
31010 .Lmemmove_begin_forward_efs:
31011 /* Forward moving data. */
31012 movq %rdx, %rcx
31013 rep movsb
31014 + pax_force_retaddr
31015 retq
31016 .Lmemmove_end_forward_efs:
31017 .previous
31018 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
31019 index 2dcb380..2eb79fe 100644
31020 --- a/arch/x86/lib/memset_64.S
31021 +++ b/arch/x86/lib/memset_64.S
31022 @@ -16,7 +16,7 @@
31023 *
31024 * rax original destination
31025 */
31026 - .section .altinstr_replacement, "ax", @progbits
31027 + .section .altinstr_replacement, "a", @progbits
31028 .Lmemset_c:
31029 movq %rdi,%r9
31030 movq %rdx,%rcx
31031 @@ -30,6 +30,7 @@
31032 movl %edx,%ecx
31033 rep stosb
31034 movq %r9,%rax
31035 + pax_force_retaddr
31036 ret
31037 .Lmemset_e:
31038 .previous
31039 @@ -45,13 +46,14 @@
31040 *
31041 * rax original destination
31042 */
31043 - .section .altinstr_replacement, "ax", @progbits
31044 + .section .altinstr_replacement, "a", @progbits
31045 .Lmemset_c_e:
31046 movq %rdi,%r9
31047 movb %sil,%al
31048 movq %rdx,%rcx
31049 rep stosb
31050 movq %r9,%rax
31051 + pax_force_retaddr
31052 ret
31053 .Lmemset_e_e:
31054 .previous
31055 @@ -118,6 +120,7 @@ ENTRY(__memset)
31056
31057 .Lende:
31058 movq %r10,%rax
31059 + pax_force_retaddr
31060 ret
31061
31062 CFI_RESTORE_STATE
31063 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
31064 index c9f2d9b..e7fd2c0 100644
31065 --- a/arch/x86/lib/mmx_32.c
31066 +++ b/arch/x86/lib/mmx_32.c
31067 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
31068 {
31069 void *p;
31070 int i;
31071 + unsigned long cr0;
31072
31073 if (unlikely(in_interrupt()))
31074 return __memcpy(to, from, len);
31075 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
31076 kernel_fpu_begin();
31077
31078 __asm__ __volatile__ (
31079 - "1: prefetch (%0)\n" /* This set is 28 bytes */
31080 - " prefetch 64(%0)\n"
31081 - " prefetch 128(%0)\n"
31082 - " prefetch 192(%0)\n"
31083 - " prefetch 256(%0)\n"
31084 + "1: prefetch (%1)\n" /* This set is 28 bytes */
31085 + " prefetch 64(%1)\n"
31086 + " prefetch 128(%1)\n"
31087 + " prefetch 192(%1)\n"
31088 + " prefetch 256(%1)\n"
31089 "2: \n"
31090 ".section .fixup, \"ax\"\n"
31091 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31092 + "3: \n"
31093 +
31094 +#ifdef CONFIG_PAX_KERNEXEC
31095 + " movl %%cr0, %0\n"
31096 + " movl %0, %%eax\n"
31097 + " andl $0xFFFEFFFF, %%eax\n"
31098 + " movl %%eax, %%cr0\n"
31099 +#endif
31100 +
31101 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31102 +
31103 +#ifdef CONFIG_PAX_KERNEXEC
31104 + " movl %0, %%cr0\n"
31105 +#endif
31106 +
31107 " jmp 2b\n"
31108 ".previous\n"
31109 _ASM_EXTABLE(1b, 3b)
31110 - : : "r" (from));
31111 + : "=&r" (cr0) : "r" (from) : "ax");
31112
31113 for ( ; i > 5; i--) {
31114 __asm__ __volatile__ (
31115 - "1: prefetch 320(%0)\n"
31116 - "2: movq (%0), %%mm0\n"
31117 - " movq 8(%0), %%mm1\n"
31118 - " movq 16(%0), %%mm2\n"
31119 - " movq 24(%0), %%mm3\n"
31120 - " movq %%mm0, (%1)\n"
31121 - " movq %%mm1, 8(%1)\n"
31122 - " movq %%mm2, 16(%1)\n"
31123 - " movq %%mm3, 24(%1)\n"
31124 - " movq 32(%0), %%mm0\n"
31125 - " movq 40(%0), %%mm1\n"
31126 - " movq 48(%0), %%mm2\n"
31127 - " movq 56(%0), %%mm3\n"
31128 - " movq %%mm0, 32(%1)\n"
31129 - " movq %%mm1, 40(%1)\n"
31130 - " movq %%mm2, 48(%1)\n"
31131 - " movq %%mm3, 56(%1)\n"
31132 + "1: prefetch 320(%1)\n"
31133 + "2: movq (%1), %%mm0\n"
31134 + " movq 8(%1), %%mm1\n"
31135 + " movq 16(%1), %%mm2\n"
31136 + " movq 24(%1), %%mm3\n"
31137 + " movq %%mm0, (%2)\n"
31138 + " movq %%mm1, 8(%2)\n"
31139 + " movq %%mm2, 16(%2)\n"
31140 + " movq %%mm3, 24(%2)\n"
31141 + " movq 32(%1), %%mm0\n"
31142 + " movq 40(%1), %%mm1\n"
31143 + " movq 48(%1), %%mm2\n"
31144 + " movq 56(%1), %%mm3\n"
31145 + " movq %%mm0, 32(%2)\n"
31146 + " movq %%mm1, 40(%2)\n"
31147 + " movq %%mm2, 48(%2)\n"
31148 + " movq %%mm3, 56(%2)\n"
31149 ".section .fixup, \"ax\"\n"
31150 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31151 + "3:\n"
31152 +
31153 +#ifdef CONFIG_PAX_KERNEXEC
31154 + " movl %%cr0, %0\n"
31155 + " movl %0, %%eax\n"
31156 + " andl $0xFFFEFFFF, %%eax\n"
31157 + " movl %%eax, %%cr0\n"
31158 +#endif
31159 +
31160 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31161 +
31162 +#ifdef CONFIG_PAX_KERNEXEC
31163 + " movl %0, %%cr0\n"
31164 +#endif
31165 +
31166 " jmp 2b\n"
31167 ".previous\n"
31168 _ASM_EXTABLE(1b, 3b)
31169 - : : "r" (from), "r" (to) : "memory");
31170 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
31171
31172 from += 64;
31173 to += 64;
31174 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
31175 static void fast_copy_page(void *to, void *from)
31176 {
31177 int i;
31178 + unsigned long cr0;
31179
31180 kernel_fpu_begin();
31181
31182 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
31183 * but that is for later. -AV
31184 */
31185 __asm__ __volatile__(
31186 - "1: prefetch (%0)\n"
31187 - " prefetch 64(%0)\n"
31188 - " prefetch 128(%0)\n"
31189 - " prefetch 192(%0)\n"
31190 - " prefetch 256(%0)\n"
31191 + "1: prefetch (%1)\n"
31192 + " prefetch 64(%1)\n"
31193 + " prefetch 128(%1)\n"
31194 + " prefetch 192(%1)\n"
31195 + " prefetch 256(%1)\n"
31196 "2: \n"
31197 ".section .fixup, \"ax\"\n"
31198 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31199 + "3: \n"
31200 +
31201 +#ifdef CONFIG_PAX_KERNEXEC
31202 + " movl %%cr0, %0\n"
31203 + " movl %0, %%eax\n"
31204 + " andl $0xFFFEFFFF, %%eax\n"
31205 + " movl %%eax, %%cr0\n"
31206 +#endif
31207 +
31208 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31209 +
31210 +#ifdef CONFIG_PAX_KERNEXEC
31211 + " movl %0, %%cr0\n"
31212 +#endif
31213 +
31214 " jmp 2b\n"
31215 ".previous\n"
31216 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
31217 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
31218
31219 for (i = 0; i < (4096-320)/64; i++) {
31220 __asm__ __volatile__ (
31221 - "1: prefetch 320(%0)\n"
31222 - "2: movq (%0), %%mm0\n"
31223 - " movntq %%mm0, (%1)\n"
31224 - " movq 8(%0), %%mm1\n"
31225 - " movntq %%mm1, 8(%1)\n"
31226 - " movq 16(%0), %%mm2\n"
31227 - " movntq %%mm2, 16(%1)\n"
31228 - " movq 24(%0), %%mm3\n"
31229 - " movntq %%mm3, 24(%1)\n"
31230 - " movq 32(%0), %%mm4\n"
31231 - " movntq %%mm4, 32(%1)\n"
31232 - " movq 40(%0), %%mm5\n"
31233 - " movntq %%mm5, 40(%1)\n"
31234 - " movq 48(%0), %%mm6\n"
31235 - " movntq %%mm6, 48(%1)\n"
31236 - " movq 56(%0), %%mm7\n"
31237 - " movntq %%mm7, 56(%1)\n"
31238 + "1: prefetch 320(%1)\n"
31239 + "2: movq (%1), %%mm0\n"
31240 + " movntq %%mm0, (%2)\n"
31241 + " movq 8(%1), %%mm1\n"
31242 + " movntq %%mm1, 8(%2)\n"
31243 + " movq 16(%1), %%mm2\n"
31244 + " movntq %%mm2, 16(%2)\n"
31245 + " movq 24(%1), %%mm3\n"
31246 + " movntq %%mm3, 24(%2)\n"
31247 + " movq 32(%1), %%mm4\n"
31248 + " movntq %%mm4, 32(%2)\n"
31249 + " movq 40(%1), %%mm5\n"
31250 + " movntq %%mm5, 40(%2)\n"
31251 + " movq 48(%1), %%mm6\n"
31252 + " movntq %%mm6, 48(%2)\n"
31253 + " movq 56(%1), %%mm7\n"
31254 + " movntq %%mm7, 56(%2)\n"
31255 ".section .fixup, \"ax\"\n"
31256 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31257 + "3:\n"
31258 +
31259 +#ifdef CONFIG_PAX_KERNEXEC
31260 + " movl %%cr0, %0\n"
31261 + " movl %0, %%eax\n"
31262 + " andl $0xFFFEFFFF, %%eax\n"
31263 + " movl %%eax, %%cr0\n"
31264 +#endif
31265 +
31266 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31267 +
31268 +#ifdef CONFIG_PAX_KERNEXEC
31269 + " movl %0, %%cr0\n"
31270 +#endif
31271 +
31272 " jmp 2b\n"
31273 ".previous\n"
31274 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
31275 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
31276
31277 from += 64;
31278 to += 64;
31279 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
31280 static void fast_copy_page(void *to, void *from)
31281 {
31282 int i;
31283 + unsigned long cr0;
31284
31285 kernel_fpu_begin();
31286
31287 __asm__ __volatile__ (
31288 - "1: prefetch (%0)\n"
31289 - " prefetch 64(%0)\n"
31290 - " prefetch 128(%0)\n"
31291 - " prefetch 192(%0)\n"
31292 - " prefetch 256(%0)\n"
31293 + "1: prefetch (%1)\n"
31294 + " prefetch 64(%1)\n"
31295 + " prefetch 128(%1)\n"
31296 + " prefetch 192(%1)\n"
31297 + " prefetch 256(%1)\n"
31298 "2: \n"
31299 ".section .fixup, \"ax\"\n"
31300 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31301 + "3: \n"
31302 +
31303 +#ifdef CONFIG_PAX_KERNEXEC
31304 + " movl %%cr0, %0\n"
31305 + " movl %0, %%eax\n"
31306 + " andl $0xFFFEFFFF, %%eax\n"
31307 + " movl %%eax, %%cr0\n"
31308 +#endif
31309 +
31310 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31311 +
31312 +#ifdef CONFIG_PAX_KERNEXEC
31313 + " movl %0, %%cr0\n"
31314 +#endif
31315 +
31316 " jmp 2b\n"
31317 ".previous\n"
31318 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
31319 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
31320
31321 for (i = 0; i < 4096/64; i++) {
31322 __asm__ __volatile__ (
31323 - "1: prefetch 320(%0)\n"
31324 - "2: movq (%0), %%mm0\n"
31325 - " movq 8(%0), %%mm1\n"
31326 - " movq 16(%0), %%mm2\n"
31327 - " movq 24(%0), %%mm3\n"
31328 - " movq %%mm0, (%1)\n"
31329 - " movq %%mm1, 8(%1)\n"
31330 - " movq %%mm2, 16(%1)\n"
31331 - " movq %%mm3, 24(%1)\n"
31332 - " movq 32(%0), %%mm0\n"
31333 - " movq 40(%0), %%mm1\n"
31334 - " movq 48(%0), %%mm2\n"
31335 - " movq 56(%0), %%mm3\n"
31336 - " movq %%mm0, 32(%1)\n"
31337 - " movq %%mm1, 40(%1)\n"
31338 - " movq %%mm2, 48(%1)\n"
31339 - " movq %%mm3, 56(%1)\n"
31340 + "1: prefetch 320(%1)\n"
31341 + "2: movq (%1), %%mm0\n"
31342 + " movq 8(%1), %%mm1\n"
31343 + " movq 16(%1), %%mm2\n"
31344 + " movq 24(%1), %%mm3\n"
31345 + " movq %%mm0, (%2)\n"
31346 + " movq %%mm1, 8(%2)\n"
31347 + " movq %%mm2, 16(%2)\n"
31348 + " movq %%mm3, 24(%2)\n"
31349 + " movq 32(%1), %%mm0\n"
31350 + " movq 40(%1), %%mm1\n"
31351 + " movq 48(%1), %%mm2\n"
31352 + " movq 56(%1), %%mm3\n"
31353 + " movq %%mm0, 32(%2)\n"
31354 + " movq %%mm1, 40(%2)\n"
31355 + " movq %%mm2, 48(%2)\n"
31356 + " movq %%mm3, 56(%2)\n"
31357 ".section .fixup, \"ax\"\n"
31358 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31359 + "3:\n"
31360 +
31361 +#ifdef CONFIG_PAX_KERNEXEC
31362 + " movl %%cr0, %0\n"
31363 + " movl %0, %%eax\n"
31364 + " andl $0xFFFEFFFF, %%eax\n"
31365 + " movl %%eax, %%cr0\n"
31366 +#endif
31367 +
31368 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31369 +
31370 +#ifdef CONFIG_PAX_KERNEXEC
31371 + " movl %0, %%cr0\n"
31372 +#endif
31373 +
31374 " jmp 2b\n"
31375 ".previous\n"
31376 _ASM_EXTABLE(1b, 3b)
31377 - : : "r" (from), "r" (to) : "memory");
31378 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
31379
31380 from += 64;
31381 to += 64;
31382 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
31383 index f6d13ee..d789440 100644
31384 --- a/arch/x86/lib/msr-reg.S
31385 +++ b/arch/x86/lib/msr-reg.S
31386 @@ -3,6 +3,7 @@
31387 #include <asm/dwarf2.h>
31388 #include <asm/asm.h>
31389 #include <asm/msr.h>
31390 +#include <asm/alternative-asm.h>
31391
31392 #ifdef CONFIG_X86_64
31393 /*
31394 @@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
31395 movl %edi, 28(%r10)
31396 popq_cfi %rbp
31397 popq_cfi %rbx
31398 + pax_force_retaddr
31399 ret
31400 3:
31401 CFI_RESTORE_STATE
31402 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
31403 index fc6ba17..d4d989d 100644
31404 --- a/arch/x86/lib/putuser.S
31405 +++ b/arch/x86/lib/putuser.S
31406 @@ -16,7 +16,9 @@
31407 #include <asm/errno.h>
31408 #include <asm/asm.h>
31409 #include <asm/smap.h>
31410 -
31411 +#include <asm/segment.h>
31412 +#include <asm/pgtable.h>
31413 +#include <asm/alternative-asm.h>
31414
31415 /*
31416 * __put_user_X
31417 @@ -30,57 +32,125 @@
31418 * as they get called from within inline assembly.
31419 */
31420
31421 -#define ENTER CFI_STARTPROC ; \
31422 - GET_THREAD_INFO(%_ASM_BX)
31423 -#define EXIT ASM_CLAC ; \
31424 - ret ; \
31425 +#define ENTER CFI_STARTPROC
31426 +#define EXIT ASM_CLAC ; \
31427 + pax_force_retaddr ; \
31428 + ret ; \
31429 CFI_ENDPROC
31430
31431 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31432 +#define _DEST %_ASM_CX,%_ASM_BX
31433 +#else
31434 +#define _DEST %_ASM_CX
31435 +#endif
31436 +
31437 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
31438 +#define __copyuser_seg gs;
31439 +#else
31440 +#define __copyuser_seg
31441 +#endif
31442 +
31443 .text
31444 ENTRY(__put_user_1)
31445 ENTER
31446 +
31447 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31448 + GET_THREAD_INFO(%_ASM_BX)
31449 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
31450 jae bad_put_user
31451 ASM_STAC
31452 -1: movb %al,(%_ASM_CX)
31453 +
31454 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31455 + mov pax_user_shadow_base,%_ASM_BX
31456 + cmp %_ASM_BX,%_ASM_CX
31457 + jb 1234f
31458 + xor %ebx,%ebx
31459 +1234:
31460 +#endif
31461 +
31462 +#endif
31463 +
31464 +1: __copyuser_seg movb %al,(_DEST)
31465 xor %eax,%eax
31466 EXIT
31467 ENDPROC(__put_user_1)
31468
31469 ENTRY(__put_user_2)
31470 ENTER
31471 +
31472 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31473 + GET_THREAD_INFO(%_ASM_BX)
31474 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
31475 sub $1,%_ASM_BX
31476 cmp %_ASM_BX,%_ASM_CX
31477 jae bad_put_user
31478 ASM_STAC
31479 -2: movw %ax,(%_ASM_CX)
31480 +
31481 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31482 + mov pax_user_shadow_base,%_ASM_BX
31483 + cmp %_ASM_BX,%_ASM_CX
31484 + jb 1234f
31485 + xor %ebx,%ebx
31486 +1234:
31487 +#endif
31488 +
31489 +#endif
31490 +
31491 +2: __copyuser_seg movw %ax,(_DEST)
31492 xor %eax,%eax
31493 EXIT
31494 ENDPROC(__put_user_2)
31495
31496 ENTRY(__put_user_4)
31497 ENTER
31498 +
31499 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31500 + GET_THREAD_INFO(%_ASM_BX)
31501 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
31502 sub $3,%_ASM_BX
31503 cmp %_ASM_BX,%_ASM_CX
31504 jae bad_put_user
31505 ASM_STAC
31506 -3: movl %eax,(%_ASM_CX)
31507 +
31508 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31509 + mov pax_user_shadow_base,%_ASM_BX
31510 + cmp %_ASM_BX,%_ASM_CX
31511 + jb 1234f
31512 + xor %ebx,%ebx
31513 +1234:
31514 +#endif
31515 +
31516 +#endif
31517 +
31518 +3: __copyuser_seg movl %eax,(_DEST)
31519 xor %eax,%eax
31520 EXIT
31521 ENDPROC(__put_user_4)
31522
31523 ENTRY(__put_user_8)
31524 ENTER
31525 +
31526 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31527 + GET_THREAD_INFO(%_ASM_BX)
31528 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
31529 sub $7,%_ASM_BX
31530 cmp %_ASM_BX,%_ASM_CX
31531 jae bad_put_user
31532 ASM_STAC
31533 -4: mov %_ASM_AX,(%_ASM_CX)
31534 +
31535 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31536 + mov pax_user_shadow_base,%_ASM_BX
31537 + cmp %_ASM_BX,%_ASM_CX
31538 + jb 1234f
31539 + xor %ebx,%ebx
31540 +1234:
31541 +#endif
31542 +
31543 +#endif
31544 +
31545 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
31546 #ifdef CONFIG_X86_32
31547 -5: movl %edx,4(%_ASM_CX)
31548 +5: __copyuser_seg movl %edx,4(_DEST)
31549 #endif
31550 xor %eax,%eax
31551 EXIT
31552 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
31553 index 1cad221..de671ee 100644
31554 --- a/arch/x86/lib/rwlock.S
31555 +++ b/arch/x86/lib/rwlock.S
31556 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
31557 FRAME
31558 0: LOCK_PREFIX
31559 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
31560 +
31561 +#ifdef CONFIG_PAX_REFCOUNT
31562 + jno 1234f
31563 + LOCK_PREFIX
31564 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
31565 + int $4
31566 +1234:
31567 + _ASM_EXTABLE(1234b, 1234b)
31568 +#endif
31569 +
31570 1: rep; nop
31571 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
31572 jne 1b
31573 LOCK_PREFIX
31574 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
31575 +
31576 +#ifdef CONFIG_PAX_REFCOUNT
31577 + jno 1234f
31578 + LOCK_PREFIX
31579 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
31580 + int $4
31581 +1234:
31582 + _ASM_EXTABLE(1234b, 1234b)
31583 +#endif
31584 +
31585 jnz 0b
31586 ENDFRAME
31587 + pax_force_retaddr
31588 ret
31589 CFI_ENDPROC
31590 END(__write_lock_failed)
31591 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
31592 FRAME
31593 0: LOCK_PREFIX
31594 READ_LOCK_SIZE(inc) (%__lock_ptr)
31595 +
31596 +#ifdef CONFIG_PAX_REFCOUNT
31597 + jno 1234f
31598 + LOCK_PREFIX
31599 + READ_LOCK_SIZE(dec) (%__lock_ptr)
31600 + int $4
31601 +1234:
31602 + _ASM_EXTABLE(1234b, 1234b)
31603 +#endif
31604 +
31605 1: rep; nop
31606 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
31607 js 1b
31608 LOCK_PREFIX
31609 READ_LOCK_SIZE(dec) (%__lock_ptr)
31610 +
31611 +#ifdef CONFIG_PAX_REFCOUNT
31612 + jno 1234f
31613 + LOCK_PREFIX
31614 + READ_LOCK_SIZE(inc) (%__lock_ptr)
31615 + int $4
31616 +1234:
31617 + _ASM_EXTABLE(1234b, 1234b)
31618 +#endif
31619 +
31620 js 0b
31621 ENDFRAME
31622 + pax_force_retaddr
31623 ret
31624 CFI_ENDPROC
31625 END(__read_lock_failed)
31626 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
31627 index 5dff5f0..cadebf4 100644
31628 --- a/arch/x86/lib/rwsem.S
31629 +++ b/arch/x86/lib/rwsem.S
31630 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
31631 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
31632 CFI_RESTORE __ASM_REG(dx)
31633 restore_common_regs
31634 + pax_force_retaddr
31635 ret
31636 CFI_ENDPROC
31637 ENDPROC(call_rwsem_down_read_failed)
31638 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
31639 movq %rax,%rdi
31640 call rwsem_down_write_failed
31641 restore_common_regs
31642 + pax_force_retaddr
31643 ret
31644 CFI_ENDPROC
31645 ENDPROC(call_rwsem_down_write_failed)
31646 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
31647 movq %rax,%rdi
31648 call rwsem_wake
31649 restore_common_regs
31650 -1: ret
31651 +1: pax_force_retaddr
31652 + ret
31653 CFI_ENDPROC
31654 ENDPROC(call_rwsem_wake)
31655
31656 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
31657 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
31658 CFI_RESTORE __ASM_REG(dx)
31659 restore_common_regs
31660 + pax_force_retaddr
31661 ret
31662 CFI_ENDPROC
31663 ENDPROC(call_rwsem_downgrade_wake)
31664 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
31665 index 92d9fea..b2762c8 100644
31666 --- a/arch/x86/lib/thunk_64.S
31667 +++ b/arch/x86/lib/thunk_64.S
31668 @@ -9,6 +9,7 @@
31669 #include <asm/dwarf2.h>
31670 #include <asm/calling.h>
31671 #include <asm/asm.h>
31672 +#include <asm/alternative-asm.h>
31673
31674 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
31675 .macro THUNK name, func, put_ret_addr_in_rdi=0
31676 @@ -16,11 +17,11 @@
31677 \name:
31678 CFI_STARTPROC
31679
31680 - /* this one pushes 9 elems, the next one would be %rIP */
31681 - SAVE_ARGS
31682 + /* this one pushes 15+1 elems, the next one would be %rIP */
31683 + SAVE_ARGS 8
31684
31685 .if \put_ret_addr_in_rdi
31686 - movq_cfi_restore 9*8, rdi
31687 + movq_cfi_restore RIP, rdi
31688 .endif
31689
31690 call \func
31691 @@ -40,9 +41,10 @@
31692
31693 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
31694 CFI_STARTPROC
31695 - SAVE_ARGS
31696 + SAVE_ARGS 8
31697 restore:
31698 - RESTORE_ARGS
31699 + RESTORE_ARGS 1,8
31700 + pax_force_retaddr
31701 ret
31702 CFI_ENDPROC
31703 _ASM_NOKPROBE(restore)
31704 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
31705 index e2f5e21..4b22130 100644
31706 --- a/arch/x86/lib/usercopy_32.c
31707 +++ b/arch/x86/lib/usercopy_32.c
31708 @@ -42,11 +42,13 @@ do { \
31709 int __d0; \
31710 might_fault(); \
31711 __asm__ __volatile__( \
31712 + __COPYUSER_SET_ES \
31713 ASM_STAC "\n" \
31714 "0: rep; stosl\n" \
31715 " movl %2,%0\n" \
31716 "1: rep; stosb\n" \
31717 "2: " ASM_CLAC "\n" \
31718 + __COPYUSER_RESTORE_ES \
31719 ".section .fixup,\"ax\"\n" \
31720 "3: lea 0(%2,%0,4),%0\n" \
31721 " jmp 2b\n" \
31722 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
31723
31724 #ifdef CONFIG_X86_INTEL_USERCOPY
31725 static unsigned long
31726 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
31727 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
31728 {
31729 int d0, d1;
31730 __asm__ __volatile__(
31731 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31732 " .align 2,0x90\n"
31733 "3: movl 0(%4), %%eax\n"
31734 "4: movl 4(%4), %%edx\n"
31735 - "5: movl %%eax, 0(%3)\n"
31736 - "6: movl %%edx, 4(%3)\n"
31737 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
31738 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
31739 "7: movl 8(%4), %%eax\n"
31740 "8: movl 12(%4),%%edx\n"
31741 - "9: movl %%eax, 8(%3)\n"
31742 - "10: movl %%edx, 12(%3)\n"
31743 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
31744 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
31745 "11: movl 16(%4), %%eax\n"
31746 "12: movl 20(%4), %%edx\n"
31747 - "13: movl %%eax, 16(%3)\n"
31748 - "14: movl %%edx, 20(%3)\n"
31749 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
31750 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
31751 "15: movl 24(%4), %%eax\n"
31752 "16: movl 28(%4), %%edx\n"
31753 - "17: movl %%eax, 24(%3)\n"
31754 - "18: movl %%edx, 28(%3)\n"
31755 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
31756 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
31757 "19: movl 32(%4), %%eax\n"
31758 "20: movl 36(%4), %%edx\n"
31759 - "21: movl %%eax, 32(%3)\n"
31760 - "22: movl %%edx, 36(%3)\n"
31761 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
31762 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
31763 "23: movl 40(%4), %%eax\n"
31764 "24: movl 44(%4), %%edx\n"
31765 - "25: movl %%eax, 40(%3)\n"
31766 - "26: movl %%edx, 44(%3)\n"
31767 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
31768 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
31769 "27: movl 48(%4), %%eax\n"
31770 "28: movl 52(%4), %%edx\n"
31771 - "29: movl %%eax, 48(%3)\n"
31772 - "30: movl %%edx, 52(%3)\n"
31773 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
31774 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
31775 "31: movl 56(%4), %%eax\n"
31776 "32: movl 60(%4), %%edx\n"
31777 - "33: movl %%eax, 56(%3)\n"
31778 - "34: movl %%edx, 60(%3)\n"
31779 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
31780 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
31781 " addl $-64, %0\n"
31782 " addl $64, %4\n"
31783 " addl $64, %3\n"
31784 @@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31785 " shrl $2, %0\n"
31786 " andl $3, %%eax\n"
31787 " cld\n"
31788 + __COPYUSER_SET_ES
31789 "99: rep; movsl\n"
31790 "36: movl %%eax, %0\n"
31791 "37: rep; movsb\n"
31792 "100:\n"
31793 + __COPYUSER_RESTORE_ES
31794 + ".section .fixup,\"ax\"\n"
31795 + "101: lea 0(%%eax,%0,4),%0\n"
31796 + " jmp 100b\n"
31797 + ".previous\n"
31798 + _ASM_EXTABLE(1b,100b)
31799 + _ASM_EXTABLE(2b,100b)
31800 + _ASM_EXTABLE(3b,100b)
31801 + _ASM_EXTABLE(4b,100b)
31802 + _ASM_EXTABLE(5b,100b)
31803 + _ASM_EXTABLE(6b,100b)
31804 + _ASM_EXTABLE(7b,100b)
31805 + _ASM_EXTABLE(8b,100b)
31806 + _ASM_EXTABLE(9b,100b)
31807 + _ASM_EXTABLE(10b,100b)
31808 + _ASM_EXTABLE(11b,100b)
31809 + _ASM_EXTABLE(12b,100b)
31810 + _ASM_EXTABLE(13b,100b)
31811 + _ASM_EXTABLE(14b,100b)
31812 + _ASM_EXTABLE(15b,100b)
31813 + _ASM_EXTABLE(16b,100b)
31814 + _ASM_EXTABLE(17b,100b)
31815 + _ASM_EXTABLE(18b,100b)
31816 + _ASM_EXTABLE(19b,100b)
31817 + _ASM_EXTABLE(20b,100b)
31818 + _ASM_EXTABLE(21b,100b)
31819 + _ASM_EXTABLE(22b,100b)
31820 + _ASM_EXTABLE(23b,100b)
31821 + _ASM_EXTABLE(24b,100b)
31822 + _ASM_EXTABLE(25b,100b)
31823 + _ASM_EXTABLE(26b,100b)
31824 + _ASM_EXTABLE(27b,100b)
31825 + _ASM_EXTABLE(28b,100b)
31826 + _ASM_EXTABLE(29b,100b)
31827 + _ASM_EXTABLE(30b,100b)
31828 + _ASM_EXTABLE(31b,100b)
31829 + _ASM_EXTABLE(32b,100b)
31830 + _ASM_EXTABLE(33b,100b)
31831 + _ASM_EXTABLE(34b,100b)
31832 + _ASM_EXTABLE(35b,100b)
31833 + _ASM_EXTABLE(36b,100b)
31834 + _ASM_EXTABLE(37b,100b)
31835 + _ASM_EXTABLE(99b,101b)
31836 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
31837 + : "1"(to), "2"(from), "0"(size)
31838 + : "eax", "edx", "memory");
31839 + return size;
31840 +}
31841 +
31842 +static unsigned long
31843 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
31844 +{
31845 + int d0, d1;
31846 + __asm__ __volatile__(
31847 + " .align 2,0x90\n"
31848 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
31849 + " cmpl $67, %0\n"
31850 + " jbe 3f\n"
31851 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
31852 + " .align 2,0x90\n"
31853 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
31854 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
31855 + "5: movl %%eax, 0(%3)\n"
31856 + "6: movl %%edx, 4(%3)\n"
31857 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
31858 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
31859 + "9: movl %%eax, 8(%3)\n"
31860 + "10: movl %%edx, 12(%3)\n"
31861 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
31862 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
31863 + "13: movl %%eax, 16(%3)\n"
31864 + "14: movl %%edx, 20(%3)\n"
31865 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
31866 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
31867 + "17: movl %%eax, 24(%3)\n"
31868 + "18: movl %%edx, 28(%3)\n"
31869 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
31870 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
31871 + "21: movl %%eax, 32(%3)\n"
31872 + "22: movl %%edx, 36(%3)\n"
31873 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
31874 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
31875 + "25: movl %%eax, 40(%3)\n"
31876 + "26: movl %%edx, 44(%3)\n"
31877 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
31878 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
31879 + "29: movl %%eax, 48(%3)\n"
31880 + "30: movl %%edx, 52(%3)\n"
31881 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
31882 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
31883 + "33: movl %%eax, 56(%3)\n"
31884 + "34: movl %%edx, 60(%3)\n"
31885 + " addl $-64, %0\n"
31886 + " addl $64, %4\n"
31887 + " addl $64, %3\n"
31888 + " cmpl $63, %0\n"
31889 + " ja 1b\n"
31890 + "35: movl %0, %%eax\n"
31891 + " shrl $2, %0\n"
31892 + " andl $3, %%eax\n"
31893 + " cld\n"
31894 + "99: rep; "__copyuser_seg" movsl\n"
31895 + "36: movl %%eax, %0\n"
31896 + "37: rep; "__copyuser_seg" movsb\n"
31897 + "100:\n"
31898 ".section .fixup,\"ax\"\n"
31899 "101: lea 0(%%eax,%0,4),%0\n"
31900 " jmp 100b\n"
31901 @@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31902 int d0, d1;
31903 __asm__ __volatile__(
31904 " .align 2,0x90\n"
31905 - "0: movl 32(%4), %%eax\n"
31906 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31907 " cmpl $67, %0\n"
31908 " jbe 2f\n"
31909 - "1: movl 64(%4), %%eax\n"
31910 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31911 " .align 2,0x90\n"
31912 - "2: movl 0(%4), %%eax\n"
31913 - "21: movl 4(%4), %%edx\n"
31914 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31915 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31916 " movl %%eax, 0(%3)\n"
31917 " movl %%edx, 4(%3)\n"
31918 - "3: movl 8(%4), %%eax\n"
31919 - "31: movl 12(%4),%%edx\n"
31920 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31921 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31922 " movl %%eax, 8(%3)\n"
31923 " movl %%edx, 12(%3)\n"
31924 - "4: movl 16(%4), %%eax\n"
31925 - "41: movl 20(%4), %%edx\n"
31926 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31927 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31928 " movl %%eax, 16(%3)\n"
31929 " movl %%edx, 20(%3)\n"
31930 - "10: movl 24(%4), %%eax\n"
31931 - "51: movl 28(%4), %%edx\n"
31932 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31933 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31934 " movl %%eax, 24(%3)\n"
31935 " movl %%edx, 28(%3)\n"
31936 - "11: movl 32(%4), %%eax\n"
31937 - "61: movl 36(%4), %%edx\n"
31938 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31939 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31940 " movl %%eax, 32(%3)\n"
31941 " movl %%edx, 36(%3)\n"
31942 - "12: movl 40(%4), %%eax\n"
31943 - "71: movl 44(%4), %%edx\n"
31944 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31945 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31946 " movl %%eax, 40(%3)\n"
31947 " movl %%edx, 44(%3)\n"
31948 - "13: movl 48(%4), %%eax\n"
31949 - "81: movl 52(%4), %%edx\n"
31950 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31951 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31952 " movl %%eax, 48(%3)\n"
31953 " movl %%edx, 52(%3)\n"
31954 - "14: movl 56(%4), %%eax\n"
31955 - "91: movl 60(%4), %%edx\n"
31956 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31957 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31958 " movl %%eax, 56(%3)\n"
31959 " movl %%edx, 60(%3)\n"
31960 " addl $-64, %0\n"
31961 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31962 " shrl $2, %0\n"
31963 " andl $3, %%eax\n"
31964 " cld\n"
31965 - "6: rep; movsl\n"
31966 + "6: rep; "__copyuser_seg" movsl\n"
31967 " movl %%eax,%0\n"
31968 - "7: rep; movsb\n"
31969 + "7: rep; "__copyuser_seg" movsb\n"
31970 "8:\n"
31971 ".section .fixup,\"ax\"\n"
31972 "9: lea 0(%%eax,%0,4),%0\n"
31973 @@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31974
31975 __asm__ __volatile__(
31976 " .align 2,0x90\n"
31977 - "0: movl 32(%4), %%eax\n"
31978 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31979 " cmpl $67, %0\n"
31980 " jbe 2f\n"
31981 - "1: movl 64(%4), %%eax\n"
31982 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31983 " .align 2,0x90\n"
31984 - "2: movl 0(%4), %%eax\n"
31985 - "21: movl 4(%4), %%edx\n"
31986 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31987 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31988 " movnti %%eax, 0(%3)\n"
31989 " movnti %%edx, 4(%3)\n"
31990 - "3: movl 8(%4), %%eax\n"
31991 - "31: movl 12(%4),%%edx\n"
31992 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31993 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31994 " movnti %%eax, 8(%3)\n"
31995 " movnti %%edx, 12(%3)\n"
31996 - "4: movl 16(%4), %%eax\n"
31997 - "41: movl 20(%4), %%edx\n"
31998 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31999 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
32000 " movnti %%eax, 16(%3)\n"
32001 " movnti %%edx, 20(%3)\n"
32002 - "10: movl 24(%4), %%eax\n"
32003 - "51: movl 28(%4), %%edx\n"
32004 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
32005 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
32006 " movnti %%eax, 24(%3)\n"
32007 " movnti %%edx, 28(%3)\n"
32008 - "11: movl 32(%4), %%eax\n"
32009 - "61: movl 36(%4), %%edx\n"
32010 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
32011 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
32012 " movnti %%eax, 32(%3)\n"
32013 " movnti %%edx, 36(%3)\n"
32014 - "12: movl 40(%4), %%eax\n"
32015 - "71: movl 44(%4), %%edx\n"
32016 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
32017 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
32018 " movnti %%eax, 40(%3)\n"
32019 " movnti %%edx, 44(%3)\n"
32020 - "13: movl 48(%4), %%eax\n"
32021 - "81: movl 52(%4), %%edx\n"
32022 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
32023 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
32024 " movnti %%eax, 48(%3)\n"
32025 " movnti %%edx, 52(%3)\n"
32026 - "14: movl 56(%4), %%eax\n"
32027 - "91: movl 60(%4), %%edx\n"
32028 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
32029 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
32030 " movnti %%eax, 56(%3)\n"
32031 " movnti %%edx, 60(%3)\n"
32032 " addl $-64, %0\n"
32033 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
32034 " shrl $2, %0\n"
32035 " andl $3, %%eax\n"
32036 " cld\n"
32037 - "6: rep; movsl\n"
32038 + "6: rep; "__copyuser_seg" movsl\n"
32039 " movl %%eax,%0\n"
32040 - "7: rep; movsb\n"
32041 + "7: rep; "__copyuser_seg" movsb\n"
32042 "8:\n"
32043 ".section .fixup,\"ax\"\n"
32044 "9: lea 0(%%eax,%0,4),%0\n"
32045 @@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
32046
32047 __asm__ __volatile__(
32048 " .align 2,0x90\n"
32049 - "0: movl 32(%4), %%eax\n"
32050 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
32051 " cmpl $67, %0\n"
32052 " jbe 2f\n"
32053 - "1: movl 64(%4), %%eax\n"
32054 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
32055 " .align 2,0x90\n"
32056 - "2: movl 0(%4), %%eax\n"
32057 - "21: movl 4(%4), %%edx\n"
32058 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
32059 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
32060 " movnti %%eax, 0(%3)\n"
32061 " movnti %%edx, 4(%3)\n"
32062 - "3: movl 8(%4), %%eax\n"
32063 - "31: movl 12(%4),%%edx\n"
32064 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
32065 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
32066 " movnti %%eax, 8(%3)\n"
32067 " movnti %%edx, 12(%3)\n"
32068 - "4: movl 16(%4), %%eax\n"
32069 - "41: movl 20(%4), %%edx\n"
32070 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
32071 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
32072 " movnti %%eax, 16(%3)\n"
32073 " movnti %%edx, 20(%3)\n"
32074 - "10: movl 24(%4), %%eax\n"
32075 - "51: movl 28(%4), %%edx\n"
32076 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
32077 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
32078 " movnti %%eax, 24(%3)\n"
32079 " movnti %%edx, 28(%3)\n"
32080 - "11: movl 32(%4), %%eax\n"
32081 - "61: movl 36(%4), %%edx\n"
32082 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
32083 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
32084 " movnti %%eax, 32(%3)\n"
32085 " movnti %%edx, 36(%3)\n"
32086 - "12: movl 40(%4), %%eax\n"
32087 - "71: movl 44(%4), %%edx\n"
32088 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
32089 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
32090 " movnti %%eax, 40(%3)\n"
32091 " movnti %%edx, 44(%3)\n"
32092 - "13: movl 48(%4), %%eax\n"
32093 - "81: movl 52(%4), %%edx\n"
32094 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
32095 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
32096 " movnti %%eax, 48(%3)\n"
32097 " movnti %%edx, 52(%3)\n"
32098 - "14: movl 56(%4), %%eax\n"
32099 - "91: movl 60(%4), %%edx\n"
32100 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
32101 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
32102 " movnti %%eax, 56(%3)\n"
32103 " movnti %%edx, 60(%3)\n"
32104 " addl $-64, %0\n"
32105 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
32106 " shrl $2, %0\n"
32107 " andl $3, %%eax\n"
32108 " cld\n"
32109 - "6: rep; movsl\n"
32110 + "6: rep; "__copyuser_seg" movsl\n"
32111 " movl %%eax,%0\n"
32112 - "7: rep; movsb\n"
32113 + "7: rep; "__copyuser_seg" movsb\n"
32114 "8:\n"
32115 ".section .fixup,\"ax\"\n"
32116 "9: lea 0(%%eax,%0,4),%0\n"
32117 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
32118 */
32119 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
32120 unsigned long size);
32121 -unsigned long __copy_user_intel(void __user *to, const void *from,
32122 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
32123 + unsigned long size);
32124 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
32125 unsigned long size);
32126 unsigned long __copy_user_zeroing_intel_nocache(void *to,
32127 const void __user *from, unsigned long size);
32128 #endif /* CONFIG_X86_INTEL_USERCOPY */
32129
32130 /* Generic arbitrary sized copy. */
32131 -#define __copy_user(to, from, size) \
32132 +#define __copy_user(to, from, size, prefix, set, restore) \
32133 do { \
32134 int __d0, __d1, __d2; \
32135 __asm__ __volatile__( \
32136 + set \
32137 " cmp $7,%0\n" \
32138 " jbe 1f\n" \
32139 " movl %1,%0\n" \
32140 " negl %0\n" \
32141 " andl $7,%0\n" \
32142 " subl %0,%3\n" \
32143 - "4: rep; movsb\n" \
32144 + "4: rep; "prefix"movsb\n" \
32145 " movl %3,%0\n" \
32146 " shrl $2,%0\n" \
32147 " andl $3,%3\n" \
32148 " .align 2,0x90\n" \
32149 - "0: rep; movsl\n" \
32150 + "0: rep; "prefix"movsl\n" \
32151 " movl %3,%0\n" \
32152 - "1: rep; movsb\n" \
32153 + "1: rep; "prefix"movsb\n" \
32154 "2:\n" \
32155 + restore \
32156 ".section .fixup,\"ax\"\n" \
32157 "5: addl %3,%0\n" \
32158 " jmp 2b\n" \
32159 @@ -538,14 +650,14 @@ do { \
32160 " negl %0\n" \
32161 " andl $7,%0\n" \
32162 " subl %0,%3\n" \
32163 - "4: rep; movsb\n" \
32164 + "4: rep; "__copyuser_seg"movsb\n" \
32165 " movl %3,%0\n" \
32166 " shrl $2,%0\n" \
32167 " andl $3,%3\n" \
32168 " .align 2,0x90\n" \
32169 - "0: rep; movsl\n" \
32170 + "0: rep; "__copyuser_seg"movsl\n" \
32171 " movl %3,%0\n" \
32172 - "1: rep; movsb\n" \
32173 + "1: rep; "__copyuser_seg"movsb\n" \
32174 "2:\n" \
32175 ".section .fixup,\"ax\"\n" \
32176 "5: addl %3,%0\n" \
32177 @@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
32178 {
32179 stac();
32180 if (movsl_is_ok(to, from, n))
32181 - __copy_user(to, from, n);
32182 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
32183 else
32184 - n = __copy_user_intel(to, from, n);
32185 + n = __generic_copy_to_user_intel(to, from, n);
32186 clac();
32187 return n;
32188 }
32189 @@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
32190 {
32191 stac();
32192 if (movsl_is_ok(to, from, n))
32193 - __copy_user(to, from, n);
32194 + __copy_user(to, from, n, __copyuser_seg, "", "");
32195 else
32196 - n = __copy_user_intel((void __user *)to,
32197 - (const void *)from, n);
32198 + n = __generic_copy_from_user_intel(to, from, n);
32199 clac();
32200 return n;
32201 }
32202 @@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
32203 if (n > 64 && cpu_has_xmm2)
32204 n = __copy_user_intel_nocache(to, from, n);
32205 else
32206 - __copy_user(to, from, n);
32207 + __copy_user(to, from, n, __copyuser_seg, "", "");
32208 #else
32209 - __copy_user(to, from, n);
32210 + __copy_user(to, from, n, __copyuser_seg, "", "");
32211 #endif
32212 clac();
32213 return n;
32214 }
32215 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
32216
32217 -/**
32218 - * copy_to_user: - Copy a block of data into user space.
32219 - * @to: Destination address, in user space.
32220 - * @from: Source address, in kernel space.
32221 - * @n: Number of bytes to copy.
32222 - *
32223 - * Context: User context only. This function may sleep.
32224 - *
32225 - * Copy data from kernel space to user space.
32226 - *
32227 - * Returns number of bytes that could not be copied.
32228 - * On success, this will be zero.
32229 - */
32230 -unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
32231 +#ifdef CONFIG_PAX_MEMORY_UDEREF
32232 +void __set_fs(mm_segment_t x)
32233 {
32234 - if (access_ok(VERIFY_WRITE, to, n))
32235 - n = __copy_to_user(to, from, n);
32236 - return n;
32237 + switch (x.seg) {
32238 + case 0:
32239 + loadsegment(gs, 0);
32240 + break;
32241 + case TASK_SIZE_MAX:
32242 + loadsegment(gs, __USER_DS);
32243 + break;
32244 + case -1UL:
32245 + loadsegment(gs, __KERNEL_DS);
32246 + break;
32247 + default:
32248 + BUG();
32249 + }
32250 }
32251 -EXPORT_SYMBOL(_copy_to_user);
32252 +EXPORT_SYMBOL(__set_fs);
32253
32254 -/**
32255 - * copy_from_user: - Copy a block of data from user space.
32256 - * @to: Destination address, in kernel space.
32257 - * @from: Source address, in user space.
32258 - * @n: Number of bytes to copy.
32259 - *
32260 - * Context: User context only. This function may sleep.
32261 - *
32262 - * Copy data from user space to kernel space.
32263 - *
32264 - * Returns number of bytes that could not be copied.
32265 - * On success, this will be zero.
32266 - *
32267 - * If some data could not be copied, this function will pad the copied
32268 - * data to the requested size using zero bytes.
32269 - */
32270 -unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
32271 +void set_fs(mm_segment_t x)
32272 {
32273 - if (access_ok(VERIFY_READ, from, n))
32274 - n = __copy_from_user(to, from, n);
32275 - else
32276 - memset(to, 0, n);
32277 - return n;
32278 + current_thread_info()->addr_limit = x;
32279 + __set_fs(x);
32280 }
32281 -EXPORT_SYMBOL(_copy_from_user);
32282 +EXPORT_SYMBOL(set_fs);
32283 +#endif
32284 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
32285 index c905e89..01ab928 100644
32286 --- a/arch/x86/lib/usercopy_64.c
32287 +++ b/arch/x86/lib/usercopy_64.c
32288 @@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
32289 might_fault();
32290 /* no memory constraint because it doesn't change any memory gcc knows
32291 about */
32292 + pax_open_userland();
32293 stac();
32294 asm volatile(
32295 " testq %[size8],%[size8]\n"
32296 @@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
32297 _ASM_EXTABLE(0b,3b)
32298 _ASM_EXTABLE(1b,2b)
32299 : [size8] "=&c"(size), [dst] "=&D" (__d0)
32300 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
32301 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
32302 [zero] "r" (0UL), [eight] "r" (8UL));
32303 clac();
32304 + pax_close_userland();
32305 return size;
32306 }
32307 EXPORT_SYMBOL(__clear_user);
32308 @@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
32309 }
32310 EXPORT_SYMBOL(clear_user);
32311
32312 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
32313 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
32314 {
32315 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
32316 - return copy_user_generic((__force void *)to, (__force void *)from, len);
32317 - }
32318 - return len;
32319 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
32320 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
32321 + return len;
32322 }
32323 EXPORT_SYMBOL(copy_in_user);
32324
32325 @@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
32326 * it is not necessary to optimize tail handling.
32327 */
32328 __visible unsigned long
32329 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
32330 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
32331 {
32332 char c;
32333 unsigned zero_len;
32334
32335 + clac();
32336 + pax_close_userland();
32337 for (; len; --len, to++) {
32338 if (__get_user_nocheck(c, from++, sizeof(char)))
32339 break;
32340 @@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
32341 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
32342 if (__put_user_nocheck(c, to++, sizeof(char)))
32343 break;
32344 - clac();
32345 return len;
32346 }
32347 diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
32348 index 6a19ad9..1c48f9a 100644
32349 --- a/arch/x86/mm/Makefile
32350 +++ b/arch/x86/mm/Makefile
32351 @@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
32352 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
32353
32354 obj-$(CONFIG_MEMTEST) += memtest.o
32355 +
32356 +quote:="
32357 +obj-$(CONFIG_X86_64) += uderef_64.o
32358 +CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
32359 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
32360 index 903ec1e..c4166b2 100644
32361 --- a/arch/x86/mm/extable.c
32362 +++ b/arch/x86/mm/extable.c
32363 @@ -6,12 +6,24 @@
32364 static inline unsigned long
32365 ex_insn_addr(const struct exception_table_entry *x)
32366 {
32367 - return (unsigned long)&x->insn + x->insn;
32368 + unsigned long reloc = 0;
32369 +
32370 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32371 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
32372 +#endif
32373 +
32374 + return (unsigned long)&x->insn + x->insn + reloc;
32375 }
32376 static inline unsigned long
32377 ex_fixup_addr(const struct exception_table_entry *x)
32378 {
32379 - return (unsigned long)&x->fixup + x->fixup;
32380 + unsigned long reloc = 0;
32381 +
32382 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32383 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
32384 +#endif
32385 +
32386 + return (unsigned long)&x->fixup + x->fixup + reloc;
32387 }
32388
32389 int fixup_exception(struct pt_regs *regs)
32390 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
32391 unsigned long new_ip;
32392
32393 #ifdef CONFIG_PNPBIOS
32394 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
32395 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
32396 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
32397 extern u32 pnp_bios_is_utter_crap;
32398 pnp_bios_is_utter_crap = 1;
32399 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
32400 i += 4;
32401 p->fixup -= i;
32402 i += 4;
32403 +
32404 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32405 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
32406 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
32407 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
32408 +#endif
32409 +
32410 }
32411 }
32412
32413 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
32414 index a241946..d7a04cf 100644
32415 --- a/arch/x86/mm/fault.c
32416 +++ b/arch/x86/mm/fault.c
32417 @@ -14,12 +14,19 @@
32418 #include <linux/hugetlb.h> /* hstate_index_to_shift */
32419 #include <linux/prefetch.h> /* prefetchw */
32420 #include <linux/context_tracking.h> /* exception_enter(), ... */
32421 +#include <linux/unistd.h>
32422 +#include <linux/compiler.h>
32423
32424 #include <asm/traps.h> /* dotraplinkage, ... */
32425 #include <asm/pgalloc.h> /* pgd_*(), ... */
32426 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
32427 #include <asm/fixmap.h> /* VSYSCALL_ADDR */
32428 #include <asm/vsyscall.h> /* emulate_vsyscall */
32429 +#include <asm/tlbflush.h>
32430 +
32431 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32432 +#include <asm/stacktrace.h>
32433 +#endif
32434
32435 #define CREATE_TRACE_POINTS
32436 #include <asm/trace/exceptions.h>
32437 @@ -60,7 +67,7 @@ static nokprobe_inline int kprobes_fault(struct pt_regs *regs)
32438 int ret = 0;
32439
32440 /* kprobe_running() needs smp_processor_id() */
32441 - if (kprobes_built_in() && !user_mode_vm(regs)) {
32442 + if (kprobes_built_in() && !user_mode(regs)) {
32443 preempt_disable();
32444 if (kprobe_running() && kprobe_fault_handler(regs, 14))
32445 ret = 1;
32446 @@ -121,7 +128,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
32447 return !instr_lo || (instr_lo>>1) == 1;
32448 case 0x00:
32449 /* Prefetch instruction is 0x0F0D or 0x0F18 */
32450 - if (probe_kernel_address(instr, opcode))
32451 + if (user_mode(regs)) {
32452 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
32453 + return 0;
32454 + } else if (probe_kernel_address(instr, opcode))
32455 return 0;
32456
32457 *prefetch = (instr_lo == 0xF) &&
32458 @@ -155,7 +165,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
32459 while (instr < max_instr) {
32460 unsigned char opcode;
32461
32462 - if (probe_kernel_address(instr, opcode))
32463 + if (user_mode(regs)) {
32464 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
32465 + break;
32466 + } else if (probe_kernel_address(instr, opcode))
32467 break;
32468
32469 instr++;
32470 @@ -186,6 +199,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
32471 force_sig_info(si_signo, &info, tsk);
32472 }
32473
32474 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32475 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
32476 +#endif
32477 +
32478 +#ifdef CONFIG_PAX_EMUTRAMP
32479 +static int pax_handle_fetch_fault(struct pt_regs *regs);
32480 +#endif
32481 +
32482 +#ifdef CONFIG_PAX_PAGEEXEC
32483 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
32484 +{
32485 + pgd_t *pgd;
32486 + pud_t *pud;
32487 + pmd_t *pmd;
32488 +
32489 + pgd = pgd_offset(mm, address);
32490 + if (!pgd_present(*pgd))
32491 + return NULL;
32492 + pud = pud_offset(pgd, address);
32493 + if (!pud_present(*pud))
32494 + return NULL;
32495 + pmd = pmd_offset(pud, address);
32496 + if (!pmd_present(*pmd))
32497 + return NULL;
32498 + return pmd;
32499 +}
32500 +#endif
32501 +
32502 DEFINE_SPINLOCK(pgd_lock);
32503 LIST_HEAD(pgd_list);
32504
32505 @@ -236,10 +277,27 @@ void vmalloc_sync_all(void)
32506 for (address = VMALLOC_START & PMD_MASK;
32507 address >= TASK_SIZE && address < FIXADDR_TOP;
32508 address += PMD_SIZE) {
32509 +
32510 +#ifdef CONFIG_PAX_PER_CPU_PGD
32511 + unsigned long cpu;
32512 +#else
32513 struct page *page;
32514 +#endif
32515
32516 spin_lock(&pgd_lock);
32517 +
32518 +#ifdef CONFIG_PAX_PER_CPU_PGD
32519 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32520 + pgd_t *pgd = get_cpu_pgd(cpu, user);
32521 + pmd_t *ret;
32522 +
32523 + ret = vmalloc_sync_one(pgd, address);
32524 + if (!ret)
32525 + break;
32526 + pgd = get_cpu_pgd(cpu, kernel);
32527 +#else
32528 list_for_each_entry(page, &pgd_list, lru) {
32529 + pgd_t *pgd;
32530 spinlock_t *pgt_lock;
32531 pmd_t *ret;
32532
32533 @@ -247,8 +305,14 @@ void vmalloc_sync_all(void)
32534 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
32535
32536 spin_lock(pgt_lock);
32537 - ret = vmalloc_sync_one(page_address(page), address);
32538 + pgd = page_address(page);
32539 +#endif
32540 +
32541 + ret = vmalloc_sync_one(pgd, address);
32542 +
32543 +#ifndef CONFIG_PAX_PER_CPU_PGD
32544 spin_unlock(pgt_lock);
32545 +#endif
32546
32547 if (!ret)
32548 break;
32549 @@ -282,6 +346,12 @@ static noinline int vmalloc_fault(unsigned long address)
32550 * an interrupt in the middle of a task switch..
32551 */
32552 pgd_paddr = read_cr3();
32553 +
32554 +#ifdef CONFIG_PAX_PER_CPU_PGD
32555 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
32556 + vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
32557 +#endif
32558 +
32559 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
32560 if (!pmd_k)
32561 return -1;
32562 @@ -378,11 +448,25 @@ static noinline int vmalloc_fault(unsigned long address)
32563 * happen within a race in page table update. In the later
32564 * case just flush:
32565 */
32566 - pgd = pgd_offset(current->active_mm, address);
32567 +
32568 pgd_ref = pgd_offset_k(address);
32569 if (pgd_none(*pgd_ref))
32570 return -1;
32571
32572 +#ifdef CONFIG_PAX_PER_CPU_PGD
32573 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
32574 + pgd = pgd_offset_cpu(smp_processor_id(), user, address);
32575 + if (pgd_none(*pgd)) {
32576 + set_pgd(pgd, *pgd_ref);
32577 + arch_flush_lazy_mmu_mode();
32578 + } else {
32579 + BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
32580 + }
32581 + pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
32582 +#else
32583 + pgd = pgd_offset(current->active_mm, address);
32584 +#endif
32585 +
32586 if (pgd_none(*pgd)) {
32587 set_pgd(pgd, *pgd_ref);
32588 arch_flush_lazy_mmu_mode();
32589 @@ -549,7 +633,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
32590 static int is_errata100(struct pt_regs *regs, unsigned long address)
32591 {
32592 #ifdef CONFIG_X86_64
32593 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
32594 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
32595 return 1;
32596 #endif
32597 return 0;
32598 @@ -576,9 +660,9 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
32599 }
32600
32601 static const char nx_warning[] = KERN_CRIT
32602 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
32603 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
32604 static const char smep_warning[] = KERN_CRIT
32605 -"unable to execute userspace code (SMEP?) (uid: %d)\n";
32606 +"unable to execute userspace code (SMEP?) (uid: %d, task: %s, pid: %d)\n";
32607
32608 static void
32609 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
32610 @@ -587,7 +671,7 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
32611 if (!oops_may_print())
32612 return;
32613
32614 - if (error_code & PF_INSTR) {
32615 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
32616 unsigned int level;
32617 pgd_t *pgd;
32618 pte_t *pte;
32619 @@ -598,13 +682,25 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
32620 pte = lookup_address_in_pgd(pgd, address, &level);
32621
32622 if (pte && pte_present(*pte) && !pte_exec(*pte))
32623 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
32624 + printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
32625 if (pte && pte_present(*pte) && pte_exec(*pte) &&
32626 (pgd_flags(*pgd) & _PAGE_USER) &&
32627 (read_cr4() & X86_CR4_SMEP))
32628 - printk(smep_warning, from_kuid(&init_user_ns, current_uid()));
32629 + printk(smep_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
32630 }
32631
32632 +#ifdef CONFIG_PAX_KERNEXEC
32633 + if (init_mm.start_code <= address && address < init_mm.end_code) {
32634 + if (current->signal->curr_ip)
32635 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
32636 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
32637 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
32638 + else
32639 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
32640 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
32641 + }
32642 +#endif
32643 +
32644 printk(KERN_ALERT "BUG: unable to handle kernel ");
32645 if (address < PAGE_SIZE)
32646 printk(KERN_CONT "NULL pointer dereference");
32647 @@ -785,6 +881,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
32648 return;
32649 }
32650 #endif
32651 +
32652 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32653 + if (pax_is_fetch_fault(regs, error_code, address)) {
32654 +
32655 +#ifdef CONFIG_PAX_EMUTRAMP
32656 + switch (pax_handle_fetch_fault(regs)) {
32657 + case 2:
32658 + return;
32659 + }
32660 +#endif
32661 +
32662 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
32663 + do_group_exit(SIGKILL);
32664 + }
32665 +#endif
32666 +
32667 /* Kernel addresses are always protection faults: */
32668 if (address >= TASK_SIZE)
32669 error_code |= PF_PROT;
32670 @@ -870,7 +982,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
32671 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
32672 printk(KERN_ERR
32673 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
32674 - tsk->comm, tsk->pid, address);
32675 + tsk->comm, task_pid_nr(tsk), address);
32676 code = BUS_MCEERR_AR;
32677 }
32678 #endif
32679 @@ -924,6 +1036,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
32680 return 1;
32681 }
32682
32683 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32684 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
32685 +{
32686 + pte_t *pte;
32687 + pmd_t *pmd;
32688 + spinlock_t *ptl;
32689 + unsigned char pte_mask;
32690 +
32691 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
32692 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
32693 + return 0;
32694 +
32695 + /* PaX: it's our fault, let's handle it if we can */
32696 +
32697 + /* PaX: take a look at read faults before acquiring any locks */
32698 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
32699 + /* instruction fetch attempt from a protected page in user mode */
32700 + up_read(&mm->mmap_sem);
32701 +
32702 +#ifdef CONFIG_PAX_EMUTRAMP
32703 + switch (pax_handle_fetch_fault(regs)) {
32704 + case 2:
32705 + return 1;
32706 + }
32707 +#endif
32708 +
32709 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
32710 + do_group_exit(SIGKILL);
32711 + }
32712 +
32713 + pmd = pax_get_pmd(mm, address);
32714 + if (unlikely(!pmd))
32715 + return 0;
32716 +
32717 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
32718 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
32719 + pte_unmap_unlock(pte, ptl);
32720 + return 0;
32721 + }
32722 +
32723 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
32724 + /* write attempt to a protected page in user mode */
32725 + pte_unmap_unlock(pte, ptl);
32726 + return 0;
32727 + }
32728 +
32729 +#ifdef CONFIG_SMP
32730 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
32731 +#else
32732 + if (likely(address > get_limit(regs->cs)))
32733 +#endif
32734 + {
32735 + set_pte(pte, pte_mkread(*pte));
32736 + __flush_tlb_one(address);
32737 + pte_unmap_unlock(pte, ptl);
32738 + up_read(&mm->mmap_sem);
32739 + return 1;
32740 + }
32741 +
32742 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
32743 +
32744 + /*
32745 + * PaX: fill DTLB with user rights and retry
32746 + */
32747 + __asm__ __volatile__ (
32748 + "orb %2,(%1)\n"
32749 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
32750 +/*
32751 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
32752 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
32753 + * page fault when examined during a TLB load attempt. this is true not only
32754 + * for PTEs holding a non-present entry but also present entries that will
32755 + * raise a page fault (such as those set up by PaX, or the copy-on-write
32756 + * mechanism). in effect it means that we do *not* need to flush the TLBs
32757 + * for our target pages since their PTEs are simply not in the TLBs at all.
32758 +
32759 + * the best thing in omitting it is that we gain around 15-20% speed in the
32760 + * fast path of the page fault handler and can get rid of tracing since we
32761 + * can no longer flush unintended entries.
32762 + */
32763 + "invlpg (%0)\n"
32764 +#endif
32765 + __copyuser_seg"testb $0,(%0)\n"
32766 + "xorb %3,(%1)\n"
32767 + :
32768 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
32769 + : "memory", "cc");
32770 + pte_unmap_unlock(pte, ptl);
32771 + up_read(&mm->mmap_sem);
32772 + return 1;
32773 +}
32774 +#endif
32775 +
32776 /*
32777 * Handle a spurious fault caused by a stale TLB entry.
32778 *
32779 @@ -991,6 +1196,9 @@ int show_unhandled_signals = 1;
32780 static inline int
32781 access_error(unsigned long error_code, struct vm_area_struct *vma)
32782 {
32783 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
32784 + return 1;
32785 +
32786 if (error_code & PF_WRITE) {
32787 /* write, present and write, not present: */
32788 if (unlikely(!(vma->vm_flags & VM_WRITE)))
32789 @@ -1025,7 +1233,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
32790 if (error_code & PF_USER)
32791 return false;
32792
32793 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
32794 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
32795 return false;
32796
32797 return true;
32798 @@ -1053,6 +1261,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32799 tsk = current;
32800 mm = tsk->mm;
32801
32802 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32803 + if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
32804 + if (!search_exception_tables(regs->ip)) {
32805 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32806 + bad_area_nosemaphore(regs, error_code, address);
32807 + return;
32808 + }
32809 + if (address < pax_user_shadow_base) {
32810 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32811 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
32812 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
32813 + } else
32814 + address -= pax_user_shadow_base;
32815 + }
32816 +#endif
32817 +
32818 /*
32819 * Detect and handle instructions that would cause a page fault for
32820 * both a tracked kernel page and a userspace page.
32821 @@ -1130,7 +1354,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32822 * User-mode registers count as a user access even for any
32823 * potential system fault or CPU buglet:
32824 */
32825 - if (user_mode_vm(regs)) {
32826 + if (user_mode(regs)) {
32827 local_irq_enable();
32828 error_code |= PF_USER;
32829 flags |= FAULT_FLAG_USER;
32830 @@ -1177,6 +1401,11 @@ retry:
32831 might_sleep();
32832 }
32833
32834 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32835 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
32836 + return;
32837 +#endif
32838 +
32839 vma = find_vma(mm, address);
32840 if (unlikely(!vma)) {
32841 bad_area(regs, error_code, address);
32842 @@ -1188,18 +1417,24 @@ retry:
32843 bad_area(regs, error_code, address);
32844 return;
32845 }
32846 - if (error_code & PF_USER) {
32847 - /*
32848 - * Accessing the stack below %sp is always a bug.
32849 - * The large cushion allows instructions like enter
32850 - * and pusha to work. ("enter $65535, $31" pushes
32851 - * 32 pointers and then decrements %sp by 65535.)
32852 - */
32853 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
32854 - bad_area(regs, error_code, address);
32855 - return;
32856 - }
32857 + /*
32858 + * Accessing the stack below %sp is always a bug.
32859 + * The large cushion allows instructions like enter
32860 + * and pusha to work. ("enter $65535, $31" pushes
32861 + * 32 pointers and then decrements %sp by 65535.)
32862 + */
32863 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
32864 + bad_area(regs, error_code, address);
32865 + return;
32866 }
32867 +
32868 +#ifdef CONFIG_PAX_SEGMEXEC
32869 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
32870 + bad_area(regs, error_code, address);
32871 + return;
32872 + }
32873 +#endif
32874 +
32875 if (unlikely(expand_stack(vma, address))) {
32876 bad_area(regs, error_code, address);
32877 return;
32878 @@ -1316,3 +1551,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
32879 }
32880 NOKPROBE_SYMBOL(trace_do_page_fault);
32881 #endif /* CONFIG_TRACING */
32882 +
32883 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32884 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
32885 +{
32886 + struct mm_struct *mm = current->mm;
32887 + unsigned long ip = regs->ip;
32888 +
32889 + if (v8086_mode(regs))
32890 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
32891 +
32892 +#ifdef CONFIG_PAX_PAGEEXEC
32893 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
32894 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
32895 + return true;
32896 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
32897 + return true;
32898 + return false;
32899 + }
32900 +#endif
32901 +
32902 +#ifdef CONFIG_PAX_SEGMEXEC
32903 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
32904 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
32905 + return true;
32906 + return false;
32907 + }
32908 +#endif
32909 +
32910 + return false;
32911 +}
32912 +#endif
32913 +
32914 +#ifdef CONFIG_PAX_EMUTRAMP
32915 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
32916 +{
32917 + int err;
32918 +
32919 + do { /* PaX: libffi trampoline emulation */
32920 + unsigned char mov, jmp;
32921 + unsigned int addr1, addr2;
32922 +
32923 +#ifdef CONFIG_X86_64
32924 + if ((regs->ip + 9) >> 32)
32925 + break;
32926 +#endif
32927 +
32928 + err = get_user(mov, (unsigned char __user *)regs->ip);
32929 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32930 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32931 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32932 +
32933 + if (err)
32934 + break;
32935 +
32936 + if (mov == 0xB8 && jmp == 0xE9) {
32937 + regs->ax = addr1;
32938 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32939 + return 2;
32940 + }
32941 + } while (0);
32942 +
32943 + do { /* PaX: gcc trampoline emulation #1 */
32944 + unsigned char mov1, mov2;
32945 + unsigned short jmp;
32946 + unsigned int addr1, addr2;
32947 +
32948 +#ifdef CONFIG_X86_64
32949 + if ((regs->ip + 11) >> 32)
32950 + break;
32951 +#endif
32952 +
32953 + err = get_user(mov1, (unsigned char __user *)regs->ip);
32954 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32955 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
32956 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32957 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
32958 +
32959 + if (err)
32960 + break;
32961 +
32962 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
32963 + regs->cx = addr1;
32964 + regs->ax = addr2;
32965 + regs->ip = addr2;
32966 + return 2;
32967 + }
32968 + } while (0);
32969 +
32970 + do { /* PaX: gcc trampoline emulation #2 */
32971 + unsigned char mov, jmp;
32972 + unsigned int addr1, addr2;
32973 +
32974 +#ifdef CONFIG_X86_64
32975 + if ((regs->ip + 9) >> 32)
32976 + break;
32977 +#endif
32978 +
32979 + err = get_user(mov, (unsigned char __user *)regs->ip);
32980 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32981 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32982 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32983 +
32984 + if (err)
32985 + break;
32986 +
32987 + if (mov == 0xB9 && jmp == 0xE9) {
32988 + regs->cx = addr1;
32989 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32990 + return 2;
32991 + }
32992 + } while (0);
32993 +
32994 + return 1; /* PaX in action */
32995 +}
32996 +
32997 +#ifdef CONFIG_X86_64
32998 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
32999 +{
33000 + int err;
33001 +
33002 + do { /* PaX: libffi trampoline emulation */
33003 + unsigned short mov1, mov2, jmp1;
33004 + unsigned char stcclc, jmp2;
33005 + unsigned long addr1, addr2;
33006 +
33007 + err = get_user(mov1, (unsigned short __user *)regs->ip);
33008 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
33009 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
33010 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
33011 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
33012 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
33013 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
33014 +
33015 + if (err)
33016 + break;
33017 +
33018 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
33019 + regs->r11 = addr1;
33020 + regs->r10 = addr2;
33021 + if (stcclc == 0xF8)
33022 + regs->flags &= ~X86_EFLAGS_CF;
33023 + else
33024 + regs->flags |= X86_EFLAGS_CF;
33025 + regs->ip = addr1;
33026 + return 2;
33027 + }
33028 + } while (0);
33029 +
33030 + do { /* PaX: gcc trampoline emulation #1 */
33031 + unsigned short mov1, mov2, jmp1;
33032 + unsigned char jmp2;
33033 + unsigned int addr1;
33034 + unsigned long addr2;
33035 +
33036 + err = get_user(mov1, (unsigned short __user *)regs->ip);
33037 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
33038 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
33039 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
33040 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
33041 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
33042 +
33043 + if (err)
33044 + break;
33045 +
33046 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
33047 + regs->r11 = addr1;
33048 + regs->r10 = addr2;
33049 + regs->ip = addr1;
33050 + return 2;
33051 + }
33052 + } while (0);
33053 +
33054 + do { /* PaX: gcc trampoline emulation #2 */
33055 + unsigned short mov1, mov2, jmp1;
33056 + unsigned char jmp2;
33057 + unsigned long addr1, addr2;
33058 +
33059 + err = get_user(mov1, (unsigned short __user *)regs->ip);
33060 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
33061 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
33062 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
33063 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
33064 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
33065 +
33066 + if (err)
33067 + break;
33068 +
33069 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
33070 + regs->r11 = addr1;
33071 + regs->r10 = addr2;
33072 + regs->ip = addr1;
33073 + return 2;
33074 + }
33075 + } while (0);
33076 +
33077 + return 1; /* PaX in action */
33078 +}
33079 +#endif
33080 +
33081 +/*
33082 + * PaX: decide what to do with offenders (regs->ip = fault address)
33083 + *
33084 + * returns 1 when task should be killed
33085 + * 2 when gcc trampoline was detected
33086 + */
33087 +static int pax_handle_fetch_fault(struct pt_regs *regs)
33088 +{
33089 + if (v8086_mode(regs))
33090 + return 1;
33091 +
33092 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
33093 + return 1;
33094 +
33095 +#ifdef CONFIG_X86_32
33096 + return pax_handle_fetch_fault_32(regs);
33097 +#else
33098 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
33099 + return pax_handle_fetch_fault_32(regs);
33100 + else
33101 + return pax_handle_fetch_fault_64(regs);
33102 +#endif
33103 +}
33104 +#endif
33105 +
33106 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
33107 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
33108 +{
33109 + long i;
33110 +
33111 + printk(KERN_ERR "PAX: bytes at PC: ");
33112 + for (i = 0; i < 20; i++) {
33113 + unsigned char c;
33114 + if (get_user(c, (unsigned char __force_user *)pc+i))
33115 + printk(KERN_CONT "?? ");
33116 + else
33117 + printk(KERN_CONT "%02x ", c);
33118 + }
33119 + printk("\n");
33120 +
33121 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
33122 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
33123 + unsigned long c;
33124 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
33125 +#ifdef CONFIG_X86_32
33126 + printk(KERN_CONT "???????? ");
33127 +#else
33128 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
33129 + printk(KERN_CONT "???????? ???????? ");
33130 + else
33131 + printk(KERN_CONT "???????????????? ");
33132 +#endif
33133 + } else {
33134 +#ifdef CONFIG_X86_64
33135 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
33136 + printk(KERN_CONT "%08x ", (unsigned int)c);
33137 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
33138 + } else
33139 +#endif
33140 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
33141 + }
33142 + }
33143 + printk("\n");
33144 +}
33145 +#endif
33146 +
33147 +/**
33148 + * probe_kernel_write(): safely attempt to write to a location
33149 + * @dst: address to write to
33150 + * @src: pointer to the data that shall be written
33151 + * @size: size of the data chunk
33152 + *
33153 + * Safely write to address @dst from the buffer at @src. If a kernel fault
33154 + * happens, handle that and return -EFAULT.
33155 + */
33156 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
33157 +{
33158 + long ret;
33159 + mm_segment_t old_fs = get_fs();
33160 +
33161 + set_fs(KERNEL_DS);
33162 + pagefault_disable();
33163 + pax_open_kernel();
33164 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
33165 + pax_close_kernel();
33166 + pagefault_enable();
33167 + set_fs(old_fs);
33168 +
33169 + return ret ? -EFAULT : 0;
33170 +}
33171 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
33172 index 207d9aef..69030980 100644
33173 --- a/arch/x86/mm/gup.c
33174 +++ b/arch/x86/mm/gup.c
33175 @@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
33176 addr = start;
33177 len = (unsigned long) nr_pages << PAGE_SHIFT;
33178 end = start + len;
33179 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
33180 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
33181 (void __user *)start, len)))
33182 return 0;
33183
33184 @@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
33185 goto slow_irqon;
33186 #endif
33187
33188 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
33189 + (void __user *)start, len)))
33190 + return 0;
33191 +
33192 /*
33193 * XXX: batch / limit 'nr', to avoid large irq off latency
33194 * needs some instrumenting to determine the common sizes used by
33195 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
33196 index 4500142..53a363c 100644
33197 --- a/arch/x86/mm/highmem_32.c
33198 +++ b/arch/x86/mm/highmem_32.c
33199 @@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
33200 idx = type + KM_TYPE_NR*smp_processor_id();
33201 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
33202 BUG_ON(!pte_none(*(kmap_pte-idx)));
33203 +
33204 + pax_open_kernel();
33205 set_pte(kmap_pte-idx, mk_pte(page, prot));
33206 + pax_close_kernel();
33207 +
33208 arch_flush_lazy_mmu_mode();
33209
33210 return (void *)vaddr;
33211 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
33212 index 8b977eb..4732c33 100644
33213 --- a/arch/x86/mm/hugetlbpage.c
33214 +++ b/arch/x86/mm/hugetlbpage.c
33215 @@ -80,23 +80,24 @@ int pud_huge(pud_t pud)
33216 #ifdef CONFIG_HUGETLB_PAGE
33217 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
33218 unsigned long addr, unsigned long len,
33219 - unsigned long pgoff, unsigned long flags)
33220 + unsigned long pgoff, unsigned long flags, unsigned long offset)
33221 {
33222 struct hstate *h = hstate_file(file);
33223 struct vm_unmapped_area_info info;
33224 -
33225 +
33226 info.flags = 0;
33227 info.length = len;
33228 info.low_limit = current->mm->mmap_legacy_base;
33229 info.high_limit = TASK_SIZE;
33230 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
33231 info.align_offset = 0;
33232 + info.threadstack_offset = offset;
33233 return vm_unmapped_area(&info);
33234 }
33235
33236 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
33237 unsigned long addr0, unsigned long len,
33238 - unsigned long pgoff, unsigned long flags)
33239 + unsigned long pgoff, unsigned long flags, unsigned long offset)
33240 {
33241 struct hstate *h = hstate_file(file);
33242 struct vm_unmapped_area_info info;
33243 @@ -108,6 +109,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
33244 info.high_limit = current->mm->mmap_base;
33245 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
33246 info.align_offset = 0;
33247 + info.threadstack_offset = offset;
33248 addr = vm_unmapped_area(&info);
33249
33250 /*
33251 @@ -120,6 +122,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
33252 VM_BUG_ON(addr != -ENOMEM);
33253 info.flags = 0;
33254 info.low_limit = TASK_UNMAPPED_BASE;
33255 +
33256 +#ifdef CONFIG_PAX_RANDMMAP
33257 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
33258 + info.low_limit += current->mm->delta_mmap;
33259 +#endif
33260 +
33261 info.high_limit = TASK_SIZE;
33262 addr = vm_unmapped_area(&info);
33263 }
33264 @@ -134,10 +142,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
33265 struct hstate *h = hstate_file(file);
33266 struct mm_struct *mm = current->mm;
33267 struct vm_area_struct *vma;
33268 + unsigned long pax_task_size = TASK_SIZE;
33269 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
33270
33271 if (len & ~huge_page_mask(h))
33272 return -EINVAL;
33273 - if (len > TASK_SIZE)
33274 +
33275 +#ifdef CONFIG_PAX_SEGMEXEC
33276 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
33277 + pax_task_size = SEGMEXEC_TASK_SIZE;
33278 +#endif
33279 +
33280 + pax_task_size -= PAGE_SIZE;
33281 +
33282 + if (len > pax_task_size)
33283 return -ENOMEM;
33284
33285 if (flags & MAP_FIXED) {
33286 @@ -146,19 +164,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
33287 return addr;
33288 }
33289
33290 +#ifdef CONFIG_PAX_RANDMMAP
33291 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
33292 +#endif
33293 +
33294 if (addr) {
33295 addr = ALIGN(addr, huge_page_size(h));
33296 vma = find_vma(mm, addr);
33297 - if (TASK_SIZE - len >= addr &&
33298 - (!vma || addr + len <= vma->vm_start))
33299 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
33300 return addr;
33301 }
33302 if (mm->get_unmapped_area == arch_get_unmapped_area)
33303 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
33304 - pgoff, flags);
33305 + pgoff, flags, offset);
33306 else
33307 return hugetlb_get_unmapped_area_topdown(file, addr, len,
33308 - pgoff, flags);
33309 + pgoff, flags, offset);
33310 }
33311 #endif /* CONFIG_HUGETLB_PAGE */
33312
33313 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
33314 index 66dba36..f8082ec 100644
33315 --- a/arch/x86/mm/init.c
33316 +++ b/arch/x86/mm/init.c
33317 @@ -4,6 +4,7 @@
33318 #include <linux/swap.h>
33319 #include <linux/memblock.h>
33320 #include <linux/bootmem.h> /* for max_low_pfn */
33321 +#include <linux/tboot.h>
33322
33323 #include <asm/cacheflush.h>
33324 #include <asm/e820.h>
33325 @@ -17,6 +18,8 @@
33326 #include <asm/proto.h>
33327 #include <asm/dma.h> /* for MAX_DMA_PFN */
33328 #include <asm/microcode.h>
33329 +#include <asm/desc.h>
33330 +#include <asm/bios_ebda.h>
33331
33332 /*
33333 * We need to define the tracepoints somewhere, and tlb.c
33334 @@ -570,7 +573,18 @@ void __init init_mem_mapping(void)
33335 early_ioremap_page_table_range_init();
33336 #endif
33337
33338 +#ifdef CONFIG_PAX_PER_CPU_PGD
33339 + clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
33340 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
33341 + KERNEL_PGD_PTRS);
33342 + clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
33343 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
33344 + KERNEL_PGD_PTRS);
33345 + load_cr3(get_cpu_pgd(0, kernel));
33346 +#else
33347 load_cr3(swapper_pg_dir);
33348 +#endif
33349 +
33350 __flush_tlb_all();
33351
33352 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
33353 @@ -586,10 +600,40 @@ void __init init_mem_mapping(void)
33354 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
33355 * mmio resources as well as potential bios/acpi data regions.
33356 */
33357 +
33358 +#ifdef CONFIG_GRKERNSEC_KMEM
33359 +static unsigned int ebda_start __read_only;
33360 +static unsigned int ebda_end __read_only;
33361 +#endif
33362 +
33363 int devmem_is_allowed(unsigned long pagenr)
33364 {
33365 - if (pagenr < 256)
33366 +#ifdef CONFIG_GRKERNSEC_KMEM
33367 + /* allow BDA */
33368 + if (!pagenr)
33369 return 1;
33370 + /* allow EBDA */
33371 + if (pagenr >= ebda_start && pagenr < ebda_end)
33372 + return 1;
33373 + /* if tboot is in use, allow access to its hardcoded serial log range */
33374 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
33375 + return 1;
33376 +#else
33377 + if (!pagenr)
33378 + return 1;
33379 +#ifdef CONFIG_VM86
33380 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
33381 + return 1;
33382 +#endif
33383 +#endif
33384 +
33385 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
33386 + return 1;
33387 +#ifdef CONFIG_GRKERNSEC_KMEM
33388 + /* throw out everything else below 1MB */
33389 + if (pagenr <= 256)
33390 + return 0;
33391 +#endif
33392 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
33393 return 0;
33394 if (!page_is_ram(pagenr))
33395 @@ -635,8 +679,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
33396 #endif
33397 }
33398
33399 +#ifdef CONFIG_GRKERNSEC_KMEM
33400 +static inline void gr_init_ebda(void)
33401 +{
33402 + unsigned int ebda_addr;
33403 + unsigned int ebda_size = 0;
33404 +
33405 + ebda_addr = get_bios_ebda();
33406 + if (ebda_addr) {
33407 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
33408 + ebda_size <<= 10;
33409 + }
33410 + if (ebda_addr && ebda_size) {
33411 + ebda_start = ebda_addr >> PAGE_SHIFT;
33412 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
33413 + } else {
33414 + ebda_start = 0x9f000 >> PAGE_SHIFT;
33415 + ebda_end = 0xa0000 >> PAGE_SHIFT;
33416 + }
33417 +}
33418 +#else
33419 +static inline void gr_init_ebda(void) { }
33420 +#endif
33421 +
33422 void free_initmem(void)
33423 {
33424 +#ifdef CONFIG_PAX_KERNEXEC
33425 +#ifdef CONFIG_X86_32
33426 + /* PaX: limit KERNEL_CS to actual size */
33427 + unsigned long addr, limit;
33428 + struct desc_struct d;
33429 + int cpu;
33430 +#else
33431 + pgd_t *pgd;
33432 + pud_t *pud;
33433 + pmd_t *pmd;
33434 + unsigned long addr, end;
33435 +#endif
33436 +#endif
33437 +
33438 + gr_init_ebda();
33439 +
33440 +#ifdef CONFIG_PAX_KERNEXEC
33441 +#ifdef CONFIG_X86_32
33442 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
33443 + limit = (limit - 1UL) >> PAGE_SHIFT;
33444 +
33445 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
33446 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
33447 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
33448 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
33449 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
33450 + }
33451 +
33452 + /* PaX: make KERNEL_CS read-only */
33453 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
33454 + if (!paravirt_enabled())
33455 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
33456 +/*
33457 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
33458 + pgd = pgd_offset_k(addr);
33459 + pud = pud_offset(pgd, addr);
33460 + pmd = pmd_offset(pud, addr);
33461 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
33462 + }
33463 +*/
33464 +#ifdef CONFIG_X86_PAE
33465 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
33466 +/*
33467 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
33468 + pgd = pgd_offset_k(addr);
33469 + pud = pud_offset(pgd, addr);
33470 + pmd = pmd_offset(pud, addr);
33471 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
33472 + }
33473 +*/
33474 +#endif
33475 +
33476 +#ifdef CONFIG_MODULES
33477 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
33478 +#endif
33479 +
33480 +#else
33481 + /* PaX: make kernel code/rodata read-only, rest non-executable */
33482 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
33483 + pgd = pgd_offset_k(addr);
33484 + pud = pud_offset(pgd, addr);
33485 + pmd = pmd_offset(pud, addr);
33486 + if (!pmd_present(*pmd))
33487 + continue;
33488 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
33489 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
33490 + else
33491 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
33492 + }
33493 +
33494 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
33495 + end = addr + KERNEL_IMAGE_SIZE;
33496 + for (; addr < end; addr += PMD_SIZE) {
33497 + pgd = pgd_offset_k(addr);
33498 + pud = pud_offset(pgd, addr);
33499 + pmd = pmd_offset(pud, addr);
33500 + if (!pmd_present(*pmd))
33501 + continue;
33502 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
33503 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
33504 + }
33505 +#endif
33506 +
33507 + flush_tlb_all();
33508 +#endif
33509 +
33510 free_init_pages("unused kernel",
33511 (unsigned long)(&__init_begin),
33512 (unsigned long)(&__init_end));
33513 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
33514 index 7d05565..bfc5338 100644
33515 --- a/arch/x86/mm/init_32.c
33516 +++ b/arch/x86/mm/init_32.c
33517 @@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
33518 bool __read_mostly __vmalloc_start_set = false;
33519
33520 /*
33521 - * Creates a middle page table and puts a pointer to it in the
33522 - * given global directory entry. This only returns the gd entry
33523 - * in non-PAE compilation mode, since the middle layer is folded.
33524 - */
33525 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
33526 -{
33527 - pud_t *pud;
33528 - pmd_t *pmd_table;
33529 -
33530 -#ifdef CONFIG_X86_PAE
33531 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
33532 - pmd_table = (pmd_t *)alloc_low_page();
33533 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
33534 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
33535 - pud = pud_offset(pgd, 0);
33536 - BUG_ON(pmd_table != pmd_offset(pud, 0));
33537 -
33538 - return pmd_table;
33539 - }
33540 -#endif
33541 - pud = pud_offset(pgd, 0);
33542 - pmd_table = pmd_offset(pud, 0);
33543 -
33544 - return pmd_table;
33545 -}
33546 -
33547 -/*
33548 * Create a page table and place a pointer to it in a middle page
33549 * directory entry:
33550 */
33551 @@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
33552 pte_t *page_table = (pte_t *)alloc_low_page();
33553
33554 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
33555 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
33556 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
33557 +#else
33558 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
33559 +#endif
33560 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
33561 }
33562
33563 return pte_offset_kernel(pmd, 0);
33564 }
33565
33566 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
33567 +{
33568 + pud_t *pud;
33569 + pmd_t *pmd_table;
33570 +
33571 + pud = pud_offset(pgd, 0);
33572 + pmd_table = pmd_offset(pud, 0);
33573 +
33574 + return pmd_table;
33575 +}
33576 +
33577 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
33578 {
33579 int pgd_idx = pgd_index(vaddr);
33580 @@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
33581 int pgd_idx, pmd_idx;
33582 unsigned long vaddr;
33583 pgd_t *pgd;
33584 + pud_t *pud;
33585 pmd_t *pmd;
33586 pte_t *pte = NULL;
33587 unsigned long count = page_table_range_init_count(start, end);
33588 @@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
33589 pgd = pgd_base + pgd_idx;
33590
33591 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
33592 - pmd = one_md_table_init(pgd);
33593 - pmd = pmd + pmd_index(vaddr);
33594 + pud = pud_offset(pgd, vaddr);
33595 + pmd = pmd_offset(pud, vaddr);
33596 +
33597 +#ifdef CONFIG_X86_PAE
33598 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
33599 +#endif
33600 +
33601 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
33602 pmd++, pmd_idx++) {
33603 pte = page_table_kmap_check(one_page_table_init(pmd),
33604 @@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
33605 }
33606 }
33607
33608 -static inline int is_kernel_text(unsigned long addr)
33609 +static inline int is_kernel_text(unsigned long start, unsigned long end)
33610 {
33611 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
33612 - return 1;
33613 - return 0;
33614 + if ((start >= ktla_ktva((unsigned long)_etext) ||
33615 + end <= ktla_ktva((unsigned long)_stext)) &&
33616 + (start >= ktla_ktva((unsigned long)_einittext) ||
33617 + end <= ktla_ktva((unsigned long)_sinittext)) &&
33618 +
33619 +#ifdef CONFIG_ACPI_SLEEP
33620 + (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
33621 +#endif
33622 +
33623 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
33624 + return 0;
33625 + return 1;
33626 }
33627
33628 /*
33629 @@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
33630 unsigned long last_map_addr = end;
33631 unsigned long start_pfn, end_pfn;
33632 pgd_t *pgd_base = swapper_pg_dir;
33633 - int pgd_idx, pmd_idx, pte_ofs;
33634 + unsigned int pgd_idx, pmd_idx, pte_ofs;
33635 unsigned long pfn;
33636 pgd_t *pgd;
33637 + pud_t *pud;
33638 pmd_t *pmd;
33639 pte_t *pte;
33640 unsigned pages_2m, pages_4k;
33641 @@ -291,8 +295,13 @@ repeat:
33642 pfn = start_pfn;
33643 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
33644 pgd = pgd_base + pgd_idx;
33645 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
33646 - pmd = one_md_table_init(pgd);
33647 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
33648 + pud = pud_offset(pgd, 0);
33649 + pmd = pmd_offset(pud, 0);
33650 +
33651 +#ifdef CONFIG_X86_PAE
33652 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
33653 +#endif
33654
33655 if (pfn >= end_pfn)
33656 continue;
33657 @@ -304,14 +313,13 @@ repeat:
33658 #endif
33659 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
33660 pmd++, pmd_idx++) {
33661 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
33662 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
33663
33664 /*
33665 * Map with big pages if possible, otherwise
33666 * create normal page tables:
33667 */
33668 if (use_pse) {
33669 - unsigned int addr2;
33670 pgprot_t prot = PAGE_KERNEL_LARGE;
33671 /*
33672 * first pass will use the same initial
33673 @@ -322,11 +330,7 @@ repeat:
33674 _PAGE_PSE);
33675
33676 pfn &= PMD_MASK >> PAGE_SHIFT;
33677 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
33678 - PAGE_OFFSET + PAGE_SIZE-1;
33679 -
33680 - if (is_kernel_text(addr) ||
33681 - is_kernel_text(addr2))
33682 + if (is_kernel_text(address, address + PMD_SIZE))
33683 prot = PAGE_KERNEL_LARGE_EXEC;
33684
33685 pages_2m++;
33686 @@ -343,7 +347,7 @@ repeat:
33687 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
33688 pte += pte_ofs;
33689 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
33690 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
33691 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
33692 pgprot_t prot = PAGE_KERNEL;
33693 /*
33694 * first pass will use the same initial
33695 @@ -351,7 +355,7 @@ repeat:
33696 */
33697 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
33698
33699 - if (is_kernel_text(addr))
33700 + if (is_kernel_text(address, address + PAGE_SIZE))
33701 prot = PAGE_KERNEL_EXEC;
33702
33703 pages_4k++;
33704 @@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
33705
33706 pud = pud_offset(pgd, va);
33707 pmd = pmd_offset(pud, va);
33708 - if (!pmd_present(*pmd))
33709 + if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
33710 break;
33711
33712 /* should not be large page here */
33713 @@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
33714
33715 static void __init pagetable_init(void)
33716 {
33717 - pgd_t *pgd_base = swapper_pg_dir;
33718 -
33719 - permanent_kmaps_init(pgd_base);
33720 + permanent_kmaps_init(swapper_pg_dir);
33721 }
33722
33723 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
33724 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
33725 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33726
33727 /* user-defined highmem size */
33728 @@ -787,10 +789,10 @@ void __init mem_init(void)
33729 ((unsigned long)&__init_end -
33730 (unsigned long)&__init_begin) >> 10,
33731
33732 - (unsigned long)&_etext, (unsigned long)&_edata,
33733 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
33734 + (unsigned long)&_sdata, (unsigned long)&_edata,
33735 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
33736
33737 - (unsigned long)&_text, (unsigned long)&_etext,
33738 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
33739 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
33740
33741 /*
33742 @@ -884,6 +886,7 @@ void set_kernel_text_rw(void)
33743 if (!kernel_set_to_readonly)
33744 return;
33745
33746 + start = ktla_ktva(start);
33747 pr_debug("Set kernel text: %lx - %lx for read write\n",
33748 start, start+size);
33749
33750 @@ -898,6 +901,7 @@ void set_kernel_text_ro(void)
33751 if (!kernel_set_to_readonly)
33752 return;
33753
33754 + start = ktla_ktva(start);
33755 pr_debug("Set kernel text: %lx - %lx for read only\n",
33756 start, start+size);
33757
33758 @@ -926,6 +930,7 @@ void mark_rodata_ro(void)
33759 unsigned long start = PFN_ALIGN(_text);
33760 unsigned long size = PFN_ALIGN(_etext) - start;
33761
33762 + start = ktla_ktva(start);
33763 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
33764 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
33765 size >> 10);
33766 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
33767 index 5621c47..5e17b7390 100644
33768 --- a/arch/x86/mm/init_64.c
33769 +++ b/arch/x86/mm/init_64.c
33770 @@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
33771 * around without checking the pgd every time.
33772 */
33773
33774 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
33775 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
33776 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33777
33778 int force_personality32;
33779 @@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33780
33781 for (address = start; address <= end; address += PGDIR_SIZE) {
33782 const pgd_t *pgd_ref = pgd_offset_k(address);
33783 +
33784 +#ifdef CONFIG_PAX_PER_CPU_PGD
33785 + unsigned long cpu;
33786 +#else
33787 struct page *page;
33788 +#endif
33789
33790 if (pgd_none(*pgd_ref))
33791 continue;
33792
33793 spin_lock(&pgd_lock);
33794 +
33795 +#ifdef CONFIG_PAX_PER_CPU_PGD
33796 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33797 + pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
33798 +
33799 + if (pgd_none(*pgd))
33800 + set_pgd(pgd, *pgd_ref);
33801 + else
33802 + BUG_ON(pgd_page_vaddr(*pgd)
33803 + != pgd_page_vaddr(*pgd_ref));
33804 + pgd = pgd_offset_cpu(cpu, kernel, address);
33805 +#else
33806 list_for_each_entry(page, &pgd_list, lru) {
33807 pgd_t *pgd;
33808 spinlock_t *pgt_lock;
33809 @@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33810 /* the pgt_lock only for Xen */
33811 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
33812 spin_lock(pgt_lock);
33813 +#endif
33814
33815 if (pgd_none(*pgd))
33816 set_pgd(pgd, *pgd_ref);
33817 @@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33818 BUG_ON(pgd_page_vaddr(*pgd)
33819 != pgd_page_vaddr(*pgd_ref));
33820
33821 +#ifndef CONFIG_PAX_PER_CPU_PGD
33822 spin_unlock(pgt_lock);
33823 +#endif
33824 +
33825 }
33826 spin_unlock(&pgd_lock);
33827 }
33828 @@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
33829 {
33830 if (pgd_none(*pgd)) {
33831 pud_t *pud = (pud_t *)spp_getpage();
33832 - pgd_populate(&init_mm, pgd, pud);
33833 + pgd_populate_kernel(&init_mm, pgd, pud);
33834 if (pud != pud_offset(pgd, 0))
33835 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
33836 pud, pud_offset(pgd, 0));
33837 @@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
33838 {
33839 if (pud_none(*pud)) {
33840 pmd_t *pmd = (pmd_t *) spp_getpage();
33841 - pud_populate(&init_mm, pud, pmd);
33842 + pud_populate_kernel(&init_mm, pud, pmd);
33843 if (pmd != pmd_offset(pud, 0))
33844 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
33845 pmd, pmd_offset(pud, 0));
33846 @@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
33847 pmd = fill_pmd(pud, vaddr);
33848 pte = fill_pte(pmd, vaddr);
33849
33850 + pax_open_kernel();
33851 set_pte(pte, new_pte);
33852 + pax_close_kernel();
33853
33854 /*
33855 * It's enough to flush this one mapping.
33856 @@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
33857 pgd = pgd_offset_k((unsigned long)__va(phys));
33858 if (pgd_none(*pgd)) {
33859 pud = (pud_t *) spp_getpage();
33860 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
33861 - _PAGE_USER));
33862 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
33863 }
33864 pud = pud_offset(pgd, (unsigned long)__va(phys));
33865 if (pud_none(*pud)) {
33866 pmd = (pmd_t *) spp_getpage();
33867 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
33868 - _PAGE_USER));
33869 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
33870 }
33871 pmd = pmd_offset(pud, phys);
33872 BUG_ON(!pmd_none(*pmd));
33873 @@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
33874 prot);
33875
33876 spin_lock(&init_mm.page_table_lock);
33877 - pud_populate(&init_mm, pud, pmd);
33878 + pud_populate_kernel(&init_mm, pud, pmd);
33879 spin_unlock(&init_mm.page_table_lock);
33880 }
33881 __flush_tlb_all();
33882 @@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
33883 page_size_mask);
33884
33885 spin_lock(&init_mm.page_table_lock);
33886 - pgd_populate(&init_mm, pgd, pud);
33887 + pgd_populate_kernel(&init_mm, pgd, pud);
33888 spin_unlock(&init_mm.page_table_lock);
33889 pgd_changed = true;
33890 }
33891 @@ -1196,8 +1217,8 @@ static struct vm_operations_struct gate_vma_ops = {
33892 static struct vm_area_struct gate_vma = {
33893 .vm_start = VSYSCALL_ADDR,
33894 .vm_end = VSYSCALL_ADDR + PAGE_SIZE,
33895 - .vm_page_prot = PAGE_READONLY_EXEC,
33896 - .vm_flags = VM_READ | VM_EXEC,
33897 + .vm_page_prot = PAGE_READONLY,
33898 + .vm_flags = VM_READ,
33899 .vm_ops = &gate_vma_ops,
33900 };
33901
33902 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
33903 index 7b179b49..6bd17777 100644
33904 --- a/arch/x86/mm/iomap_32.c
33905 +++ b/arch/x86/mm/iomap_32.c
33906 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
33907 type = kmap_atomic_idx_push();
33908 idx = type + KM_TYPE_NR * smp_processor_id();
33909 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
33910 +
33911 + pax_open_kernel();
33912 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
33913 + pax_close_kernel();
33914 +
33915 arch_flush_lazy_mmu_mode();
33916
33917 return (void *)vaddr;
33918 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
33919 index baff1da..2816ef4 100644
33920 --- a/arch/x86/mm/ioremap.c
33921 +++ b/arch/x86/mm/ioremap.c
33922 @@ -56,8 +56,8 @@ static int __ioremap_check_ram(unsigned long start_pfn, unsigned long nr_pages,
33923 unsigned long i;
33924
33925 for (i = 0; i < nr_pages; ++i)
33926 - if (pfn_valid(start_pfn + i) &&
33927 - !PageReserved(pfn_to_page(start_pfn + i)))
33928 + if (pfn_valid(start_pfn + i) && (start_pfn + i >= 0x100 ||
33929 + !PageReserved(pfn_to_page(start_pfn + i))))
33930 return 1;
33931
33932 WARN_ONCE(1, "ioremap on RAM pfn 0x%lx\n", start_pfn);
33933 @@ -268,7 +268,7 @@ EXPORT_SYMBOL(ioremap_prot);
33934 *
33935 * Caller must ensure there is only one unmapping for the same pointer.
33936 */
33937 -void iounmap(volatile void __iomem *addr)
33938 +void iounmap(const volatile void __iomem *addr)
33939 {
33940 struct vm_struct *p, *o;
33941
33942 @@ -322,6 +322,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
33943
33944 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
33945 if (page_is_ram(start >> PAGE_SHIFT))
33946 +#ifdef CONFIG_HIGHMEM
33947 + if ((start >> PAGE_SHIFT) < max_low_pfn)
33948 +#endif
33949 return __va(phys);
33950
33951 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
33952 @@ -334,13 +337,16 @@ void *xlate_dev_mem_ptr(unsigned long phys)
33953 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
33954 {
33955 if (page_is_ram(phys >> PAGE_SHIFT))
33956 +#ifdef CONFIG_HIGHMEM
33957 + if ((phys >> PAGE_SHIFT) < max_low_pfn)
33958 +#endif
33959 return;
33960
33961 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
33962 return;
33963 }
33964
33965 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
33966 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
33967
33968 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
33969 {
33970 @@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
33971 early_ioremap_setup();
33972
33973 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
33974 - memset(bm_pte, 0, sizeof(bm_pte));
33975 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
33976 + pmd_populate_user(&init_mm, pmd, bm_pte);
33977
33978 /*
33979 * The boot-ioremap range spans multiple pmds, for which
33980 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
33981 index dd89a13..d77bdcc 100644
33982 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
33983 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
33984 @@ -628,9 +628,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
33985 * memory (e.g. tracked pages)? For now, we need this to avoid
33986 * invoking kmemcheck for PnP BIOS calls.
33987 */
33988 - if (regs->flags & X86_VM_MASK)
33989 + if (v8086_mode(regs))
33990 return false;
33991 - if (regs->cs != __KERNEL_CS)
33992 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
33993 return false;
33994
33995 pte = kmemcheck_pte_lookup(address);
33996 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
33997 index 919b912..9267313 100644
33998 --- a/arch/x86/mm/mmap.c
33999 +++ b/arch/x86/mm/mmap.c
34000 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
34001 * Leave an at least ~128 MB hole with possible stack randomization.
34002 */
34003 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
34004 -#define MAX_GAP (TASK_SIZE/6*5)
34005 +#define MAX_GAP (pax_task_size/6*5)
34006
34007 static int mmap_is_legacy(void)
34008 {
34009 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
34010 return rnd << PAGE_SHIFT;
34011 }
34012
34013 -static unsigned long mmap_base(void)
34014 +static unsigned long mmap_base(struct mm_struct *mm)
34015 {
34016 unsigned long gap = rlimit(RLIMIT_STACK);
34017 + unsigned long pax_task_size = TASK_SIZE;
34018 +
34019 +#ifdef CONFIG_PAX_SEGMEXEC
34020 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
34021 + pax_task_size = SEGMEXEC_TASK_SIZE;
34022 +#endif
34023
34024 if (gap < MIN_GAP)
34025 gap = MIN_GAP;
34026 else if (gap > MAX_GAP)
34027 gap = MAX_GAP;
34028
34029 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
34030 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
34031 }
34032
34033 /*
34034 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
34035 * does, but not when emulating X86_32
34036 */
34037 -static unsigned long mmap_legacy_base(void)
34038 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
34039 {
34040 - if (mmap_is_ia32())
34041 + if (mmap_is_ia32()) {
34042 +
34043 +#ifdef CONFIG_PAX_SEGMEXEC
34044 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
34045 + return SEGMEXEC_TASK_UNMAPPED_BASE;
34046 + else
34047 +#endif
34048 +
34049 return TASK_UNMAPPED_BASE;
34050 - else
34051 + } else
34052 return TASK_UNMAPPED_BASE + mmap_rnd();
34053 }
34054
34055 @@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
34056 */
34057 void arch_pick_mmap_layout(struct mm_struct *mm)
34058 {
34059 - mm->mmap_legacy_base = mmap_legacy_base();
34060 - mm->mmap_base = mmap_base();
34061 + mm->mmap_legacy_base = mmap_legacy_base(mm);
34062 + mm->mmap_base = mmap_base(mm);
34063 +
34064 +#ifdef CONFIG_PAX_RANDMMAP
34065 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
34066 + mm->mmap_legacy_base += mm->delta_mmap;
34067 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
34068 + }
34069 +#endif
34070
34071 if (mmap_is_legacy()) {
34072 mm->mmap_base = mm->mmap_legacy_base;
34073 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
34074 index 0057a7a..95c7edd 100644
34075 --- a/arch/x86/mm/mmio-mod.c
34076 +++ b/arch/x86/mm/mmio-mod.c
34077 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
34078 break;
34079 default:
34080 {
34081 - unsigned char *ip = (unsigned char *)instptr;
34082 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
34083 my_trace->opcode = MMIO_UNKNOWN_OP;
34084 my_trace->width = 0;
34085 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
34086 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
34087 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
34088 void __iomem *addr)
34089 {
34090 - static atomic_t next_id;
34091 + static atomic_unchecked_t next_id;
34092 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
34093 /* These are page-unaligned. */
34094 struct mmiotrace_map map = {
34095 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
34096 .private = trace
34097 },
34098 .phys = offset,
34099 - .id = atomic_inc_return(&next_id)
34100 + .id = atomic_inc_return_unchecked(&next_id)
34101 };
34102 map.map_id = trace->id;
34103
34104 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
34105 ioremap_trace_core(offset, size, addr);
34106 }
34107
34108 -static void iounmap_trace_core(volatile void __iomem *addr)
34109 +static void iounmap_trace_core(const volatile void __iomem *addr)
34110 {
34111 struct mmiotrace_map map = {
34112 .phys = 0,
34113 @@ -328,7 +328,7 @@ not_enabled:
34114 }
34115 }
34116
34117 -void mmiotrace_iounmap(volatile void __iomem *addr)
34118 +void mmiotrace_iounmap(const volatile void __iomem *addr)
34119 {
34120 might_sleep();
34121 if (is_enabled()) /* recheck and proper locking in *_core() */
34122 diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
34123 index a32b706..efb308b 100644
34124 --- a/arch/x86/mm/numa.c
34125 +++ b/arch/x86/mm/numa.c
34126 @@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
34127 return true;
34128 }
34129
34130 -static int __init numa_register_memblks(struct numa_meminfo *mi)
34131 +static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
34132 {
34133 unsigned long uninitialized_var(pfn_align);
34134 int i, nid;
34135 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
34136 index 36de293..b820ddc 100644
34137 --- a/arch/x86/mm/pageattr.c
34138 +++ b/arch/x86/mm/pageattr.c
34139 @@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
34140 */
34141 #ifdef CONFIG_PCI_BIOS
34142 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
34143 - pgprot_val(forbidden) |= _PAGE_NX;
34144 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
34145 #endif
34146
34147 /*
34148 @@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
34149 * Does not cover __inittext since that is gone later on. On
34150 * 64bit we do not enforce !NX on the low mapping
34151 */
34152 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
34153 - pgprot_val(forbidden) |= _PAGE_NX;
34154 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
34155 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
34156
34157 +#ifdef CONFIG_DEBUG_RODATA
34158 /*
34159 * The .rodata section needs to be read-only. Using the pfn
34160 * catches all aliases.
34161 @@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
34162 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
34163 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
34164 pgprot_val(forbidden) |= _PAGE_RW;
34165 +#endif
34166
34167 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
34168 /*
34169 @@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
34170 }
34171 #endif
34172
34173 +#ifdef CONFIG_PAX_KERNEXEC
34174 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
34175 + pgprot_val(forbidden) |= _PAGE_RW;
34176 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
34177 + }
34178 +#endif
34179 +
34180 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
34181
34182 return prot;
34183 @@ -420,23 +429,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
34184 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
34185 {
34186 /* change init_mm */
34187 + pax_open_kernel();
34188 set_pte_atomic(kpte, pte);
34189 +
34190 #ifdef CONFIG_X86_32
34191 if (!SHARED_KERNEL_PMD) {
34192 +
34193 +#ifdef CONFIG_PAX_PER_CPU_PGD
34194 + unsigned long cpu;
34195 +#else
34196 struct page *page;
34197 +#endif
34198
34199 +#ifdef CONFIG_PAX_PER_CPU_PGD
34200 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
34201 + pgd_t *pgd = get_cpu_pgd(cpu, kernel);
34202 +#else
34203 list_for_each_entry(page, &pgd_list, lru) {
34204 - pgd_t *pgd;
34205 + pgd_t *pgd = (pgd_t *)page_address(page);
34206 +#endif
34207 +
34208 pud_t *pud;
34209 pmd_t *pmd;
34210
34211 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
34212 + pgd += pgd_index(address);
34213 pud = pud_offset(pgd, address);
34214 pmd = pmd_offset(pud, address);
34215 set_pte_atomic((pte_t *)pmd, pte);
34216 }
34217 }
34218 #endif
34219 + pax_close_kernel();
34220 }
34221
34222 static int
34223 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
34224 index 6574388..87e9bef 100644
34225 --- a/arch/x86/mm/pat.c
34226 +++ b/arch/x86/mm/pat.c
34227 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
34228
34229 if (!entry) {
34230 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
34231 - current->comm, current->pid, start, end - 1);
34232 + current->comm, task_pid_nr(current), start, end - 1);
34233 return -EINVAL;
34234 }
34235
34236 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34237
34238 while (cursor < to) {
34239 if (!devmem_is_allowed(pfn)) {
34240 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
34241 - current->comm, from, to - 1);
34242 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
34243 + current->comm, from, to - 1, cursor);
34244 return 0;
34245 }
34246 cursor += PAGE_SIZE;
34247 @@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
34248 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
34249 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
34250 "for [mem %#010Lx-%#010Lx]\n",
34251 - current->comm, current->pid,
34252 + current->comm, task_pid_nr(current),
34253 cattr_name(flags),
34254 base, (unsigned long long)(base + size-1));
34255 return -EINVAL;
34256 @@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
34257 flags = lookup_memtype(paddr);
34258 if (want_flags != flags) {
34259 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
34260 - current->comm, current->pid,
34261 + current->comm, task_pid_nr(current),
34262 cattr_name(want_flags),
34263 (unsigned long long)paddr,
34264 (unsigned long long)(paddr + size - 1),
34265 @@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
34266 free_memtype(paddr, paddr + size);
34267 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
34268 " for [mem %#010Lx-%#010Lx], got %s\n",
34269 - current->comm, current->pid,
34270 + current->comm, task_pid_nr(current),
34271 cattr_name(want_flags),
34272 (unsigned long long)paddr,
34273 (unsigned long long)(paddr + size - 1),
34274 diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
34275 index 415f6c4..d319983 100644
34276 --- a/arch/x86/mm/pat_rbtree.c
34277 +++ b/arch/x86/mm/pat_rbtree.c
34278 @@ -160,7 +160,7 @@ success:
34279
34280 failure:
34281 printk(KERN_INFO "%s:%d conflicting memory types "
34282 - "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
34283 + "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
34284 end, cattr_name(found_type), cattr_name(match->type));
34285 return -EBUSY;
34286 }
34287 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
34288 index 9f0614d..92ae64a 100644
34289 --- a/arch/x86/mm/pf_in.c
34290 +++ b/arch/x86/mm/pf_in.c
34291 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
34292 int i;
34293 enum reason_type rv = OTHERS;
34294
34295 - p = (unsigned char *)ins_addr;
34296 + p = (unsigned char *)ktla_ktva(ins_addr);
34297 p += skip_prefix(p, &prf);
34298 p += get_opcode(p, &opcode);
34299
34300 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
34301 struct prefix_bits prf;
34302 int i;
34303
34304 - p = (unsigned char *)ins_addr;
34305 + p = (unsigned char *)ktla_ktva(ins_addr);
34306 p += skip_prefix(p, &prf);
34307 p += get_opcode(p, &opcode);
34308
34309 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
34310 struct prefix_bits prf;
34311 int i;
34312
34313 - p = (unsigned char *)ins_addr;
34314 + p = (unsigned char *)ktla_ktva(ins_addr);
34315 p += skip_prefix(p, &prf);
34316 p += get_opcode(p, &opcode);
34317
34318 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
34319 struct prefix_bits prf;
34320 int i;
34321
34322 - p = (unsigned char *)ins_addr;
34323 + p = (unsigned char *)ktla_ktva(ins_addr);
34324 p += skip_prefix(p, &prf);
34325 p += get_opcode(p, &opcode);
34326 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
34327 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
34328 struct prefix_bits prf;
34329 int i;
34330
34331 - p = (unsigned char *)ins_addr;
34332 + p = (unsigned char *)ktla_ktva(ins_addr);
34333 p += skip_prefix(p, &prf);
34334 p += get_opcode(p, &opcode);
34335 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
34336 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
34337 index 6fb6927..4fc13c0 100644
34338 --- a/arch/x86/mm/pgtable.c
34339 +++ b/arch/x86/mm/pgtable.c
34340 @@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
34341 list_del(&page->lru);
34342 }
34343
34344 -#define UNSHARED_PTRS_PER_PGD \
34345 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
34346 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
34347 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
34348
34349 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
34350 +{
34351 + unsigned int count = USER_PGD_PTRS;
34352
34353 + if (!pax_user_shadow_base)
34354 + return;
34355 +
34356 + while (count--)
34357 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
34358 +}
34359 +#endif
34360 +
34361 +#ifdef CONFIG_PAX_PER_CPU_PGD
34362 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
34363 +{
34364 + unsigned int count = USER_PGD_PTRS;
34365 +
34366 + while (count--) {
34367 + pgd_t pgd;
34368 +
34369 +#ifdef CONFIG_X86_64
34370 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
34371 +#else
34372 + pgd = *src++;
34373 +#endif
34374 +
34375 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
34376 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
34377 +#endif
34378 +
34379 + *dst++ = pgd;
34380 + }
34381 +
34382 +}
34383 +#endif
34384 +
34385 +#ifdef CONFIG_X86_64
34386 +#define pxd_t pud_t
34387 +#define pyd_t pgd_t
34388 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
34389 +#define pgtable_pxd_page_ctor(page) true
34390 +#define pgtable_pxd_page_dtor(page)
34391 +#define pxd_free(mm, pud) pud_free((mm), (pud))
34392 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
34393 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
34394 +#define PYD_SIZE PGDIR_SIZE
34395 +#else
34396 +#define pxd_t pmd_t
34397 +#define pyd_t pud_t
34398 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
34399 +#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
34400 +#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
34401 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
34402 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
34403 +#define pyd_offset(mm, address) pud_offset((mm), (address))
34404 +#define PYD_SIZE PUD_SIZE
34405 +#endif
34406 +
34407 +#ifdef CONFIG_PAX_PER_CPU_PGD
34408 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
34409 +static inline void pgd_dtor(pgd_t *pgd) {}
34410 +#else
34411 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
34412 {
34413 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
34414 @@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
34415 pgd_list_del(pgd);
34416 spin_unlock(&pgd_lock);
34417 }
34418 +#endif
34419
34420 /*
34421 * List of all pgd's needed for non-PAE so it can invalidate entries
34422 @@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
34423 * -- nyc
34424 */
34425
34426 -#ifdef CONFIG_X86_PAE
34427 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
34428 /*
34429 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
34430 * updating the top-level pagetable entries to guarantee the
34431 @@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
34432 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
34433 * and initialize the kernel pmds here.
34434 */
34435 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
34436 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
34437
34438 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
34439 {
34440 @@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
34441 */
34442 flush_tlb_mm(mm);
34443 }
34444 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
34445 +#define PREALLOCATED_PXDS USER_PGD_PTRS
34446 #else /* !CONFIG_X86_PAE */
34447
34448 /* No need to prepopulate any pagetable entries in non-PAE modes. */
34449 -#define PREALLOCATED_PMDS 0
34450 +#define PREALLOCATED_PXDS 0
34451
34452 #endif /* CONFIG_X86_PAE */
34453
34454 -static void free_pmds(pmd_t *pmds[])
34455 +static void free_pxds(pxd_t *pxds[])
34456 {
34457 int i;
34458
34459 - for(i = 0; i < PREALLOCATED_PMDS; i++)
34460 - if (pmds[i]) {
34461 - pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
34462 - free_page((unsigned long)pmds[i]);
34463 + for(i = 0; i < PREALLOCATED_PXDS; i++)
34464 + if (pxds[i]) {
34465 + pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
34466 + free_page((unsigned long)pxds[i]);
34467 }
34468 }
34469
34470 -static int preallocate_pmds(pmd_t *pmds[])
34471 +static int preallocate_pxds(pxd_t *pxds[])
34472 {
34473 int i;
34474 bool failed = false;
34475
34476 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
34477 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
34478 - if (!pmd)
34479 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
34480 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
34481 + if (!pxd)
34482 failed = true;
34483 - if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
34484 - free_page((unsigned long)pmd);
34485 - pmd = NULL;
34486 + if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
34487 + free_page((unsigned long)pxd);
34488 + pxd = NULL;
34489 failed = true;
34490 }
34491 - pmds[i] = pmd;
34492 + pxds[i] = pxd;
34493 }
34494
34495 if (failed) {
34496 - free_pmds(pmds);
34497 + free_pxds(pxds);
34498 return -ENOMEM;
34499 }
34500
34501 @@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
34502 * preallocate which never got a corresponding vma will need to be
34503 * freed manually.
34504 */
34505 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
34506 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
34507 {
34508 int i;
34509
34510 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
34511 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
34512 pgd_t pgd = pgdp[i];
34513
34514 if (pgd_val(pgd) != 0) {
34515 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
34516 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
34517
34518 - pgdp[i] = native_make_pgd(0);
34519 + set_pgd(pgdp + i, native_make_pgd(0));
34520
34521 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
34522 - pmd_free(mm, pmd);
34523 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
34524 + pxd_free(mm, pxd);
34525 }
34526 }
34527 }
34528
34529 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
34530 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
34531 {
34532 - pud_t *pud;
34533 + pyd_t *pyd;
34534 int i;
34535
34536 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
34537 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
34538 return;
34539
34540 - pud = pud_offset(pgd, 0);
34541 -
34542 - for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
34543 - pmd_t *pmd = pmds[i];
34544 +#ifdef CONFIG_X86_64
34545 + pyd = pyd_offset(mm, 0L);
34546 +#else
34547 + pyd = pyd_offset(pgd, 0L);
34548 +#endif
34549
34550 + for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
34551 + pxd_t *pxd = pxds[i];
34552 if (i >= KERNEL_PGD_BOUNDARY)
34553 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
34554 - sizeof(pmd_t) * PTRS_PER_PMD);
34555 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
34556 + sizeof(pxd_t) * PTRS_PER_PMD);
34557
34558 - pud_populate(mm, pud, pmd);
34559 + pyd_populate(mm, pyd, pxd);
34560 }
34561 }
34562
34563 pgd_t *pgd_alloc(struct mm_struct *mm)
34564 {
34565 pgd_t *pgd;
34566 - pmd_t *pmds[PREALLOCATED_PMDS];
34567 + pxd_t *pxds[PREALLOCATED_PXDS];
34568
34569 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
34570
34571 @@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
34572
34573 mm->pgd = pgd;
34574
34575 - if (preallocate_pmds(pmds) != 0)
34576 + if (preallocate_pxds(pxds) != 0)
34577 goto out_free_pgd;
34578
34579 if (paravirt_pgd_alloc(mm) != 0)
34580 - goto out_free_pmds;
34581 + goto out_free_pxds;
34582
34583 /*
34584 * Make sure that pre-populating the pmds is atomic with
34585 @@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
34586 spin_lock(&pgd_lock);
34587
34588 pgd_ctor(mm, pgd);
34589 - pgd_prepopulate_pmd(mm, pgd, pmds);
34590 + pgd_prepopulate_pxd(mm, pgd, pxds);
34591
34592 spin_unlock(&pgd_lock);
34593
34594 return pgd;
34595
34596 -out_free_pmds:
34597 - free_pmds(pmds);
34598 +out_free_pxds:
34599 + free_pxds(pxds);
34600 out_free_pgd:
34601 free_page((unsigned long)pgd);
34602 out:
34603 @@ -313,7 +380,7 @@ out:
34604
34605 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
34606 {
34607 - pgd_mop_up_pmds(mm, pgd);
34608 + pgd_mop_up_pxds(mm, pgd);
34609 pgd_dtor(pgd);
34610 paravirt_pgd_free(mm, pgd);
34611 free_page((unsigned long)pgd);
34612 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
34613 index 4dd8cf6..f9d143e 100644
34614 --- a/arch/x86/mm/pgtable_32.c
34615 +++ b/arch/x86/mm/pgtable_32.c
34616 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
34617 return;
34618 }
34619 pte = pte_offset_kernel(pmd, vaddr);
34620 +
34621 + pax_open_kernel();
34622 if (pte_val(pteval))
34623 set_pte_at(&init_mm, vaddr, pte, pteval);
34624 else
34625 pte_clear(&init_mm, vaddr, pte);
34626 + pax_close_kernel();
34627
34628 /*
34629 * It's enough to flush this one mapping.
34630 diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
34631 index e666cbb..61788c45 100644
34632 --- a/arch/x86/mm/physaddr.c
34633 +++ b/arch/x86/mm/physaddr.c
34634 @@ -10,7 +10,7 @@
34635 #ifdef CONFIG_X86_64
34636
34637 #ifdef CONFIG_DEBUG_VIRTUAL
34638 -unsigned long __phys_addr(unsigned long x)
34639 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
34640 {
34641 unsigned long y = x - __START_KERNEL_map;
34642
34643 @@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
34644 #else
34645
34646 #ifdef CONFIG_DEBUG_VIRTUAL
34647 -unsigned long __phys_addr(unsigned long x)
34648 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
34649 {
34650 unsigned long phys_addr = x - PAGE_OFFSET;
34651 /* VMALLOC_* aren't constants */
34652 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
34653 index 90555bf..f5f1828 100644
34654 --- a/arch/x86/mm/setup_nx.c
34655 +++ b/arch/x86/mm/setup_nx.c
34656 @@ -5,8 +5,10 @@
34657 #include <asm/pgtable.h>
34658 #include <asm/proto.h>
34659
34660 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34661 static int disable_nx;
34662
34663 +#ifndef CONFIG_PAX_PAGEEXEC
34664 /*
34665 * noexec = on|off
34666 *
34667 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
34668 return 0;
34669 }
34670 early_param("noexec", noexec_setup);
34671 +#endif
34672 +
34673 +#endif
34674
34675 void x86_configure_nx(void)
34676 {
34677 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34678 if (cpu_has_nx && !disable_nx)
34679 __supported_pte_mask |= _PAGE_NX;
34680 else
34681 +#endif
34682 __supported_pte_mask &= ~_PAGE_NX;
34683 }
34684
34685 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
34686 index ee61c36..e6fedeb 100644
34687 --- a/arch/x86/mm/tlb.c
34688 +++ b/arch/x86/mm/tlb.c
34689 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
34690 BUG();
34691 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
34692 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
34693 +
34694 +#ifndef CONFIG_PAX_PER_CPU_PGD
34695 load_cr3(swapper_pg_dir);
34696 +#endif
34697 +
34698 /*
34699 * This gets called in the idle path where RCU
34700 * functions differently. Tracing normally
34701 diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
34702 new file mode 100644
34703 index 0000000..dace51c
34704 --- /dev/null
34705 +++ b/arch/x86/mm/uderef_64.c
34706 @@ -0,0 +1,37 @@
34707 +#include <linux/mm.h>
34708 +#include <asm/pgtable.h>
34709 +#include <asm/uaccess.h>
34710 +
34711 +#ifdef CONFIG_PAX_MEMORY_UDEREF
34712 +/* PaX: due to the special call convention these functions must
34713 + * - remain leaf functions under all configurations,
34714 + * - never be called directly, only dereferenced from the wrappers.
34715 + */
34716 +void __pax_open_userland(void)
34717 +{
34718 + unsigned int cpu;
34719 +
34720 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
34721 + return;
34722 +
34723 + cpu = raw_get_cpu();
34724 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
34725 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
34726 + raw_put_cpu_no_resched();
34727 +}
34728 +EXPORT_SYMBOL(__pax_open_userland);
34729 +
34730 +void __pax_close_userland(void)
34731 +{
34732 + unsigned int cpu;
34733 +
34734 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
34735 + return;
34736 +
34737 + cpu = raw_get_cpu();
34738 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
34739 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
34740 + raw_put_cpu_no_resched();
34741 +}
34742 +EXPORT_SYMBOL(__pax_close_userland);
34743 +#endif
34744 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
34745 index 6440221..f84b5c7 100644
34746 --- a/arch/x86/net/bpf_jit.S
34747 +++ b/arch/x86/net/bpf_jit.S
34748 @@ -9,6 +9,7 @@
34749 */
34750 #include <linux/linkage.h>
34751 #include <asm/dwarf2.h>
34752 +#include <asm/alternative-asm.h>
34753
34754 /*
34755 * Calling convention :
34756 @@ -38,6 +39,7 @@ sk_load_word_positive_offset:
34757 jle bpf_slow_path_word
34758 mov (SKBDATA,%rsi),%eax
34759 bswap %eax /* ntohl() */
34760 + pax_force_retaddr
34761 ret
34762
34763 sk_load_half:
34764 @@ -55,6 +57,7 @@ sk_load_half_positive_offset:
34765 jle bpf_slow_path_half
34766 movzwl (SKBDATA,%rsi),%eax
34767 rol $8,%ax # ntohs()
34768 + pax_force_retaddr
34769 ret
34770
34771 sk_load_byte:
34772 @@ -69,6 +72,7 @@ sk_load_byte_positive_offset:
34773 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
34774 jle bpf_slow_path_byte
34775 movzbl (SKBDATA,%rsi),%eax
34776 + pax_force_retaddr
34777 ret
34778
34779 /* rsi contains offset and can be scratched */
34780 @@ -90,6 +94,7 @@ bpf_slow_path_word:
34781 js bpf_error
34782 mov - MAX_BPF_STACK + 32(%rbp),%eax
34783 bswap %eax
34784 + pax_force_retaddr
34785 ret
34786
34787 bpf_slow_path_half:
34788 @@ -98,12 +103,14 @@ bpf_slow_path_half:
34789 mov - MAX_BPF_STACK + 32(%rbp),%ax
34790 rol $8,%ax
34791 movzwl %ax,%eax
34792 + pax_force_retaddr
34793 ret
34794
34795 bpf_slow_path_byte:
34796 bpf_slow_path_common(1)
34797 js bpf_error
34798 movzbl - MAX_BPF_STACK + 32(%rbp),%eax
34799 + pax_force_retaddr
34800 ret
34801
34802 #define sk_negative_common(SIZE) \
34803 @@ -126,6 +133,7 @@ sk_load_word_negative_offset:
34804 sk_negative_common(4)
34805 mov (%rax), %eax
34806 bswap %eax
34807 + pax_force_retaddr
34808 ret
34809
34810 bpf_slow_path_half_neg:
34811 @@ -137,6 +145,7 @@ sk_load_half_negative_offset:
34812 mov (%rax),%ax
34813 rol $8,%ax
34814 movzwl %ax,%eax
34815 + pax_force_retaddr
34816 ret
34817
34818 bpf_slow_path_byte_neg:
34819 @@ -146,6 +155,7 @@ sk_load_byte_negative_offset:
34820 .globl sk_load_byte_negative_offset
34821 sk_negative_common(1)
34822 movzbl (%rax), %eax
34823 + pax_force_retaddr
34824 ret
34825
34826 bpf_error:
34827 @@ -156,4 +166,5 @@ bpf_error:
34828 mov - MAX_BPF_STACK + 16(%rbp),%r14
34829 mov - MAX_BPF_STACK + 24(%rbp),%r15
34830 leaveq
34831 + pax_force_retaddr
34832 ret
34833 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
34834 index c881ba8..71aca2e 100644
34835 --- a/arch/x86/net/bpf_jit_comp.c
34836 +++ b/arch/x86/net/bpf_jit_comp.c
34837 @@ -15,7 +15,11 @@
34838 #include <linux/if_vlan.h>
34839 #include <linux/random.h>
34840
34841 +#ifdef CONFIG_GRKERNSEC_BPF_HARDEN
34842 +int bpf_jit_enable __read_only;
34843 +#else
34844 int bpf_jit_enable __read_mostly;
34845 +#endif
34846
34847 /*
34848 * assembly code in arch/x86/net/bpf_jit.S
34849 @@ -109,36 +113,32 @@ static inline void bpf_flush_icache(void *start, void *end)
34850 #define CHOOSE_LOAD_FUNC(K, func) \
34851 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
34852
34853 -struct bpf_binary_header {
34854 - unsigned int pages;
34855 - /* Note : for security reasons, bpf code will follow a randomly
34856 - * sized amount of int3 instructions
34857 - */
34858 - u8 image[];
34859 -};
34860 -
34861 -static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
34862 +/* Note : for security reasons, bpf code will follow a randomly
34863 + * sized amount of int3 instructions
34864 + */
34865 +static u8 *bpf_alloc_binary(unsigned int proglen,
34866 u8 **image_ptr)
34867 {
34868 unsigned int sz, hole;
34869 - struct bpf_binary_header *header;
34870 + u8 *header;
34871
34872 /* Most of BPF filters are really small,
34873 * but if some of them fill a page, allow at least
34874 * 128 extra bytes to insert a random section of int3
34875 */
34876 - sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
34877 - header = module_alloc(sz);
34878 + sz = round_up(proglen + 128, PAGE_SIZE);
34879 + header = module_alloc_exec(sz);
34880 if (!header)
34881 return NULL;
34882
34883 + pax_open_kernel();
34884 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
34885 + pax_close_kernel();
34886
34887 - header->pages = sz / PAGE_SIZE;
34888 - hole = min(sz - (proglen + sizeof(*header)), PAGE_SIZE - sizeof(*header));
34889 + hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
34890
34891 /* insert a random number of int3 instructions before BPF code */
34892 - *image_ptr = &header->image[prandom_u32() % hole];
34893 + *image_ptr = &header[prandom_u32() % hole];
34894 return header;
34895 }
34896
34897 @@ -864,7 +864,9 @@ common_load:
34898 pr_err("bpf_jit_compile fatal error\n");
34899 return -EFAULT;
34900 }
34901 + pax_open_kernel();
34902 memcpy(image + proglen, temp, ilen);
34903 + pax_close_kernel();
34904 }
34905 proglen += ilen;
34906 addrs[i] = proglen;
34907 @@ -879,7 +881,7 @@ void bpf_jit_compile(struct bpf_prog *prog)
34908
34909 void bpf_int_jit_compile(struct bpf_prog *prog)
34910 {
34911 - struct bpf_binary_header *header = NULL;
34912 + u8 *header = NULL;
34913 int proglen, oldproglen = 0;
34914 struct jit_context ctx = {};
34915 u8 *image = NULL;
34916 @@ -911,7 +913,7 @@ void bpf_int_jit_compile(struct bpf_prog *prog)
34917 if (proglen <= 0) {
34918 image = NULL;
34919 if (header)
34920 - module_free(NULL, header);
34921 + module_free_exec(NULL, image);
34922 goto out;
34923 }
34924 if (image) {
34925 @@ -935,7 +937,6 @@ void bpf_int_jit_compile(struct bpf_prog *prog)
34926
34927 if (image) {
34928 bpf_flush_icache(header, image + proglen);
34929 - set_memory_ro((unsigned long)header, header->pages);
34930 prog->bpf_func = (void *)image;
34931 prog->jited = 1;
34932 }
34933 @@ -943,23 +944,15 @@ out:
34934 kfree(addrs);
34935 }
34936
34937 -static void bpf_jit_free_deferred(struct work_struct *work)
34938 -{
34939 - struct bpf_prog *fp = container_of(work, struct bpf_prog, work);
34940 - unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
34941 - struct bpf_binary_header *header = (void *)addr;
34942 -
34943 - set_memory_rw(addr, header->pages);
34944 - module_free(NULL, header);
34945 - kfree(fp);
34946 -}
34947 -
34948 void bpf_jit_free(struct bpf_prog *fp)
34949 {
34950 - if (fp->jited) {
34951 - INIT_WORK(&fp->work, bpf_jit_free_deferred);
34952 - schedule_work(&fp->work);
34953 - } else {
34954 - kfree(fp);
34955 - }
34956 + unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
34957 +
34958 + if (!fp->jited)
34959 + goto free_filter;
34960 +
34961 + module_free_exec(NULL, (void *)addr);
34962 +
34963 +free_filter:
34964 + bpf_prog_unlock_free(fp);
34965 }
34966 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
34967 index 5d04be5..2beeaa2 100644
34968 --- a/arch/x86/oprofile/backtrace.c
34969 +++ b/arch/x86/oprofile/backtrace.c
34970 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
34971 struct stack_frame_ia32 *fp;
34972 unsigned long bytes;
34973
34974 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34975 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34976 if (bytes != 0)
34977 return NULL;
34978
34979 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
34980 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
34981
34982 oprofile_add_trace(bufhead[0].return_address);
34983
34984 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
34985 struct stack_frame bufhead[2];
34986 unsigned long bytes;
34987
34988 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34989 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34990 if (bytes != 0)
34991 return NULL;
34992
34993 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
34994 {
34995 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
34996
34997 - if (!user_mode_vm(regs)) {
34998 + if (!user_mode(regs)) {
34999 unsigned long stack = kernel_stack_pointer(regs);
35000 if (depth)
35001 dump_trace(NULL, regs, (unsigned long *)stack, 0,
35002 diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
35003 index 379e8bd..6386e09 100644
35004 --- a/arch/x86/oprofile/nmi_int.c
35005 +++ b/arch/x86/oprofile/nmi_int.c
35006 @@ -23,6 +23,7 @@
35007 #include <asm/nmi.h>
35008 #include <asm/msr.h>
35009 #include <asm/apic.h>
35010 +#include <asm/pgtable.h>
35011
35012 #include "op_counter.h"
35013 #include "op_x86_model.h"
35014 @@ -785,8 +786,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
35015 if (ret)
35016 return ret;
35017
35018 - if (!model->num_virt_counters)
35019 - model->num_virt_counters = model->num_counters;
35020 + if (!model->num_virt_counters) {
35021 + pax_open_kernel();
35022 + *(unsigned int *)&model->num_virt_counters = model->num_counters;
35023 + pax_close_kernel();
35024 + }
35025
35026 mux_init(ops);
35027
35028 diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
35029 index 50d86c0..7985318 100644
35030 --- a/arch/x86/oprofile/op_model_amd.c
35031 +++ b/arch/x86/oprofile/op_model_amd.c
35032 @@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
35033 num_counters = AMD64_NUM_COUNTERS;
35034 }
35035
35036 - op_amd_spec.num_counters = num_counters;
35037 - op_amd_spec.num_controls = num_counters;
35038 - op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
35039 + pax_open_kernel();
35040 + *(unsigned int *)&op_amd_spec.num_counters = num_counters;
35041 + *(unsigned int *)&op_amd_spec.num_controls = num_counters;
35042 + *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
35043 + pax_close_kernel();
35044
35045 return 0;
35046 }
35047 diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
35048 index d90528e..0127e2b 100644
35049 --- a/arch/x86/oprofile/op_model_ppro.c
35050 +++ b/arch/x86/oprofile/op_model_ppro.c
35051 @@ -19,6 +19,7 @@
35052 #include <asm/msr.h>
35053 #include <asm/apic.h>
35054 #include <asm/nmi.h>
35055 +#include <asm/pgtable.h>
35056
35057 #include "op_x86_model.h"
35058 #include "op_counter.h"
35059 @@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
35060
35061 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
35062
35063 - op_arch_perfmon_spec.num_counters = num_counters;
35064 - op_arch_perfmon_spec.num_controls = num_counters;
35065 + pax_open_kernel();
35066 + *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
35067 + *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
35068 + pax_close_kernel();
35069 }
35070
35071 static int arch_perfmon_init(struct oprofile_operations *ignore)
35072 diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
35073 index 71e8a67..6a313bb 100644
35074 --- a/arch/x86/oprofile/op_x86_model.h
35075 +++ b/arch/x86/oprofile/op_x86_model.h
35076 @@ -52,7 +52,7 @@ struct op_x86_model_spec {
35077 void (*switch_ctrl)(struct op_x86_model_spec const *model,
35078 struct op_msrs const * const msrs);
35079 #endif
35080 -};
35081 +} __do_const;
35082
35083 struct op_counter_config;
35084
35085 diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
35086 index b9958c3..24229ab 100644
35087 --- a/arch/x86/pci/intel_mid_pci.c
35088 +++ b/arch/x86/pci/intel_mid_pci.c
35089 @@ -250,7 +250,7 @@ int __init intel_mid_pci_init(void)
35090 pci_mmcfg_late_init();
35091 pcibios_enable_irq = intel_mid_pci_irq_enable;
35092 pcibios_disable_irq = intel_mid_pci_irq_disable;
35093 - pci_root_ops = intel_mid_pci_ops;
35094 + memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
35095 pci_soc_mode = 1;
35096 /* Continue with standard init */
35097 return 1;
35098 diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
35099 index eb500c2..eab9e70 100644
35100 --- a/arch/x86/pci/irq.c
35101 +++ b/arch/x86/pci/irq.c
35102 @@ -51,7 +51,7 @@ struct irq_router {
35103 struct irq_router_handler {
35104 u16 vendor;
35105 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
35106 -};
35107 +} __do_const;
35108
35109 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
35110 void (*pcibios_disable_irq)(struct pci_dev *dev) = pirq_disable_irq;
35111 @@ -791,7 +791,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
35112 return 0;
35113 }
35114
35115 -static __initdata struct irq_router_handler pirq_routers[] = {
35116 +static __initconst const struct irq_router_handler pirq_routers[] = {
35117 { PCI_VENDOR_ID_INTEL, intel_router_probe },
35118 { PCI_VENDOR_ID_AL, ali_router_probe },
35119 { PCI_VENDOR_ID_ITE, ite_router_probe },
35120 @@ -818,7 +818,7 @@ static struct pci_dev *pirq_router_dev;
35121 static void __init pirq_find_router(struct irq_router *r)
35122 {
35123 struct irq_routing_table *rt = pirq_table;
35124 - struct irq_router_handler *h;
35125 + const struct irq_router_handler *h;
35126
35127 #ifdef CONFIG_PCI_BIOS
35128 if (!rt->signature) {
35129 @@ -1091,7 +1091,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
35130 return 0;
35131 }
35132
35133 -static struct dmi_system_id __initdata pciirq_dmi_table[] = {
35134 +static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
35135 {
35136 .callback = fix_broken_hp_bios_irq9,
35137 .ident = "HP Pavilion N5400 Series Laptop",
35138 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
35139 index c77b24a..c979855 100644
35140 --- a/arch/x86/pci/pcbios.c
35141 +++ b/arch/x86/pci/pcbios.c
35142 @@ -79,7 +79,7 @@ union bios32 {
35143 static struct {
35144 unsigned long address;
35145 unsigned short segment;
35146 -} bios32_indirect = { 0, __KERNEL_CS };
35147 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
35148
35149 /*
35150 * Returns the entry point for the given service, NULL on error
35151 @@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
35152 unsigned long length; /* %ecx */
35153 unsigned long entry; /* %edx */
35154 unsigned long flags;
35155 + struct desc_struct d, *gdt;
35156
35157 local_irq_save(flags);
35158 - __asm__("lcall *(%%edi); cld"
35159 +
35160 + gdt = get_cpu_gdt_table(smp_processor_id());
35161 +
35162 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
35163 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
35164 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
35165 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
35166 +
35167 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
35168 : "=a" (return_code),
35169 "=b" (address),
35170 "=c" (length),
35171 "=d" (entry)
35172 : "0" (service),
35173 "1" (0),
35174 - "D" (&bios32_indirect));
35175 + "D" (&bios32_indirect),
35176 + "r"(__PCIBIOS_DS)
35177 + : "memory");
35178 +
35179 + pax_open_kernel();
35180 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
35181 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
35182 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
35183 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
35184 + pax_close_kernel();
35185 +
35186 local_irq_restore(flags);
35187
35188 switch (return_code) {
35189 - case 0:
35190 - return address + entry;
35191 - case 0x80: /* Not present */
35192 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
35193 - return 0;
35194 - default: /* Shouldn't happen */
35195 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
35196 - service, return_code);
35197 + case 0: {
35198 + int cpu;
35199 + unsigned char flags;
35200 +
35201 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
35202 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
35203 + printk(KERN_WARNING "bios32_service: not valid\n");
35204 return 0;
35205 + }
35206 + address = address + PAGE_OFFSET;
35207 + length += 16UL; /* some BIOSs underreport this... */
35208 + flags = 4;
35209 + if (length >= 64*1024*1024) {
35210 + length >>= PAGE_SHIFT;
35211 + flags |= 8;
35212 + }
35213 +
35214 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
35215 + gdt = get_cpu_gdt_table(cpu);
35216 + pack_descriptor(&d, address, length, 0x9b, flags);
35217 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
35218 + pack_descriptor(&d, address, length, 0x93, flags);
35219 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
35220 + }
35221 + return entry;
35222 + }
35223 + case 0x80: /* Not present */
35224 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
35225 + return 0;
35226 + default: /* Shouldn't happen */
35227 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
35228 + service, return_code);
35229 + return 0;
35230 }
35231 }
35232
35233 static struct {
35234 unsigned long address;
35235 unsigned short segment;
35236 -} pci_indirect = { 0, __KERNEL_CS };
35237 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
35238
35239 -static int pci_bios_present;
35240 +static int pci_bios_present __read_only;
35241
35242 static int check_pcibios(void)
35243 {
35244 @@ -131,11 +174,13 @@ static int check_pcibios(void)
35245 unsigned long flags, pcibios_entry;
35246
35247 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
35248 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
35249 + pci_indirect.address = pcibios_entry;
35250
35251 local_irq_save(flags);
35252 - __asm__(
35253 - "lcall *(%%edi); cld\n\t"
35254 + __asm__("movw %w6, %%ds\n\t"
35255 + "lcall *%%ss:(%%edi); cld\n\t"
35256 + "push %%ss\n\t"
35257 + "pop %%ds\n\t"
35258 "jc 1f\n\t"
35259 "xor %%ah, %%ah\n"
35260 "1:"
35261 @@ -144,7 +189,8 @@ static int check_pcibios(void)
35262 "=b" (ebx),
35263 "=c" (ecx)
35264 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
35265 - "D" (&pci_indirect)
35266 + "D" (&pci_indirect),
35267 + "r" (__PCIBIOS_DS)
35268 : "memory");
35269 local_irq_restore(flags);
35270
35271 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35272
35273 switch (len) {
35274 case 1:
35275 - __asm__("lcall *(%%esi); cld\n\t"
35276 + __asm__("movw %w6, %%ds\n\t"
35277 + "lcall *%%ss:(%%esi); cld\n\t"
35278 + "push %%ss\n\t"
35279 + "pop %%ds\n\t"
35280 "jc 1f\n\t"
35281 "xor %%ah, %%ah\n"
35282 "1:"
35283 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35284 : "1" (PCIBIOS_READ_CONFIG_BYTE),
35285 "b" (bx),
35286 "D" ((long)reg),
35287 - "S" (&pci_indirect));
35288 + "S" (&pci_indirect),
35289 + "r" (__PCIBIOS_DS));
35290 /*
35291 * Zero-extend the result beyond 8 bits, do not trust the
35292 * BIOS having done it:
35293 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35294 *value &= 0xff;
35295 break;
35296 case 2:
35297 - __asm__("lcall *(%%esi); cld\n\t"
35298 + __asm__("movw %w6, %%ds\n\t"
35299 + "lcall *%%ss:(%%esi); cld\n\t"
35300 + "push %%ss\n\t"
35301 + "pop %%ds\n\t"
35302 "jc 1f\n\t"
35303 "xor %%ah, %%ah\n"
35304 "1:"
35305 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35306 : "1" (PCIBIOS_READ_CONFIG_WORD),
35307 "b" (bx),
35308 "D" ((long)reg),
35309 - "S" (&pci_indirect));
35310 + "S" (&pci_indirect),
35311 + "r" (__PCIBIOS_DS));
35312 /*
35313 * Zero-extend the result beyond 16 bits, do not trust the
35314 * BIOS having done it:
35315 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35316 *value &= 0xffff;
35317 break;
35318 case 4:
35319 - __asm__("lcall *(%%esi); cld\n\t"
35320 + __asm__("movw %w6, %%ds\n\t"
35321 + "lcall *%%ss:(%%esi); cld\n\t"
35322 + "push %%ss\n\t"
35323 + "pop %%ds\n\t"
35324 "jc 1f\n\t"
35325 "xor %%ah, %%ah\n"
35326 "1:"
35327 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35328 : "1" (PCIBIOS_READ_CONFIG_DWORD),
35329 "b" (bx),
35330 "D" ((long)reg),
35331 - "S" (&pci_indirect));
35332 + "S" (&pci_indirect),
35333 + "r" (__PCIBIOS_DS));
35334 break;
35335 }
35336
35337 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
35338
35339 switch (len) {
35340 case 1:
35341 - __asm__("lcall *(%%esi); cld\n\t"
35342 + __asm__("movw %w6, %%ds\n\t"
35343 + "lcall *%%ss:(%%esi); cld\n\t"
35344 + "push %%ss\n\t"
35345 + "pop %%ds\n\t"
35346 "jc 1f\n\t"
35347 "xor %%ah, %%ah\n"
35348 "1:"
35349 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
35350 "c" (value),
35351 "b" (bx),
35352 "D" ((long)reg),
35353 - "S" (&pci_indirect));
35354 + "S" (&pci_indirect),
35355 + "r" (__PCIBIOS_DS));
35356 break;
35357 case 2:
35358 - __asm__("lcall *(%%esi); cld\n\t"
35359 + __asm__("movw %w6, %%ds\n\t"
35360 + "lcall *%%ss:(%%esi); cld\n\t"
35361 + "push %%ss\n\t"
35362 + "pop %%ds\n\t"
35363 "jc 1f\n\t"
35364 "xor %%ah, %%ah\n"
35365 "1:"
35366 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
35367 "c" (value),
35368 "b" (bx),
35369 "D" ((long)reg),
35370 - "S" (&pci_indirect));
35371 + "S" (&pci_indirect),
35372 + "r" (__PCIBIOS_DS));
35373 break;
35374 case 4:
35375 - __asm__("lcall *(%%esi); cld\n\t"
35376 + __asm__("movw %w6, %%ds\n\t"
35377 + "lcall *%%ss:(%%esi); cld\n\t"
35378 + "push %%ss\n\t"
35379 + "pop %%ds\n\t"
35380 "jc 1f\n\t"
35381 "xor %%ah, %%ah\n"
35382 "1:"
35383 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
35384 "c" (value),
35385 "b" (bx),
35386 "D" ((long)reg),
35387 - "S" (&pci_indirect));
35388 + "S" (&pci_indirect),
35389 + "r" (__PCIBIOS_DS));
35390 break;
35391 }
35392
35393 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
35394
35395 DBG("PCI: Fetching IRQ routing table... ");
35396 __asm__("push %%es\n\t"
35397 + "movw %w8, %%ds\n\t"
35398 "push %%ds\n\t"
35399 "pop %%es\n\t"
35400 - "lcall *(%%esi); cld\n\t"
35401 + "lcall *%%ss:(%%esi); cld\n\t"
35402 "pop %%es\n\t"
35403 + "push %%ss\n\t"
35404 + "pop %%ds\n"
35405 "jc 1f\n\t"
35406 "xor %%ah, %%ah\n"
35407 "1:"
35408 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
35409 "1" (0),
35410 "D" ((long) &opt),
35411 "S" (&pci_indirect),
35412 - "m" (opt)
35413 + "m" (opt),
35414 + "r" (__PCIBIOS_DS)
35415 : "memory");
35416 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
35417 if (ret & 0xff00)
35418 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
35419 {
35420 int ret;
35421
35422 - __asm__("lcall *(%%esi); cld\n\t"
35423 + __asm__("movw %w5, %%ds\n\t"
35424 + "lcall *%%ss:(%%esi); cld\n\t"
35425 + "push %%ss\n\t"
35426 + "pop %%ds\n"
35427 "jc 1f\n\t"
35428 "xor %%ah, %%ah\n"
35429 "1:"
35430 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
35431 : "0" (PCIBIOS_SET_PCI_HW_INT),
35432 "b" ((dev->bus->number << 8) | dev->devfn),
35433 "c" ((irq << 8) | (pin + 10)),
35434 - "S" (&pci_indirect));
35435 + "S" (&pci_indirect),
35436 + "r" (__PCIBIOS_DS));
35437 return !(ret & 0xff00);
35438 }
35439 EXPORT_SYMBOL(pcibios_set_irq_routing);
35440 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
35441 index 9ee3491..872192f 100644
35442 --- a/arch/x86/platform/efi/efi_32.c
35443 +++ b/arch/x86/platform/efi/efi_32.c
35444 @@ -59,11 +59,22 @@ void efi_call_phys_prelog(void)
35445 {
35446 struct desc_ptr gdt_descr;
35447
35448 +#ifdef CONFIG_PAX_KERNEXEC
35449 + struct desc_struct d;
35450 +#endif
35451 +
35452 local_irq_save(efi_rt_eflags);
35453
35454 load_cr3(initial_page_table);
35455 __flush_tlb_all();
35456
35457 +#ifdef CONFIG_PAX_KERNEXEC
35458 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
35459 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
35460 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
35461 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
35462 +#endif
35463 +
35464 gdt_descr.address = __pa(get_cpu_gdt_table(0));
35465 gdt_descr.size = GDT_SIZE - 1;
35466 load_gdt(&gdt_descr);
35467 @@ -73,11 +84,24 @@ void efi_call_phys_epilog(void)
35468 {
35469 struct desc_ptr gdt_descr;
35470
35471 +#ifdef CONFIG_PAX_KERNEXEC
35472 + struct desc_struct d;
35473 +
35474 + memset(&d, 0, sizeof d);
35475 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
35476 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
35477 +#endif
35478 +
35479 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
35480 gdt_descr.size = GDT_SIZE - 1;
35481 load_gdt(&gdt_descr);
35482
35483 +#ifdef CONFIG_PAX_PER_CPU_PGD
35484 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
35485 +#else
35486 load_cr3(swapper_pg_dir);
35487 +#endif
35488 +
35489 __flush_tlb_all();
35490
35491 local_irq_restore(efi_rt_eflags);
35492 diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
35493 index 290d397..e09d270 100644
35494 --- a/arch/x86/platform/efi/efi_64.c
35495 +++ b/arch/x86/platform/efi/efi_64.c
35496 @@ -99,6 +99,11 @@ void __init efi_call_phys_prelog(void)
35497 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
35498 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
35499 }
35500 +
35501 +#ifdef CONFIG_PAX_PER_CPU_PGD
35502 + load_cr3(swapper_pg_dir);
35503 +#endif
35504 +
35505 __flush_tlb_all();
35506 }
35507
35508 @@ -116,6 +121,11 @@ void __init efi_call_phys_epilog(void)
35509 for (pgd = 0; pgd < n_pgds; pgd++)
35510 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
35511 kfree(save_pgd);
35512 +
35513 +#ifdef CONFIG_PAX_PER_CPU_PGD
35514 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
35515 +#endif
35516 +
35517 __flush_tlb_all();
35518 local_irq_restore(efi_flags);
35519 early_code_mapping_set_exec(0);
35520 @@ -146,8 +156,23 @@ int efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
35521 unsigned npages;
35522 pgd_t *pgd;
35523
35524 - if (efi_enabled(EFI_OLD_MEMMAP))
35525 + if (efi_enabled(EFI_OLD_MEMMAP)) {
35526 + /* PaX: We need to disable the NX bit in the PGD, otherwise we won't be
35527 + * able to execute the EFI services.
35528 + */
35529 + if (__supported_pte_mask & _PAGE_NX) {
35530 + unsigned long addr = (unsigned long) __va(0);
35531 + pgd_t pe = __pgd(pgd_val(*pgd_offset_k(addr)) & ~_PAGE_NX);
35532 +
35533 + pr_alert("PAX: Disabling NX protection for low memory map. Try booting without \"efi=old_map\"\n");
35534 +#ifdef CONFIG_PAX_PER_CPU_PGD
35535 + set_pgd(pgd_offset_cpu(0, kernel, addr), pe);
35536 +#endif
35537 + set_pgd(pgd_offset_k(addr), pe);
35538 + }
35539 +
35540 return 0;
35541 + }
35542
35543 efi_scratch.efi_pgt = (pgd_t *)(unsigned long)real_mode_header->trampoline_pgd;
35544 pgd = __va(efi_scratch.efi_pgt);
35545 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
35546 index fbe66e6..eae5e38 100644
35547 --- a/arch/x86/platform/efi/efi_stub_32.S
35548 +++ b/arch/x86/platform/efi/efi_stub_32.S
35549 @@ -6,7 +6,9 @@
35550 */
35551
35552 #include <linux/linkage.h>
35553 +#include <linux/init.h>
35554 #include <asm/page_types.h>
35555 +#include <asm/segment.h>
35556
35557 /*
35558 * efi_call_phys(void *, ...) is a function with variable parameters.
35559 @@ -20,7 +22,7 @@
35560 * service functions will comply with gcc calling convention, too.
35561 */
35562
35563 -.text
35564 +__INIT
35565 ENTRY(efi_call_phys)
35566 /*
35567 * 0. The function can only be called in Linux kernel. So CS has been
35568 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
35569 * The mapping of lower virtual memory has been created in prelog and
35570 * epilog.
35571 */
35572 - movl $1f, %edx
35573 - subl $__PAGE_OFFSET, %edx
35574 - jmp *%edx
35575 +#ifdef CONFIG_PAX_KERNEXEC
35576 + movl $(__KERNEXEC_EFI_DS), %edx
35577 + mov %edx, %ds
35578 + mov %edx, %es
35579 + mov %edx, %ss
35580 + addl $2f,(1f)
35581 + ljmp *(1f)
35582 +
35583 +__INITDATA
35584 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
35585 +.previous
35586 +
35587 +2:
35588 + subl $2b,(1b)
35589 +#else
35590 + jmp 1f-__PAGE_OFFSET
35591 1:
35592 +#endif
35593
35594 /*
35595 * 2. Now on the top of stack is the return
35596 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
35597 * parameter 2, ..., param n. To make things easy, we save the return
35598 * address of efi_call_phys in a global variable.
35599 */
35600 - popl %edx
35601 - movl %edx, saved_return_addr
35602 - /* get the function pointer into ECX*/
35603 - popl %ecx
35604 - movl %ecx, efi_rt_function_ptr
35605 - movl $2f, %edx
35606 - subl $__PAGE_OFFSET, %edx
35607 - pushl %edx
35608 + popl (saved_return_addr)
35609 + popl (efi_rt_function_ptr)
35610
35611 /*
35612 * 3. Clear PG bit in %CR0.
35613 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
35614 /*
35615 * 5. Call the physical function.
35616 */
35617 - jmp *%ecx
35618 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
35619
35620 -2:
35621 /*
35622 * 6. After EFI runtime service returns, control will return to
35623 * following instruction. We'd better readjust stack pointer first.
35624 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
35625 movl %cr0, %edx
35626 orl $0x80000000, %edx
35627 movl %edx, %cr0
35628 - jmp 1f
35629 -1:
35630 +
35631 /*
35632 * 8. Now restore the virtual mode from flat mode by
35633 * adding EIP with PAGE_OFFSET.
35634 */
35635 - movl $1f, %edx
35636 - jmp *%edx
35637 +#ifdef CONFIG_PAX_KERNEXEC
35638 + movl $(__KERNEL_DS), %edx
35639 + mov %edx, %ds
35640 + mov %edx, %es
35641 + mov %edx, %ss
35642 + ljmp $(__KERNEL_CS),$1f
35643 +#else
35644 + jmp 1f+__PAGE_OFFSET
35645 +#endif
35646 1:
35647
35648 /*
35649 * 9. Balance the stack. And because EAX contain the return value,
35650 * we'd better not clobber it.
35651 */
35652 - leal efi_rt_function_ptr, %edx
35653 - movl (%edx), %ecx
35654 - pushl %ecx
35655 + pushl (efi_rt_function_ptr)
35656
35657 /*
35658 - * 10. Push the saved return address onto the stack and return.
35659 + * 10. Return to the saved return address.
35660 */
35661 - leal saved_return_addr, %edx
35662 - movl (%edx), %ecx
35663 - pushl %ecx
35664 - ret
35665 + jmpl *(saved_return_addr)
35666 ENDPROC(efi_call_phys)
35667 .previous
35668
35669 -.data
35670 +__INITDATA
35671 saved_return_addr:
35672 .long 0
35673 efi_rt_function_ptr:
35674 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
35675 index 5fcda72..cd4dc41 100644
35676 --- a/arch/x86/platform/efi/efi_stub_64.S
35677 +++ b/arch/x86/platform/efi/efi_stub_64.S
35678 @@ -11,6 +11,7 @@
35679 #include <asm/msr.h>
35680 #include <asm/processor-flags.h>
35681 #include <asm/page_types.h>
35682 +#include <asm/alternative-asm.h>
35683
35684 #define SAVE_XMM \
35685 mov %rsp, %rax; \
35686 @@ -88,6 +89,7 @@ ENTRY(efi_call)
35687 RESTORE_PGT
35688 addq $48, %rsp
35689 RESTORE_XMM
35690 + pax_force_retaddr 0, 1
35691 ret
35692 ENDPROC(efi_call)
35693
35694 @@ -245,8 +247,8 @@ efi_gdt64:
35695 .long 0 /* Filled out by user */
35696 .word 0
35697 .quad 0x0000000000000000 /* NULL descriptor */
35698 - .quad 0x00af9a000000ffff /* __KERNEL_CS */
35699 - .quad 0x00cf92000000ffff /* __KERNEL_DS */
35700 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
35701 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
35702 .quad 0x0080890000000000 /* TS descriptor */
35703 .quad 0x0000000000000000 /* TS continued */
35704 efi_gdt64_end:
35705 diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
35706 index 1bbedc4..eb795b5 100644
35707 --- a/arch/x86/platform/intel-mid/intel-mid.c
35708 +++ b/arch/x86/platform/intel-mid/intel-mid.c
35709 @@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
35710 {
35711 };
35712
35713 -static void intel_mid_reboot(void)
35714 +static void __noreturn intel_mid_reboot(void)
35715 {
35716 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
35717 + BUG();
35718 }
35719
35720 static unsigned long __init intel_mid_calibrate_tsc(void)
35721 diff --git a/arch/x86/platform/intel-mid/intel_mid_weak_decls.h b/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
35722 index 46aa25c..59a68ed 100644
35723 --- a/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
35724 +++ b/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
35725 @@ -10,10 +10,9 @@
35726 */
35727
35728
35729 -/* __attribute__((weak)) makes these declarations overridable */
35730 /* For every CPU addition a new get_<cpuname>_ops interface needs
35731 * to be added.
35732 */
35733 -extern void *get_penwell_ops(void) __attribute__((weak));
35734 -extern void *get_cloverview_ops(void) __attribute__((weak));
35735 -extern void *get_tangier_ops(void) __attribute__((weak));
35736 +extern const void *get_penwell_ops(void);
35737 +extern const void *get_cloverview_ops(void);
35738 +extern const void *get_tangier_ops(void);
35739 diff --git a/arch/x86/platform/intel-mid/mfld.c b/arch/x86/platform/intel-mid/mfld.c
35740 index 23381d2..8ddc10e 100644
35741 --- a/arch/x86/platform/intel-mid/mfld.c
35742 +++ b/arch/x86/platform/intel-mid/mfld.c
35743 @@ -64,12 +64,12 @@ static void __init penwell_arch_setup(void)
35744 pm_power_off = mfld_power_off;
35745 }
35746
35747 -void *get_penwell_ops(void)
35748 +const void *get_penwell_ops(void)
35749 {
35750 return &penwell_ops;
35751 }
35752
35753 -void *get_cloverview_ops(void)
35754 +const void *get_cloverview_ops(void)
35755 {
35756 return &penwell_ops;
35757 }
35758 diff --git a/arch/x86/platform/intel-mid/mrfl.c b/arch/x86/platform/intel-mid/mrfl.c
35759 index aaca917..66eadbc 100644
35760 --- a/arch/x86/platform/intel-mid/mrfl.c
35761 +++ b/arch/x86/platform/intel-mid/mrfl.c
35762 @@ -97,7 +97,7 @@ static struct intel_mid_ops tangier_ops = {
35763 .arch_setup = tangier_arch_setup,
35764 };
35765
35766 -void *get_tangier_ops(void)
35767 +const void *get_tangier_ops(void)
35768 {
35769 return &tangier_ops;
35770 }
35771 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
35772 index d6ee929..3637cb5 100644
35773 --- a/arch/x86/platform/olpc/olpc_dt.c
35774 +++ b/arch/x86/platform/olpc/olpc_dt.c
35775 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
35776 return res;
35777 }
35778
35779 -static struct of_pdt_ops prom_olpc_ops __initdata = {
35780 +static struct of_pdt_ops prom_olpc_ops __initconst = {
35781 .nextprop = olpc_dt_nextprop,
35782 .getproplen = olpc_dt_getproplen,
35783 .getproperty = olpc_dt_getproperty,
35784 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
35785 index 6ec7910..ecdbb11 100644
35786 --- a/arch/x86/power/cpu.c
35787 +++ b/arch/x86/power/cpu.c
35788 @@ -137,11 +137,8 @@ static void do_fpu_end(void)
35789 static void fix_processor_context(void)
35790 {
35791 int cpu = smp_processor_id();
35792 - struct tss_struct *t = &per_cpu(init_tss, cpu);
35793 -#ifdef CONFIG_X86_64
35794 - struct desc_struct *desc = get_cpu_gdt_table(cpu);
35795 - tss_desc tss;
35796 -#endif
35797 + struct tss_struct *t = init_tss + cpu;
35798 +
35799 set_tss_desc(cpu, t); /*
35800 * This just modifies memory; should not be
35801 * necessary. But... This is necessary, because
35802 @@ -150,10 +147,6 @@ static void fix_processor_context(void)
35803 */
35804
35805 #ifdef CONFIG_X86_64
35806 - memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
35807 - tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
35808 - write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
35809 -
35810 syscall_init(); /* This sets MSR_*STAR and related */
35811 #endif
35812 load_TR_desc(); /* This does ltr */
35813 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
35814 index bad628a..a102610 100644
35815 --- a/arch/x86/realmode/init.c
35816 +++ b/arch/x86/realmode/init.c
35817 @@ -68,7 +68,13 @@ void __init setup_real_mode(void)
35818 __va(real_mode_header->trampoline_header);
35819
35820 #ifdef CONFIG_X86_32
35821 - trampoline_header->start = __pa_symbol(startup_32_smp);
35822 + trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
35823 +
35824 +#ifdef CONFIG_PAX_KERNEXEC
35825 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
35826 +#endif
35827 +
35828 + trampoline_header->boot_cs = __BOOT_CS;
35829 trampoline_header->gdt_limit = __BOOT_DS + 7;
35830 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
35831 #else
35832 @@ -84,7 +90,7 @@ void __init setup_real_mode(void)
35833 *trampoline_cr4_features = read_cr4();
35834
35835 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
35836 - trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
35837 + trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
35838 trampoline_pgd[511] = init_level4_pgt[511].pgd;
35839 #endif
35840 }
35841 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
35842 index 7c0d7be..d24dc88 100644
35843 --- a/arch/x86/realmode/rm/Makefile
35844 +++ b/arch/x86/realmode/rm/Makefile
35845 @@ -67,5 +67,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
35846
35847 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
35848 -I$(srctree)/arch/x86/boot
35849 +ifdef CONSTIFY_PLUGIN
35850 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
35851 +endif
35852 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
35853 GCOV_PROFILE := n
35854 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
35855 index a28221d..93c40f1 100644
35856 --- a/arch/x86/realmode/rm/header.S
35857 +++ b/arch/x86/realmode/rm/header.S
35858 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
35859 #endif
35860 /* APM/BIOS reboot */
35861 .long pa_machine_real_restart_asm
35862 -#ifdef CONFIG_X86_64
35863 +#ifdef CONFIG_X86_32
35864 + .long __KERNEL_CS
35865 +#else
35866 .long __KERNEL32_CS
35867 #endif
35868 END(real_mode_header)
35869 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
35870 index 48ddd76..c26749f 100644
35871 --- a/arch/x86/realmode/rm/trampoline_32.S
35872 +++ b/arch/x86/realmode/rm/trampoline_32.S
35873 @@ -24,6 +24,12 @@
35874 #include <asm/page_types.h>
35875 #include "realmode.h"
35876
35877 +#ifdef CONFIG_PAX_KERNEXEC
35878 +#define ta(X) (X)
35879 +#else
35880 +#define ta(X) (pa_ ## X)
35881 +#endif
35882 +
35883 .text
35884 .code16
35885
35886 @@ -38,8 +44,6 @@ ENTRY(trampoline_start)
35887
35888 cli # We should be safe anyway
35889
35890 - movl tr_start, %eax # where we need to go
35891 -
35892 movl $0xA5A5A5A5, trampoline_status
35893 # write marker for master knows we're running
35894
35895 @@ -55,7 +59,7 @@ ENTRY(trampoline_start)
35896 movw $1, %dx # protected mode (PE) bit
35897 lmsw %dx # into protected mode
35898
35899 - ljmpl $__BOOT_CS, $pa_startup_32
35900 + ljmpl *(trampoline_header)
35901
35902 .section ".text32","ax"
35903 .code32
35904 @@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
35905 .balign 8
35906 GLOBAL(trampoline_header)
35907 tr_start: .space 4
35908 - tr_gdt_pad: .space 2
35909 + tr_boot_cs: .space 2
35910 tr_gdt: .space 6
35911 END(trampoline_header)
35912
35913 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
35914 index dac7b20..72dbaca 100644
35915 --- a/arch/x86/realmode/rm/trampoline_64.S
35916 +++ b/arch/x86/realmode/rm/trampoline_64.S
35917 @@ -93,6 +93,7 @@ ENTRY(startup_32)
35918 movl %edx, %gs
35919
35920 movl pa_tr_cr4, %eax
35921 + andl $~X86_CR4_PCIDE, %eax
35922 movl %eax, %cr4 # Enable PAE mode
35923
35924 # Setup trampoline 4 level pagetables
35925 @@ -106,7 +107,7 @@ ENTRY(startup_32)
35926 wrmsr
35927
35928 # Enable paging and in turn activate Long Mode
35929 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
35930 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
35931 movl %eax, %cr0
35932
35933 /*
35934 diff --git a/arch/x86/realmode/rm/wakeup_asm.S b/arch/x86/realmode/rm/wakeup_asm.S
35935 index 9e7e147..25a4158 100644
35936 --- a/arch/x86/realmode/rm/wakeup_asm.S
35937 +++ b/arch/x86/realmode/rm/wakeup_asm.S
35938 @@ -126,11 +126,10 @@ ENTRY(wakeup_start)
35939 lgdtl pmode_gdt
35940
35941 /* This really couldn't... */
35942 - movl pmode_entry, %eax
35943 movl pmode_cr0, %ecx
35944 movl %ecx, %cr0
35945 - ljmpl $__KERNEL_CS, $pa_startup_32
35946 - /* -> jmp *%eax in trampoline_32.S */
35947 +
35948 + ljmpl *pmode_entry
35949 #else
35950 jmp trampoline_start
35951 #endif
35952 diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
35953 index 604a37e..e49702a 100644
35954 --- a/arch/x86/tools/Makefile
35955 +++ b/arch/x86/tools/Makefile
35956 @@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
35957
35958 $(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
35959
35960 -HOST_EXTRACFLAGS += -I$(srctree)/tools/include
35961 +HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
35962 hostprogs-y += relocs
35963 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
35964 PHONY += relocs
35965 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
35966 index bbb1d22..e505211 100644
35967 --- a/arch/x86/tools/relocs.c
35968 +++ b/arch/x86/tools/relocs.c
35969 @@ -1,5 +1,7 @@
35970 /* This is included from relocs_32/64.c */
35971
35972 +#include "../../../include/generated/autoconf.h"
35973 +
35974 #define ElfW(type) _ElfW(ELF_BITS, type)
35975 #define _ElfW(bits, type) __ElfW(bits, type)
35976 #define __ElfW(bits, type) Elf##bits##_##type
35977 @@ -11,6 +13,7 @@
35978 #define Elf_Sym ElfW(Sym)
35979
35980 static Elf_Ehdr ehdr;
35981 +static Elf_Phdr *phdr;
35982
35983 struct relocs {
35984 uint32_t *offset;
35985 @@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
35986 }
35987 }
35988
35989 +static void read_phdrs(FILE *fp)
35990 +{
35991 + unsigned int i;
35992 +
35993 + phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
35994 + if (!phdr) {
35995 + die("Unable to allocate %d program headers\n",
35996 + ehdr.e_phnum);
35997 + }
35998 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
35999 + die("Seek to %d failed: %s\n",
36000 + ehdr.e_phoff, strerror(errno));
36001 + }
36002 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
36003 + die("Cannot read ELF program headers: %s\n",
36004 + strerror(errno));
36005 + }
36006 + for(i = 0; i < ehdr.e_phnum; i++) {
36007 + phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
36008 + phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
36009 + phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
36010 + phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
36011 + phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
36012 + phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
36013 + phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
36014 + phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
36015 + }
36016 +
36017 +}
36018 +
36019 static void read_shdrs(FILE *fp)
36020 {
36021 - int i;
36022 + unsigned int i;
36023 Elf_Shdr shdr;
36024
36025 secs = calloc(ehdr.e_shnum, sizeof(struct section));
36026 @@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
36027
36028 static void read_strtabs(FILE *fp)
36029 {
36030 - int i;
36031 + unsigned int i;
36032 for (i = 0; i < ehdr.e_shnum; i++) {
36033 struct section *sec = &secs[i];
36034 if (sec->shdr.sh_type != SHT_STRTAB) {
36035 @@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
36036
36037 static void read_symtabs(FILE *fp)
36038 {
36039 - int i,j;
36040 + unsigned int i,j;
36041 for (i = 0; i < ehdr.e_shnum; i++) {
36042 struct section *sec = &secs[i];
36043 if (sec->shdr.sh_type != SHT_SYMTAB) {
36044 @@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
36045 }
36046
36047
36048 -static void read_relocs(FILE *fp)
36049 +static void read_relocs(FILE *fp, int use_real_mode)
36050 {
36051 - int i,j;
36052 + unsigned int i,j;
36053 + uint32_t base;
36054 +
36055 for (i = 0; i < ehdr.e_shnum; i++) {
36056 struct section *sec = &secs[i];
36057 if (sec->shdr.sh_type != SHT_REL_TYPE) {
36058 @@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
36059 die("Cannot read symbol table: %s\n",
36060 strerror(errno));
36061 }
36062 + base = 0;
36063 +
36064 +#ifdef CONFIG_X86_32
36065 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
36066 + if (phdr[j].p_type != PT_LOAD )
36067 + continue;
36068 + 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)
36069 + continue;
36070 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
36071 + break;
36072 + }
36073 +#endif
36074 +
36075 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
36076 Elf_Rel *rel = &sec->reltab[j];
36077 - rel->r_offset = elf_addr_to_cpu(rel->r_offset);
36078 + rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
36079 rel->r_info = elf_xword_to_cpu(rel->r_info);
36080 #if (SHT_REL_TYPE == SHT_RELA)
36081 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
36082 @@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
36083
36084 static void print_absolute_symbols(void)
36085 {
36086 - int i;
36087 + unsigned int i;
36088 const char *format;
36089
36090 if (ELF_BITS == 64)
36091 @@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
36092 for (i = 0; i < ehdr.e_shnum; i++) {
36093 struct section *sec = &secs[i];
36094 char *sym_strtab;
36095 - int j;
36096 + unsigned int j;
36097
36098 if (sec->shdr.sh_type != SHT_SYMTAB) {
36099 continue;
36100 @@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
36101
36102 static void print_absolute_relocs(void)
36103 {
36104 - int i, printed = 0;
36105 + unsigned int i, printed = 0;
36106 const char *format;
36107
36108 if (ELF_BITS == 64)
36109 @@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
36110 struct section *sec_applies, *sec_symtab;
36111 char *sym_strtab;
36112 Elf_Sym *sh_symtab;
36113 - int j;
36114 + unsigned int j;
36115 if (sec->shdr.sh_type != SHT_REL_TYPE) {
36116 continue;
36117 }
36118 @@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
36119 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
36120 Elf_Sym *sym, const char *symname))
36121 {
36122 - int i;
36123 + unsigned int i;
36124 /* Walk through the relocations */
36125 for (i = 0; i < ehdr.e_shnum; i++) {
36126 char *sym_strtab;
36127 Elf_Sym *sh_symtab;
36128 struct section *sec_applies, *sec_symtab;
36129 - int j;
36130 + unsigned int j;
36131 struct section *sec = &secs[i];
36132
36133 if (sec->shdr.sh_type != SHT_REL_TYPE) {
36134 @@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
36135 {
36136 unsigned r_type = ELF32_R_TYPE(rel->r_info);
36137 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
36138 + char *sym_strtab = sec->link->link->strtab;
36139 +
36140 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
36141 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
36142 + return 0;
36143 +
36144 +#ifdef CONFIG_PAX_KERNEXEC
36145 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
36146 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
36147 + return 0;
36148 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
36149 + return 0;
36150 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
36151 + return 0;
36152 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
36153 + return 0;
36154 +#endif
36155
36156 switch (r_type) {
36157 case R_386_NONE:
36158 @@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
36159
36160 static void emit_relocs(int as_text, int use_real_mode)
36161 {
36162 - int i;
36163 + unsigned int i;
36164 int (*write_reloc)(uint32_t, FILE *) = write32;
36165 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
36166 const char *symname);
36167 @@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
36168 {
36169 regex_init(use_real_mode);
36170 read_ehdr(fp);
36171 + read_phdrs(fp);
36172 read_shdrs(fp);
36173 read_strtabs(fp);
36174 read_symtabs(fp);
36175 - read_relocs(fp);
36176 + read_relocs(fp, use_real_mode);
36177 if (ELF_BITS == 64)
36178 percpu_init();
36179 if (show_absolute_syms) {
36180 diff --git a/arch/x86/um/mem_32.c b/arch/x86/um/mem_32.c
36181 index f40281e..92728c9 100644
36182 --- a/arch/x86/um/mem_32.c
36183 +++ b/arch/x86/um/mem_32.c
36184 @@ -21,7 +21,7 @@ static int __init gate_vma_init(void)
36185 gate_vma.vm_start = FIXADDR_USER_START;
36186 gate_vma.vm_end = FIXADDR_USER_END;
36187 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
36188 - gate_vma.vm_page_prot = __P101;
36189 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
36190
36191 return 0;
36192 }
36193 diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
36194 index 80ffa5b..a33bd15 100644
36195 --- a/arch/x86/um/tls_32.c
36196 +++ b/arch/x86/um/tls_32.c
36197 @@ -260,7 +260,7 @@ out:
36198 if (unlikely(task == current &&
36199 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
36200 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
36201 - "without flushed TLS.", current->pid);
36202 + "without flushed TLS.", task_pid_nr(current));
36203 }
36204
36205 return 0;
36206 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
36207 index 5a4affe..9e2d522 100644
36208 --- a/arch/x86/vdso/Makefile
36209 +++ b/arch/x86/vdso/Makefile
36210 @@ -174,7 +174,7 @@ quiet_cmd_vdso = VDSO $@
36211 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
36212 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
36213
36214 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
36215 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
36216 $(call cc-ldoption, -Wl$(comma)--build-id) -Wl,-Bsymbolic $(LTO_CFLAGS)
36217 GCOV_PROFILE := n
36218
36219 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
36220 index e904c27..b9eaa03 100644
36221 --- a/arch/x86/vdso/vdso32-setup.c
36222 +++ b/arch/x86/vdso/vdso32-setup.c
36223 @@ -14,6 +14,7 @@
36224 #include <asm/cpufeature.h>
36225 #include <asm/processor.h>
36226 #include <asm/vdso.h>
36227 +#include <asm/mman.h>
36228
36229 #ifdef CONFIG_COMPAT_VDSO
36230 #define VDSO_DEFAULT 0
36231 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
36232 index 970463b..da82d3e 100644
36233 --- a/arch/x86/vdso/vma.c
36234 +++ b/arch/x86/vdso/vma.c
36235 @@ -16,10 +16,9 @@
36236 #include <asm/vdso.h>
36237 #include <asm/page.h>
36238 #include <asm/hpet.h>
36239 +#include <asm/mman.h>
36240
36241 #if defined(CONFIG_X86_64)
36242 -unsigned int __read_mostly vdso64_enabled = 1;
36243 -
36244 extern unsigned short vdso_sync_cpuid;
36245 #endif
36246
36247 @@ -101,6 +100,11 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
36248 .pages = no_pages,
36249 };
36250
36251 +#ifdef CONFIG_PAX_RANDMMAP
36252 + if (mm->pax_flags & MF_PAX_RANDMMAP)
36253 + calculate_addr = false;
36254 +#endif
36255 +
36256 if (calculate_addr) {
36257 addr = vdso_addr(current->mm->start_stack,
36258 image->size - image->sym_vvar_start);
36259 @@ -111,14 +115,14 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
36260 down_write(&mm->mmap_sem);
36261
36262 addr = get_unmapped_area(NULL, addr,
36263 - image->size - image->sym_vvar_start, 0, 0);
36264 + image->size - image->sym_vvar_start, 0, MAP_EXECUTABLE);
36265 if (IS_ERR_VALUE(addr)) {
36266 ret = addr;
36267 goto up_fail;
36268 }
36269
36270 text_start = addr - image->sym_vvar_start;
36271 - current->mm->context.vdso = (void __user *)text_start;
36272 + mm->context.vdso = text_start;
36273
36274 /*
36275 * MAYWRITE to allow gdb to COW and set breakpoints
36276 @@ -163,15 +167,12 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
36277 hpet_address >> PAGE_SHIFT,
36278 PAGE_SIZE,
36279 pgprot_noncached(PAGE_READONLY));
36280 -
36281 - if (ret)
36282 - goto up_fail;
36283 }
36284 #endif
36285
36286 up_fail:
36287 if (ret)
36288 - current->mm->context.vdso = NULL;
36289 + current->mm->context.vdso = 0;
36290
36291 up_write(&mm->mmap_sem);
36292 return ret;
36293 @@ -191,8 +192,8 @@ static int load_vdso32(void)
36294
36295 if (selected_vdso32->sym_VDSO32_SYSENTER_RETURN)
36296 current_thread_info()->sysenter_return =
36297 - current->mm->context.vdso +
36298 - selected_vdso32->sym_VDSO32_SYSENTER_RETURN;
36299 + (void __force_user *)(current->mm->context.vdso +
36300 + selected_vdso32->sym_VDSO32_SYSENTER_RETURN);
36301
36302 return 0;
36303 }
36304 @@ -201,9 +202,6 @@ static int load_vdso32(void)
36305 #ifdef CONFIG_X86_64
36306 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
36307 {
36308 - if (!vdso64_enabled)
36309 - return 0;
36310 -
36311 return map_vdso(&vdso_image_64, true);
36312 }
36313
36314 @@ -212,12 +210,8 @@ int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
36315 int uses_interp)
36316 {
36317 #ifdef CONFIG_X86_X32_ABI
36318 - if (test_thread_flag(TIF_X32)) {
36319 - if (!vdso64_enabled)
36320 - return 0;
36321 -
36322 + if (test_thread_flag(TIF_X32))
36323 return map_vdso(&vdso_image_x32, true);
36324 - }
36325 #endif
36326
36327 return load_vdso32();
36328 @@ -229,12 +223,3 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
36329 return load_vdso32();
36330 }
36331 #endif
36332 -
36333 -#ifdef CONFIG_X86_64
36334 -static __init int vdso_setup(char *s)
36335 -{
36336 - vdso64_enabled = simple_strtoul(s, NULL, 0);
36337 - return 0;
36338 -}
36339 -__setup("vdso=", vdso_setup);
36340 -#endif
36341 diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
36342 index e88fda8..76ce7ce 100644
36343 --- a/arch/x86/xen/Kconfig
36344 +++ b/arch/x86/xen/Kconfig
36345 @@ -9,6 +9,7 @@ config XEN
36346 select XEN_HAVE_PVMMU
36347 depends on X86_64 || (X86_32 && X86_PAE)
36348 depends on X86_TSC
36349 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
36350 help
36351 This is the Linux Xen port. Enabling this will allow the
36352 kernel to boot in a paravirtualized environment under the
36353 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
36354 index c0cb11f..bed56ff 100644
36355 --- a/arch/x86/xen/enlighten.c
36356 +++ b/arch/x86/xen/enlighten.c
36357 @@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
36358
36359 struct shared_info xen_dummy_shared_info;
36360
36361 -void *xen_initial_gdt;
36362 -
36363 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
36364 __read_mostly int xen_have_vector_callback;
36365 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
36366 @@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
36367 {
36368 unsigned long va = dtr->address;
36369 unsigned int size = dtr->size + 1;
36370 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
36371 - unsigned long frames[pages];
36372 + unsigned long frames[65536 / PAGE_SIZE];
36373 int f;
36374
36375 /*
36376 @@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
36377 {
36378 unsigned long va = dtr->address;
36379 unsigned int size = dtr->size + 1;
36380 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
36381 - unsigned long frames[pages];
36382 + unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
36383 int f;
36384
36385 /*
36386 @@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
36387 * 8-byte entries, or 16 4k pages..
36388 */
36389
36390 - BUG_ON(size > 65536);
36391 + BUG_ON(size > GDT_SIZE);
36392 BUG_ON(va & ~PAGE_MASK);
36393
36394 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
36395 @@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
36396 return 0;
36397 }
36398
36399 -static void set_xen_basic_apic_ops(void)
36400 +static void __init set_xen_basic_apic_ops(void)
36401 {
36402 apic->read = xen_apic_read;
36403 apic->write = xen_apic_write;
36404 @@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
36405 #endif
36406 };
36407
36408 -static void xen_reboot(int reason)
36409 +static __noreturn void xen_reboot(int reason)
36410 {
36411 struct sched_shutdown r = { .reason = reason };
36412
36413 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
36414 - BUG();
36415 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
36416 + BUG();
36417 }
36418
36419 -static void xen_restart(char *msg)
36420 +static __noreturn void xen_restart(char *msg)
36421 {
36422 xen_reboot(SHUTDOWN_reboot);
36423 }
36424
36425 -static void xen_emergency_restart(void)
36426 +static __noreturn void xen_emergency_restart(void)
36427 {
36428 xen_reboot(SHUTDOWN_reboot);
36429 }
36430
36431 -static void xen_machine_halt(void)
36432 +static __noreturn void xen_machine_halt(void)
36433 {
36434 xen_reboot(SHUTDOWN_poweroff);
36435 }
36436
36437 -static void xen_machine_power_off(void)
36438 +static __noreturn void xen_machine_power_off(void)
36439 {
36440 if (pm_power_off)
36441 pm_power_off();
36442 @@ -1568,7 +1564,17 @@ asmlinkage __visible void __init xen_start_kernel(void)
36443 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
36444
36445 /* Work out if we support NX */
36446 - x86_configure_nx();
36447 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
36448 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
36449 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
36450 + unsigned l, h;
36451 +
36452 + __supported_pte_mask |= _PAGE_NX;
36453 + rdmsr(MSR_EFER, l, h);
36454 + l |= EFER_NX;
36455 + wrmsr(MSR_EFER, l, h);
36456 + }
36457 +#endif
36458
36459 /* Get mfn list */
36460 xen_build_dynamic_phys_to_machine();
36461 @@ -1596,13 +1602,6 @@ asmlinkage __visible void __init xen_start_kernel(void)
36462
36463 machine_ops = xen_machine_ops;
36464
36465 - /*
36466 - * The only reliable way to retain the initial address of the
36467 - * percpu gdt_page is to remember it here, so we can go and
36468 - * mark it RW later, when the initial percpu area is freed.
36469 - */
36470 - xen_initial_gdt = &per_cpu(gdt_page, 0);
36471 -
36472 xen_smp_init();
36473
36474 #ifdef CONFIG_ACPI_NUMA
36475 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
36476 index 16fb009..02b7801 100644
36477 --- a/arch/x86/xen/mmu.c
36478 +++ b/arch/x86/xen/mmu.c
36479 @@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
36480 return val;
36481 }
36482
36483 -static pteval_t pte_pfn_to_mfn(pteval_t val)
36484 +static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
36485 {
36486 if (val & _PAGE_PRESENT) {
36487 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
36488 @@ -1904,7 +1904,11 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
36489 * L3_k[511] -> level2_fixmap_pgt */
36490 convert_pfn_mfn(level3_kernel_pgt);
36491
36492 + convert_pfn_mfn(level3_vmalloc_start_pgt);
36493 + convert_pfn_mfn(level3_vmalloc_end_pgt);
36494 + convert_pfn_mfn(level3_vmemmap_pgt);
36495 /* L3_k[511][506] -> level1_fixmap_pgt */
36496 + /* L3_k[511][507] -> level1_vsyscall_pgt */
36497 convert_pfn_mfn(level2_fixmap_pgt);
36498 }
36499 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
36500 @@ -1929,11 +1933,16 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
36501 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
36502 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
36503 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
36504 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
36505 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
36506 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
36507 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
36508 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
36509 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
36510 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
36511 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
36512 set_page_prot(level1_fixmap_pgt, PAGE_KERNEL_RO);
36513 + set_page_prot(level1_vsyscall_pgt, PAGE_KERNEL_RO);
36514
36515 /* Pin down new L4 */
36516 pin_pagetable_pfn(MMUEXT_PIN_L4_TABLE,
36517 @@ -2117,6 +2126,7 @@ static void __init xen_post_allocator_init(void)
36518 pv_mmu_ops.set_pud = xen_set_pud;
36519 #if PAGETABLE_LEVELS == 4
36520 pv_mmu_ops.set_pgd = xen_set_pgd;
36521 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
36522 #endif
36523
36524 /* This will work as long as patching hasn't happened yet
36525 @@ -2195,6 +2205,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
36526 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
36527 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
36528 .set_pgd = xen_set_pgd_hyper,
36529 + .set_pgd_batched = xen_set_pgd_hyper,
36530
36531 .alloc_pud = xen_alloc_pmd_init,
36532 .release_pud = xen_release_pmd_init,
36533 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
36534 index 7005974..54fb05f 100644
36535 --- a/arch/x86/xen/smp.c
36536 +++ b/arch/x86/xen/smp.c
36537 @@ -283,17 +283,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
36538
36539 if (xen_pv_domain()) {
36540 if (!xen_feature(XENFEAT_writable_page_tables))
36541 - /* We've switched to the "real" per-cpu gdt, so make
36542 - * sure the old memory can be recycled. */
36543 - make_lowmem_page_readwrite(xen_initial_gdt);
36544 -
36545 #ifdef CONFIG_X86_32
36546 /*
36547 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
36548 * expects __USER_DS
36549 */
36550 - loadsegment(ds, __USER_DS);
36551 - loadsegment(es, __USER_DS);
36552 + loadsegment(ds, __KERNEL_DS);
36553 + loadsegment(es, __KERNEL_DS);
36554 #endif
36555
36556 xen_filter_cpu_maps();
36557 @@ -372,7 +368,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
36558 #ifdef CONFIG_X86_32
36559 /* Note: PVH is not yet supported on x86_32. */
36560 ctxt->user_regs.fs = __KERNEL_PERCPU;
36561 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
36562 + savesegment(gs, ctxt->user_regs.gs);
36563 #endif
36564 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
36565
36566 @@ -381,8 +377,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
36567 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
36568 ctxt->flags = VGCF_IN_KERNEL;
36569 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
36570 - ctxt->user_regs.ds = __USER_DS;
36571 - ctxt->user_regs.es = __USER_DS;
36572 + ctxt->user_regs.ds = __KERNEL_DS;
36573 + ctxt->user_regs.es = __KERNEL_DS;
36574 ctxt->user_regs.ss = __KERNEL_DS;
36575
36576 xen_copy_trap_info(ctxt->trap_ctxt);
36577 @@ -437,14 +433,13 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
36578 int rc;
36579
36580 per_cpu(current_task, cpu) = idle;
36581 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
36582 #ifdef CONFIG_X86_32
36583 irq_ctx_init(cpu);
36584 #else
36585 clear_tsk_thread_flag(idle, TIF_FORK);
36586 #endif
36587 - per_cpu(kernel_stack, cpu) =
36588 - (unsigned long)task_stack_page(idle) -
36589 - KERNEL_STACK_OFFSET + THREAD_SIZE;
36590 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
36591
36592 xen_setup_runstate_info(cpu);
36593 xen_setup_timer(cpu);
36594 @@ -720,7 +715,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
36595
36596 void __init xen_smp_init(void)
36597 {
36598 - smp_ops = xen_smp_ops;
36599 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
36600 xen_fill_possible_map();
36601 }
36602
36603 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
36604 index fd92a64..1f72641 100644
36605 --- a/arch/x86/xen/xen-asm_32.S
36606 +++ b/arch/x86/xen/xen-asm_32.S
36607 @@ -99,7 +99,7 @@ ENTRY(xen_iret)
36608 pushw %fs
36609 movl $(__KERNEL_PERCPU), %eax
36610 movl %eax, %fs
36611 - movl %fs:xen_vcpu, %eax
36612 + mov PER_CPU_VAR(xen_vcpu), %eax
36613 POP_FS
36614 #else
36615 movl %ss:xen_vcpu, %eax
36616 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
36617 index 485b695..fda3e7c 100644
36618 --- a/arch/x86/xen/xen-head.S
36619 +++ b/arch/x86/xen/xen-head.S
36620 @@ -39,6 +39,17 @@ ENTRY(startup_xen)
36621 #ifdef CONFIG_X86_32
36622 mov %esi,xen_start_info
36623 mov $init_thread_union+THREAD_SIZE,%esp
36624 +#ifdef CONFIG_SMP
36625 + movl $cpu_gdt_table,%edi
36626 + movl $__per_cpu_load,%eax
36627 + movw %ax,__KERNEL_PERCPU + 2(%edi)
36628 + rorl $16,%eax
36629 + movb %al,__KERNEL_PERCPU + 4(%edi)
36630 + movb %ah,__KERNEL_PERCPU + 7(%edi)
36631 + movl $__per_cpu_end - 1,%eax
36632 + subl $__per_cpu_start,%eax
36633 + movw %ax,__KERNEL_PERCPU + 0(%edi)
36634 +#endif
36635 #else
36636 mov %rsi,xen_start_info
36637 mov $init_thread_union+THREAD_SIZE,%rsp
36638 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
36639 index 28c7e0b..2acfec7 100644
36640 --- a/arch/x86/xen/xen-ops.h
36641 +++ b/arch/x86/xen/xen-ops.h
36642 @@ -10,8 +10,6 @@
36643 extern const char xen_hypervisor_callback[];
36644 extern const char xen_failsafe_callback[];
36645
36646 -extern void *xen_initial_gdt;
36647 -
36648 struct trap_info;
36649 void xen_copy_trap_info(struct trap_info *traps);
36650
36651 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
36652 index 525bd3d..ef888b1 100644
36653 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
36654 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
36655 @@ -119,9 +119,9 @@
36656 ----------------------------------------------------------------------*/
36657
36658 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
36659 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
36660 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
36661 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
36662 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36663
36664 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
36665 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
36666 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
36667 index 2f33760..835e50a 100644
36668 --- a/arch/xtensa/variants/fsf/include/variant/core.h
36669 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
36670 @@ -11,6 +11,7 @@
36671 #ifndef _XTENSA_CORE_H
36672 #define _XTENSA_CORE_H
36673
36674 +#include <linux/const.h>
36675
36676 /****************************************************************************
36677 Parameters Useful for Any Code, USER or PRIVILEGED
36678 @@ -112,9 +113,9 @@
36679 ----------------------------------------------------------------------*/
36680
36681 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
36682 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
36683 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
36684 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
36685 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36686
36687 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
36688 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
36689 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
36690 index af00795..2bb8105 100644
36691 --- a/arch/xtensa/variants/s6000/include/variant/core.h
36692 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
36693 @@ -11,6 +11,7 @@
36694 #ifndef _XTENSA_CORE_CONFIGURATION_H
36695 #define _XTENSA_CORE_CONFIGURATION_H
36696
36697 +#include <linux/const.h>
36698
36699 /****************************************************************************
36700 Parameters Useful for Any Code, USER or PRIVILEGED
36701 @@ -118,9 +119,9 @@
36702 ----------------------------------------------------------------------*/
36703
36704 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
36705 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
36706 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
36707 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
36708 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36709
36710 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
36711 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
36712 diff --git a/block/bio.c b/block/bio.c
36713 index 3e6331d..f970433 100644
36714 --- a/block/bio.c
36715 +++ b/block/bio.c
36716 @@ -1160,7 +1160,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
36717 /*
36718 * Overflow, abort
36719 */
36720 - if (end < start)
36721 + if (end < start || end - start > INT_MAX - nr_pages)
36722 return ERR_PTR(-EINVAL);
36723
36724 nr_pages += end - start;
36725 @@ -1294,7 +1294,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
36726 /*
36727 * Overflow, abort
36728 */
36729 - if (end < start)
36730 + if (end < start || end - start > INT_MAX - nr_pages)
36731 return ERR_PTR(-EINVAL);
36732
36733 nr_pages += end - start;
36734 @@ -1556,7 +1556,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
36735 const int read = bio_data_dir(bio) == READ;
36736 struct bio_map_data *bmd = bio->bi_private;
36737 int i;
36738 - char *p = bmd->sgvecs[0].iov_base;
36739 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
36740
36741 bio_for_each_segment_all(bvec, bio, i) {
36742 char *addr = page_address(bvec->bv_page);
36743 diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
36744 index e17da94..e01cce1 100644
36745 --- a/block/blk-cgroup.c
36746 +++ b/block/blk-cgroup.c
36747 @@ -822,7 +822,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
36748 static struct cgroup_subsys_state *
36749 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
36750 {
36751 - static atomic64_t id_seq = ATOMIC64_INIT(0);
36752 + static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
36753 struct blkcg *blkcg;
36754
36755 if (!parent_css) {
36756 @@ -836,7 +836,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
36757
36758 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
36759 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
36760 - blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
36761 + blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
36762 done:
36763 spin_lock_init(&blkcg->lock);
36764 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
36765 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
36766 index 0736729..2ec3b48 100644
36767 --- a/block/blk-iopoll.c
36768 +++ b/block/blk-iopoll.c
36769 @@ -74,7 +74,7 @@ void blk_iopoll_complete(struct blk_iopoll *iop)
36770 }
36771 EXPORT_SYMBOL(blk_iopoll_complete);
36772
36773 -static void blk_iopoll_softirq(struct softirq_action *h)
36774 +static __latent_entropy void blk_iopoll_softirq(void)
36775 {
36776 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
36777 int rearm = 0, budget = blk_iopoll_budget;
36778 diff --git a/block/blk-map.c b/block/blk-map.c
36779 index f890d43..97b0482 100644
36780 --- a/block/blk-map.c
36781 +++ b/block/blk-map.c
36782 @@ -300,7 +300,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
36783 if (!len || !kbuf)
36784 return -EINVAL;
36785
36786 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
36787 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
36788 if (do_copy)
36789 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
36790 else
36791 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
36792 index 53b1737..08177d2e 100644
36793 --- a/block/blk-softirq.c
36794 +++ b/block/blk-softirq.c
36795 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
36796 * Softirq action handler - move entries to local list and loop over them
36797 * while passing them to the queue registered handler.
36798 */
36799 -static void blk_done_softirq(struct softirq_action *h)
36800 +static __latent_entropy void blk_done_softirq(void)
36801 {
36802 struct list_head *cpu_list, local_list;
36803
36804 diff --git a/block/bsg.c b/block/bsg.c
36805 index ff46add..c4ba8ee 100644
36806 --- a/block/bsg.c
36807 +++ b/block/bsg.c
36808 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
36809 struct sg_io_v4 *hdr, struct bsg_device *bd,
36810 fmode_t has_write_perm)
36811 {
36812 + unsigned char tmpcmd[sizeof(rq->__cmd)];
36813 + unsigned char *cmdptr;
36814 +
36815 if (hdr->request_len > BLK_MAX_CDB) {
36816 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
36817 if (!rq->cmd)
36818 return -ENOMEM;
36819 - }
36820 + cmdptr = rq->cmd;
36821 + } else
36822 + cmdptr = tmpcmd;
36823
36824 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
36825 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
36826 hdr->request_len))
36827 return -EFAULT;
36828
36829 + if (cmdptr != rq->cmd)
36830 + memcpy(rq->cmd, cmdptr, hdr->request_len);
36831 +
36832 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
36833 if (blk_verify_command(rq->cmd, has_write_perm))
36834 return -EPERM;
36835 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
36836 index 18b282c..050dbe5 100644
36837 --- a/block/compat_ioctl.c
36838 +++ b/block/compat_ioctl.c
36839 @@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
36840 cgc = compat_alloc_user_space(sizeof(*cgc));
36841 cgc32 = compat_ptr(arg);
36842
36843 - if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
36844 + if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
36845 get_user(data, &cgc32->buffer) ||
36846 put_user(compat_ptr(data), &cgc->buffer) ||
36847 copy_in_user(&cgc->buflen, &cgc32->buflen,
36848 @@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
36849 err |= __get_user(f->spec1, &uf->spec1);
36850 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
36851 err |= __get_user(name, &uf->name);
36852 - f->name = compat_ptr(name);
36853 + f->name = (void __force_kernel *)compat_ptr(name);
36854 if (err) {
36855 err = -EFAULT;
36856 goto out;
36857 diff --git a/block/genhd.c b/block/genhd.c
36858 index e6723bd..703e4ac 100644
36859 --- a/block/genhd.c
36860 +++ b/block/genhd.c
36861 @@ -469,21 +469,24 @@ static char *bdevt_str(dev_t devt, char *buf)
36862
36863 /*
36864 * Register device numbers dev..(dev+range-1)
36865 - * range must be nonzero
36866 + * Noop if @range is zero.
36867 * The hash chain is sorted on range, so that subranges can override.
36868 */
36869 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
36870 struct kobject *(*probe)(dev_t, int *, void *),
36871 int (*lock)(dev_t, void *), void *data)
36872 {
36873 - kobj_map(bdev_map, devt, range, module, probe, lock, data);
36874 + if (range)
36875 + kobj_map(bdev_map, devt, range, module, probe, lock, data);
36876 }
36877
36878 EXPORT_SYMBOL(blk_register_region);
36879
36880 +/* undo blk_register_region(), noop if @range is zero */
36881 void blk_unregister_region(dev_t devt, unsigned long range)
36882 {
36883 - kobj_unmap(bdev_map, devt, range);
36884 + if (range)
36885 + kobj_unmap(bdev_map, devt, range);
36886 }
36887
36888 EXPORT_SYMBOL(blk_unregister_region);
36889 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
36890 index 56d08fd..2e07090 100644
36891 --- a/block/partitions/efi.c
36892 +++ b/block/partitions/efi.c
36893 @@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
36894 if (!gpt)
36895 return NULL;
36896
36897 + if (!le32_to_cpu(gpt->num_partition_entries))
36898 + return NULL;
36899 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
36900 + if (!pte)
36901 + return NULL;
36902 +
36903 count = le32_to_cpu(gpt->num_partition_entries) *
36904 le32_to_cpu(gpt->sizeof_partition_entry);
36905 - if (!count)
36906 - return NULL;
36907 - pte = kmalloc(count, GFP_KERNEL);
36908 - if (!pte)
36909 - return NULL;
36910 -
36911 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
36912 (u8 *) pte, count) < count) {
36913 kfree(pte);
36914 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
36915 index a6d6270..c4bb72f 100644
36916 --- a/block/scsi_ioctl.c
36917 +++ b/block/scsi_ioctl.c
36918 @@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
36919 return put_user(0, p);
36920 }
36921
36922 -static int sg_get_timeout(struct request_queue *q)
36923 +static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
36924 {
36925 return jiffies_to_clock_t(q->sg_timeout);
36926 }
36927 @@ -227,8 +227,20 @@ EXPORT_SYMBOL(blk_verify_command);
36928 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
36929 struct sg_io_hdr *hdr, fmode_t mode)
36930 {
36931 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
36932 + unsigned char tmpcmd[sizeof(rq->__cmd)];
36933 + unsigned char *cmdptr;
36934 +
36935 + if (rq->cmd != rq->__cmd)
36936 + cmdptr = rq->cmd;
36937 + else
36938 + cmdptr = tmpcmd;
36939 +
36940 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
36941 return -EFAULT;
36942 +
36943 + if (cmdptr != rq->cmd)
36944 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
36945 +
36946 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
36947 return -EPERM;
36948
36949 @@ -432,6 +444,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36950 int err;
36951 unsigned int in_len, out_len, bytes, opcode, cmdlen;
36952 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
36953 + unsigned char tmpcmd[sizeof(rq->__cmd)];
36954 + unsigned char *cmdptr;
36955
36956 if (!sic)
36957 return -EINVAL;
36958 @@ -470,9 +484,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36959 */
36960 err = -EFAULT;
36961 rq->cmd_len = cmdlen;
36962 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
36963 +
36964 + if (rq->cmd != rq->__cmd)
36965 + cmdptr = rq->cmd;
36966 + else
36967 + cmdptr = tmpcmd;
36968 +
36969 + if (copy_from_user(cmdptr, sic->data, cmdlen))
36970 goto error;
36971
36972 + if (rq->cmd != cmdptr)
36973 + memcpy(rq->cmd, cmdptr, cmdlen);
36974 +
36975 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
36976 goto error;
36977
36978 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
36979 index e592c90..c566114 100644
36980 --- a/crypto/cryptd.c
36981 +++ b/crypto/cryptd.c
36982 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
36983
36984 struct cryptd_blkcipher_request_ctx {
36985 crypto_completion_t complete;
36986 -};
36987 +} __no_const;
36988
36989 struct cryptd_hash_ctx {
36990 struct crypto_shash *child;
36991 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
36992
36993 struct cryptd_aead_request_ctx {
36994 crypto_completion_t complete;
36995 -};
36996 +} __no_const;
36997
36998 static void cryptd_queue_worker(struct work_struct *work);
36999
37000 diff --git a/crypto/cts.c b/crypto/cts.c
37001 index 042223f..133f087 100644
37002 --- a/crypto/cts.c
37003 +++ b/crypto/cts.c
37004 @@ -202,7 +202,8 @@ static int cts_cbc_decrypt(struct crypto_cts_ctx *ctx,
37005 /* 5. Append the tail (BB - Ln) bytes of Xn (tmp) to Cn to create En */
37006 memcpy(s + bsize + lastn, tmp + lastn, bsize - lastn);
37007 /* 6. Decrypt En to create Pn-1 */
37008 - memset(iv, 0, sizeof(iv));
37009 + memzero_explicit(iv, sizeof(iv));
37010 +
37011 sg_set_buf(&sgsrc[0], s + bsize, bsize);
37012 sg_set_buf(&sgdst[0], d, bsize);
37013 err = crypto_blkcipher_decrypt_iv(&lcldesc, sgdst, sgsrc, bsize);
37014 diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
37015 index 309d345..1632720 100644
37016 --- a/crypto/pcrypt.c
37017 +++ b/crypto/pcrypt.c
37018 @@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
37019 int ret;
37020
37021 pinst->kobj.kset = pcrypt_kset;
37022 - ret = kobject_add(&pinst->kobj, NULL, name);
37023 + ret = kobject_add(&pinst->kobj, NULL, "%s", name);
37024 if (!ret)
37025 kobject_uevent(&pinst->kobj, KOBJ_ADD);
37026
37027 diff --git a/crypto/sha1_generic.c b/crypto/sha1_generic.c
37028 index 4279480..7bb0474 100644
37029 --- a/crypto/sha1_generic.c
37030 +++ b/crypto/sha1_generic.c
37031 @@ -64,7 +64,7 @@ int crypto_sha1_update(struct shash_desc *desc, const u8 *data,
37032 src = data + done;
37033 } while (done + SHA1_BLOCK_SIZE <= len);
37034
37035 - memset(temp, 0, sizeof(temp));
37036 + memzero_explicit(temp, sizeof(temp));
37037 partial = 0;
37038 }
37039 memcpy(sctx->buffer + partial, src, len - done);
37040 diff --git a/crypto/sha256_generic.c b/crypto/sha256_generic.c
37041 index 5433667..32c5e5e 100644
37042 --- a/crypto/sha256_generic.c
37043 +++ b/crypto/sha256_generic.c
37044 @@ -210,10 +210,9 @@ static void sha256_transform(u32 *state, const u8 *input)
37045
37046 /* clear any sensitive info... */
37047 a = b = c = d = e = f = g = h = t1 = t2 = 0;
37048 - memset(W, 0, 64 * sizeof(u32));
37049 + memzero_explicit(W, 64 * sizeof(u32));
37050 }
37051
37052 -
37053 static int sha224_init(struct shash_desc *desc)
37054 {
37055 struct sha256_state *sctx = shash_desc_ctx(desc);
37056 @@ -316,7 +315,7 @@ static int sha224_final(struct shash_desc *desc, u8 *hash)
37057 sha256_final(desc, D);
37058
37059 memcpy(hash, D, SHA224_DIGEST_SIZE);
37060 - memset(D, 0, SHA256_DIGEST_SIZE);
37061 + memzero_explicit(D, SHA256_DIGEST_SIZE);
37062
37063 return 0;
37064 }
37065 diff --git a/crypto/sha512_generic.c b/crypto/sha512_generic.c
37066 index 6ed124f..04d295a 100644
37067 --- a/crypto/sha512_generic.c
37068 +++ b/crypto/sha512_generic.c
37069 @@ -238,7 +238,7 @@ static int sha384_final(struct shash_desc *desc, u8 *hash)
37070 sha512_final(desc, D);
37071
37072 memcpy(hash, D, 48);
37073 - memset(D, 0, 64);
37074 + memzero_explicit(D, 64);
37075
37076 return 0;
37077 }
37078 diff --git a/crypto/tgr192.c b/crypto/tgr192.c
37079 index 8740355..3c7af0d 100644
37080 --- a/crypto/tgr192.c
37081 +++ b/crypto/tgr192.c
37082 @@ -612,7 +612,7 @@ static int tgr160_final(struct shash_desc *desc, u8 * out)
37083
37084 tgr192_final(desc, D);
37085 memcpy(out, D, TGR160_DIGEST_SIZE);
37086 - memset(D, 0, TGR192_DIGEST_SIZE);
37087 + memzero_explicit(D, TGR192_DIGEST_SIZE);
37088
37089 return 0;
37090 }
37091 @@ -623,7 +623,7 @@ static int tgr128_final(struct shash_desc *desc, u8 * out)
37092
37093 tgr192_final(desc, D);
37094 memcpy(out, D, TGR128_DIGEST_SIZE);
37095 - memset(D, 0, TGR192_DIGEST_SIZE);
37096 + memzero_explicit(D, TGR192_DIGEST_SIZE);
37097
37098 return 0;
37099 }
37100 diff --git a/crypto/vmac.c b/crypto/vmac.c
37101 index 2eb11a3..d84c24b 100644
37102 --- a/crypto/vmac.c
37103 +++ b/crypto/vmac.c
37104 @@ -613,7 +613,7 @@ static int vmac_final(struct shash_desc *pdesc, u8 *out)
37105 }
37106 mac = vmac(ctx->partial, ctx->partial_size, nonce, NULL, ctx);
37107 memcpy(out, &mac, sizeof(vmac_t));
37108 - memset(&mac, 0, sizeof(vmac_t));
37109 + memzero_explicit(&mac, sizeof(vmac_t));
37110 memset(&ctx->__vmac_ctx, 0, sizeof(struct vmac_ctx));
37111 ctx->partial_size = 0;
37112 return 0;
37113 diff --git a/crypto/wp512.c b/crypto/wp512.c
37114 index 180f1d6..ec64e77 100644
37115 --- a/crypto/wp512.c
37116 +++ b/crypto/wp512.c
37117 @@ -1102,8 +1102,8 @@ static int wp384_final(struct shash_desc *desc, u8 *out)
37118 u8 D[64];
37119
37120 wp512_final(desc, D);
37121 - memcpy (out, D, WP384_DIGEST_SIZE);
37122 - memset (D, 0, WP512_DIGEST_SIZE);
37123 + memcpy(out, D, WP384_DIGEST_SIZE);
37124 + memzero_explicit(D, WP512_DIGEST_SIZE);
37125
37126 return 0;
37127 }
37128 @@ -1113,8 +1113,8 @@ static int wp256_final(struct shash_desc *desc, u8 *out)
37129 u8 D[64];
37130
37131 wp512_final(desc, D);
37132 - memcpy (out, D, WP256_DIGEST_SIZE);
37133 - memset (D, 0, WP512_DIGEST_SIZE);
37134 + memcpy(out, D, WP256_DIGEST_SIZE);
37135 + memzero_explicit(D, WP512_DIGEST_SIZE);
37136
37137 return 0;
37138 }
37139 diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
37140 index 6921c7f..78e1af7 100644
37141 --- a/drivers/acpi/acpica/hwxfsleep.c
37142 +++ b/drivers/acpi/acpica/hwxfsleep.c
37143 @@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
37144 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
37145
37146 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
37147 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
37148 - acpi_hw_extended_sleep},
37149 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
37150 - acpi_hw_extended_wake_prep},
37151 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
37152 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
37153 + .extended_function = acpi_hw_extended_sleep},
37154 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
37155 + .extended_function = acpi_hw_extended_wake_prep},
37156 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
37157 + .extended_function = acpi_hw_extended_wake}
37158 };
37159
37160 /*
37161 diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
37162 index 16129c7..8b675cd 100644
37163 --- a/drivers/acpi/apei/apei-internal.h
37164 +++ b/drivers/acpi/apei/apei-internal.h
37165 @@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
37166 struct apei_exec_ins_type {
37167 u32 flags;
37168 apei_exec_ins_func_t run;
37169 -};
37170 +} __do_const;
37171
37172 struct apei_exec_context {
37173 u32 ip;
37174 diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
37175 index fc5f780..e5ac91a 100644
37176 --- a/drivers/acpi/apei/ghes.c
37177 +++ b/drivers/acpi/apei/ghes.c
37178 @@ -478,7 +478,7 @@ static void __ghes_print_estatus(const char *pfx,
37179 const struct acpi_hest_generic *generic,
37180 const struct acpi_hest_generic_status *estatus)
37181 {
37182 - static atomic_t seqno;
37183 + static atomic_unchecked_t seqno;
37184 unsigned int curr_seqno;
37185 char pfx_seq[64];
37186
37187 @@ -489,7 +489,7 @@ static void __ghes_print_estatus(const char *pfx,
37188 else
37189 pfx = KERN_ERR;
37190 }
37191 - curr_seqno = atomic_inc_return(&seqno);
37192 + curr_seqno = atomic_inc_return_unchecked(&seqno);
37193 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
37194 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
37195 pfx_seq, generic->header.source_id);
37196 diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
37197 index a83e3c6..c3d617f 100644
37198 --- a/drivers/acpi/bgrt.c
37199 +++ b/drivers/acpi/bgrt.c
37200 @@ -86,8 +86,10 @@ static int __init bgrt_init(void)
37201 if (!bgrt_image)
37202 return -ENODEV;
37203
37204 - bin_attr_image.private = bgrt_image;
37205 - bin_attr_image.size = bgrt_image_size;
37206 + pax_open_kernel();
37207 + *(void **)&bin_attr_image.private = bgrt_image;
37208 + *(size_t *)&bin_attr_image.size = bgrt_image_size;
37209 + pax_close_kernel();
37210
37211 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
37212 if (!bgrt_kobj)
37213 diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
37214 index 36eb42e..3b2f47e 100644
37215 --- a/drivers/acpi/blacklist.c
37216 +++ b/drivers/acpi/blacklist.c
37217 @@ -51,7 +51,7 @@ struct acpi_blacklist_item {
37218 u32 is_critical_error;
37219 };
37220
37221 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
37222 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
37223
37224 /*
37225 * POLICY: If *anything* doesn't work, put it on the blacklist.
37226 @@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
37227 return 0;
37228 }
37229
37230 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
37231 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
37232 {
37233 .callback = dmi_disable_osi_vista,
37234 .ident = "Fujitsu Siemens",
37235 diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
37236 index c68e724..e863008 100644
37237 --- a/drivers/acpi/custom_method.c
37238 +++ b/drivers/acpi/custom_method.c
37239 @@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
37240 struct acpi_table_header table;
37241 acpi_status status;
37242
37243 +#ifdef CONFIG_GRKERNSEC_KMEM
37244 + return -EPERM;
37245 +#endif
37246 +
37247 if (!(*ppos)) {
37248 /* parse the table header to get the table length */
37249 if (count <= sizeof(struct acpi_table_header))
37250 diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
37251 index 17f9ec5..d9a455e 100644
37252 --- a/drivers/acpi/processor_idle.c
37253 +++ b/drivers/acpi/processor_idle.c
37254 @@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
37255 {
37256 int i, count = CPUIDLE_DRIVER_STATE_START;
37257 struct acpi_processor_cx *cx;
37258 - struct cpuidle_state *state;
37259 + cpuidle_state_no_const *state;
37260 struct cpuidle_driver *drv = &acpi_idle_driver;
37261
37262 if (!pr->flags.power_setup_done)
37263 diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
37264 index 38cb978..352c761 100644
37265 --- a/drivers/acpi/sysfs.c
37266 +++ b/drivers/acpi/sysfs.c
37267 @@ -423,11 +423,11 @@ static u32 num_counters;
37268 static struct attribute **all_attrs;
37269 static u32 acpi_gpe_count;
37270
37271 -static struct attribute_group interrupt_stats_attr_group = {
37272 +static attribute_group_no_const interrupt_stats_attr_group = {
37273 .name = "interrupts",
37274 };
37275
37276 -static struct kobj_attribute *counter_attrs;
37277 +static kobj_attribute_no_const *counter_attrs;
37278
37279 static void delete_gpe_attr_array(void)
37280 {
37281 diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
37282 index b784e9d..a69a049 100644
37283 --- a/drivers/ata/libahci.c
37284 +++ b/drivers/ata/libahci.c
37285 @@ -1252,7 +1252,7 @@ int ahci_kick_engine(struct ata_port *ap)
37286 }
37287 EXPORT_SYMBOL_GPL(ahci_kick_engine);
37288
37289 -static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
37290 +static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
37291 struct ata_taskfile *tf, int is_cmd, u16 flags,
37292 unsigned long timeout_msec)
37293 {
37294 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
37295 index 6f67490..f951ead 100644
37296 --- a/drivers/ata/libata-core.c
37297 +++ b/drivers/ata/libata-core.c
37298 @@ -99,7 +99,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
37299 static void ata_dev_xfermask(struct ata_device *dev);
37300 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
37301
37302 -atomic_t ata_print_id = ATOMIC_INIT(0);
37303 +atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
37304
37305 struct ata_force_param {
37306 const char *name;
37307 @@ -4797,7 +4797,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
37308 struct ata_port *ap;
37309 unsigned int tag;
37310
37311 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
37312 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
37313 ap = qc->ap;
37314
37315 qc->flags = 0;
37316 @@ -4813,7 +4813,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
37317 struct ata_port *ap;
37318 struct ata_link *link;
37319
37320 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
37321 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
37322 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
37323 ap = qc->ap;
37324 link = qc->dev->link;
37325 @@ -5917,6 +5917,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
37326 return;
37327
37328 spin_lock(&lock);
37329 + pax_open_kernel();
37330
37331 for (cur = ops->inherits; cur; cur = cur->inherits) {
37332 void **inherit = (void **)cur;
37333 @@ -5930,8 +5931,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
37334 if (IS_ERR(*pp))
37335 *pp = NULL;
37336
37337 - ops->inherits = NULL;
37338 + *(struct ata_port_operations **)&ops->inherits = NULL;
37339
37340 + pax_close_kernel();
37341 spin_unlock(&lock);
37342 }
37343
37344 @@ -6127,7 +6129,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
37345
37346 /* give ports names and add SCSI hosts */
37347 for (i = 0; i < host->n_ports; i++) {
37348 - host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
37349 + host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
37350 host->ports[i]->local_port_no = i + 1;
37351 }
37352
37353 diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
37354 index 0586f66..1a8f74a 100644
37355 --- a/drivers/ata/libata-scsi.c
37356 +++ b/drivers/ata/libata-scsi.c
37357 @@ -4151,7 +4151,7 @@ int ata_sas_port_init(struct ata_port *ap)
37358
37359 if (rc)
37360 return rc;
37361 - ap->print_id = atomic_inc_return(&ata_print_id);
37362 + ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
37363 return 0;
37364 }
37365 EXPORT_SYMBOL_GPL(ata_sas_port_init);
37366 diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
37367 index 5f4e0cc..ff2c347 100644
37368 --- a/drivers/ata/libata.h
37369 +++ b/drivers/ata/libata.h
37370 @@ -53,7 +53,7 @@ enum {
37371 ATA_DNXFER_QUIET = (1 << 31),
37372 };
37373
37374 -extern atomic_t ata_print_id;
37375 +extern atomic_unchecked_t ata_print_id;
37376 extern int atapi_passthru16;
37377 extern int libata_fua;
37378 extern int libata_noacpi;
37379 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
37380 index 4edb1a8..84e1658 100644
37381 --- a/drivers/ata/pata_arasan_cf.c
37382 +++ b/drivers/ata/pata_arasan_cf.c
37383 @@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
37384 /* Handle platform specific quirks */
37385 if (quirk) {
37386 if (quirk & CF_BROKEN_PIO) {
37387 - ap->ops->set_piomode = NULL;
37388 + pax_open_kernel();
37389 + *(void **)&ap->ops->set_piomode = NULL;
37390 + pax_close_kernel();
37391 ap->pio_mask = 0;
37392 }
37393 if (quirk & CF_BROKEN_MWDMA)
37394 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
37395 index f9b983a..887b9d8 100644
37396 --- a/drivers/atm/adummy.c
37397 +++ b/drivers/atm/adummy.c
37398 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
37399 vcc->pop(vcc, skb);
37400 else
37401 dev_kfree_skb_any(skb);
37402 - atomic_inc(&vcc->stats->tx);
37403 + atomic_inc_unchecked(&vcc->stats->tx);
37404
37405 return 0;
37406 }
37407 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
37408 index f1a9198..f466a4a 100644
37409 --- a/drivers/atm/ambassador.c
37410 +++ b/drivers/atm/ambassador.c
37411 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
37412 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
37413
37414 // VC layer stats
37415 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
37416 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
37417
37418 // free the descriptor
37419 kfree (tx_descr);
37420 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
37421 dump_skb ("<<<", vc, skb);
37422
37423 // VC layer stats
37424 - atomic_inc(&atm_vcc->stats->rx);
37425 + atomic_inc_unchecked(&atm_vcc->stats->rx);
37426 __net_timestamp(skb);
37427 // end of our responsibility
37428 atm_vcc->push (atm_vcc, skb);
37429 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
37430 } else {
37431 PRINTK (KERN_INFO, "dropped over-size frame");
37432 // should we count this?
37433 - atomic_inc(&atm_vcc->stats->rx_drop);
37434 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
37435 }
37436
37437 } else {
37438 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
37439 }
37440
37441 if (check_area (skb->data, skb->len)) {
37442 - atomic_inc(&atm_vcc->stats->tx_err);
37443 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
37444 return -ENOMEM; // ?
37445 }
37446
37447 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
37448 index 480fa6f..947067c 100644
37449 --- a/drivers/atm/atmtcp.c
37450 +++ b/drivers/atm/atmtcp.c
37451 @@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
37452 if (vcc->pop) vcc->pop(vcc,skb);
37453 else dev_kfree_skb(skb);
37454 if (dev_data) return 0;
37455 - atomic_inc(&vcc->stats->tx_err);
37456 + atomic_inc_unchecked(&vcc->stats->tx_err);
37457 return -ENOLINK;
37458 }
37459 size = skb->len+sizeof(struct atmtcp_hdr);
37460 @@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
37461 if (!new_skb) {
37462 if (vcc->pop) vcc->pop(vcc,skb);
37463 else dev_kfree_skb(skb);
37464 - atomic_inc(&vcc->stats->tx_err);
37465 + atomic_inc_unchecked(&vcc->stats->tx_err);
37466 return -ENOBUFS;
37467 }
37468 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
37469 @@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
37470 if (vcc->pop) vcc->pop(vcc,skb);
37471 else dev_kfree_skb(skb);
37472 out_vcc->push(out_vcc,new_skb);
37473 - atomic_inc(&vcc->stats->tx);
37474 - atomic_inc(&out_vcc->stats->rx);
37475 + atomic_inc_unchecked(&vcc->stats->tx);
37476 + atomic_inc_unchecked(&out_vcc->stats->rx);
37477 return 0;
37478 }
37479
37480 @@ -300,7 +300,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
37481 read_unlock(&vcc_sklist_lock);
37482 if (!out_vcc) {
37483 result = -EUNATCH;
37484 - atomic_inc(&vcc->stats->tx_err);
37485 + atomic_inc_unchecked(&vcc->stats->tx_err);
37486 goto done;
37487 }
37488 skb_pull(skb,sizeof(struct atmtcp_hdr));
37489 @@ -312,8 +312,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
37490 __net_timestamp(new_skb);
37491 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
37492 out_vcc->push(out_vcc,new_skb);
37493 - atomic_inc(&vcc->stats->tx);
37494 - atomic_inc(&out_vcc->stats->rx);
37495 + atomic_inc_unchecked(&vcc->stats->tx);
37496 + atomic_inc_unchecked(&out_vcc->stats->rx);
37497 done:
37498 if (vcc->pop) vcc->pop(vcc,skb);
37499 else dev_kfree_skb(skb);
37500 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
37501 index d65975a..0b87e20 100644
37502 --- a/drivers/atm/eni.c
37503 +++ b/drivers/atm/eni.c
37504 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
37505 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
37506 vcc->dev->number);
37507 length = 0;
37508 - atomic_inc(&vcc->stats->rx_err);
37509 + atomic_inc_unchecked(&vcc->stats->rx_err);
37510 }
37511 else {
37512 length = ATM_CELL_SIZE-1; /* no HEC */
37513 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
37514 size);
37515 }
37516 eff = length = 0;
37517 - atomic_inc(&vcc->stats->rx_err);
37518 + atomic_inc_unchecked(&vcc->stats->rx_err);
37519 }
37520 else {
37521 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
37522 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
37523 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
37524 vcc->dev->number,vcc->vci,length,size << 2,descr);
37525 length = eff = 0;
37526 - atomic_inc(&vcc->stats->rx_err);
37527 + atomic_inc_unchecked(&vcc->stats->rx_err);
37528 }
37529 }
37530 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
37531 @@ -767,7 +767,7 @@ rx_dequeued++;
37532 vcc->push(vcc,skb);
37533 pushed++;
37534 }
37535 - atomic_inc(&vcc->stats->rx);
37536 + atomic_inc_unchecked(&vcc->stats->rx);
37537 }
37538 wake_up(&eni_dev->rx_wait);
37539 }
37540 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
37541 PCI_DMA_TODEVICE);
37542 if (vcc->pop) vcc->pop(vcc,skb);
37543 else dev_kfree_skb_irq(skb);
37544 - atomic_inc(&vcc->stats->tx);
37545 + atomic_inc_unchecked(&vcc->stats->tx);
37546 wake_up(&eni_dev->tx_wait);
37547 dma_complete++;
37548 }
37549 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
37550 index 82f2ae0..f205c02 100644
37551 --- a/drivers/atm/firestream.c
37552 +++ b/drivers/atm/firestream.c
37553 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
37554 }
37555 }
37556
37557 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
37558 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
37559
37560 fs_dprintk (FS_DEBUG_TXMEM, "i");
37561 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
37562 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
37563 #endif
37564 skb_put (skb, qe->p1 & 0xffff);
37565 ATM_SKB(skb)->vcc = atm_vcc;
37566 - atomic_inc(&atm_vcc->stats->rx);
37567 + atomic_inc_unchecked(&atm_vcc->stats->rx);
37568 __net_timestamp(skb);
37569 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
37570 atm_vcc->push (atm_vcc, skb);
37571 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
37572 kfree (pe);
37573 }
37574 if (atm_vcc)
37575 - atomic_inc(&atm_vcc->stats->rx_drop);
37576 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
37577 break;
37578 case 0x1f: /* Reassembly abort: no buffers. */
37579 /* Silently increment error counter. */
37580 if (atm_vcc)
37581 - atomic_inc(&atm_vcc->stats->rx_drop);
37582 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
37583 break;
37584 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
37585 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
37586 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
37587 index d4725fc..2d4ea65 100644
37588 --- a/drivers/atm/fore200e.c
37589 +++ b/drivers/atm/fore200e.c
37590 @@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
37591 #endif
37592 /* check error condition */
37593 if (*entry->status & STATUS_ERROR)
37594 - atomic_inc(&vcc->stats->tx_err);
37595 + atomic_inc_unchecked(&vcc->stats->tx_err);
37596 else
37597 - atomic_inc(&vcc->stats->tx);
37598 + atomic_inc_unchecked(&vcc->stats->tx);
37599 }
37600 }
37601
37602 @@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
37603 if (skb == NULL) {
37604 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
37605
37606 - atomic_inc(&vcc->stats->rx_drop);
37607 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37608 return -ENOMEM;
37609 }
37610
37611 @@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
37612
37613 dev_kfree_skb_any(skb);
37614
37615 - atomic_inc(&vcc->stats->rx_drop);
37616 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37617 return -ENOMEM;
37618 }
37619
37620 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
37621
37622 vcc->push(vcc, skb);
37623 - atomic_inc(&vcc->stats->rx);
37624 + atomic_inc_unchecked(&vcc->stats->rx);
37625
37626 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
37627
37628 @@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
37629 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
37630 fore200e->atm_dev->number,
37631 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
37632 - atomic_inc(&vcc->stats->rx_err);
37633 + atomic_inc_unchecked(&vcc->stats->rx_err);
37634 }
37635 }
37636
37637 @@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
37638 goto retry_here;
37639 }
37640
37641 - atomic_inc(&vcc->stats->tx_err);
37642 + atomic_inc_unchecked(&vcc->stats->tx_err);
37643
37644 fore200e->tx_sat++;
37645 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
37646 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
37647 index c39702b..785b73b 100644
37648 --- a/drivers/atm/he.c
37649 +++ b/drivers/atm/he.c
37650 @@ -1689,7 +1689,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
37651
37652 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
37653 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
37654 - atomic_inc(&vcc->stats->rx_drop);
37655 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37656 goto return_host_buffers;
37657 }
37658
37659 @@ -1716,7 +1716,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
37660 RBRQ_LEN_ERR(he_dev->rbrq_head)
37661 ? "LEN_ERR" : "",
37662 vcc->vpi, vcc->vci);
37663 - atomic_inc(&vcc->stats->rx_err);
37664 + atomic_inc_unchecked(&vcc->stats->rx_err);
37665 goto return_host_buffers;
37666 }
37667
37668 @@ -1768,7 +1768,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
37669 vcc->push(vcc, skb);
37670 spin_lock(&he_dev->global_lock);
37671
37672 - atomic_inc(&vcc->stats->rx);
37673 + atomic_inc_unchecked(&vcc->stats->rx);
37674
37675 return_host_buffers:
37676 ++pdus_assembled;
37677 @@ -2094,7 +2094,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
37678 tpd->vcc->pop(tpd->vcc, tpd->skb);
37679 else
37680 dev_kfree_skb_any(tpd->skb);
37681 - atomic_inc(&tpd->vcc->stats->tx_err);
37682 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
37683 }
37684 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
37685 return;
37686 @@ -2506,7 +2506,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37687 vcc->pop(vcc, skb);
37688 else
37689 dev_kfree_skb_any(skb);
37690 - atomic_inc(&vcc->stats->tx_err);
37691 + atomic_inc_unchecked(&vcc->stats->tx_err);
37692 return -EINVAL;
37693 }
37694
37695 @@ -2517,7 +2517,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37696 vcc->pop(vcc, skb);
37697 else
37698 dev_kfree_skb_any(skb);
37699 - atomic_inc(&vcc->stats->tx_err);
37700 + atomic_inc_unchecked(&vcc->stats->tx_err);
37701 return -EINVAL;
37702 }
37703 #endif
37704 @@ -2529,7 +2529,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37705 vcc->pop(vcc, skb);
37706 else
37707 dev_kfree_skb_any(skb);
37708 - atomic_inc(&vcc->stats->tx_err);
37709 + atomic_inc_unchecked(&vcc->stats->tx_err);
37710 spin_unlock_irqrestore(&he_dev->global_lock, flags);
37711 return -ENOMEM;
37712 }
37713 @@ -2571,7 +2571,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37714 vcc->pop(vcc, skb);
37715 else
37716 dev_kfree_skb_any(skb);
37717 - atomic_inc(&vcc->stats->tx_err);
37718 + atomic_inc_unchecked(&vcc->stats->tx_err);
37719 spin_unlock_irqrestore(&he_dev->global_lock, flags);
37720 return -ENOMEM;
37721 }
37722 @@ -2602,7 +2602,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37723 __enqueue_tpd(he_dev, tpd, cid);
37724 spin_unlock_irqrestore(&he_dev->global_lock, flags);
37725
37726 - atomic_inc(&vcc->stats->tx);
37727 + atomic_inc_unchecked(&vcc->stats->tx);
37728
37729 return 0;
37730 }
37731 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
37732 index 1dc0519..1aadaf7 100644
37733 --- a/drivers/atm/horizon.c
37734 +++ b/drivers/atm/horizon.c
37735 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
37736 {
37737 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
37738 // VC layer stats
37739 - atomic_inc(&vcc->stats->rx);
37740 + atomic_inc_unchecked(&vcc->stats->rx);
37741 __net_timestamp(skb);
37742 // end of our responsibility
37743 vcc->push (vcc, skb);
37744 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
37745 dev->tx_iovec = NULL;
37746
37747 // VC layer stats
37748 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
37749 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
37750
37751 // free the skb
37752 hrz_kfree_skb (skb);
37753 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
37754 index 2b24ed0..b3d6acc 100644
37755 --- a/drivers/atm/idt77252.c
37756 +++ b/drivers/atm/idt77252.c
37757 @@ -810,7 +810,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
37758 else
37759 dev_kfree_skb(skb);
37760
37761 - atomic_inc(&vcc->stats->tx);
37762 + atomic_inc_unchecked(&vcc->stats->tx);
37763 }
37764
37765 atomic_dec(&scq->used);
37766 @@ -1072,13 +1072,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37767 if ((sb = dev_alloc_skb(64)) == NULL) {
37768 printk("%s: Can't allocate buffers for aal0.\n",
37769 card->name);
37770 - atomic_add(i, &vcc->stats->rx_drop);
37771 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
37772 break;
37773 }
37774 if (!atm_charge(vcc, sb->truesize)) {
37775 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
37776 card->name);
37777 - atomic_add(i - 1, &vcc->stats->rx_drop);
37778 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
37779 dev_kfree_skb(sb);
37780 break;
37781 }
37782 @@ -1095,7 +1095,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37783 ATM_SKB(sb)->vcc = vcc;
37784 __net_timestamp(sb);
37785 vcc->push(vcc, sb);
37786 - atomic_inc(&vcc->stats->rx);
37787 + atomic_inc_unchecked(&vcc->stats->rx);
37788
37789 cell += ATM_CELL_PAYLOAD;
37790 }
37791 @@ -1132,13 +1132,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37792 "(CDC: %08x)\n",
37793 card->name, len, rpp->len, readl(SAR_REG_CDC));
37794 recycle_rx_pool_skb(card, rpp);
37795 - atomic_inc(&vcc->stats->rx_err);
37796 + atomic_inc_unchecked(&vcc->stats->rx_err);
37797 return;
37798 }
37799 if (stat & SAR_RSQE_CRC) {
37800 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
37801 recycle_rx_pool_skb(card, rpp);
37802 - atomic_inc(&vcc->stats->rx_err);
37803 + atomic_inc_unchecked(&vcc->stats->rx_err);
37804 return;
37805 }
37806 if (skb_queue_len(&rpp->queue) > 1) {
37807 @@ -1149,7 +1149,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37808 RXPRINTK("%s: Can't alloc RX skb.\n",
37809 card->name);
37810 recycle_rx_pool_skb(card, rpp);
37811 - atomic_inc(&vcc->stats->rx_err);
37812 + atomic_inc_unchecked(&vcc->stats->rx_err);
37813 return;
37814 }
37815 if (!atm_charge(vcc, skb->truesize)) {
37816 @@ -1168,7 +1168,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37817 __net_timestamp(skb);
37818
37819 vcc->push(vcc, skb);
37820 - atomic_inc(&vcc->stats->rx);
37821 + atomic_inc_unchecked(&vcc->stats->rx);
37822
37823 return;
37824 }
37825 @@ -1190,7 +1190,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37826 __net_timestamp(skb);
37827
37828 vcc->push(vcc, skb);
37829 - atomic_inc(&vcc->stats->rx);
37830 + atomic_inc_unchecked(&vcc->stats->rx);
37831
37832 if (skb->truesize > SAR_FB_SIZE_3)
37833 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
37834 @@ -1301,14 +1301,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
37835 if (vcc->qos.aal != ATM_AAL0) {
37836 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
37837 card->name, vpi, vci);
37838 - atomic_inc(&vcc->stats->rx_drop);
37839 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37840 goto drop;
37841 }
37842
37843 if ((sb = dev_alloc_skb(64)) == NULL) {
37844 printk("%s: Can't allocate buffers for AAL0.\n",
37845 card->name);
37846 - atomic_inc(&vcc->stats->rx_err);
37847 + atomic_inc_unchecked(&vcc->stats->rx_err);
37848 goto drop;
37849 }
37850
37851 @@ -1327,7 +1327,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
37852 ATM_SKB(sb)->vcc = vcc;
37853 __net_timestamp(sb);
37854 vcc->push(vcc, sb);
37855 - atomic_inc(&vcc->stats->rx);
37856 + atomic_inc_unchecked(&vcc->stats->rx);
37857
37858 drop:
37859 skb_pull(queue, 64);
37860 @@ -1952,13 +1952,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37861
37862 if (vc == NULL) {
37863 printk("%s: NULL connection in send().\n", card->name);
37864 - atomic_inc(&vcc->stats->tx_err);
37865 + atomic_inc_unchecked(&vcc->stats->tx_err);
37866 dev_kfree_skb(skb);
37867 return -EINVAL;
37868 }
37869 if (!test_bit(VCF_TX, &vc->flags)) {
37870 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
37871 - atomic_inc(&vcc->stats->tx_err);
37872 + atomic_inc_unchecked(&vcc->stats->tx_err);
37873 dev_kfree_skb(skb);
37874 return -EINVAL;
37875 }
37876 @@ -1970,14 +1970,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37877 break;
37878 default:
37879 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
37880 - atomic_inc(&vcc->stats->tx_err);
37881 + atomic_inc_unchecked(&vcc->stats->tx_err);
37882 dev_kfree_skb(skb);
37883 return -EINVAL;
37884 }
37885
37886 if (skb_shinfo(skb)->nr_frags != 0) {
37887 printk("%s: No scatter-gather yet.\n", card->name);
37888 - atomic_inc(&vcc->stats->tx_err);
37889 + atomic_inc_unchecked(&vcc->stats->tx_err);
37890 dev_kfree_skb(skb);
37891 return -EINVAL;
37892 }
37893 @@ -1985,7 +1985,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37894
37895 err = queue_skb(card, vc, skb, oam);
37896 if (err) {
37897 - atomic_inc(&vcc->stats->tx_err);
37898 + atomic_inc_unchecked(&vcc->stats->tx_err);
37899 dev_kfree_skb(skb);
37900 return err;
37901 }
37902 @@ -2008,7 +2008,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
37903 skb = dev_alloc_skb(64);
37904 if (!skb) {
37905 printk("%s: Out of memory in send_oam().\n", card->name);
37906 - atomic_inc(&vcc->stats->tx_err);
37907 + atomic_inc_unchecked(&vcc->stats->tx_err);
37908 return -ENOMEM;
37909 }
37910 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
37911 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
37912 index 4217f29..88f547a 100644
37913 --- a/drivers/atm/iphase.c
37914 +++ b/drivers/atm/iphase.c
37915 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
37916 status = (u_short) (buf_desc_ptr->desc_mode);
37917 if (status & (RX_CER | RX_PTE | RX_OFL))
37918 {
37919 - atomic_inc(&vcc->stats->rx_err);
37920 + atomic_inc_unchecked(&vcc->stats->rx_err);
37921 IF_ERR(printk("IA: bad packet, dropping it");)
37922 if (status & RX_CER) {
37923 IF_ERR(printk(" cause: packet CRC error\n");)
37924 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
37925 len = dma_addr - buf_addr;
37926 if (len > iadev->rx_buf_sz) {
37927 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
37928 - atomic_inc(&vcc->stats->rx_err);
37929 + atomic_inc_unchecked(&vcc->stats->rx_err);
37930 goto out_free_desc;
37931 }
37932
37933 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37934 ia_vcc = INPH_IA_VCC(vcc);
37935 if (ia_vcc == NULL)
37936 {
37937 - atomic_inc(&vcc->stats->rx_err);
37938 + atomic_inc_unchecked(&vcc->stats->rx_err);
37939 atm_return(vcc, skb->truesize);
37940 dev_kfree_skb_any(skb);
37941 goto INCR_DLE;
37942 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37943 if ((length > iadev->rx_buf_sz) || (length >
37944 (skb->len - sizeof(struct cpcs_trailer))))
37945 {
37946 - atomic_inc(&vcc->stats->rx_err);
37947 + atomic_inc_unchecked(&vcc->stats->rx_err);
37948 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
37949 length, skb->len);)
37950 atm_return(vcc, skb->truesize);
37951 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37952
37953 IF_RX(printk("rx_dle_intr: skb push");)
37954 vcc->push(vcc,skb);
37955 - atomic_inc(&vcc->stats->rx);
37956 + atomic_inc_unchecked(&vcc->stats->rx);
37957 iadev->rx_pkt_cnt++;
37958 }
37959 INCR_DLE:
37960 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
37961 {
37962 struct k_sonet_stats *stats;
37963 stats = &PRIV(_ia_dev[board])->sonet_stats;
37964 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
37965 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
37966 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
37967 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
37968 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
37969 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
37970 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
37971 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
37972 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
37973 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
37974 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
37975 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
37976 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
37977 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
37978 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
37979 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
37980 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
37981 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
37982 }
37983 ia_cmds.status = 0;
37984 break;
37985 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37986 if ((desc == 0) || (desc > iadev->num_tx_desc))
37987 {
37988 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
37989 - atomic_inc(&vcc->stats->tx);
37990 + atomic_inc_unchecked(&vcc->stats->tx);
37991 if (vcc->pop)
37992 vcc->pop(vcc, skb);
37993 else
37994 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37995 ATM_DESC(skb) = vcc->vci;
37996 skb_queue_tail(&iadev->tx_dma_q, skb);
37997
37998 - atomic_inc(&vcc->stats->tx);
37999 + atomic_inc_unchecked(&vcc->stats->tx);
38000 iadev->tx_pkt_cnt++;
38001 /* Increment transaction counter */
38002 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
38003
38004 #if 0
38005 /* add flow control logic */
38006 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
38007 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
38008 if (iavcc->vc_desc_cnt > 10) {
38009 vcc->tx_quota = vcc->tx_quota * 3 / 4;
38010 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
38011 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
38012 index fa7d7019..1e404c7 100644
38013 --- a/drivers/atm/lanai.c
38014 +++ b/drivers/atm/lanai.c
38015 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
38016 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
38017 lanai_endtx(lanai, lvcc);
38018 lanai_free_skb(lvcc->tx.atmvcc, skb);
38019 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
38020 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
38021 }
38022
38023 /* Try to fill the buffer - don't call unless there is backlog */
38024 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
38025 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
38026 __net_timestamp(skb);
38027 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
38028 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
38029 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
38030 out:
38031 lvcc->rx.buf.ptr = end;
38032 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
38033 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38034 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
38035 "vcc %d\n", lanai->number, (unsigned int) s, vci);
38036 lanai->stats.service_rxnotaal5++;
38037 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38038 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38039 return 0;
38040 }
38041 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
38042 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38043 int bytes;
38044 read_unlock(&vcc_sklist_lock);
38045 DPRINTK("got trashed rx pdu on vci %d\n", vci);
38046 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38047 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38048 lvcc->stats.x.aal5.service_trash++;
38049 bytes = (SERVICE_GET_END(s) * 16) -
38050 (((unsigned long) lvcc->rx.buf.ptr) -
38051 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38052 }
38053 if (s & SERVICE_STREAM) {
38054 read_unlock(&vcc_sklist_lock);
38055 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38056 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38057 lvcc->stats.x.aal5.service_stream++;
38058 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
38059 "PDU on VCI %d!\n", lanai->number, vci);
38060 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38061 return 0;
38062 }
38063 DPRINTK("got rx crc error on vci %d\n", vci);
38064 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38065 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38066 lvcc->stats.x.aal5.service_rxcrc++;
38067 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
38068 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
38069 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
38070 index 9988ac9..7c52585 100644
38071 --- a/drivers/atm/nicstar.c
38072 +++ b/drivers/atm/nicstar.c
38073 @@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
38074 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
38075 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
38076 card->index);
38077 - atomic_inc(&vcc->stats->tx_err);
38078 + atomic_inc_unchecked(&vcc->stats->tx_err);
38079 dev_kfree_skb_any(skb);
38080 return -EINVAL;
38081 }
38082 @@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
38083 if (!vc->tx) {
38084 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
38085 card->index);
38086 - atomic_inc(&vcc->stats->tx_err);
38087 + atomic_inc_unchecked(&vcc->stats->tx_err);
38088 dev_kfree_skb_any(skb);
38089 return -EINVAL;
38090 }
38091 @@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
38092 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
38093 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
38094 card->index);
38095 - atomic_inc(&vcc->stats->tx_err);
38096 + atomic_inc_unchecked(&vcc->stats->tx_err);
38097 dev_kfree_skb_any(skb);
38098 return -EINVAL;
38099 }
38100
38101 if (skb_shinfo(skb)->nr_frags != 0) {
38102 printk("nicstar%d: No scatter-gather yet.\n", card->index);
38103 - atomic_inc(&vcc->stats->tx_err);
38104 + atomic_inc_unchecked(&vcc->stats->tx_err);
38105 dev_kfree_skb_any(skb);
38106 return -EINVAL;
38107 }
38108 @@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
38109 }
38110
38111 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
38112 - atomic_inc(&vcc->stats->tx_err);
38113 + atomic_inc_unchecked(&vcc->stats->tx_err);
38114 dev_kfree_skb_any(skb);
38115 return -EIO;
38116 }
38117 - atomic_inc(&vcc->stats->tx);
38118 + atomic_inc_unchecked(&vcc->stats->tx);
38119
38120 return 0;
38121 }
38122 @@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38123 printk
38124 ("nicstar%d: Can't allocate buffers for aal0.\n",
38125 card->index);
38126 - atomic_add(i, &vcc->stats->rx_drop);
38127 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
38128 break;
38129 }
38130 if (!atm_charge(vcc, sb->truesize)) {
38131 RXPRINTK
38132 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
38133 card->index);
38134 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
38135 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
38136 dev_kfree_skb_any(sb);
38137 break;
38138 }
38139 @@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38140 ATM_SKB(sb)->vcc = vcc;
38141 __net_timestamp(sb);
38142 vcc->push(vcc, sb);
38143 - atomic_inc(&vcc->stats->rx);
38144 + atomic_inc_unchecked(&vcc->stats->rx);
38145 cell += ATM_CELL_PAYLOAD;
38146 }
38147
38148 @@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38149 if (iovb == NULL) {
38150 printk("nicstar%d: Out of iovec buffers.\n",
38151 card->index);
38152 - atomic_inc(&vcc->stats->rx_drop);
38153 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38154 recycle_rx_buf(card, skb);
38155 return;
38156 }
38157 @@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38158 small or large buffer itself. */
38159 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
38160 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
38161 - atomic_inc(&vcc->stats->rx_err);
38162 + atomic_inc_unchecked(&vcc->stats->rx_err);
38163 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
38164 NS_MAX_IOVECS);
38165 NS_PRV_IOVCNT(iovb) = 0;
38166 @@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38167 ("nicstar%d: Expected a small buffer, and this is not one.\n",
38168 card->index);
38169 which_list(card, skb);
38170 - atomic_inc(&vcc->stats->rx_err);
38171 + atomic_inc_unchecked(&vcc->stats->rx_err);
38172 recycle_rx_buf(card, skb);
38173 vc->rx_iov = NULL;
38174 recycle_iov_buf(card, iovb);
38175 @@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38176 ("nicstar%d: Expected a large buffer, and this is not one.\n",
38177 card->index);
38178 which_list(card, skb);
38179 - atomic_inc(&vcc->stats->rx_err);
38180 + atomic_inc_unchecked(&vcc->stats->rx_err);
38181 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
38182 NS_PRV_IOVCNT(iovb));
38183 vc->rx_iov = NULL;
38184 @@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38185 printk(" - PDU size mismatch.\n");
38186 else
38187 printk(".\n");
38188 - atomic_inc(&vcc->stats->rx_err);
38189 + atomic_inc_unchecked(&vcc->stats->rx_err);
38190 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
38191 NS_PRV_IOVCNT(iovb));
38192 vc->rx_iov = NULL;
38193 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38194 /* skb points to a small buffer */
38195 if (!atm_charge(vcc, skb->truesize)) {
38196 push_rxbufs(card, skb);
38197 - atomic_inc(&vcc->stats->rx_drop);
38198 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38199 } else {
38200 skb_put(skb, len);
38201 dequeue_sm_buf(card, skb);
38202 @@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38203 ATM_SKB(skb)->vcc = vcc;
38204 __net_timestamp(skb);
38205 vcc->push(vcc, skb);
38206 - atomic_inc(&vcc->stats->rx);
38207 + atomic_inc_unchecked(&vcc->stats->rx);
38208 }
38209 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
38210 struct sk_buff *sb;
38211 @@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38212 if (len <= NS_SMBUFSIZE) {
38213 if (!atm_charge(vcc, sb->truesize)) {
38214 push_rxbufs(card, sb);
38215 - atomic_inc(&vcc->stats->rx_drop);
38216 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38217 } else {
38218 skb_put(sb, len);
38219 dequeue_sm_buf(card, sb);
38220 @@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38221 ATM_SKB(sb)->vcc = vcc;
38222 __net_timestamp(sb);
38223 vcc->push(vcc, sb);
38224 - atomic_inc(&vcc->stats->rx);
38225 + atomic_inc_unchecked(&vcc->stats->rx);
38226 }
38227
38228 push_rxbufs(card, skb);
38229 @@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38230
38231 if (!atm_charge(vcc, skb->truesize)) {
38232 push_rxbufs(card, skb);
38233 - atomic_inc(&vcc->stats->rx_drop);
38234 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38235 } else {
38236 dequeue_lg_buf(card, skb);
38237 #ifdef NS_USE_DESTRUCTORS
38238 @@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38239 ATM_SKB(skb)->vcc = vcc;
38240 __net_timestamp(skb);
38241 vcc->push(vcc, skb);
38242 - atomic_inc(&vcc->stats->rx);
38243 + atomic_inc_unchecked(&vcc->stats->rx);
38244 }
38245
38246 push_rxbufs(card, sb);
38247 @@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38248 printk
38249 ("nicstar%d: Out of huge buffers.\n",
38250 card->index);
38251 - atomic_inc(&vcc->stats->rx_drop);
38252 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38253 recycle_iovec_rx_bufs(card,
38254 (struct iovec *)
38255 iovb->data,
38256 @@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38257 card->hbpool.count++;
38258 } else
38259 dev_kfree_skb_any(hb);
38260 - atomic_inc(&vcc->stats->rx_drop);
38261 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38262 } else {
38263 /* Copy the small buffer to the huge buffer */
38264 sb = (struct sk_buff *)iov->iov_base;
38265 @@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38266 #endif /* NS_USE_DESTRUCTORS */
38267 __net_timestamp(hb);
38268 vcc->push(vcc, hb);
38269 - atomic_inc(&vcc->stats->rx);
38270 + atomic_inc_unchecked(&vcc->stats->rx);
38271 }
38272 }
38273
38274 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
38275 index 7652e8d..db45069 100644
38276 --- a/drivers/atm/solos-pci.c
38277 +++ b/drivers/atm/solos-pci.c
38278 @@ -838,7 +838,7 @@ static void solos_bh(unsigned long card_arg)
38279 }
38280 atm_charge(vcc, skb->truesize);
38281 vcc->push(vcc, skb);
38282 - atomic_inc(&vcc->stats->rx);
38283 + atomic_inc_unchecked(&vcc->stats->rx);
38284 break;
38285
38286 case PKT_STATUS:
38287 @@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
38288 vcc = SKB_CB(oldskb)->vcc;
38289
38290 if (vcc) {
38291 - atomic_inc(&vcc->stats->tx);
38292 + atomic_inc_unchecked(&vcc->stats->tx);
38293 solos_pop(vcc, oldskb);
38294 } else {
38295 dev_kfree_skb_irq(oldskb);
38296 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
38297 index 0215934..ce9f5b1 100644
38298 --- a/drivers/atm/suni.c
38299 +++ b/drivers/atm/suni.c
38300 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
38301
38302
38303 #define ADD_LIMITED(s,v) \
38304 - atomic_add((v),&stats->s); \
38305 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
38306 + atomic_add_unchecked((v),&stats->s); \
38307 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
38308
38309
38310 static void suni_hz(unsigned long from_timer)
38311 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
38312 index 5120a96..e2572bd 100644
38313 --- a/drivers/atm/uPD98402.c
38314 +++ b/drivers/atm/uPD98402.c
38315 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
38316 struct sonet_stats tmp;
38317 int error = 0;
38318
38319 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
38320 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
38321 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
38322 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
38323 if (zero && !error) {
38324 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
38325
38326
38327 #define ADD_LIMITED(s,v) \
38328 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
38329 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
38330 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
38331 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
38332 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
38333 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
38334
38335
38336 static void stat_event(struct atm_dev *dev)
38337 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
38338 if (reason & uPD98402_INT_PFM) stat_event(dev);
38339 if (reason & uPD98402_INT_PCO) {
38340 (void) GET(PCOCR); /* clear interrupt cause */
38341 - atomic_add(GET(HECCT),
38342 + atomic_add_unchecked(GET(HECCT),
38343 &PRIV(dev)->sonet_stats.uncorr_hcs);
38344 }
38345 if ((reason & uPD98402_INT_RFO) &&
38346 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
38347 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
38348 uPD98402_INT_LOS),PIMR); /* enable them */
38349 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
38350 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
38351 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
38352 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
38353 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
38354 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
38355 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
38356 return 0;
38357 }
38358
38359 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
38360 index 969c3c2..9b72956 100644
38361 --- a/drivers/atm/zatm.c
38362 +++ b/drivers/atm/zatm.c
38363 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
38364 }
38365 if (!size) {
38366 dev_kfree_skb_irq(skb);
38367 - if (vcc) atomic_inc(&vcc->stats->rx_err);
38368 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
38369 continue;
38370 }
38371 if (!atm_charge(vcc,skb->truesize)) {
38372 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
38373 skb->len = size;
38374 ATM_SKB(skb)->vcc = vcc;
38375 vcc->push(vcc,skb);
38376 - atomic_inc(&vcc->stats->rx);
38377 + atomic_inc_unchecked(&vcc->stats->rx);
38378 }
38379 zout(pos & 0xffff,MTA(mbx));
38380 #if 0 /* probably a stupid idea */
38381 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
38382 skb_queue_head(&zatm_vcc->backlog,skb);
38383 break;
38384 }
38385 - atomic_inc(&vcc->stats->tx);
38386 + atomic_inc_unchecked(&vcc->stats->tx);
38387 wake_up(&zatm_vcc->tx_wait);
38388 }
38389
38390 diff --git a/drivers/base/bus.c b/drivers/base/bus.c
38391 index 83e910a..b224a73 100644
38392 --- a/drivers/base/bus.c
38393 +++ b/drivers/base/bus.c
38394 @@ -1124,7 +1124,7 @@ int subsys_interface_register(struct subsys_interface *sif)
38395 return -EINVAL;
38396
38397 mutex_lock(&subsys->p->mutex);
38398 - list_add_tail(&sif->node, &subsys->p->interfaces);
38399 + pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
38400 if (sif->add_dev) {
38401 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
38402 while ((dev = subsys_dev_iter_next(&iter)))
38403 @@ -1149,7 +1149,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
38404 subsys = sif->subsys;
38405
38406 mutex_lock(&subsys->p->mutex);
38407 - list_del_init(&sif->node);
38408 + pax_list_del_init((struct list_head *)&sif->node);
38409 if (sif->remove_dev) {
38410 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
38411 while ((dev = subsys_dev_iter_next(&iter)))
38412 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
38413 index 25798db..15f130e 100644
38414 --- a/drivers/base/devtmpfs.c
38415 +++ b/drivers/base/devtmpfs.c
38416 @@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
38417 if (!thread)
38418 return 0;
38419
38420 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
38421 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
38422 if (err)
38423 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
38424 else
38425 @@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
38426 *err = sys_unshare(CLONE_NEWNS);
38427 if (*err)
38428 goto out;
38429 - *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
38430 + *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
38431 if (*err)
38432 goto out;
38433 - sys_chdir("/.."); /* will traverse into overmounted root */
38434 - sys_chroot(".");
38435 + sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
38436 + sys_chroot((char __force_user *)".");
38437 complete(&setup_done);
38438 while (1) {
38439 spin_lock(&req_lock);
38440 diff --git a/drivers/base/node.c b/drivers/base/node.c
38441 index d51c49c..28908df 100644
38442 --- a/drivers/base/node.c
38443 +++ b/drivers/base/node.c
38444 @@ -623,7 +623,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
38445 struct node_attr {
38446 struct device_attribute attr;
38447 enum node_states state;
38448 -};
38449 +} __do_const;
38450
38451 static ssize_t show_node_state(struct device *dev,
38452 struct device_attribute *attr, char *buf)
38453 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
38454 index eee55c1..b8c9393 100644
38455 --- a/drivers/base/power/domain.c
38456 +++ b/drivers/base/power/domain.c
38457 @@ -1821,9 +1821,9 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
38458
38459 if (dev->power.subsys_data->domain_data) {
38460 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
38461 - gpd_data->ops = (struct gpd_dev_ops){ NULL };
38462 + memset(&gpd_data->ops, 0, sizeof(gpd_data->ops));
38463 if (clear_td)
38464 - gpd_data->td = (struct gpd_timing_data){ 0 };
38465 + memset(&gpd_data->td, 0, sizeof(gpd_data->td));
38466
38467 if (--gpd_data->refcount == 0) {
38468 dev->power.subsys_data->domain_data = NULL;
38469 @@ -1862,7 +1862,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
38470 {
38471 struct cpuidle_driver *cpuidle_drv;
38472 struct gpd_cpu_data *cpu_data;
38473 - struct cpuidle_state *idle_state;
38474 + cpuidle_state_no_const *idle_state;
38475 int ret = 0;
38476
38477 if (IS_ERR_OR_NULL(genpd) || state < 0)
38478 @@ -1930,7 +1930,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
38479 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
38480 {
38481 struct gpd_cpu_data *cpu_data;
38482 - struct cpuidle_state *idle_state;
38483 + cpuidle_state_no_const *idle_state;
38484 int ret = 0;
38485
38486 if (IS_ERR_OR_NULL(genpd))
38487 diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
38488 index 95b181d1..c4f0e19 100644
38489 --- a/drivers/base/power/sysfs.c
38490 +++ b/drivers/base/power/sysfs.c
38491 @@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
38492 return -EIO;
38493 }
38494 }
38495 - return sprintf(buf, p);
38496 + return sprintf(buf, "%s", p);
38497 }
38498
38499 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
38500 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
38501 index eb1bd2e..2667d3a 100644
38502 --- a/drivers/base/power/wakeup.c
38503 +++ b/drivers/base/power/wakeup.c
38504 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
38505 * They need to be modified together atomically, so it's better to use one
38506 * atomic variable to hold them both.
38507 */
38508 -static atomic_t combined_event_count = ATOMIC_INIT(0);
38509 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
38510
38511 #define IN_PROGRESS_BITS (sizeof(int) * 4)
38512 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
38513
38514 static void split_counters(unsigned int *cnt, unsigned int *inpr)
38515 {
38516 - unsigned int comb = atomic_read(&combined_event_count);
38517 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
38518
38519 *cnt = (comb >> IN_PROGRESS_BITS);
38520 *inpr = comb & MAX_IN_PROGRESS;
38521 @@ -401,7 +401,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
38522 ws->start_prevent_time = ws->last_time;
38523
38524 /* Increment the counter of events in progress. */
38525 - cec = atomic_inc_return(&combined_event_count);
38526 + cec = atomic_inc_return_unchecked(&combined_event_count);
38527
38528 trace_wakeup_source_activate(ws->name, cec);
38529 }
38530 @@ -527,7 +527,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
38531 * Increment the counter of registered wakeup events and decrement the
38532 * couter of wakeup events in progress simultaneously.
38533 */
38534 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
38535 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
38536 trace_wakeup_source_deactivate(ws->name, cec);
38537
38538 split_counters(&cnt, &inpr);
38539 diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
38540 index dbb8350..4762f4c 100644
38541 --- a/drivers/base/syscore.c
38542 +++ b/drivers/base/syscore.c
38543 @@ -22,7 +22,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
38544 void register_syscore_ops(struct syscore_ops *ops)
38545 {
38546 mutex_lock(&syscore_ops_lock);
38547 - list_add_tail(&ops->node, &syscore_ops_list);
38548 + pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
38549 mutex_unlock(&syscore_ops_lock);
38550 }
38551 EXPORT_SYMBOL_GPL(register_syscore_ops);
38552 @@ -34,7 +34,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
38553 void unregister_syscore_ops(struct syscore_ops *ops)
38554 {
38555 mutex_lock(&syscore_ops_lock);
38556 - list_del(&ops->node);
38557 + pax_list_del((struct list_head *)&ops->node);
38558 mutex_unlock(&syscore_ops_lock);
38559 }
38560 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
38561 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
38562 index ff20f19..018f1da 100644
38563 --- a/drivers/block/cciss.c
38564 +++ b/drivers/block/cciss.c
38565 @@ -3008,7 +3008,7 @@ static void start_io(ctlr_info_t *h)
38566 while (!list_empty(&h->reqQ)) {
38567 c = list_entry(h->reqQ.next, CommandList_struct, list);
38568 /* can't do anything if fifo is full */
38569 - if ((h->access.fifo_full(h))) {
38570 + if ((h->access->fifo_full(h))) {
38571 dev_warn(&h->pdev->dev, "fifo full\n");
38572 break;
38573 }
38574 @@ -3018,7 +3018,7 @@ static void start_io(ctlr_info_t *h)
38575 h->Qdepth--;
38576
38577 /* Tell the controller execute command */
38578 - h->access.submit_command(h, c);
38579 + h->access->submit_command(h, c);
38580
38581 /* Put job onto the completed Q */
38582 addQ(&h->cmpQ, c);
38583 @@ -3444,17 +3444,17 @@ startio:
38584
38585 static inline unsigned long get_next_completion(ctlr_info_t *h)
38586 {
38587 - return h->access.command_completed(h);
38588 + return h->access->command_completed(h);
38589 }
38590
38591 static inline int interrupt_pending(ctlr_info_t *h)
38592 {
38593 - return h->access.intr_pending(h);
38594 + return h->access->intr_pending(h);
38595 }
38596
38597 static inline long interrupt_not_for_us(ctlr_info_t *h)
38598 {
38599 - return ((h->access.intr_pending(h) == 0) ||
38600 + return ((h->access->intr_pending(h) == 0) ||
38601 (h->interrupts_enabled == 0));
38602 }
38603
38604 @@ -3487,7 +3487,7 @@ static inline u32 next_command(ctlr_info_t *h)
38605 u32 a;
38606
38607 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
38608 - return h->access.command_completed(h);
38609 + return h->access->command_completed(h);
38610
38611 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
38612 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
38613 @@ -4044,7 +4044,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
38614 trans_support & CFGTBL_Trans_use_short_tags);
38615
38616 /* Change the access methods to the performant access methods */
38617 - h->access = SA5_performant_access;
38618 + h->access = &SA5_performant_access;
38619 h->transMethod = CFGTBL_Trans_Performant;
38620
38621 return;
38622 @@ -4318,7 +4318,7 @@ static int cciss_pci_init(ctlr_info_t *h)
38623 if (prod_index < 0)
38624 return -ENODEV;
38625 h->product_name = products[prod_index].product_name;
38626 - h->access = *(products[prod_index].access);
38627 + h->access = products[prod_index].access;
38628
38629 if (cciss_board_disabled(h)) {
38630 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
38631 @@ -5050,7 +5050,7 @@ reinit_after_soft_reset:
38632 }
38633
38634 /* make sure the board interrupts are off */
38635 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
38636 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
38637 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
38638 if (rc)
38639 goto clean2;
38640 @@ -5100,7 +5100,7 @@ reinit_after_soft_reset:
38641 * fake ones to scoop up any residual completions.
38642 */
38643 spin_lock_irqsave(&h->lock, flags);
38644 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
38645 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
38646 spin_unlock_irqrestore(&h->lock, flags);
38647 free_irq(h->intr[h->intr_mode], h);
38648 rc = cciss_request_irq(h, cciss_msix_discard_completions,
38649 @@ -5120,9 +5120,9 @@ reinit_after_soft_reset:
38650 dev_info(&h->pdev->dev, "Board READY.\n");
38651 dev_info(&h->pdev->dev,
38652 "Waiting for stale completions to drain.\n");
38653 - h->access.set_intr_mask(h, CCISS_INTR_ON);
38654 + h->access->set_intr_mask(h, CCISS_INTR_ON);
38655 msleep(10000);
38656 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
38657 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
38658
38659 rc = controller_reset_failed(h->cfgtable);
38660 if (rc)
38661 @@ -5145,7 +5145,7 @@ reinit_after_soft_reset:
38662 cciss_scsi_setup(h);
38663
38664 /* Turn the interrupts on so we can service requests */
38665 - h->access.set_intr_mask(h, CCISS_INTR_ON);
38666 + h->access->set_intr_mask(h, CCISS_INTR_ON);
38667
38668 /* Get the firmware version */
38669 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
38670 @@ -5217,7 +5217,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
38671 kfree(flush_buf);
38672 if (return_code != IO_OK)
38673 dev_warn(&h->pdev->dev, "Error flushing cache\n");
38674 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
38675 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
38676 free_irq(h->intr[h->intr_mode], h);
38677 }
38678
38679 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
38680 index 7fda30e..2f27946 100644
38681 --- a/drivers/block/cciss.h
38682 +++ b/drivers/block/cciss.h
38683 @@ -101,7 +101,7 @@ struct ctlr_info
38684 /* information about each logical volume */
38685 drive_info_struct *drv[CISS_MAX_LUN];
38686
38687 - struct access_method access;
38688 + struct access_method *access;
38689
38690 /* queue and queue Info */
38691 struct list_head reqQ;
38692 @@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
38693 }
38694
38695 static struct access_method SA5_access = {
38696 - SA5_submit_command,
38697 - SA5_intr_mask,
38698 - SA5_fifo_full,
38699 - SA5_intr_pending,
38700 - SA5_completed,
38701 + .submit_command = SA5_submit_command,
38702 + .set_intr_mask = SA5_intr_mask,
38703 + .fifo_full = SA5_fifo_full,
38704 + .intr_pending = SA5_intr_pending,
38705 + .command_completed = SA5_completed,
38706 };
38707
38708 static struct access_method SA5B_access = {
38709 - SA5_submit_command,
38710 - SA5B_intr_mask,
38711 - SA5_fifo_full,
38712 - SA5B_intr_pending,
38713 - SA5_completed,
38714 + .submit_command = SA5_submit_command,
38715 + .set_intr_mask = SA5B_intr_mask,
38716 + .fifo_full = SA5_fifo_full,
38717 + .intr_pending = SA5B_intr_pending,
38718 + .command_completed = SA5_completed,
38719 };
38720
38721 static struct access_method SA5_performant_access = {
38722 - SA5_submit_command,
38723 - SA5_performant_intr_mask,
38724 - SA5_fifo_full,
38725 - SA5_performant_intr_pending,
38726 - SA5_performant_completed,
38727 + .submit_command = SA5_submit_command,
38728 + .set_intr_mask = SA5_performant_intr_mask,
38729 + .fifo_full = SA5_fifo_full,
38730 + .intr_pending = SA5_performant_intr_pending,
38731 + .command_completed = SA5_performant_completed,
38732 };
38733
38734 struct board_type {
38735 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
38736 index 2b94403..fd6ad1f 100644
38737 --- a/drivers/block/cpqarray.c
38738 +++ b/drivers/block/cpqarray.c
38739 @@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
38740 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
38741 goto Enomem4;
38742 }
38743 - hba[i]->access.set_intr_mask(hba[i], 0);
38744 + hba[i]->access->set_intr_mask(hba[i], 0);
38745 if (request_irq(hba[i]->intr, do_ida_intr,
38746 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
38747 {
38748 @@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
38749 add_timer(&hba[i]->timer);
38750
38751 /* Enable IRQ now that spinlock and rate limit timer are set up */
38752 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
38753 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
38754
38755 for(j=0; j<NWD; j++) {
38756 struct gendisk *disk = ida_gendisk[i][j];
38757 @@ -694,7 +694,7 @@ DBGINFO(
38758 for(i=0; i<NR_PRODUCTS; i++) {
38759 if (board_id == products[i].board_id) {
38760 c->product_name = products[i].product_name;
38761 - c->access = *(products[i].access);
38762 + c->access = products[i].access;
38763 break;
38764 }
38765 }
38766 @@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
38767 hba[ctlr]->intr = intr;
38768 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
38769 hba[ctlr]->product_name = products[j].product_name;
38770 - hba[ctlr]->access = *(products[j].access);
38771 + hba[ctlr]->access = products[j].access;
38772 hba[ctlr]->ctlr = ctlr;
38773 hba[ctlr]->board_id = board_id;
38774 hba[ctlr]->pci_dev = NULL; /* not PCI */
38775 @@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
38776
38777 while((c = h->reqQ) != NULL) {
38778 /* Can't do anything if we're busy */
38779 - if (h->access.fifo_full(h) == 0)
38780 + if (h->access->fifo_full(h) == 0)
38781 return;
38782
38783 /* Get the first entry from the request Q */
38784 @@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
38785 h->Qdepth--;
38786
38787 /* Tell the controller to do our bidding */
38788 - h->access.submit_command(h, c);
38789 + h->access->submit_command(h, c);
38790
38791 /* Get onto the completion Q */
38792 addQ(&h->cmpQ, c);
38793 @@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
38794 unsigned long flags;
38795 __u32 a,a1;
38796
38797 - istat = h->access.intr_pending(h);
38798 + istat = h->access->intr_pending(h);
38799 /* Is this interrupt for us? */
38800 if (istat == 0)
38801 return IRQ_NONE;
38802 @@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
38803 */
38804 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
38805 if (istat & FIFO_NOT_EMPTY) {
38806 - while((a = h->access.command_completed(h))) {
38807 + while((a = h->access->command_completed(h))) {
38808 a1 = a; a &= ~3;
38809 if ((c = h->cmpQ) == NULL)
38810 {
38811 @@ -1448,11 +1448,11 @@ static int sendcmd(
38812 /*
38813 * Disable interrupt
38814 */
38815 - info_p->access.set_intr_mask(info_p, 0);
38816 + info_p->access->set_intr_mask(info_p, 0);
38817 /* Make sure there is room in the command FIFO */
38818 /* Actually it should be completely empty at this time. */
38819 for (i = 200000; i > 0; i--) {
38820 - temp = info_p->access.fifo_full(info_p);
38821 + temp = info_p->access->fifo_full(info_p);
38822 if (temp != 0) {
38823 break;
38824 }
38825 @@ -1465,7 +1465,7 @@ DBG(
38826 /*
38827 * Send the cmd
38828 */
38829 - info_p->access.submit_command(info_p, c);
38830 + info_p->access->submit_command(info_p, c);
38831 complete = pollcomplete(ctlr);
38832
38833 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
38834 @@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
38835 * we check the new geometry. Then turn interrupts back on when
38836 * we're done.
38837 */
38838 - host->access.set_intr_mask(host, 0);
38839 + host->access->set_intr_mask(host, 0);
38840 getgeometry(ctlr);
38841 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
38842 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
38843
38844 for(i=0; i<NWD; i++) {
38845 struct gendisk *disk = ida_gendisk[ctlr][i];
38846 @@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
38847 /* Wait (up to 2 seconds) for a command to complete */
38848
38849 for (i = 200000; i > 0; i--) {
38850 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
38851 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
38852 if (done == 0) {
38853 udelay(10); /* a short fixed delay */
38854 } else
38855 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
38856 index be73e9d..7fbf140 100644
38857 --- a/drivers/block/cpqarray.h
38858 +++ b/drivers/block/cpqarray.h
38859 @@ -99,7 +99,7 @@ struct ctlr_info {
38860 drv_info_t drv[NWD];
38861 struct proc_dir_entry *proc;
38862
38863 - struct access_method access;
38864 + struct access_method *access;
38865
38866 cmdlist_t *reqQ;
38867 cmdlist_t *cmpQ;
38868 diff --git a/drivers/block/drbd/drbd_bitmap.c b/drivers/block/drbd/drbd_bitmap.c
38869 index 426c97a..8c58607 100644
38870 --- a/drivers/block/drbd/drbd_bitmap.c
38871 +++ b/drivers/block/drbd/drbd_bitmap.c
38872 @@ -1036,7 +1036,7 @@ static void bm_page_io_async(struct drbd_bm_aio_ctx *ctx, int page_nr) __must_ho
38873 submit_bio(rw, bio);
38874 /* this should not count as user activity and cause the
38875 * resync to throttle -- see drbd_rs_should_slow_down(). */
38876 - atomic_add(len >> 9, &device->rs_sect_ev);
38877 + atomic_add_unchecked(len >> 9, &device->rs_sect_ev);
38878 }
38879 }
38880
38881 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
38882 index 1a00001..c0d4253 100644
38883 --- a/drivers/block/drbd/drbd_int.h
38884 +++ b/drivers/block/drbd/drbd_int.h
38885 @@ -387,7 +387,7 @@ struct drbd_epoch {
38886 struct drbd_connection *connection;
38887 struct list_head list;
38888 unsigned int barrier_nr;
38889 - atomic_t epoch_size; /* increased on every request added. */
38890 + atomic_unchecked_t epoch_size; /* increased on every request added. */
38891 atomic_t active; /* increased on every req. added, and dec on every finished. */
38892 unsigned long flags;
38893 };
38894 @@ -948,7 +948,7 @@ struct drbd_device {
38895 unsigned int al_tr_number;
38896 int al_tr_cycle;
38897 wait_queue_head_t seq_wait;
38898 - atomic_t packet_seq;
38899 + atomic_unchecked_t packet_seq;
38900 unsigned int peer_seq;
38901 spinlock_t peer_seq_lock;
38902 unsigned long comm_bm_set; /* communicated number of set bits. */
38903 @@ -957,8 +957,8 @@ struct drbd_device {
38904 struct mutex own_state_mutex;
38905 struct mutex *state_mutex; /* either own_state_mutex or first_peer_device(device)->connection->cstate_mutex */
38906 char congestion_reason; /* Why we where congested... */
38907 - atomic_t rs_sect_in; /* for incoming resync data rate, SyncTarget */
38908 - atomic_t rs_sect_ev; /* for submitted resync data rate, both */
38909 + atomic_unchecked_t rs_sect_in; /* for incoming resync data rate, SyncTarget */
38910 + atomic_unchecked_t rs_sect_ev; /* for submitted resync data rate, both */
38911 int rs_last_sect_ev; /* counter to compare with */
38912 int rs_last_events; /* counter of read or write "events" (unit sectors)
38913 * on the lower level device when we last looked. */
38914 @@ -1569,7 +1569,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
38915 char __user *uoptval;
38916 int err;
38917
38918 - uoptval = (char __user __force *)optval;
38919 + uoptval = (char __force_user *)optval;
38920
38921 set_fs(KERNEL_DS);
38922 if (level == SOL_SOCKET)
38923 diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
38924 index 04a14e0..5b8f0aa 100644
38925 --- a/drivers/block/drbd/drbd_interval.c
38926 +++ b/drivers/block/drbd/drbd_interval.c
38927 @@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
38928 }
38929
38930 static const struct rb_augment_callbacks augment_callbacks = {
38931 - augment_propagate,
38932 - augment_copy,
38933 - augment_rotate,
38934 + .propagate = augment_propagate,
38935 + .copy = augment_copy,
38936 + .rotate = augment_rotate,
38937 };
38938
38939 /**
38940 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
38941 index 9b465bb..00034ecf 100644
38942 --- a/drivers/block/drbd/drbd_main.c
38943 +++ b/drivers/block/drbd/drbd_main.c
38944 @@ -1328,7 +1328,7 @@ static int _drbd_send_ack(struct drbd_peer_device *peer_device, enum drbd_packet
38945 p->sector = sector;
38946 p->block_id = block_id;
38947 p->blksize = blksize;
38948 - p->seq_num = cpu_to_be32(atomic_inc_return(&peer_device->device->packet_seq));
38949 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&peer_device->device->packet_seq));
38950 return drbd_send_command(peer_device, sock, cmd, sizeof(*p), NULL, 0);
38951 }
38952
38953 @@ -1634,7 +1634,7 @@ int drbd_send_dblock(struct drbd_peer_device *peer_device, struct drbd_request *
38954 return -EIO;
38955 p->sector = cpu_to_be64(req->i.sector);
38956 p->block_id = (unsigned long)req;
38957 - p->seq_num = cpu_to_be32(atomic_inc_return(&device->packet_seq));
38958 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&device->packet_seq));
38959 dp_flags = bio_flags_to_wire(peer_device->connection, req->master_bio->bi_rw);
38960 if (device->state.conn >= C_SYNC_SOURCE &&
38961 device->state.conn <= C_PAUSED_SYNC_T)
38962 @@ -1915,8 +1915,8 @@ void drbd_init_set_defaults(struct drbd_device *device)
38963 atomic_set(&device->unacked_cnt, 0);
38964 atomic_set(&device->local_cnt, 0);
38965 atomic_set(&device->pp_in_use_by_net, 0);
38966 - atomic_set(&device->rs_sect_in, 0);
38967 - atomic_set(&device->rs_sect_ev, 0);
38968 + atomic_set_unchecked(&device->rs_sect_in, 0);
38969 + atomic_set_unchecked(&device->rs_sect_ev, 0);
38970 atomic_set(&device->ap_in_flight, 0);
38971 atomic_set(&device->md_io.in_use, 0);
38972
38973 @@ -2688,8 +2688,8 @@ void drbd_destroy_connection(struct kref *kref)
38974 struct drbd_connection *connection = container_of(kref, struct drbd_connection, kref);
38975 struct drbd_resource *resource = connection->resource;
38976
38977 - if (atomic_read(&connection->current_epoch->epoch_size) != 0)
38978 - drbd_err(connection, "epoch_size:%d\n", atomic_read(&connection->current_epoch->epoch_size));
38979 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size) != 0)
38980 + drbd_err(connection, "epoch_size:%d\n", atomic_read_unchecked(&connection->current_epoch->epoch_size));
38981 kfree(connection->current_epoch);
38982
38983 idr_destroy(&connection->peer_devices);
38984 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
38985 index 1cd47df..57c53c0 100644
38986 --- a/drivers/block/drbd/drbd_nl.c
38987 +++ b/drivers/block/drbd/drbd_nl.c
38988 @@ -3645,13 +3645,13 @@ finish:
38989
38990 void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
38991 {
38992 - static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38993 + static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38994 struct sk_buff *msg;
38995 struct drbd_genlmsghdr *d_out;
38996 unsigned seq;
38997 int err = -ENOMEM;
38998
38999 - seq = atomic_inc_return(&drbd_genl_seq);
39000 + seq = atomic_inc_return_unchecked(&drbd_genl_seq);
39001 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
39002 if (!msg)
39003 goto failed;
39004 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
39005 index 9342b8d..b6a6825 100644
39006 --- a/drivers/block/drbd/drbd_receiver.c
39007 +++ b/drivers/block/drbd/drbd_receiver.c
39008 @@ -870,7 +870,7 @@ int drbd_connected(struct drbd_peer_device *peer_device)
39009 struct drbd_device *device = peer_device->device;
39010 int err;
39011
39012 - atomic_set(&device->packet_seq, 0);
39013 + atomic_set_unchecked(&device->packet_seq, 0);
39014 device->peer_seq = 0;
39015
39016 device->state_mutex = peer_device->connection->agreed_pro_version < 100 ?
39017 @@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
39018 do {
39019 next_epoch = NULL;
39020
39021 - epoch_size = atomic_read(&epoch->epoch_size);
39022 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
39023
39024 switch (ev & ~EV_CLEANUP) {
39025 case EV_PUT:
39026 @@ -1273,7 +1273,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
39027 rv = FE_DESTROYED;
39028 } else {
39029 epoch->flags = 0;
39030 - atomic_set(&epoch->epoch_size, 0);
39031 + atomic_set_unchecked(&epoch->epoch_size, 0);
39032 /* atomic_set(&epoch->active, 0); is already zero */
39033 if (rv == FE_STILL_LIVE)
39034 rv = FE_RECYCLED;
39035 @@ -1550,7 +1550,7 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
39036 conn_wait_active_ee_empty(connection);
39037 drbd_flush(connection);
39038
39039 - if (atomic_read(&connection->current_epoch->epoch_size)) {
39040 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
39041 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
39042 if (epoch)
39043 break;
39044 @@ -1564,11 +1564,11 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
39045 }
39046
39047 epoch->flags = 0;
39048 - atomic_set(&epoch->epoch_size, 0);
39049 + atomic_set_unchecked(&epoch->epoch_size, 0);
39050 atomic_set(&epoch->active, 0);
39051
39052 spin_lock(&connection->epoch_lock);
39053 - if (atomic_read(&connection->current_epoch->epoch_size)) {
39054 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
39055 list_add(&epoch->list, &connection->current_epoch->list);
39056 connection->current_epoch = epoch;
39057 connection->epochs++;
39058 @@ -1802,7 +1802,7 @@ static int recv_resync_read(struct drbd_peer_device *peer_device, sector_t secto
39059 list_add_tail(&peer_req->w.list, &device->sync_ee);
39060 spin_unlock_irq(&device->resource->req_lock);
39061
39062 - atomic_add(pi->size >> 9, &device->rs_sect_ev);
39063 + atomic_add_unchecked(pi->size >> 9, &device->rs_sect_ev);
39064 if (drbd_submit_peer_request(device, peer_req, WRITE, DRBD_FAULT_RS_WR) == 0)
39065 return 0;
39066
39067 @@ -1900,7 +1900,7 @@ static int receive_RSDataReply(struct drbd_connection *connection, struct packet
39068 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
39069 }
39070
39071 - atomic_add(pi->size >> 9, &device->rs_sect_in);
39072 + atomic_add_unchecked(pi->size >> 9, &device->rs_sect_in);
39073
39074 return err;
39075 }
39076 @@ -2290,7 +2290,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
39077
39078 err = wait_for_and_update_peer_seq(peer_device, peer_seq);
39079 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
39080 - atomic_inc(&connection->current_epoch->epoch_size);
39081 + atomic_inc_unchecked(&connection->current_epoch->epoch_size);
39082 err2 = drbd_drain_block(peer_device, pi->size);
39083 if (!err)
39084 err = err2;
39085 @@ -2334,7 +2334,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
39086
39087 spin_lock(&connection->epoch_lock);
39088 peer_req->epoch = connection->current_epoch;
39089 - atomic_inc(&peer_req->epoch->epoch_size);
39090 + atomic_inc_unchecked(&peer_req->epoch->epoch_size);
39091 atomic_inc(&peer_req->epoch->active);
39092 spin_unlock(&connection->epoch_lock);
39093
39094 @@ -2479,7 +2479,7 @@ bool drbd_rs_c_min_rate_throttle(struct drbd_device *device)
39095
39096 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
39097 (int)part_stat_read(&disk->part0, sectors[1]) -
39098 - atomic_read(&device->rs_sect_ev);
39099 + atomic_read_unchecked(&device->rs_sect_ev);
39100
39101 if (atomic_read(&device->ap_actlog_cnt)
39102 || !device->rs_last_events || curr_events - device->rs_last_events > 64) {
39103 @@ -2618,7 +2618,7 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet
39104 device->use_csums = true;
39105 } else if (pi->cmd == P_OV_REPLY) {
39106 /* track progress, we may need to throttle */
39107 - atomic_add(size >> 9, &device->rs_sect_in);
39108 + atomic_add_unchecked(size >> 9, &device->rs_sect_in);
39109 peer_req->w.cb = w_e_end_ov_reply;
39110 dec_rs_pending(device);
39111 /* drbd_rs_begin_io done when we sent this request,
39112 @@ -2691,7 +2691,7 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet
39113 goto out_free_e;
39114
39115 submit_for_resync:
39116 - atomic_add(size >> 9, &device->rs_sect_ev);
39117 + atomic_add_unchecked(size >> 9, &device->rs_sect_ev);
39118
39119 submit:
39120 update_receiver_timing_details(connection, drbd_submit_peer_request);
39121 @@ -4564,7 +4564,7 @@ struct data_cmd {
39122 int expect_payload;
39123 size_t pkt_size;
39124 int (*fn)(struct drbd_connection *, struct packet_info *);
39125 -};
39126 +} __do_const;
39127
39128 static struct data_cmd drbd_cmd_handler[] = {
39129 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
39130 @@ -4678,7 +4678,7 @@ static void conn_disconnect(struct drbd_connection *connection)
39131 if (!list_empty(&connection->current_epoch->list))
39132 drbd_err(connection, "ASSERTION FAILED: connection->current_epoch->list not empty\n");
39133 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
39134 - atomic_set(&connection->current_epoch->epoch_size, 0);
39135 + atomic_set_unchecked(&connection->current_epoch->epoch_size, 0);
39136 connection->send.seen_any_write_yet = false;
39137
39138 drbd_info(connection, "Connection closed\n");
39139 @@ -5182,7 +5182,7 @@ static int got_IsInSync(struct drbd_connection *connection, struct packet_info *
39140 put_ldev(device);
39141 }
39142 dec_rs_pending(device);
39143 - atomic_add(blksize >> 9, &device->rs_sect_in);
39144 + atomic_add_unchecked(blksize >> 9, &device->rs_sect_in);
39145
39146 return 0;
39147 }
39148 @@ -5470,7 +5470,7 @@ static int connection_finish_peer_reqs(struct drbd_connection *connection)
39149 struct asender_cmd {
39150 size_t pkt_size;
39151 int (*fn)(struct drbd_connection *connection, struct packet_info *);
39152 -};
39153 +} __do_const;
39154
39155 static struct asender_cmd asender_tbl[] = {
39156 [P_PING] = { 0, got_Ping },
39157 diff --git a/drivers/block/drbd/drbd_worker.c b/drivers/block/drbd/drbd_worker.c
39158 index 50776b3..1477c3f 100644
39159 --- a/drivers/block/drbd/drbd_worker.c
39160 +++ b/drivers/block/drbd/drbd_worker.c
39161 @@ -408,7 +408,7 @@ static int read_for_csum(struct drbd_peer_device *peer_device, sector_t sector,
39162 list_add_tail(&peer_req->w.list, &device->read_ee);
39163 spin_unlock_irq(&device->resource->req_lock);
39164
39165 - atomic_add(size >> 9, &device->rs_sect_ev);
39166 + atomic_add_unchecked(size >> 9, &device->rs_sect_ev);
39167 if (drbd_submit_peer_request(device, peer_req, READ, DRBD_FAULT_RS_RD) == 0)
39168 return 0;
39169
39170 @@ -553,7 +553,7 @@ static int drbd_rs_number_requests(struct drbd_device *device)
39171 unsigned int sect_in; /* Number of sectors that came in since the last turn */
39172 int number, mxb;
39173
39174 - sect_in = atomic_xchg(&device->rs_sect_in, 0);
39175 + sect_in = atomic_xchg_unchecked(&device->rs_sect_in, 0);
39176 device->rs_in_flight -= sect_in;
39177
39178 rcu_read_lock();
39179 @@ -1594,8 +1594,8 @@ void drbd_rs_controller_reset(struct drbd_device *device)
39180 {
39181 struct fifo_buffer *plan;
39182
39183 - atomic_set(&device->rs_sect_in, 0);
39184 - atomic_set(&device->rs_sect_ev, 0);
39185 + atomic_set_unchecked(&device->rs_sect_in, 0);
39186 + atomic_set_unchecked(&device->rs_sect_ev, 0);
39187 device->rs_in_flight = 0;
39188
39189 /* Updating the RCU protected object in place is necessary since
39190 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39191 index 6cb1beb..bf490f7 100644
39192 --- a/drivers/block/loop.c
39193 +++ b/drivers/block/loop.c
39194 @@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
39195
39196 file_start_write(file);
39197 set_fs(get_ds());
39198 - bw = file->f_op->write(file, buf, len, &pos);
39199 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
39200 set_fs(old_fs);
39201 file_end_write(file);
39202 if (likely(bw == len))
39203 diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c
39204 index 02351e2..a9ea617 100644
39205 --- a/drivers/block/nvme-core.c
39206 +++ b/drivers/block/nvme-core.c
39207 @@ -73,7 +73,6 @@ static LIST_HEAD(dev_list);
39208 static struct task_struct *nvme_thread;
39209 static struct workqueue_struct *nvme_workq;
39210 static wait_queue_head_t nvme_kthread_wait;
39211 -static struct notifier_block nvme_nb;
39212
39213 static void nvme_reset_failed_dev(struct work_struct *ws);
39214
39215 @@ -2925,6 +2924,10 @@ static struct pci_driver nvme_driver = {
39216 .err_handler = &nvme_err_handler,
39217 };
39218
39219 +static struct notifier_block nvme_nb = {
39220 + .notifier_call = &nvme_cpu_notify,
39221 +};
39222 +
39223 static int __init nvme_init(void)
39224 {
39225 int result;
39226 @@ -2941,7 +2944,6 @@ static int __init nvme_init(void)
39227 else if (result > 0)
39228 nvme_major = result;
39229
39230 - nvme_nb.notifier_call = &nvme_cpu_notify;
39231 result = register_hotcpu_notifier(&nvme_nb);
39232 if (result)
39233 goto unregister_blkdev;
39234 diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
39235 index 758ac44..58087fd 100644
39236 --- a/drivers/block/pktcdvd.c
39237 +++ b/drivers/block/pktcdvd.c
39238 @@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
39239
39240 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
39241 {
39242 - return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
39243 + return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
39244 }
39245
39246 /*
39247 @@ -1888,7 +1888,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
39248 return -EROFS;
39249 }
39250 pd->settings.fp = ti.fp;
39251 - pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
39252 + pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
39253
39254 if (ti.nwa_v) {
39255 pd->nwa = be32_to_cpu(ti.next_writable);
39256 diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
39257 index e5565fb..71be10b4 100644
39258 --- a/drivers/block/smart1,2.h
39259 +++ b/drivers/block/smart1,2.h
39260 @@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
39261 }
39262
39263 static struct access_method smart4_access = {
39264 - smart4_submit_command,
39265 - smart4_intr_mask,
39266 - smart4_fifo_full,
39267 - smart4_intr_pending,
39268 - smart4_completed,
39269 + .submit_command = smart4_submit_command,
39270 + .set_intr_mask = smart4_intr_mask,
39271 + .fifo_full = smart4_fifo_full,
39272 + .intr_pending = smart4_intr_pending,
39273 + .command_completed = smart4_completed,
39274 };
39275
39276 /*
39277 @@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
39278 }
39279
39280 static struct access_method smart2_access = {
39281 - smart2_submit_command,
39282 - smart2_intr_mask,
39283 - smart2_fifo_full,
39284 - smart2_intr_pending,
39285 - smart2_completed,
39286 + .submit_command = smart2_submit_command,
39287 + .set_intr_mask = smart2_intr_mask,
39288 + .fifo_full = smart2_fifo_full,
39289 + .intr_pending = smart2_intr_pending,
39290 + .command_completed = smart2_completed,
39291 };
39292
39293 /*
39294 @@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
39295 }
39296
39297 static struct access_method smart2e_access = {
39298 - smart2e_submit_command,
39299 - smart2e_intr_mask,
39300 - smart2e_fifo_full,
39301 - smart2e_intr_pending,
39302 - smart2e_completed,
39303 + .submit_command = smart2e_submit_command,
39304 + .set_intr_mask = smart2e_intr_mask,
39305 + .fifo_full = smart2e_fifo_full,
39306 + .intr_pending = smart2e_intr_pending,
39307 + .command_completed = smart2e_completed,
39308 };
39309
39310 /*
39311 @@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
39312 }
39313
39314 static struct access_method smart1_access = {
39315 - smart1_submit_command,
39316 - smart1_intr_mask,
39317 - smart1_fifo_full,
39318 - smart1_intr_pending,
39319 - smart1_completed,
39320 + .submit_command = smart1_submit_command,
39321 + .set_intr_mask = smart1_intr_mask,
39322 + .fifo_full = smart1_fifo_full,
39323 + .intr_pending = smart1_intr_pending,
39324 + .command_completed = smart1_completed,
39325 };
39326 diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
39327 index f038dba..bb74c08 100644
39328 --- a/drivers/bluetooth/btwilink.c
39329 +++ b/drivers/bluetooth/btwilink.c
39330 @@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
39331
39332 static int bt_ti_probe(struct platform_device *pdev)
39333 {
39334 - static struct ti_st *hst;
39335 + struct ti_st *hst;
39336 struct hci_dev *hdev;
39337 int err;
39338
39339 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
39340 index 898b84b..86f74b9 100644
39341 --- a/drivers/cdrom/cdrom.c
39342 +++ b/drivers/cdrom/cdrom.c
39343 @@ -610,7 +610,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
39344 ENSURE(reset, CDC_RESET);
39345 ENSURE(generic_packet, CDC_GENERIC_PACKET);
39346 cdi->mc_flags = 0;
39347 - cdo->n_minors = 0;
39348 cdi->options = CDO_USE_FFLAGS;
39349
39350 if (autoclose == 1 && CDROM_CAN(CDC_CLOSE_TRAY))
39351 @@ -630,8 +629,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
39352 else
39353 cdi->cdda_method = CDDA_OLD;
39354
39355 - if (!cdo->generic_packet)
39356 - cdo->generic_packet = cdrom_dummy_generic_packet;
39357 + if (!cdo->generic_packet) {
39358 + pax_open_kernel();
39359 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
39360 + pax_close_kernel();
39361 + }
39362
39363 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
39364 mutex_lock(&cdrom_mutex);
39365 @@ -652,7 +654,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
39366 if (cdi->exit)
39367 cdi->exit(cdi);
39368
39369 - cdi->ops->n_minors--;
39370 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
39371 }
39372
39373 @@ -2126,7 +2127,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
39374 */
39375 nr = nframes;
39376 do {
39377 - cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
39378 + cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
39379 if (cgc.buffer)
39380 break;
39381
39382 @@ -3434,7 +3435,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
39383 struct cdrom_device_info *cdi;
39384 int ret;
39385
39386 - ret = scnprintf(info + *pos, max_size - *pos, header);
39387 + ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
39388 if (!ret)
39389 return 1;
39390
39391 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
39392 index 584bc31..e64a12c 100644
39393 --- a/drivers/cdrom/gdrom.c
39394 +++ b/drivers/cdrom/gdrom.c
39395 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
39396 .audio_ioctl = gdrom_audio_ioctl,
39397 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
39398 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
39399 - .n_minors = 1,
39400 };
39401
39402 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
39403 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
39404 index 6e9f74a..50c7cea 100644
39405 --- a/drivers/char/Kconfig
39406 +++ b/drivers/char/Kconfig
39407 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
39408
39409 config DEVKMEM
39410 bool "/dev/kmem virtual device support"
39411 - default y
39412 + default n
39413 + depends on !GRKERNSEC_KMEM
39414 help
39415 Say Y here if you want to support the /dev/kmem device. The
39416 /dev/kmem device is rarely used, but can be used for certain
39417 @@ -577,6 +578,7 @@ config DEVPORT
39418 bool
39419 depends on !M68K
39420 depends on ISA || PCI
39421 + depends on !GRKERNSEC_KMEM
39422 default y
39423
39424 source "drivers/s390/char/Kconfig"
39425 diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
39426 index a48e05b..6bac831 100644
39427 --- a/drivers/char/agp/compat_ioctl.c
39428 +++ b/drivers/char/agp/compat_ioctl.c
39429 @@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
39430 return -ENOMEM;
39431 }
39432
39433 - if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
39434 + if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
39435 sizeof(*usegment) * ureserve.seg_count)) {
39436 kfree(usegment);
39437 kfree(ksegment);
39438 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
39439 index 09f17eb..8531d2f 100644
39440 --- a/drivers/char/agp/frontend.c
39441 +++ b/drivers/char/agp/frontend.c
39442 @@ -806,7 +806,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
39443 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
39444 return -EFAULT;
39445
39446 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
39447 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
39448 return -EFAULT;
39449
39450 client = agp_find_client_by_pid(reserve.pid);
39451 @@ -836,7 +836,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
39452 if (segment == NULL)
39453 return -ENOMEM;
39454
39455 - if (copy_from_user(segment, (void __user *) reserve.seg_list,
39456 + if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
39457 sizeof(struct agp_segment) * reserve.seg_count)) {
39458 kfree(segment);
39459 return -EFAULT;
39460 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
39461 index 4f94375..413694e 100644
39462 --- a/drivers/char/genrtc.c
39463 +++ b/drivers/char/genrtc.c
39464 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
39465 switch (cmd) {
39466
39467 case RTC_PLL_GET:
39468 + memset(&pll, 0, sizeof(pll));
39469 if (get_rtc_pll(&pll))
39470 return -EINVAL;
39471 else
39472 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
39473 index d5d4cd8..22d561d 100644
39474 --- a/drivers/char/hpet.c
39475 +++ b/drivers/char/hpet.c
39476 @@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
39477 }
39478
39479 static int
39480 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
39481 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
39482 struct hpet_info *info)
39483 {
39484 struct hpet_timer __iomem *timer;
39485 diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
39486 index 86fe45c..c0ea948 100644
39487 --- a/drivers/char/hw_random/intel-rng.c
39488 +++ b/drivers/char/hw_random/intel-rng.c
39489 @@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
39490
39491 if (no_fwh_detect)
39492 return -ENODEV;
39493 - printk(warning);
39494 + printk("%s", warning);
39495 return -EBUSY;
39496 }
39497
39498 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
39499 index e6db938..835e3a2 100644
39500 --- a/drivers/char/ipmi/ipmi_msghandler.c
39501 +++ b/drivers/char/ipmi/ipmi_msghandler.c
39502 @@ -438,7 +438,7 @@ struct ipmi_smi {
39503 struct proc_dir_entry *proc_dir;
39504 char proc_dir_name[10];
39505
39506 - atomic_t stats[IPMI_NUM_STATS];
39507 + atomic_unchecked_t stats[IPMI_NUM_STATS];
39508
39509 /*
39510 * run_to_completion duplicate of smb_info, smi_info
39511 @@ -470,9 +470,9 @@ static LIST_HEAD(smi_watchers);
39512 static DEFINE_MUTEX(smi_watchers_mutex);
39513
39514 #define ipmi_inc_stat(intf, stat) \
39515 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
39516 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
39517 #define ipmi_get_stat(intf, stat) \
39518 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
39519 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
39520
39521 static int is_lan_addr(struct ipmi_addr *addr)
39522 {
39523 @@ -2926,7 +2926,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
39524 INIT_LIST_HEAD(&intf->cmd_rcvrs);
39525 init_waitqueue_head(&intf->waitq);
39526 for (i = 0; i < IPMI_NUM_STATS; i++)
39527 - atomic_set(&intf->stats[i], 0);
39528 + atomic_set_unchecked(&intf->stats[i], 0);
39529
39530 intf->proc_dir = NULL;
39531
39532 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
39533 index 5d66568..c9d93c3 100644
39534 --- a/drivers/char/ipmi/ipmi_si_intf.c
39535 +++ b/drivers/char/ipmi/ipmi_si_intf.c
39536 @@ -285,7 +285,7 @@ struct smi_info {
39537 unsigned char slave_addr;
39538
39539 /* Counters and things for the proc filesystem. */
39540 - atomic_t stats[SI_NUM_STATS];
39541 + atomic_unchecked_t stats[SI_NUM_STATS];
39542
39543 struct task_struct *thread;
39544
39545 @@ -294,9 +294,9 @@ struct smi_info {
39546 };
39547
39548 #define smi_inc_stat(smi, stat) \
39549 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
39550 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
39551 #define smi_get_stat(smi, stat) \
39552 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
39553 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
39554
39555 #define SI_MAX_PARMS 4
39556
39557 @@ -3374,7 +3374,7 @@ static int try_smi_init(struct smi_info *new_smi)
39558 atomic_set(&new_smi->req_events, 0);
39559 new_smi->run_to_completion = false;
39560 for (i = 0; i < SI_NUM_STATS; i++)
39561 - atomic_set(&new_smi->stats[i], 0);
39562 + atomic_set_unchecked(&new_smi->stats[i], 0);
39563
39564 new_smi->interrupt_disabled = true;
39565 atomic_set(&new_smi->stop_operation, 0);
39566 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
39567 index 917403f..dddd899 100644
39568 --- a/drivers/char/mem.c
39569 +++ b/drivers/char/mem.c
39570 @@ -18,6 +18,7 @@
39571 #include <linux/raw.h>
39572 #include <linux/tty.h>
39573 #include <linux/capability.h>
39574 +#include <linux/security.h>
39575 #include <linux/ptrace.h>
39576 #include <linux/device.h>
39577 #include <linux/highmem.h>
39578 @@ -36,6 +37,10 @@
39579
39580 #define DEVPORT_MINOR 4
39581
39582 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
39583 +extern const struct file_operations grsec_fops;
39584 +#endif
39585 +
39586 static inline unsigned long size_inside_page(unsigned long start,
39587 unsigned long size)
39588 {
39589 @@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
39590
39591 while (cursor < to) {
39592 if (!devmem_is_allowed(pfn)) {
39593 +#ifdef CONFIG_GRKERNSEC_KMEM
39594 + gr_handle_mem_readwrite(from, to);
39595 +#else
39596 printk(KERN_INFO
39597 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
39598 current->comm, from, to);
39599 +#endif
39600 return 0;
39601 }
39602 cursor += PAGE_SIZE;
39603 @@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
39604 }
39605 return 1;
39606 }
39607 +#elif defined(CONFIG_GRKERNSEC_KMEM)
39608 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
39609 +{
39610 + return 0;
39611 +}
39612 #else
39613 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
39614 {
39615 @@ -122,6 +136,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
39616
39617 while (count > 0) {
39618 unsigned long remaining;
39619 + char *temp;
39620
39621 sz = size_inside_page(p, count);
39622
39623 @@ -137,7 +152,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
39624 if (!ptr)
39625 return -EFAULT;
39626
39627 - remaining = copy_to_user(buf, ptr, sz);
39628 +#ifdef CONFIG_PAX_USERCOPY
39629 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
39630 + if (!temp) {
39631 + unxlate_dev_mem_ptr(p, ptr);
39632 + return -ENOMEM;
39633 + }
39634 + memcpy(temp, ptr, sz);
39635 +#else
39636 + temp = ptr;
39637 +#endif
39638 +
39639 + remaining = copy_to_user(buf, temp, sz);
39640 +
39641 +#ifdef CONFIG_PAX_USERCOPY
39642 + kfree(temp);
39643 +#endif
39644 +
39645 unxlate_dev_mem_ptr(p, ptr);
39646 if (remaining)
39647 return -EFAULT;
39648 @@ -369,9 +400,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
39649 size_t count, loff_t *ppos)
39650 {
39651 unsigned long p = *ppos;
39652 - ssize_t low_count, read, sz;
39653 + ssize_t low_count, read, sz, err = 0;
39654 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
39655 - int err = 0;
39656
39657 read = 0;
39658 if (p < (unsigned long) high_memory) {
39659 @@ -393,6 +423,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
39660 }
39661 #endif
39662 while (low_count > 0) {
39663 + char *temp;
39664 +
39665 sz = size_inside_page(p, low_count);
39666
39667 /*
39668 @@ -402,7 +434,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
39669 */
39670 kbuf = xlate_dev_kmem_ptr((char *)p);
39671
39672 - if (copy_to_user(buf, kbuf, sz))
39673 +#ifdef CONFIG_PAX_USERCOPY
39674 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
39675 + if (!temp)
39676 + return -ENOMEM;
39677 + memcpy(temp, kbuf, sz);
39678 +#else
39679 + temp = kbuf;
39680 +#endif
39681 +
39682 + err = copy_to_user(buf, temp, sz);
39683 +
39684 +#ifdef CONFIG_PAX_USERCOPY
39685 + kfree(temp);
39686 +#endif
39687 +
39688 + if (err)
39689 return -EFAULT;
39690 buf += sz;
39691 p += sz;
39692 @@ -827,6 +874,9 @@ static const struct memdev {
39693 #ifdef CONFIG_PRINTK
39694 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
39695 #endif
39696 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
39697 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
39698 +#endif
39699 };
39700
39701 static int memory_open(struct inode *inode, struct file *filp)
39702 @@ -898,7 +948,7 @@ static int __init chr_dev_init(void)
39703 continue;
39704
39705 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
39706 - NULL, devlist[minor].name);
39707 + NULL, "%s", devlist[minor].name);
39708 }
39709
39710 return tty_init();
39711 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
39712 index 9df78e2..01ba9ae 100644
39713 --- a/drivers/char/nvram.c
39714 +++ b/drivers/char/nvram.c
39715 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
39716
39717 spin_unlock_irq(&rtc_lock);
39718
39719 - if (copy_to_user(buf, contents, tmp - contents))
39720 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
39721 return -EFAULT;
39722
39723 *ppos = i;
39724 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
39725 index 0ea9986..e7b07e4 100644
39726 --- a/drivers/char/pcmcia/synclink_cs.c
39727 +++ b/drivers/char/pcmcia/synclink_cs.c
39728 @@ -2345,7 +2345,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
39729
39730 if (debug_level >= DEBUG_LEVEL_INFO)
39731 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
39732 - __FILE__, __LINE__, info->device_name, port->count);
39733 + __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
39734
39735 if (tty_port_close_start(port, tty, filp) == 0)
39736 goto cleanup;
39737 @@ -2363,7 +2363,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
39738 cleanup:
39739 if (debug_level >= DEBUG_LEVEL_INFO)
39740 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
39741 - tty->driver->name, port->count);
39742 + tty->driver->name, atomic_read(&port->count));
39743 }
39744
39745 /* Wait until the transmitter is empty.
39746 @@ -2505,7 +2505,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
39747
39748 if (debug_level >= DEBUG_LEVEL_INFO)
39749 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
39750 - __FILE__, __LINE__, tty->driver->name, port->count);
39751 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
39752
39753 /* If port is closing, signal caller to try again */
39754 if (port->flags & ASYNC_CLOSING){
39755 @@ -2525,11 +2525,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
39756 goto cleanup;
39757 }
39758 spin_lock(&port->lock);
39759 - port->count++;
39760 + atomic_inc(&port->count);
39761 spin_unlock(&port->lock);
39762 spin_unlock_irqrestore(&info->netlock, flags);
39763
39764 - if (port->count == 1) {
39765 + if (atomic_read(&port->count) == 1) {
39766 /* 1st open on this device, init hardware */
39767 retval = startup(info, tty);
39768 if (retval < 0)
39769 @@ -3918,7 +3918,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
39770 unsigned short new_crctype;
39771
39772 /* return error if TTY interface open */
39773 - if (info->port.count)
39774 + if (atomic_read(&info->port.count))
39775 return -EBUSY;
39776
39777 switch (encoding)
39778 @@ -4022,7 +4022,7 @@ static int hdlcdev_open(struct net_device *dev)
39779
39780 /* arbitrate between network and tty opens */
39781 spin_lock_irqsave(&info->netlock, flags);
39782 - if (info->port.count != 0 || info->netcount != 0) {
39783 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
39784 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
39785 spin_unlock_irqrestore(&info->netlock, flags);
39786 return -EBUSY;
39787 @@ -4112,7 +4112,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39788 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
39789
39790 /* return error if TTY interface open */
39791 - if (info->port.count)
39792 + if (atomic_read(&info->port.count))
39793 return -EBUSY;
39794
39795 if (cmd != SIOCWANDEV)
39796 diff --git a/drivers/char/random.c b/drivers/char/random.c
39797 index 8c86a95..7c499f3 100644
39798 --- a/drivers/char/random.c
39799 +++ b/drivers/char/random.c
39800 @@ -289,9 +289,6 @@
39801 /*
39802 * To allow fractional bits to be tracked, the entropy_count field is
39803 * denominated in units of 1/8th bits.
39804 - *
39805 - * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
39806 - * credit_entropy_bits() needs to be 64 bits wide.
39807 */
39808 #define ENTROPY_SHIFT 3
39809 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
39810 @@ -439,9 +436,9 @@ struct entropy_store {
39811 };
39812
39813 static void push_to_pool(struct work_struct *work);
39814 -static __u32 input_pool_data[INPUT_POOL_WORDS];
39815 -static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
39816 -static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
39817 +static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
39818 +static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
39819 +static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
39820
39821 static struct entropy_store input_pool = {
39822 .poolinfo = &poolinfo_table[0],
39823 @@ -635,7 +632,7 @@ retry:
39824 /* The +2 corresponds to the /4 in the denominator */
39825
39826 do {
39827 - unsigned int anfrac = min(pnfrac, pool_size/2);
39828 + u64 anfrac = min(pnfrac, pool_size/2);
39829 unsigned int add =
39830 ((pool_size - entropy_count)*anfrac*3) >> s;
39831
39832 @@ -1207,7 +1204,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
39833
39834 extract_buf(r, tmp);
39835 i = min_t(int, nbytes, EXTRACT_SIZE);
39836 - if (copy_to_user(buf, tmp, i)) {
39837 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
39838 ret = -EFAULT;
39839 break;
39840 }
39841 @@ -1590,7 +1587,7 @@ static char sysctl_bootid[16];
39842 static int proc_do_uuid(struct ctl_table *table, int write,
39843 void __user *buffer, size_t *lenp, loff_t *ppos)
39844 {
39845 - struct ctl_table fake_table;
39846 + ctl_table_no_const fake_table;
39847 unsigned char buf[64], tmp_uuid[16], *uuid;
39848
39849 uuid = table->data;
39850 @@ -1620,7 +1617,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
39851 static int proc_do_entropy(struct ctl_table *table, int write,
39852 void __user *buffer, size_t *lenp, loff_t *ppos)
39853 {
39854 - struct ctl_table fake_table;
39855 + ctl_table_no_const fake_table;
39856 int entropy_count;
39857
39858 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
39859 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
39860 index 7cc1fe22..b602d6b 100644
39861 --- a/drivers/char/sonypi.c
39862 +++ b/drivers/char/sonypi.c
39863 @@ -54,6 +54,7 @@
39864
39865 #include <asm/uaccess.h>
39866 #include <asm/io.h>
39867 +#include <asm/local.h>
39868
39869 #include <linux/sonypi.h>
39870
39871 @@ -490,7 +491,7 @@ static struct sonypi_device {
39872 spinlock_t fifo_lock;
39873 wait_queue_head_t fifo_proc_list;
39874 struct fasync_struct *fifo_async;
39875 - int open_count;
39876 + local_t open_count;
39877 int model;
39878 struct input_dev *input_jog_dev;
39879 struct input_dev *input_key_dev;
39880 @@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
39881 static int sonypi_misc_release(struct inode *inode, struct file *file)
39882 {
39883 mutex_lock(&sonypi_device.lock);
39884 - sonypi_device.open_count--;
39885 + local_dec(&sonypi_device.open_count);
39886 mutex_unlock(&sonypi_device.lock);
39887 return 0;
39888 }
39889 @@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
39890 {
39891 mutex_lock(&sonypi_device.lock);
39892 /* Flush input queue on first open */
39893 - if (!sonypi_device.open_count)
39894 + if (!local_read(&sonypi_device.open_count))
39895 kfifo_reset(&sonypi_device.fifo);
39896 - sonypi_device.open_count++;
39897 + local_inc(&sonypi_device.open_count);
39898 mutex_unlock(&sonypi_device.lock);
39899
39900 return 0;
39901 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
39902 index 565a947..dcdc06e 100644
39903 --- a/drivers/char/tpm/tpm_acpi.c
39904 +++ b/drivers/char/tpm/tpm_acpi.c
39905 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
39906 virt = acpi_os_map_iomem(start, len);
39907 if (!virt) {
39908 kfree(log->bios_event_log);
39909 + log->bios_event_log = NULL;
39910 printk("%s: ERROR - Unable to map memory\n", __func__);
39911 return -EIO;
39912 }
39913
39914 - memcpy_fromio(log->bios_event_log, virt, len);
39915 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
39916
39917 acpi_os_unmap_iomem(virt, len);
39918 return 0;
39919 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
39920 index 3a56a13..f8cbd25 100644
39921 --- a/drivers/char/tpm/tpm_eventlog.c
39922 +++ b/drivers/char/tpm/tpm_eventlog.c
39923 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
39924 event = addr;
39925
39926 if ((event->event_type == 0 && event->event_size == 0) ||
39927 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
39928 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
39929 return NULL;
39930
39931 return addr;
39932 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
39933 return NULL;
39934
39935 if ((event->event_type == 0 && event->event_size == 0) ||
39936 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
39937 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
39938 return NULL;
39939
39940 (*pos)++;
39941 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
39942 int i;
39943
39944 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
39945 - seq_putc(m, data[i]);
39946 + if (!seq_putc(m, data[i]))
39947 + return -EFAULT;
39948
39949 return 0;
39950 }
39951 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
39952 index b585b47..488f43e 100644
39953 --- a/drivers/char/virtio_console.c
39954 +++ b/drivers/char/virtio_console.c
39955 @@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
39956 if (to_user) {
39957 ssize_t ret;
39958
39959 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
39960 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
39961 if (ret)
39962 return -EFAULT;
39963 } else {
39964 @@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
39965 if (!port_has_data(port) && !port->host_connected)
39966 return 0;
39967
39968 - return fill_readbuf(port, ubuf, count, true);
39969 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
39970 }
39971
39972 static int wait_port_writable(struct port *port, bool nonblock)
39973 diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
39974 index b9355da..9611f4e 100644
39975 --- a/drivers/clk/clk-composite.c
39976 +++ b/drivers/clk/clk-composite.c
39977 @@ -191,7 +191,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
39978 struct clk *clk;
39979 struct clk_init_data init;
39980 struct clk_composite *composite;
39981 - struct clk_ops *clk_composite_ops;
39982 + clk_ops_no_const *clk_composite_ops;
39983
39984 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
39985 if (!composite) {
39986 diff --git a/drivers/clk/socfpga/clk-gate.c b/drivers/clk/socfpga/clk-gate.c
39987 index dd3a78c..386d49c 100644
39988 --- a/drivers/clk/socfpga/clk-gate.c
39989 +++ b/drivers/clk/socfpga/clk-gate.c
39990 @@ -22,6 +22,7 @@
39991 #include <linux/mfd/syscon.h>
39992 #include <linux/of.h>
39993 #include <linux/regmap.h>
39994 +#include <asm/pgtable.h>
39995
39996 #include "clk.h"
39997
39998 @@ -174,7 +175,7 @@ static int socfpga_clk_prepare(struct clk_hw *hwclk)
39999 return 0;
40000 }
40001
40002 -static struct clk_ops gateclk_ops = {
40003 +static clk_ops_no_const gateclk_ops __read_only = {
40004 .prepare = socfpga_clk_prepare,
40005 .recalc_rate = socfpga_clk_recalc_rate,
40006 .get_parent = socfpga_clk_get_parent,
40007 @@ -208,8 +209,10 @@ static void __init __socfpga_gate_init(struct device_node *node,
40008 socfpga_clk->hw.reg = clk_mgr_base_addr + clk_gate[0];
40009 socfpga_clk->hw.bit_idx = clk_gate[1];
40010
40011 - gateclk_ops.enable = clk_gate_ops.enable;
40012 - gateclk_ops.disable = clk_gate_ops.disable;
40013 + pax_open_kernel();
40014 + *(void **)&gateclk_ops.enable = clk_gate_ops.enable;
40015 + *(void **)&gateclk_ops.disable = clk_gate_ops.disable;
40016 + pax_close_kernel();
40017 }
40018
40019 rc = of_property_read_u32(node, "fixed-divider", &fixed_div);
40020 diff --git a/drivers/clk/socfpga/clk-pll.c b/drivers/clk/socfpga/clk-pll.c
40021 index de6da95..c98278b 100644
40022 --- a/drivers/clk/socfpga/clk-pll.c
40023 +++ b/drivers/clk/socfpga/clk-pll.c
40024 @@ -21,6 +21,7 @@
40025 #include <linux/io.h>
40026 #include <linux/of.h>
40027 #include <linux/of_address.h>
40028 +#include <asm/pgtable.h>
40029
40030 #include "clk.h"
40031
40032 @@ -76,7 +77,7 @@ static u8 clk_pll_get_parent(struct clk_hw *hwclk)
40033 CLK_MGR_PLL_CLK_SRC_MASK;
40034 }
40035
40036 -static struct clk_ops clk_pll_ops = {
40037 +static clk_ops_no_const clk_pll_ops __read_only = {
40038 .recalc_rate = clk_pll_recalc_rate,
40039 .get_parent = clk_pll_get_parent,
40040 };
40041 @@ -120,8 +121,10 @@ static __init struct clk *__socfpga_pll_init(struct device_node *node,
40042 pll_clk->hw.hw.init = &init;
40043
40044 pll_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
40045 - clk_pll_ops.enable = clk_gate_ops.enable;
40046 - clk_pll_ops.disable = clk_gate_ops.disable;
40047 + pax_open_kernel();
40048 + *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
40049 + *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
40050 + pax_close_kernel();
40051
40052 clk = clk_register(NULL, &pll_clk->hw.hw);
40053 if (WARN_ON(IS_ERR(clk))) {
40054 diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
40055 index b0c18ed..1713a80 100644
40056 --- a/drivers/cpufreq/acpi-cpufreq.c
40057 +++ b/drivers/cpufreq/acpi-cpufreq.c
40058 @@ -675,8 +675,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
40059 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
40060 per_cpu(acfreq_data, cpu) = data;
40061
40062 - if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
40063 - acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
40064 + if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
40065 + pax_open_kernel();
40066 + *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
40067 + pax_close_kernel();
40068 + }
40069
40070 result = acpi_processor_register_performance(data->acpi_data, cpu);
40071 if (result)
40072 @@ -809,7 +812,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
40073 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
40074 break;
40075 case ACPI_ADR_SPACE_FIXED_HARDWARE:
40076 - acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
40077 + pax_open_kernel();
40078 + *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
40079 + pax_close_kernel();
40080 break;
40081 default:
40082 break;
40083 @@ -903,8 +908,10 @@ static void __init acpi_cpufreq_boost_init(void)
40084 if (!msrs)
40085 return;
40086
40087 - acpi_cpufreq_driver.boost_supported = true;
40088 - acpi_cpufreq_driver.boost_enabled = boost_state(0);
40089 + pax_open_kernel();
40090 + *(bool *)&acpi_cpufreq_driver.boost_supported = true;
40091 + *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
40092 + pax_close_kernel();
40093
40094 cpu_notifier_register_begin();
40095
40096 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
40097 index 07c8276..38bd07c 100644
40098 --- a/drivers/cpufreq/cpufreq.c
40099 +++ b/drivers/cpufreq/cpufreq.c
40100 @@ -2107,7 +2107,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
40101 }
40102
40103 mutex_lock(&cpufreq_governor_mutex);
40104 - list_del(&governor->governor_list);
40105 + pax_list_del(&governor->governor_list);
40106 mutex_unlock(&cpufreq_governor_mutex);
40107 return;
40108 }
40109 @@ -2323,7 +2323,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
40110 return NOTIFY_OK;
40111 }
40112
40113 -static struct notifier_block __refdata cpufreq_cpu_notifier = {
40114 +static struct notifier_block cpufreq_cpu_notifier = {
40115 .notifier_call = cpufreq_cpu_callback,
40116 };
40117
40118 @@ -2363,13 +2363,17 @@ int cpufreq_boost_trigger_state(int state)
40119 return 0;
40120
40121 write_lock_irqsave(&cpufreq_driver_lock, flags);
40122 - cpufreq_driver->boost_enabled = state;
40123 + pax_open_kernel();
40124 + *(bool *)&cpufreq_driver->boost_enabled = state;
40125 + pax_close_kernel();
40126 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
40127
40128 ret = cpufreq_driver->set_boost(state);
40129 if (ret) {
40130 write_lock_irqsave(&cpufreq_driver_lock, flags);
40131 - cpufreq_driver->boost_enabled = !state;
40132 + pax_open_kernel();
40133 + *(bool *)&cpufreq_driver->boost_enabled = !state;
40134 + pax_close_kernel();
40135 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
40136
40137 pr_err("%s: Cannot %s BOOST\n",
40138 @@ -2426,8 +2430,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
40139
40140 pr_debug("trying to register driver %s\n", driver_data->name);
40141
40142 - if (driver_data->setpolicy)
40143 - driver_data->flags |= CPUFREQ_CONST_LOOPS;
40144 + if (driver_data->setpolicy) {
40145 + pax_open_kernel();
40146 + *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
40147 + pax_close_kernel();
40148 + }
40149
40150 write_lock_irqsave(&cpufreq_driver_lock, flags);
40151 if (cpufreq_driver) {
40152 @@ -2442,8 +2449,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
40153 * Check if driver provides function to enable boost -
40154 * if not, use cpufreq_boost_set_sw as default
40155 */
40156 - if (!cpufreq_driver->set_boost)
40157 - cpufreq_driver->set_boost = cpufreq_boost_set_sw;
40158 + if (!cpufreq_driver->set_boost) {
40159 + pax_open_kernel();
40160 + *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
40161 + pax_close_kernel();
40162 + }
40163
40164 ret = cpufreq_sysfs_create_file(&boost.attr);
40165 if (ret) {
40166 diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
40167 index 1b44496..b80ff5e 100644
40168 --- a/drivers/cpufreq/cpufreq_governor.c
40169 +++ b/drivers/cpufreq/cpufreq_governor.c
40170 @@ -245,7 +245,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
40171 struct dbs_data *dbs_data;
40172 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
40173 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
40174 - struct od_ops *od_ops = NULL;
40175 + const struct od_ops *od_ops = NULL;
40176 struct od_dbs_tuners *od_tuners = NULL;
40177 struct cs_dbs_tuners *cs_tuners = NULL;
40178 struct cpu_dbs_common_info *cpu_cdbs;
40179 @@ -311,7 +311,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
40180
40181 if ((cdata->governor == GOV_CONSERVATIVE) &&
40182 (!policy->governor->initialized)) {
40183 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
40184 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
40185
40186 cpufreq_register_notifier(cs_ops->notifier_block,
40187 CPUFREQ_TRANSITION_NOTIFIER);
40188 @@ -331,7 +331,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
40189
40190 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
40191 (policy->governor->initialized == 1)) {
40192 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
40193 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
40194
40195 cpufreq_unregister_notifier(cs_ops->notifier_block,
40196 CPUFREQ_TRANSITION_NOTIFIER);
40197 diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
40198 index cc401d1..8197340 100644
40199 --- a/drivers/cpufreq/cpufreq_governor.h
40200 +++ b/drivers/cpufreq/cpufreq_governor.h
40201 @@ -212,7 +212,7 @@ struct common_dbs_data {
40202 void (*exit)(struct dbs_data *dbs_data);
40203
40204 /* Governor specific ops, see below */
40205 - void *gov_ops;
40206 + const void *gov_ops;
40207 };
40208
40209 /* Governor Per policy data */
40210 @@ -232,7 +232,7 @@ struct od_ops {
40211 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
40212 unsigned int freq_next, unsigned int relation);
40213 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
40214 -};
40215 +} __no_const;
40216
40217 struct cs_ops {
40218 struct notifier_block *notifier_block;
40219 diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
40220 index ad3f38f..8f086cd 100644
40221 --- a/drivers/cpufreq/cpufreq_ondemand.c
40222 +++ b/drivers/cpufreq/cpufreq_ondemand.c
40223 @@ -524,7 +524,7 @@ static void od_exit(struct dbs_data *dbs_data)
40224
40225 define_get_cpu_dbs_routines(od_cpu_dbs_info);
40226
40227 -static struct od_ops od_ops = {
40228 +static struct od_ops od_ops __read_only = {
40229 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
40230 .powersave_bias_target = generic_powersave_bias_target,
40231 .freq_increase = dbs_freq_increase,
40232 @@ -579,14 +579,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
40233 (struct cpufreq_policy *, unsigned int, unsigned int),
40234 unsigned int powersave_bias)
40235 {
40236 - od_ops.powersave_bias_target = f;
40237 + pax_open_kernel();
40238 + *(void **)&od_ops.powersave_bias_target = f;
40239 + pax_close_kernel();
40240 od_set_powersave_bias(powersave_bias);
40241 }
40242 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
40243
40244 void od_unregister_powersave_bias_handler(void)
40245 {
40246 - od_ops.powersave_bias_target = generic_powersave_bias_target;
40247 + pax_open_kernel();
40248 + *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
40249 + pax_close_kernel();
40250 od_set_powersave_bias(0);
40251 }
40252 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
40253 diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
40254 index 27bb6d3..4cf595c 100644
40255 --- a/drivers/cpufreq/intel_pstate.c
40256 +++ b/drivers/cpufreq/intel_pstate.c
40257 @@ -133,10 +133,10 @@ struct pstate_funcs {
40258 struct cpu_defaults {
40259 struct pstate_adjust_policy pid_policy;
40260 struct pstate_funcs funcs;
40261 -};
40262 +} __do_const;
40263
40264 static struct pstate_adjust_policy pid_params;
40265 -static struct pstate_funcs pstate_funcs;
40266 +static struct pstate_funcs *pstate_funcs;
40267
40268 struct perf_limits {
40269 int no_turbo;
40270 @@ -594,18 +594,18 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
40271
40272 cpu->pstate.current_pstate = pstate;
40273
40274 - pstate_funcs.set(cpu, pstate);
40275 + pstate_funcs->set(cpu, pstate);
40276 }
40277
40278 static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
40279 {
40280 - cpu->pstate.min_pstate = pstate_funcs.get_min();
40281 - cpu->pstate.max_pstate = pstate_funcs.get_max();
40282 - cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
40283 - cpu->pstate.scaling = pstate_funcs.get_scaling();
40284 + cpu->pstate.min_pstate = pstate_funcs->get_min();
40285 + cpu->pstate.max_pstate = pstate_funcs->get_max();
40286 + cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
40287 + cpu->pstate.scaling = pstate_funcs->get_scaling();
40288
40289 - if (pstate_funcs.get_vid)
40290 - pstate_funcs.get_vid(cpu);
40291 + if (pstate_funcs->get_vid)
40292 + pstate_funcs->get_vid(cpu);
40293 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate);
40294 }
40295
40296 @@ -875,9 +875,9 @@ static int intel_pstate_msrs_not_valid(void)
40297 rdmsrl(MSR_IA32_APERF, aperf);
40298 rdmsrl(MSR_IA32_MPERF, mperf);
40299
40300 - if (!pstate_funcs.get_max() ||
40301 - !pstate_funcs.get_min() ||
40302 - !pstate_funcs.get_turbo())
40303 + if (!pstate_funcs->get_max() ||
40304 + !pstate_funcs->get_min() ||
40305 + !pstate_funcs->get_turbo())
40306 return -ENODEV;
40307
40308 rdmsrl(MSR_IA32_APERF, tmp);
40309 @@ -891,7 +891,7 @@ static int intel_pstate_msrs_not_valid(void)
40310 return 0;
40311 }
40312
40313 -static void copy_pid_params(struct pstate_adjust_policy *policy)
40314 +static void copy_pid_params(const struct pstate_adjust_policy *policy)
40315 {
40316 pid_params.sample_rate_ms = policy->sample_rate_ms;
40317 pid_params.p_gain_pct = policy->p_gain_pct;
40318 @@ -903,12 +903,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
40319
40320 static void copy_cpu_funcs(struct pstate_funcs *funcs)
40321 {
40322 - pstate_funcs.get_max = funcs->get_max;
40323 - pstate_funcs.get_min = funcs->get_min;
40324 - pstate_funcs.get_turbo = funcs->get_turbo;
40325 - pstate_funcs.get_scaling = funcs->get_scaling;
40326 - pstate_funcs.set = funcs->set;
40327 - pstate_funcs.get_vid = funcs->get_vid;
40328 + pstate_funcs = funcs;
40329 }
40330
40331 #if IS_ENABLED(CONFIG_ACPI)
40332 diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
40333 index 529cfd9..0e28fff 100644
40334 --- a/drivers/cpufreq/p4-clockmod.c
40335 +++ b/drivers/cpufreq/p4-clockmod.c
40336 @@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
40337 case 0x0F: /* Core Duo */
40338 case 0x16: /* Celeron Core */
40339 case 0x1C: /* Atom */
40340 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40341 + pax_open_kernel();
40342 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40343 + pax_close_kernel();
40344 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
40345 case 0x0D: /* Pentium M (Dothan) */
40346 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40347 + pax_open_kernel();
40348 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40349 + pax_close_kernel();
40350 /* fall through */
40351 case 0x09: /* Pentium M (Banias) */
40352 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
40353 @@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
40354
40355 /* on P-4s, the TSC runs with constant frequency independent whether
40356 * throttling is active or not. */
40357 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40358 + pax_open_kernel();
40359 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40360 + pax_close_kernel();
40361
40362 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
40363 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
40364 diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
40365 index 9bb42ba..b01b4a2 100644
40366 --- a/drivers/cpufreq/sparc-us3-cpufreq.c
40367 +++ b/drivers/cpufreq/sparc-us3-cpufreq.c
40368 @@ -18,14 +18,12 @@
40369 #include <asm/head.h>
40370 #include <asm/timer.h>
40371
40372 -static struct cpufreq_driver *cpufreq_us3_driver;
40373 -
40374 struct us3_freq_percpu_info {
40375 struct cpufreq_frequency_table table[4];
40376 };
40377
40378 /* Indexed by cpu number. */
40379 -static struct us3_freq_percpu_info *us3_freq_table;
40380 +static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
40381
40382 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
40383 * in the Safari config register.
40384 @@ -156,16 +154,27 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
40385
40386 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
40387 {
40388 - if (cpufreq_us3_driver)
40389 - us3_freq_target(policy, 0);
40390 + us3_freq_target(policy, 0);
40391
40392 return 0;
40393 }
40394
40395 +static int __init us3_freq_init(void);
40396 +static void __exit us3_freq_exit(void);
40397 +
40398 +static struct cpufreq_driver cpufreq_us3_driver = {
40399 + .init = us3_freq_cpu_init,
40400 + .verify = cpufreq_generic_frequency_table_verify,
40401 + .target_index = us3_freq_target,
40402 + .get = us3_freq_get,
40403 + .exit = us3_freq_cpu_exit,
40404 + .name = "UltraSPARC-III",
40405 +
40406 +};
40407 +
40408 static int __init us3_freq_init(void)
40409 {
40410 unsigned long manuf, impl, ver;
40411 - int ret;
40412
40413 if (tlb_type != cheetah && tlb_type != cheetah_plus)
40414 return -ENODEV;
40415 @@ -178,55 +187,15 @@ static int __init us3_freq_init(void)
40416 (impl == CHEETAH_IMPL ||
40417 impl == CHEETAH_PLUS_IMPL ||
40418 impl == JAGUAR_IMPL ||
40419 - impl == PANTHER_IMPL)) {
40420 - struct cpufreq_driver *driver;
40421 -
40422 - ret = -ENOMEM;
40423 - driver = kzalloc(sizeof(*driver), GFP_KERNEL);
40424 - if (!driver)
40425 - goto err_out;
40426 -
40427 - us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
40428 - GFP_KERNEL);
40429 - if (!us3_freq_table)
40430 - goto err_out;
40431 -
40432 - driver->init = us3_freq_cpu_init;
40433 - driver->verify = cpufreq_generic_frequency_table_verify;
40434 - driver->target_index = us3_freq_target;
40435 - driver->get = us3_freq_get;
40436 - driver->exit = us3_freq_cpu_exit;
40437 - strcpy(driver->name, "UltraSPARC-III");
40438 -
40439 - cpufreq_us3_driver = driver;
40440 - ret = cpufreq_register_driver(driver);
40441 - if (ret)
40442 - goto err_out;
40443 -
40444 - return 0;
40445 -
40446 -err_out:
40447 - if (driver) {
40448 - kfree(driver);
40449 - cpufreq_us3_driver = NULL;
40450 - }
40451 - kfree(us3_freq_table);
40452 - us3_freq_table = NULL;
40453 - return ret;
40454 - }
40455 + impl == PANTHER_IMPL))
40456 + return cpufreq_register_driver(&cpufreq_us3_driver);
40457
40458 return -ENODEV;
40459 }
40460
40461 static void __exit us3_freq_exit(void)
40462 {
40463 - if (cpufreq_us3_driver) {
40464 - cpufreq_unregister_driver(cpufreq_us3_driver);
40465 - kfree(cpufreq_us3_driver);
40466 - cpufreq_us3_driver = NULL;
40467 - kfree(us3_freq_table);
40468 - us3_freq_table = NULL;
40469 - }
40470 + cpufreq_unregister_driver(&cpufreq_us3_driver);
40471 }
40472
40473 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
40474 diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
40475 index 7d4a315..21bb886 100644
40476 --- a/drivers/cpufreq/speedstep-centrino.c
40477 +++ b/drivers/cpufreq/speedstep-centrino.c
40478 @@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
40479 !cpu_has(cpu, X86_FEATURE_EST))
40480 return -ENODEV;
40481
40482 - if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
40483 - centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
40484 + if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
40485 + pax_open_kernel();
40486 + *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
40487 + pax_close_kernel();
40488 + }
40489
40490 if (policy->cpu != 0)
40491 return -ENODEV;
40492 diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
40493 index e431d11..d0b997e 100644
40494 --- a/drivers/cpuidle/driver.c
40495 +++ b/drivers/cpuidle/driver.c
40496 @@ -194,7 +194,7 @@ static int poll_idle(struct cpuidle_device *dev,
40497
40498 static void poll_idle_init(struct cpuidle_driver *drv)
40499 {
40500 - struct cpuidle_state *state = &drv->states[0];
40501 + cpuidle_state_no_const *state = &drv->states[0];
40502
40503 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
40504 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
40505 diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
40506 index ca89412..a7b9c49 100644
40507 --- a/drivers/cpuidle/governor.c
40508 +++ b/drivers/cpuidle/governor.c
40509 @@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
40510 mutex_lock(&cpuidle_lock);
40511 if (__cpuidle_find_governor(gov->name) == NULL) {
40512 ret = 0;
40513 - list_add_tail(&gov->governor_list, &cpuidle_governors);
40514 + pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
40515 if (!cpuidle_curr_governor ||
40516 cpuidle_curr_governor->rating < gov->rating)
40517 cpuidle_switch_governor(gov);
40518 diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
40519 index 97c5903..023ad23 100644
40520 --- a/drivers/cpuidle/sysfs.c
40521 +++ b/drivers/cpuidle/sysfs.c
40522 @@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
40523 NULL
40524 };
40525
40526 -static struct attribute_group cpuidle_attr_group = {
40527 +static attribute_group_no_const cpuidle_attr_group = {
40528 .attrs = cpuidle_default_attrs,
40529 .name = "cpuidle",
40530 };
40531 diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
40532 index 8d2a772..33826c9 100644
40533 --- a/drivers/crypto/hifn_795x.c
40534 +++ b/drivers/crypto/hifn_795x.c
40535 @@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
40536 MODULE_PARM_DESC(hifn_pll_ref,
40537 "PLL reference clock (pci[freq] or ext[freq], default ext)");
40538
40539 -static atomic_t hifn_dev_number;
40540 +static atomic_unchecked_t hifn_dev_number;
40541
40542 #define ACRYPTO_OP_DECRYPT 0
40543 #define ACRYPTO_OP_ENCRYPT 1
40544 @@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
40545 goto err_out_disable_pci_device;
40546
40547 snprintf(name, sizeof(name), "hifn%d",
40548 - atomic_inc_return(&hifn_dev_number)-1);
40549 + atomic_inc_return_unchecked(&hifn_dev_number)-1);
40550
40551 err = pci_request_regions(pdev, name);
40552 if (err)
40553 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
40554 index 9f90369..bfcacdb 100644
40555 --- a/drivers/devfreq/devfreq.c
40556 +++ b/drivers/devfreq/devfreq.c
40557 @@ -673,7 +673,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
40558 goto err_out;
40559 }
40560
40561 - list_add(&governor->node, &devfreq_governor_list);
40562 + pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
40563
40564 list_for_each_entry(devfreq, &devfreq_list, node) {
40565 int ret = 0;
40566 @@ -761,7 +761,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
40567 }
40568 }
40569
40570 - list_del(&governor->node);
40571 + pax_list_del((struct list_head *)&governor->node);
40572 err_out:
40573 mutex_unlock(&devfreq_list_lock);
40574
40575 diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
40576 index 42d4974..2714f36 100644
40577 --- a/drivers/dma/sh/shdma-base.c
40578 +++ b/drivers/dma/sh/shdma-base.c
40579 @@ -228,8 +228,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
40580 schan->slave_id = -EINVAL;
40581 }
40582
40583 - schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
40584 - sdev->desc_size, GFP_KERNEL);
40585 + schan->desc = kcalloc(sdev->desc_size,
40586 + NR_DESCS_PER_CHANNEL, GFP_KERNEL);
40587 if (!schan->desc) {
40588 ret = -ENOMEM;
40589 goto edescalloc;
40590 diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
40591 index 58eb857..d7e42c8 100644
40592 --- a/drivers/dma/sh/shdmac.c
40593 +++ b/drivers/dma/sh/shdmac.c
40594 @@ -513,7 +513,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
40595 return ret;
40596 }
40597
40598 -static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
40599 +static struct notifier_block sh_dmae_nmi_notifier = {
40600 .notifier_call = sh_dmae_nmi_handler,
40601
40602 /* Run before NMI debug handler and KGDB */
40603 diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
40604 index 592af5f..bb1d583 100644
40605 --- a/drivers/edac/edac_device.c
40606 +++ b/drivers/edac/edac_device.c
40607 @@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
40608 */
40609 int edac_device_alloc_index(void)
40610 {
40611 - static atomic_t device_indexes = ATOMIC_INIT(0);
40612 + static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
40613
40614 - return atomic_inc_return(&device_indexes) - 1;
40615 + return atomic_inc_return_unchecked(&device_indexes) - 1;
40616 }
40617 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
40618
40619 diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
40620 index a6cd361..7bdbf53 100644
40621 --- a/drivers/edac/edac_mc_sysfs.c
40622 +++ b/drivers/edac/edac_mc_sysfs.c
40623 @@ -154,7 +154,7 @@ static const char * const edac_caps[] = {
40624 struct dev_ch_attribute {
40625 struct device_attribute attr;
40626 int channel;
40627 -};
40628 +} __do_const;
40629
40630 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
40631 struct dev_ch_attribute dev_attr_legacy_##_name = \
40632 @@ -1011,14 +1011,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
40633 }
40634
40635 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
40636 + pax_open_kernel();
40637 if (mci->get_sdram_scrub_rate) {
40638 - dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
40639 - dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
40640 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
40641 + *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
40642 }
40643 if (mci->set_sdram_scrub_rate) {
40644 - dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
40645 - dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
40646 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
40647 + *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
40648 }
40649 + pax_close_kernel();
40650 err = device_create_file(&mci->dev,
40651 &dev_attr_sdram_scrub_rate);
40652 if (err) {
40653 diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
40654 index 2cf44b4d..6dd2dc7 100644
40655 --- a/drivers/edac/edac_pci.c
40656 +++ b/drivers/edac/edac_pci.c
40657 @@ -29,7 +29,7 @@
40658
40659 static DEFINE_MUTEX(edac_pci_ctls_mutex);
40660 static LIST_HEAD(edac_pci_list);
40661 -static atomic_t pci_indexes = ATOMIC_INIT(0);
40662 +static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
40663
40664 /*
40665 * edac_pci_alloc_ctl_info
40666 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
40667 */
40668 int edac_pci_alloc_index(void)
40669 {
40670 - return atomic_inc_return(&pci_indexes) - 1;
40671 + return atomic_inc_return_unchecked(&pci_indexes) - 1;
40672 }
40673 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
40674
40675 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
40676 index e8658e4..22746d6 100644
40677 --- a/drivers/edac/edac_pci_sysfs.c
40678 +++ b/drivers/edac/edac_pci_sysfs.c
40679 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
40680 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
40681 static int edac_pci_poll_msec = 1000; /* one second workq period */
40682
40683 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
40684 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
40685 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
40686 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
40687
40688 static struct kobject *edac_pci_top_main_kobj;
40689 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
40690 @@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
40691 void *value;
40692 ssize_t(*show) (void *, char *);
40693 ssize_t(*store) (void *, const char *, size_t);
40694 -};
40695 +} __do_const;
40696
40697 /* Set of show/store abstract level functions for PCI Parity object */
40698 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
40699 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40700 edac_printk(KERN_CRIT, EDAC_PCI,
40701 "Signaled System Error on %s\n",
40702 pci_name(dev));
40703 - atomic_inc(&pci_nonparity_count);
40704 + atomic_inc_unchecked(&pci_nonparity_count);
40705 }
40706
40707 if (status & (PCI_STATUS_PARITY)) {
40708 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40709 "Master Data Parity Error on %s\n",
40710 pci_name(dev));
40711
40712 - atomic_inc(&pci_parity_count);
40713 + atomic_inc_unchecked(&pci_parity_count);
40714 }
40715
40716 if (status & (PCI_STATUS_DETECTED_PARITY)) {
40717 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40718 "Detected Parity Error on %s\n",
40719 pci_name(dev));
40720
40721 - atomic_inc(&pci_parity_count);
40722 + atomic_inc_unchecked(&pci_parity_count);
40723 }
40724 }
40725
40726 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40727 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
40728 "Signaled System Error on %s\n",
40729 pci_name(dev));
40730 - atomic_inc(&pci_nonparity_count);
40731 + atomic_inc_unchecked(&pci_nonparity_count);
40732 }
40733
40734 if (status & (PCI_STATUS_PARITY)) {
40735 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40736 "Master Data Parity Error on "
40737 "%s\n", pci_name(dev));
40738
40739 - atomic_inc(&pci_parity_count);
40740 + atomic_inc_unchecked(&pci_parity_count);
40741 }
40742
40743 if (status & (PCI_STATUS_DETECTED_PARITY)) {
40744 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40745 "Detected Parity Error on %s\n",
40746 pci_name(dev));
40747
40748 - atomic_inc(&pci_parity_count);
40749 + atomic_inc_unchecked(&pci_parity_count);
40750 }
40751 }
40752 }
40753 @@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
40754 if (!check_pci_errors)
40755 return;
40756
40757 - before_count = atomic_read(&pci_parity_count);
40758 + before_count = atomic_read_unchecked(&pci_parity_count);
40759
40760 /* scan all PCI devices looking for a Parity Error on devices and
40761 * bridges.
40762 @@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
40763 /* Only if operator has selected panic on PCI Error */
40764 if (edac_pci_get_panic_on_pe()) {
40765 /* If the count is different 'after' from 'before' */
40766 - if (before_count != atomic_read(&pci_parity_count))
40767 + if (before_count != atomic_read_unchecked(&pci_parity_count))
40768 panic("EDAC: PCI Parity Error");
40769 }
40770 }
40771 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
40772 index 51b7e3a..aa8a3e8 100644
40773 --- a/drivers/edac/mce_amd.h
40774 +++ b/drivers/edac/mce_amd.h
40775 @@ -77,7 +77,7 @@ struct amd_decoder_ops {
40776 bool (*mc0_mce)(u16, u8);
40777 bool (*mc1_mce)(u16, u8);
40778 bool (*mc2_mce)(u16, u8);
40779 -};
40780 +} __no_const;
40781
40782 void amd_report_gart_errors(bool);
40783 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
40784 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
40785 index 57ea7f4..af06b76 100644
40786 --- a/drivers/firewire/core-card.c
40787 +++ b/drivers/firewire/core-card.c
40788 @@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
40789 const struct fw_card_driver *driver,
40790 struct device *device)
40791 {
40792 - static atomic_t index = ATOMIC_INIT(-1);
40793 + static atomic_unchecked_t index = ATOMIC_INIT(-1);
40794
40795 - card->index = atomic_inc_return(&index);
40796 + card->index = atomic_inc_return_unchecked(&index);
40797 card->driver = driver;
40798 card->device = device;
40799 card->current_tlabel = 0;
40800 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
40801
40802 void fw_core_remove_card(struct fw_card *card)
40803 {
40804 - struct fw_card_driver dummy_driver = dummy_driver_template;
40805 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
40806
40807 card->driver->update_phy_reg(card, 4,
40808 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
40809 diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
40810 index 2c6d5e1..a2cca6b 100644
40811 --- a/drivers/firewire/core-device.c
40812 +++ b/drivers/firewire/core-device.c
40813 @@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
40814 struct config_rom_attribute {
40815 struct device_attribute attr;
40816 u32 key;
40817 -};
40818 +} __do_const;
40819
40820 static ssize_t show_immediate(struct device *dev,
40821 struct device_attribute *dattr, char *buf)
40822 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
40823 index eb6935c..3cc2bfa 100644
40824 --- a/drivers/firewire/core-transaction.c
40825 +++ b/drivers/firewire/core-transaction.c
40826 @@ -38,6 +38,7 @@
40827 #include <linux/timer.h>
40828 #include <linux/types.h>
40829 #include <linux/workqueue.h>
40830 +#include <linux/sched.h>
40831
40832 #include <asm/byteorder.h>
40833
40834 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
40835 index e1480ff6..1a429bd 100644
40836 --- a/drivers/firewire/core.h
40837 +++ b/drivers/firewire/core.h
40838 @@ -111,6 +111,7 @@ struct fw_card_driver {
40839
40840 int (*stop_iso)(struct fw_iso_context *ctx);
40841 };
40842 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
40843
40844 void fw_card_initialize(struct fw_card *card,
40845 const struct fw_card_driver *driver, struct device *device);
40846 diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
40847 index a66a321..f6caf20 100644
40848 --- a/drivers/firewire/ohci.c
40849 +++ b/drivers/firewire/ohci.c
40850 @@ -2056,10 +2056,12 @@ static void bus_reset_work(struct work_struct *work)
40851 be32_to_cpu(ohci->next_header));
40852 }
40853
40854 +#ifndef CONFIG_GRKERNSEC
40855 if (param_remote_dma) {
40856 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
40857 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
40858 }
40859 +#endif
40860
40861 spin_unlock_irq(&ohci->lock);
40862
40863 @@ -2591,8 +2593,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
40864 unsigned long flags;
40865 int n, ret = 0;
40866
40867 +#ifndef CONFIG_GRKERNSEC
40868 if (param_remote_dma)
40869 return 0;
40870 +#endif
40871
40872 /*
40873 * FIXME: Make sure this bitmask is cleared when we clear the busReset
40874 diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
40875 index 94a58a0..f5eba42 100644
40876 --- a/drivers/firmware/dmi-id.c
40877 +++ b/drivers/firmware/dmi-id.c
40878 @@ -16,7 +16,7 @@
40879 struct dmi_device_attribute{
40880 struct device_attribute dev_attr;
40881 int field;
40882 -};
40883 +} __do_const;
40884 #define to_dmi_dev_attr(_dev_attr) \
40885 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
40886
40887 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
40888 index 17afc51..0ef90cd 100644
40889 --- a/drivers/firmware/dmi_scan.c
40890 +++ b/drivers/firmware/dmi_scan.c
40891 @@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
40892 if (buf == NULL)
40893 return -1;
40894
40895 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
40896 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
40897
40898 dmi_unmap(buf);
40899 return 0;
40900 diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
40901 index 5b53d61..72cee96 100644
40902 --- a/drivers/firmware/efi/cper.c
40903 +++ b/drivers/firmware/efi/cper.c
40904 @@ -44,12 +44,12 @@ static char rcd_decode_str[CPER_REC_LEN];
40905 */
40906 u64 cper_next_record_id(void)
40907 {
40908 - static atomic64_t seq;
40909 + static atomic64_unchecked_t seq;
40910
40911 - if (!atomic64_read(&seq))
40912 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
40913 + if (!atomic64_read_unchecked(&seq))
40914 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
40915
40916 - return atomic64_inc_return(&seq);
40917 + return atomic64_inc_return_unchecked(&seq);
40918 }
40919 EXPORT_SYMBOL_GPL(cper_next_record_id);
40920
40921 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
40922 index 64ecbb5..d921eb3 100644
40923 --- a/drivers/firmware/efi/efi.c
40924 +++ b/drivers/firmware/efi/efi.c
40925 @@ -126,14 +126,16 @@ static struct attribute_group efi_subsys_attr_group = {
40926 };
40927
40928 static struct efivars generic_efivars;
40929 -static struct efivar_operations generic_ops;
40930 +static efivar_operations_no_const generic_ops __read_only;
40931
40932 static int generic_ops_register(void)
40933 {
40934 - generic_ops.get_variable = efi.get_variable;
40935 - generic_ops.set_variable = efi.set_variable;
40936 - generic_ops.get_next_variable = efi.get_next_variable;
40937 - generic_ops.query_variable_store = efi_query_variable_store;
40938 + pax_open_kernel();
40939 + *(void **)&generic_ops.get_variable = efi.get_variable;
40940 + *(void **)&generic_ops.set_variable = efi.set_variable;
40941 + *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
40942 + *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
40943 + pax_close_kernel();
40944
40945 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
40946 }
40947 diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
40948 index f256ecd..387dcb1 100644
40949 --- a/drivers/firmware/efi/efivars.c
40950 +++ b/drivers/firmware/efi/efivars.c
40951 @@ -589,7 +589,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
40952 static int
40953 create_efivars_bin_attributes(void)
40954 {
40955 - struct bin_attribute *attr;
40956 + bin_attribute_no_const *attr;
40957 int error;
40958
40959 /* new_var */
40960 diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
40961 index 2f569aa..c95f4fb 100644
40962 --- a/drivers/firmware/google/memconsole.c
40963 +++ b/drivers/firmware/google/memconsole.c
40964 @@ -155,7 +155,10 @@ static int __init memconsole_init(void)
40965 if (!found_memconsole())
40966 return -ENODEV;
40967
40968 - memconsole_bin_attr.size = memconsole_length;
40969 + pax_open_kernel();
40970 + *(size_t *)&memconsole_bin_attr.size = memconsole_length;
40971 + pax_close_kernel();
40972 +
40973 return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
40974 }
40975
40976 diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
40977 index fe49ec3..1ade794 100644
40978 --- a/drivers/gpio/gpio-em.c
40979 +++ b/drivers/gpio/gpio-em.c
40980 @@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
40981 struct em_gio_priv *p;
40982 struct resource *io[2], *irq[2];
40983 struct gpio_chip *gpio_chip;
40984 - struct irq_chip *irq_chip;
40985 + irq_chip_no_const *irq_chip;
40986 const char *name = dev_name(&pdev->dev);
40987 int ret;
40988
40989 diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
40990 index 3784e81..73637b5 100644
40991 --- a/drivers/gpio/gpio-ich.c
40992 +++ b/drivers/gpio/gpio-ich.c
40993 @@ -94,7 +94,7 @@ struct ichx_desc {
40994 * this option allows driver caching written output values
40995 */
40996 bool use_outlvl_cache;
40997 -};
40998 +} __do_const;
40999
41000 static struct {
41001 spinlock_t lock;
41002 diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
41003 index bf6c094..6573caf 100644
41004 --- a/drivers/gpio/gpio-rcar.c
41005 +++ b/drivers/gpio/gpio-rcar.c
41006 @@ -357,7 +357,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
41007 struct gpio_rcar_priv *p;
41008 struct resource *io, *irq;
41009 struct gpio_chip *gpio_chip;
41010 - struct irq_chip *irq_chip;
41011 + irq_chip_no_const *irq_chip;
41012 struct device *dev = &pdev->dev;
41013 const char *name = dev_name(dev);
41014 int ret;
41015 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
41016 index dbf28fa..04dad4e 100644
41017 --- a/drivers/gpio/gpio-vr41xx.c
41018 +++ b/drivers/gpio/gpio-vr41xx.c
41019 @@ -224,7 +224,7 @@ static int giu_get_irq(unsigned int irq)
41020 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
41021 maskl, pendl, maskh, pendh);
41022
41023 - atomic_inc(&irq_err_count);
41024 + atomic_inc_unchecked(&irq_err_count);
41025
41026 return -EINVAL;
41027 }
41028 diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
41029 index c68d037..2f4f9a9 100644
41030 --- a/drivers/gpio/gpiolib.c
41031 +++ b/drivers/gpio/gpiolib.c
41032 @@ -529,8 +529,10 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip)
41033 }
41034
41035 if (gpiochip->irqchip) {
41036 - gpiochip->irqchip->irq_request_resources = NULL;
41037 - gpiochip->irqchip->irq_release_resources = NULL;
41038 + pax_open_kernel();
41039 + *(void **)&gpiochip->irqchip->irq_request_resources = NULL;
41040 + *(void **)&gpiochip->irqchip->irq_release_resources = NULL;
41041 + pax_close_kernel();
41042 gpiochip->irqchip = NULL;
41043 }
41044 }
41045 @@ -596,8 +598,11 @@ int gpiochip_irqchip_add(struct gpio_chip *gpiochip,
41046 gpiochip->irqchip = NULL;
41047 return -EINVAL;
41048 }
41049 - irqchip->irq_request_resources = gpiochip_irq_reqres;
41050 - irqchip->irq_release_resources = gpiochip_irq_relres;
41051 +
41052 + pax_open_kernel();
41053 + *(void **)&irqchip->irq_request_resources = gpiochip_irq_reqres;
41054 + *(void **)&irqchip->irq_release_resources = gpiochip_irq_relres;
41055 + pax_close_kernel();
41056
41057 /*
41058 * Prepare the mapping since the irqchip shall be orthogonal to
41059 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
41060 index 90e7730..3b41807 100644
41061 --- a/drivers/gpu/drm/drm_crtc.c
41062 +++ b/drivers/gpu/drm/drm_crtc.c
41063 @@ -3861,7 +3861,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
41064 goto done;
41065 }
41066
41067 - if (copy_to_user(&enum_ptr[copied].name,
41068 + if (copy_to_user(enum_ptr[copied].name,
41069 &prop_enum->name, DRM_PROP_NAME_LEN)) {
41070 ret = -EFAULT;
41071 goto done;
41072 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
41073 index 3242e20..7e4f621 100644
41074 --- a/drivers/gpu/drm/drm_drv.c
41075 +++ b/drivers/gpu/drm/drm_drv.c
41076 @@ -463,7 +463,7 @@ void drm_unplug_dev(struct drm_device *dev)
41077
41078 drm_device_set_unplugged(dev);
41079
41080 - if (dev->open_count == 0) {
41081 + if (local_read(&dev->open_count) == 0) {
41082 drm_put_dev(dev);
41083 }
41084 mutex_unlock(&drm_global_mutex);
41085 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
41086 index 79d5221..7ff73496 100644
41087 --- a/drivers/gpu/drm/drm_fops.c
41088 +++ b/drivers/gpu/drm/drm_fops.c
41089 @@ -89,7 +89,7 @@ int drm_open(struct inode *inode, struct file *filp)
41090 return PTR_ERR(minor);
41091
41092 dev = minor->dev;
41093 - if (!dev->open_count++)
41094 + if (local_inc_return(&dev->open_count) == 1)
41095 need_setup = 1;
41096
41097 /* share address_space across all char-devs of a single device */
41098 @@ -106,7 +106,7 @@ int drm_open(struct inode *inode, struct file *filp)
41099 return 0;
41100
41101 err_undo:
41102 - dev->open_count--;
41103 + local_dec(&dev->open_count);
41104 drm_minor_release(minor);
41105 return retcode;
41106 }
41107 @@ -384,7 +384,7 @@ int drm_release(struct inode *inode, struct file *filp)
41108
41109 mutex_lock(&drm_global_mutex);
41110
41111 - DRM_DEBUG("open_count = %d\n", dev->open_count);
41112 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
41113
41114 mutex_lock(&dev->struct_mutex);
41115 list_del(&file_priv->lhead);
41116 @@ -397,10 +397,10 @@ int drm_release(struct inode *inode, struct file *filp)
41117 * Begin inline drm_release
41118 */
41119
41120 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
41121 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
41122 task_pid_nr(current),
41123 (long)old_encode_dev(file_priv->minor->kdev->devt),
41124 - dev->open_count);
41125 + local_read(&dev->open_count));
41126
41127 /* Release any auth tokens that might point to this file_priv,
41128 (do that under the drm_global_mutex) */
41129 @@ -471,7 +471,7 @@ int drm_release(struct inode *inode, struct file *filp)
41130 * End inline drm_release
41131 */
41132
41133 - if (!--dev->open_count) {
41134 + if (local_dec_and_test(&dev->open_count)) {
41135 retcode = drm_lastclose(dev);
41136 if (drm_device_is_unplugged(dev))
41137 drm_put_dev(dev);
41138 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
41139 index 3d2e91c..d31c4c9 100644
41140 --- a/drivers/gpu/drm/drm_global.c
41141 +++ b/drivers/gpu/drm/drm_global.c
41142 @@ -36,7 +36,7 @@
41143 struct drm_global_item {
41144 struct mutex mutex;
41145 void *object;
41146 - int refcount;
41147 + atomic_t refcount;
41148 };
41149
41150 static struct drm_global_item glob[DRM_GLOBAL_NUM];
41151 @@ -49,7 +49,7 @@ void drm_global_init(void)
41152 struct drm_global_item *item = &glob[i];
41153 mutex_init(&item->mutex);
41154 item->object = NULL;
41155 - item->refcount = 0;
41156 + atomic_set(&item->refcount, 0);
41157 }
41158 }
41159
41160 @@ -59,7 +59,7 @@ void drm_global_release(void)
41161 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
41162 struct drm_global_item *item = &glob[i];
41163 BUG_ON(item->object != NULL);
41164 - BUG_ON(item->refcount != 0);
41165 + BUG_ON(atomic_read(&item->refcount) != 0);
41166 }
41167 }
41168
41169 @@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
41170 struct drm_global_item *item = &glob[ref->global_type];
41171
41172 mutex_lock(&item->mutex);
41173 - if (item->refcount == 0) {
41174 + if (atomic_read(&item->refcount) == 0) {
41175 item->object = kzalloc(ref->size, GFP_KERNEL);
41176 if (unlikely(item->object == NULL)) {
41177 ret = -ENOMEM;
41178 @@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
41179 goto out_err;
41180
41181 }
41182 - ++item->refcount;
41183 + atomic_inc(&item->refcount);
41184 ref->object = item->object;
41185 mutex_unlock(&item->mutex);
41186 return 0;
41187 @@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
41188 struct drm_global_item *item = &glob[ref->global_type];
41189
41190 mutex_lock(&item->mutex);
41191 - BUG_ON(item->refcount == 0);
41192 + BUG_ON(atomic_read(&item->refcount) == 0);
41193 BUG_ON(ref->object != item->object);
41194 - if (--item->refcount == 0) {
41195 + if (atomic_dec_and_test(&item->refcount)) {
41196 ref->release(ref);
41197 item->object = NULL;
41198 }
41199 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
41200 index ecaf0fa..a49cee9 100644
41201 --- a/drivers/gpu/drm/drm_info.c
41202 +++ b/drivers/gpu/drm/drm_info.c
41203 @@ -73,10 +73,13 @@ int drm_vm_info(struct seq_file *m, void *data)
41204 struct drm_local_map *map;
41205 struct drm_map_list *r_list;
41206
41207 - /* Hardcoded from _DRM_FRAME_BUFFER,
41208 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
41209 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
41210 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
41211 + static const char * const types[] = {
41212 + [_DRM_FRAME_BUFFER] = "FB",
41213 + [_DRM_REGISTERS] = "REG",
41214 + [_DRM_SHM] = "SHM",
41215 + [_DRM_AGP] = "AGP",
41216 + [_DRM_SCATTER_GATHER] = "SG",
41217 + [_DRM_CONSISTENT] = "PCI"};
41218 const char *type;
41219 int i;
41220
41221 @@ -87,7 +90,7 @@ int drm_vm_info(struct seq_file *m, void *data)
41222 map = r_list->map;
41223 if (!map)
41224 continue;
41225 - if (map->type < 0 || map->type > 5)
41226 + if (map->type >= ARRAY_SIZE(types))
41227 type = "??";
41228 else
41229 type = types[map->type];
41230 @@ -259,7 +262,11 @@ int drm_vma_info(struct seq_file *m, void *data)
41231 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
41232 vma->vm_flags & VM_LOCKED ? 'l' : '-',
41233 vma->vm_flags & VM_IO ? 'i' : '-',
41234 +#ifdef CONFIG_GRKERNSEC_HIDESYM
41235 + 0);
41236 +#else
41237 vma->vm_pgoff);
41238 +#endif
41239
41240 #if defined(__i386__)
41241 pgprot = pgprot_val(vma->vm_page_prot);
41242 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
41243 index 2f4c4343..dd12cd2 100644
41244 --- a/drivers/gpu/drm/drm_ioc32.c
41245 +++ b/drivers/gpu/drm/drm_ioc32.c
41246 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
41247 request = compat_alloc_user_space(nbytes);
41248 if (!access_ok(VERIFY_WRITE, request, nbytes))
41249 return -EFAULT;
41250 - list = (struct drm_buf_desc *) (request + 1);
41251 + list = (struct drm_buf_desc __user *) (request + 1);
41252
41253 if (__put_user(count, &request->count)
41254 || __put_user(list, &request->list))
41255 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
41256 request = compat_alloc_user_space(nbytes);
41257 if (!access_ok(VERIFY_WRITE, request, nbytes))
41258 return -EFAULT;
41259 - list = (struct drm_buf_pub *) (request + 1);
41260 + list = (struct drm_buf_pub __user *) (request + 1);
41261
41262 if (__put_user(count, &request->count)
41263 || __put_user(list, &request->list))
41264 @@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
41265 return 0;
41266 }
41267
41268 -drm_ioctl_compat_t *drm_compat_ioctls[] = {
41269 +drm_ioctl_compat_t drm_compat_ioctls[] = {
41270 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
41271 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
41272 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
41273 @@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
41274 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41275 {
41276 unsigned int nr = DRM_IOCTL_NR(cmd);
41277 - drm_ioctl_compat_t *fn;
41278 int ret;
41279
41280 /* Assume that ioctls without an explicit compat routine will just
41281 @@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41282 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
41283 return drm_ioctl(filp, cmd, arg);
41284
41285 - fn = drm_compat_ioctls[nr];
41286 -
41287 - if (fn != NULL)
41288 - ret = (*fn) (filp, cmd, arg);
41289 + if (drm_compat_ioctls[nr] != NULL)
41290 + ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
41291 else
41292 ret = drm_ioctl(filp, cmd, arg);
41293
41294 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
41295 index 40be746..fd78faf 100644
41296 --- a/drivers/gpu/drm/drm_ioctl.c
41297 +++ b/drivers/gpu/drm/drm_ioctl.c
41298 @@ -642,7 +642,7 @@ long drm_ioctl(struct file *filp,
41299 struct drm_file *file_priv = filp->private_data;
41300 struct drm_device *dev;
41301 const struct drm_ioctl_desc *ioctl = NULL;
41302 - drm_ioctl_t *func;
41303 + drm_ioctl_no_const_t func;
41304 unsigned int nr = DRM_IOCTL_NR(cmd);
41305 int retcode = -EINVAL;
41306 char stack_kdata[128];
41307 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
41308 index d4d16ed..8fb0b51 100644
41309 --- a/drivers/gpu/drm/i810/i810_drv.h
41310 +++ b/drivers/gpu/drm/i810/i810_drv.h
41311 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
41312 int page_flipping;
41313
41314 wait_queue_head_t irq_queue;
41315 - atomic_t irq_received;
41316 - atomic_t irq_emitted;
41317 + atomic_unchecked_t irq_received;
41318 + atomic_unchecked_t irq_emitted;
41319
41320 int front_offset;
41321 } drm_i810_private_t;
41322 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
41323 index 9933c26..32cc097 100644
41324 --- a/drivers/gpu/drm/i915/i915_dma.c
41325 +++ b/drivers/gpu/drm/i915/i915_dma.c
41326 @@ -1292,7 +1292,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
41327 * locking inversion with the driver load path. And the access here is
41328 * completely racy anyway. So don't bother with locking for now.
41329 */
41330 - return dev->open_count == 0;
41331 + return local_read(&dev->open_count) == 0;
41332 }
41333
41334 static const struct vga_switcheroo_client_ops i915_switcheroo_ops = {
41335 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
41336 index 60998fc..3b244bc 100644
41337 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
41338 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
41339 @@ -891,9 +891,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
41340
41341 static int
41342 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
41343 - int count)
41344 + unsigned int count)
41345 {
41346 - int i;
41347 + unsigned int i;
41348 unsigned relocs_total = 0;
41349 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
41350
41351 diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
41352 index 2e0613e..a8b94d9 100644
41353 --- a/drivers/gpu/drm/i915/i915_ioc32.c
41354 +++ b/drivers/gpu/drm/i915/i915_ioc32.c
41355 @@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
41356 (unsigned long)request);
41357 }
41358
41359 -static drm_ioctl_compat_t *i915_compat_ioctls[] = {
41360 +static drm_ioctl_compat_t i915_compat_ioctls[] = {
41361 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
41362 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
41363 [DRM_I915_GETPARAM] = compat_i915_getparam,
41364 @@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
41365 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41366 {
41367 unsigned int nr = DRM_IOCTL_NR(cmd);
41368 - drm_ioctl_compat_t *fn = NULL;
41369 int ret;
41370
41371 if (nr < DRM_COMMAND_BASE)
41372 return drm_compat_ioctl(filp, cmd, arg);
41373
41374 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls))
41375 - fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
41376 -
41377 - if (fn != NULL)
41378 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls)) {
41379 + drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
41380 ret = (*fn) (filp, cmd, arg);
41381 - else
41382 + } else
41383 ret = drm_ioctl(filp, cmd, arg);
41384
41385 return ret;
41386 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
41387 index b71a026..8b6cc10 100644
41388 --- a/drivers/gpu/drm/i915/intel_display.c
41389 +++ b/drivers/gpu/drm/i915/intel_display.c
41390 @@ -12437,13 +12437,13 @@ struct intel_quirk {
41391 int subsystem_vendor;
41392 int subsystem_device;
41393 void (*hook)(struct drm_device *dev);
41394 -};
41395 +} __do_const;
41396
41397 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
41398 struct intel_dmi_quirk {
41399 void (*hook)(struct drm_device *dev);
41400 const struct dmi_system_id (*dmi_id_list)[];
41401 -};
41402 +} __do_const;
41403
41404 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
41405 {
41406 @@ -12451,18 +12451,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
41407 return 1;
41408 }
41409
41410 -static const struct intel_dmi_quirk intel_dmi_quirks[] = {
41411 +static const struct dmi_system_id intel_dmi_quirks_table[] = {
41412 {
41413 - .dmi_id_list = &(const struct dmi_system_id[]) {
41414 - {
41415 - .callback = intel_dmi_reverse_brightness,
41416 - .ident = "NCR Corporation",
41417 - .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
41418 - DMI_MATCH(DMI_PRODUCT_NAME, ""),
41419 - },
41420 - },
41421 - { } /* terminating entry */
41422 + .callback = intel_dmi_reverse_brightness,
41423 + .ident = "NCR Corporation",
41424 + .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
41425 + DMI_MATCH(DMI_PRODUCT_NAME, ""),
41426 },
41427 + },
41428 + { } /* terminating entry */
41429 +};
41430 +
41431 +static const struct intel_dmi_quirk intel_dmi_quirks[] = {
41432 + {
41433 + .dmi_id_list = &intel_dmi_quirks_table,
41434 .hook = quirk_invert_brightness,
41435 },
41436 };
41437 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
41438 index fe45321..836fdca 100644
41439 --- a/drivers/gpu/drm/mga/mga_drv.h
41440 +++ b/drivers/gpu/drm/mga/mga_drv.h
41441 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
41442 u32 clear_cmd;
41443 u32 maccess;
41444
41445 - atomic_t vbl_received; /**< Number of vblanks received. */
41446 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
41447 wait_queue_head_t fence_queue;
41448 - atomic_t last_fence_retired;
41449 + atomic_unchecked_t last_fence_retired;
41450 u32 next_fence_to_post;
41451
41452 unsigned int fb_cpp;
41453 diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
41454 index 729bfd5..ead8823 100644
41455 --- a/drivers/gpu/drm/mga/mga_ioc32.c
41456 +++ b/drivers/gpu/drm/mga/mga_ioc32.c
41457 @@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
41458 return 0;
41459 }
41460
41461 -drm_ioctl_compat_t *mga_compat_ioctls[] = {
41462 +drm_ioctl_compat_t mga_compat_ioctls[] = {
41463 [DRM_MGA_INIT] = compat_mga_init,
41464 [DRM_MGA_GETPARAM] = compat_mga_getparam,
41465 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
41466 @@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
41467 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41468 {
41469 unsigned int nr = DRM_IOCTL_NR(cmd);
41470 - drm_ioctl_compat_t *fn = NULL;
41471 int ret;
41472
41473 if (nr < DRM_COMMAND_BASE)
41474 return drm_compat_ioctl(filp, cmd, arg);
41475
41476 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls))
41477 - fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
41478 -
41479 - if (fn != NULL)
41480 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls)) {
41481 + drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
41482 ret = (*fn) (filp, cmd, arg);
41483 - else
41484 + } else
41485 ret = drm_ioctl(filp, cmd, arg);
41486
41487 return ret;
41488 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
41489 index 1b071b8..de8601a 100644
41490 --- a/drivers/gpu/drm/mga/mga_irq.c
41491 +++ b/drivers/gpu/drm/mga/mga_irq.c
41492 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
41493 if (crtc != 0)
41494 return 0;
41495
41496 - return atomic_read(&dev_priv->vbl_received);
41497 + return atomic_read_unchecked(&dev_priv->vbl_received);
41498 }
41499
41500
41501 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
41502 /* VBLANK interrupt */
41503 if (status & MGA_VLINEPEN) {
41504 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
41505 - atomic_inc(&dev_priv->vbl_received);
41506 + atomic_inc_unchecked(&dev_priv->vbl_received);
41507 drm_handle_vblank(dev, 0);
41508 handled = 1;
41509 }
41510 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
41511 if ((prim_start & ~0x03) != (prim_end & ~0x03))
41512 MGA_WRITE(MGA_PRIMEND, prim_end);
41513
41514 - atomic_inc(&dev_priv->last_fence_retired);
41515 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
41516 wake_up(&dev_priv->fence_queue);
41517 handled = 1;
41518 }
41519 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
41520 * using fences.
41521 */
41522 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
41523 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
41524 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
41525 - *sequence) <= (1 << 23)));
41526
41527 *sequence = cur_fence;
41528 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
41529 index dae2c96..324dbe4 100644
41530 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
41531 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
41532 @@ -963,7 +963,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
41533 struct bit_table {
41534 const char id;
41535 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
41536 -};
41537 +} __no_const;
41538
41539 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
41540
41541 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
41542 index b02b024..aed7bad 100644
41543 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
41544 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
41545 @@ -119,7 +119,6 @@ struct nouveau_drm {
41546 struct drm_global_reference mem_global_ref;
41547 struct ttm_bo_global_ref bo_global_ref;
41548 struct ttm_bo_device bdev;
41549 - atomic_t validate_sequence;
41550 int (*move)(struct nouveau_channel *,
41551 struct ttm_buffer_object *,
41552 struct ttm_mem_reg *, struct ttm_mem_reg *);
41553 diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
41554 index 462679a..88e32a7 100644
41555 --- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
41556 +++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
41557 @@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
41558 unsigned long arg)
41559 {
41560 unsigned int nr = DRM_IOCTL_NR(cmd);
41561 - drm_ioctl_compat_t *fn = NULL;
41562 + drm_ioctl_compat_t fn = NULL;
41563 int ret;
41564
41565 if (nr < DRM_COMMAND_BASE)
41566 diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
41567 index 53874b7..1db0a68 100644
41568 --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
41569 +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
41570 @@ -127,11 +127,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
41571 }
41572
41573 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
41574 - nouveau_vram_manager_init,
41575 - nouveau_vram_manager_fini,
41576 - nouveau_vram_manager_new,
41577 - nouveau_vram_manager_del,
41578 - nouveau_vram_manager_debug
41579 + .init = nouveau_vram_manager_init,
41580 + .takedown = nouveau_vram_manager_fini,
41581 + .get_node = nouveau_vram_manager_new,
41582 + .put_node = nouveau_vram_manager_del,
41583 + .debug = nouveau_vram_manager_debug
41584 };
41585
41586 static int
41587 @@ -196,11 +196,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
41588 }
41589
41590 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
41591 - nouveau_gart_manager_init,
41592 - nouveau_gart_manager_fini,
41593 - nouveau_gart_manager_new,
41594 - nouveau_gart_manager_del,
41595 - nouveau_gart_manager_debug
41596 + .init = nouveau_gart_manager_init,
41597 + .takedown = nouveau_gart_manager_fini,
41598 + .get_node = nouveau_gart_manager_new,
41599 + .put_node = nouveau_gart_manager_del,
41600 + .debug = nouveau_gart_manager_debug
41601 };
41602
41603 /*XXX*/
41604 @@ -270,11 +270,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
41605 }
41606
41607 const struct ttm_mem_type_manager_func nv04_gart_manager = {
41608 - nv04_gart_manager_init,
41609 - nv04_gart_manager_fini,
41610 - nv04_gart_manager_new,
41611 - nv04_gart_manager_del,
41612 - nv04_gart_manager_debug
41613 + .init = nv04_gart_manager_init,
41614 + .takedown = nv04_gart_manager_fini,
41615 + .get_node = nv04_gart_manager_new,
41616 + .put_node = nv04_gart_manager_del,
41617 + .debug = nv04_gart_manager_debug
41618 };
41619
41620 int
41621 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
41622 index c7592ec..dd45ebc 100644
41623 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
41624 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
41625 @@ -72,7 +72,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
41626 * locking inversion with the driver load path. And the access here is
41627 * completely racy anyway. So don't bother with locking for now.
41628 */
41629 - return dev->open_count == 0;
41630 + return local_read(&dev->open_count) == 0;
41631 }
41632
41633 static const struct vga_switcheroo_client_ops
41634 diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
41635 index eb89653..613cf71 100644
41636 --- a/drivers/gpu/drm/qxl/qxl_cmd.c
41637 +++ b/drivers/gpu/drm/qxl/qxl_cmd.c
41638 @@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
41639 int ret;
41640
41641 mutex_lock(&qdev->async_io_mutex);
41642 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
41643 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
41644 if (qdev->last_sent_io_cmd > irq_num) {
41645 if (intr)
41646 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
41647 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41648 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41649 else
41650 ret = wait_event_timeout(qdev->io_cmd_event,
41651 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41652 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41653 /* 0 is timeout, just bail the "hw" has gone away */
41654 if (ret <= 0)
41655 goto out;
41656 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
41657 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
41658 }
41659 outb(val, addr);
41660 qdev->last_sent_io_cmd = irq_num + 1;
41661 if (intr)
41662 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
41663 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41664 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41665 else
41666 ret = wait_event_timeout(qdev->io_cmd_event,
41667 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41668 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41669 out:
41670 if (ret > 0)
41671 ret = 0;
41672 diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
41673 index c3c2bbd..bc3c0fb 100644
41674 --- a/drivers/gpu/drm/qxl/qxl_debugfs.c
41675 +++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
41676 @@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
41677 struct drm_info_node *node = (struct drm_info_node *) m->private;
41678 struct qxl_device *qdev = node->minor->dev->dev_private;
41679
41680 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
41681 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
41682 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
41683 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
41684 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
41685 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
41686 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
41687 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
41688 seq_printf(m, "%d\n", qdev->irq_received_error);
41689 return 0;
41690 }
41691 diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
41692 index 36ed40b..0397633 100644
41693 --- a/drivers/gpu/drm/qxl/qxl_drv.h
41694 +++ b/drivers/gpu/drm/qxl/qxl_drv.h
41695 @@ -290,10 +290,10 @@ struct qxl_device {
41696 unsigned int last_sent_io_cmd;
41697
41698 /* interrupt handling */
41699 - atomic_t irq_received;
41700 - atomic_t irq_received_display;
41701 - atomic_t irq_received_cursor;
41702 - atomic_t irq_received_io_cmd;
41703 + atomic_unchecked_t irq_received;
41704 + atomic_unchecked_t irq_received_display;
41705 + atomic_unchecked_t irq_received_cursor;
41706 + atomic_unchecked_t irq_received_io_cmd;
41707 unsigned irq_received_error;
41708 wait_queue_head_t display_event;
41709 wait_queue_head_t cursor_event;
41710 diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
41711 index b110883..dd06418 100644
41712 --- a/drivers/gpu/drm/qxl/qxl_ioctl.c
41713 +++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
41714 @@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
41715
41716 /* TODO copy slow path code from i915 */
41717 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
41718 - 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);
41719 + 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);
41720
41721 {
41722 struct qxl_drawable *draw = fb_cmd;
41723 @@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
41724 struct drm_qxl_reloc reloc;
41725
41726 if (copy_from_user(&reloc,
41727 - &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
41728 + &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
41729 sizeof(reloc))) {
41730 ret = -EFAULT;
41731 goto out_free_bos;
41732 @@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
41733
41734 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
41735
41736 - struct drm_qxl_command *commands =
41737 - (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
41738 + struct drm_qxl_command __user *commands =
41739 + (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
41740
41741 - if (copy_from_user(&user_cmd, &commands[cmd_num],
41742 + if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
41743 sizeof(user_cmd)))
41744 return -EFAULT;
41745
41746 diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
41747 index 0bf1e20..42a7310 100644
41748 --- a/drivers/gpu/drm/qxl/qxl_irq.c
41749 +++ b/drivers/gpu/drm/qxl/qxl_irq.c
41750 @@ -36,19 +36,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
41751 if (!pending)
41752 return IRQ_NONE;
41753
41754 - atomic_inc(&qdev->irq_received);
41755 + atomic_inc_unchecked(&qdev->irq_received);
41756
41757 if (pending & QXL_INTERRUPT_DISPLAY) {
41758 - atomic_inc(&qdev->irq_received_display);
41759 + atomic_inc_unchecked(&qdev->irq_received_display);
41760 wake_up_all(&qdev->display_event);
41761 qxl_queue_garbage_collect(qdev, false);
41762 }
41763 if (pending & QXL_INTERRUPT_CURSOR) {
41764 - atomic_inc(&qdev->irq_received_cursor);
41765 + atomic_inc_unchecked(&qdev->irq_received_cursor);
41766 wake_up_all(&qdev->cursor_event);
41767 }
41768 if (pending & QXL_INTERRUPT_IO_CMD) {
41769 - atomic_inc(&qdev->irq_received_io_cmd);
41770 + atomic_inc_unchecked(&qdev->irq_received_io_cmd);
41771 wake_up_all(&qdev->io_cmd_event);
41772 }
41773 if (pending & QXL_INTERRUPT_ERROR) {
41774 @@ -85,10 +85,10 @@ int qxl_irq_init(struct qxl_device *qdev)
41775 init_waitqueue_head(&qdev->io_cmd_event);
41776 INIT_WORK(&qdev->client_monitors_config_work,
41777 qxl_client_monitors_config_work_func);
41778 - atomic_set(&qdev->irq_received, 0);
41779 - atomic_set(&qdev->irq_received_display, 0);
41780 - atomic_set(&qdev->irq_received_cursor, 0);
41781 - atomic_set(&qdev->irq_received_io_cmd, 0);
41782 + atomic_set_unchecked(&qdev->irq_received, 0);
41783 + atomic_set_unchecked(&qdev->irq_received_display, 0);
41784 + atomic_set_unchecked(&qdev->irq_received_cursor, 0);
41785 + atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
41786 qdev->irq_received_error = 0;
41787 ret = drm_irq_install(qdev->ddev, qdev->ddev->pdev->irq);
41788 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
41789 diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
41790 index 71a1bae..cb1f103 100644
41791 --- a/drivers/gpu/drm/qxl/qxl_ttm.c
41792 +++ b/drivers/gpu/drm/qxl/qxl_ttm.c
41793 @@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
41794 }
41795 }
41796
41797 -static struct vm_operations_struct qxl_ttm_vm_ops;
41798 +static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
41799 static const struct vm_operations_struct *ttm_vm_ops;
41800
41801 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41802 @@ -145,8 +145,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
41803 return r;
41804 if (unlikely(ttm_vm_ops == NULL)) {
41805 ttm_vm_ops = vma->vm_ops;
41806 + pax_open_kernel();
41807 qxl_ttm_vm_ops = *ttm_vm_ops;
41808 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
41809 + pax_close_kernel();
41810 }
41811 vma->vm_ops = &qxl_ttm_vm_ops;
41812 return 0;
41813 @@ -555,25 +557,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
41814 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
41815 {
41816 #if defined(CONFIG_DEBUG_FS)
41817 - static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
41818 - static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
41819 - unsigned i;
41820 + static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
41821 + {
41822 + .name = "qxl_mem_mm",
41823 + .show = &qxl_mm_dump_table,
41824 + },
41825 + {
41826 + .name = "qxl_surf_mm",
41827 + .show = &qxl_mm_dump_table,
41828 + }
41829 + };
41830
41831 - for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
41832 - if (i == 0)
41833 - sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
41834 - else
41835 - sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
41836 - qxl_mem_types_list[i].name = qxl_mem_types_names[i];
41837 - qxl_mem_types_list[i].show = &qxl_mm_dump_table;
41838 - qxl_mem_types_list[i].driver_features = 0;
41839 - if (i == 0)
41840 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
41841 - else
41842 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
41843 + pax_open_kernel();
41844 + *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
41845 + *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
41846 + pax_close_kernel();
41847
41848 - }
41849 - return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
41850 + return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
41851 #else
41852 return 0;
41853 #endif
41854 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
41855 index 59459fe..be26b31 100644
41856 --- a/drivers/gpu/drm/r128/r128_cce.c
41857 +++ b/drivers/gpu/drm/r128/r128_cce.c
41858 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
41859
41860 /* GH: Simple idle check.
41861 */
41862 - atomic_set(&dev_priv->idle_count, 0);
41863 + atomic_set_unchecked(&dev_priv->idle_count, 0);
41864
41865 /* We don't support anything other than bus-mastering ring mode,
41866 * but the ring can be in either AGP or PCI space for the ring
41867 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
41868 index 5bf3f5f..7000661 100644
41869 --- a/drivers/gpu/drm/r128/r128_drv.h
41870 +++ b/drivers/gpu/drm/r128/r128_drv.h
41871 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
41872 int is_pci;
41873 unsigned long cce_buffers_offset;
41874
41875 - atomic_t idle_count;
41876 + atomic_unchecked_t idle_count;
41877
41878 int page_flipping;
41879 int current_page;
41880 u32 crtc_offset;
41881 u32 crtc_offset_cntl;
41882
41883 - atomic_t vbl_received;
41884 + atomic_unchecked_t vbl_received;
41885
41886 u32 color_fmt;
41887 unsigned int front_offset;
41888 diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
41889 index 663f38c..c689495 100644
41890 --- a/drivers/gpu/drm/r128/r128_ioc32.c
41891 +++ b/drivers/gpu/drm/r128/r128_ioc32.c
41892 @@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
41893 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
41894 }
41895
41896 -drm_ioctl_compat_t *r128_compat_ioctls[] = {
41897 +drm_ioctl_compat_t r128_compat_ioctls[] = {
41898 [DRM_R128_INIT] = compat_r128_init,
41899 [DRM_R128_DEPTH] = compat_r128_depth,
41900 [DRM_R128_STIPPLE] = compat_r128_stipple,
41901 @@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
41902 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41903 {
41904 unsigned int nr = DRM_IOCTL_NR(cmd);
41905 - drm_ioctl_compat_t *fn = NULL;
41906 int ret;
41907
41908 if (nr < DRM_COMMAND_BASE)
41909 return drm_compat_ioctl(filp, cmd, arg);
41910
41911 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls))
41912 - fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41913 -
41914 - if (fn != NULL)
41915 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls)) {
41916 + drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41917 ret = (*fn) (filp, cmd, arg);
41918 - else
41919 + } else
41920 ret = drm_ioctl(filp, cmd, arg);
41921
41922 return ret;
41923 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
41924 index c2ae496..30b5993 100644
41925 --- a/drivers/gpu/drm/r128/r128_irq.c
41926 +++ b/drivers/gpu/drm/r128/r128_irq.c
41927 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
41928 if (crtc != 0)
41929 return 0;
41930
41931 - return atomic_read(&dev_priv->vbl_received);
41932 + return atomic_read_unchecked(&dev_priv->vbl_received);
41933 }
41934
41935 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
41936 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
41937 /* VBLANK interrupt */
41938 if (status & R128_CRTC_VBLANK_INT) {
41939 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
41940 - atomic_inc(&dev_priv->vbl_received);
41941 + atomic_inc_unchecked(&dev_priv->vbl_received);
41942 drm_handle_vblank(dev, 0);
41943 return IRQ_HANDLED;
41944 }
41945 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
41946 index 575e986..66e62ca 100644
41947 --- a/drivers/gpu/drm/r128/r128_state.c
41948 +++ b/drivers/gpu/drm/r128/r128_state.c
41949 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
41950
41951 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
41952 {
41953 - if (atomic_read(&dev_priv->idle_count) == 0)
41954 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
41955 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
41956 else
41957 - atomic_set(&dev_priv->idle_count, 0);
41958 + atomic_set_unchecked(&dev_priv->idle_count, 0);
41959 }
41960
41961 #endif
41962 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
41963 index 4a85bb6..aaea819 100644
41964 --- a/drivers/gpu/drm/radeon/mkregtable.c
41965 +++ b/drivers/gpu/drm/radeon/mkregtable.c
41966 @@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
41967 regex_t mask_rex;
41968 regmatch_t match[4];
41969 char buf[1024];
41970 - size_t end;
41971 + long end;
41972 int len;
41973 int done = 0;
41974 int r;
41975 unsigned o;
41976 struct offset *offset;
41977 char last_reg_s[10];
41978 - int last_reg;
41979 + unsigned long last_reg;
41980
41981 if (regcomp
41982 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
41983 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
41984 index 5d4416f..80b7fc4 100644
41985 --- a/drivers/gpu/drm/radeon/radeon_device.c
41986 +++ b/drivers/gpu/drm/radeon/radeon_device.c
41987 @@ -1214,7 +1214,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
41988 * locking inversion with the driver load path. And the access here is
41989 * completely racy anyway. So don't bother with locking for now.
41990 */
41991 - return dev->open_count == 0;
41992 + return local_read(&dev->open_count) == 0;
41993 }
41994
41995 static const struct vga_switcheroo_client_ops radeon_switcheroo_ops = {
41996 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
41997 index dafd812..1bf20c7 100644
41998 --- a/drivers/gpu/drm/radeon/radeon_drv.h
41999 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
42000 @@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
42001
42002 /* SW interrupt */
42003 wait_queue_head_t swi_queue;
42004 - atomic_t swi_emitted;
42005 + atomic_unchecked_t swi_emitted;
42006 int vblank_crtc;
42007 uint32_t irq_enable_reg;
42008 uint32_t r500_disp_irq_reg;
42009 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
42010 index 0b98ea1..0881827 100644
42011 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
42012 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
42013 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
42014 request = compat_alloc_user_space(sizeof(*request));
42015 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
42016 || __put_user(req32.param, &request->param)
42017 - || __put_user((void __user *)(unsigned long)req32.value,
42018 + || __put_user((unsigned long)req32.value,
42019 &request->value))
42020 return -EFAULT;
42021
42022 @@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
42023 #define compat_radeon_cp_setparam NULL
42024 #endif /* X86_64 || IA64 */
42025
42026 -static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
42027 +static drm_ioctl_compat_t radeon_compat_ioctls[] = {
42028 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
42029 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
42030 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
42031 @@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
42032 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
42033 {
42034 unsigned int nr = DRM_IOCTL_NR(cmd);
42035 - drm_ioctl_compat_t *fn = NULL;
42036 int ret;
42037
42038 if (nr < DRM_COMMAND_BASE)
42039 return drm_compat_ioctl(filp, cmd, arg);
42040
42041 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls))
42042 - fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
42043 -
42044 - if (fn != NULL)
42045 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls)) {
42046 + drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
42047 ret = (*fn) (filp, cmd, arg);
42048 - else
42049 + } else
42050 ret = drm_ioctl(filp, cmd, arg);
42051
42052 return ret;
42053 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
42054 index 244b19b..c19226d 100644
42055 --- a/drivers/gpu/drm/radeon/radeon_irq.c
42056 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
42057 @@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
42058 unsigned int ret;
42059 RING_LOCALS;
42060
42061 - atomic_inc(&dev_priv->swi_emitted);
42062 - ret = atomic_read(&dev_priv->swi_emitted);
42063 + atomic_inc_unchecked(&dev_priv->swi_emitted);
42064 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
42065
42066 BEGIN_RING(4);
42067 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
42068 @@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
42069 drm_radeon_private_t *dev_priv =
42070 (drm_radeon_private_t *) dev->dev_private;
42071
42072 - atomic_set(&dev_priv->swi_emitted, 0);
42073 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
42074 init_waitqueue_head(&dev_priv->swi_queue);
42075
42076 dev->max_vblank_count = 0x001fffff;
42077 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
42078 index 23bb64f..69d7234 100644
42079 --- a/drivers/gpu/drm/radeon/radeon_state.c
42080 +++ b/drivers/gpu/drm/radeon/radeon_state.c
42081 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
42082 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
42083 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
42084
42085 - if (copy_from_user(&depth_boxes, clear->depth_boxes,
42086 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
42087 sarea_priv->nbox * sizeof(depth_boxes[0])))
42088 return -EFAULT;
42089
42090 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
42091 {
42092 drm_radeon_private_t *dev_priv = dev->dev_private;
42093 drm_radeon_getparam_t *param = data;
42094 - int value;
42095 + int value = 0;
42096
42097 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
42098
42099 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
42100 index 72afe82..056a57a 100644
42101 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
42102 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
42103 @@ -801,7 +801,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
42104 man->size = size >> PAGE_SHIFT;
42105 }
42106
42107 -static struct vm_operations_struct radeon_ttm_vm_ops;
42108 +static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
42109 static const struct vm_operations_struct *ttm_vm_ops = NULL;
42110
42111 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
42112 @@ -842,8 +842,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
42113 }
42114 if (unlikely(ttm_vm_ops == NULL)) {
42115 ttm_vm_ops = vma->vm_ops;
42116 + pax_open_kernel();
42117 radeon_ttm_vm_ops = *ttm_vm_ops;
42118 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
42119 + pax_close_kernel();
42120 }
42121 vma->vm_ops = &radeon_ttm_vm_ops;
42122 return 0;
42123 diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
42124 index 6553fd2..aecd29c 100644
42125 --- a/drivers/gpu/drm/tegra/dc.c
42126 +++ b/drivers/gpu/drm/tegra/dc.c
42127 @@ -1243,7 +1243,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
42128 }
42129
42130 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
42131 - dc->debugfs_files[i].data = dc;
42132 + *(void **)&dc->debugfs_files[i].data = dc;
42133
42134 err = drm_debugfs_create_files(dc->debugfs_files,
42135 ARRAY_SIZE(debugfs_files),
42136 diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
42137 index f787445..2df2c65 100644
42138 --- a/drivers/gpu/drm/tegra/dsi.c
42139 +++ b/drivers/gpu/drm/tegra/dsi.c
42140 @@ -41,7 +41,7 @@ struct tegra_dsi {
42141 struct clk *clk_lp;
42142 struct clk *clk;
42143
42144 - struct drm_info_list *debugfs_files;
42145 + drm_info_list_no_const *debugfs_files;
42146 struct drm_minor *minor;
42147 struct dentry *debugfs;
42148
42149 diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
42150 index ffe2654..03c7b1c 100644
42151 --- a/drivers/gpu/drm/tegra/hdmi.c
42152 +++ b/drivers/gpu/drm/tegra/hdmi.c
42153 @@ -60,7 +60,7 @@ struct tegra_hdmi {
42154 bool stereo;
42155 bool dvi;
42156
42157 - struct drm_info_list *debugfs_files;
42158 + drm_info_list_no_const *debugfs_files;
42159 struct drm_minor *minor;
42160 struct dentry *debugfs;
42161 };
42162 diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
42163 index 9e103a48..0e117f3 100644
42164 --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
42165 +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
42166 @@ -147,10 +147,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
42167 }
42168
42169 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
42170 - ttm_bo_man_init,
42171 - ttm_bo_man_takedown,
42172 - ttm_bo_man_get_node,
42173 - ttm_bo_man_put_node,
42174 - ttm_bo_man_debug
42175 + .init = ttm_bo_man_init,
42176 + .takedown = ttm_bo_man_takedown,
42177 + .get_node = ttm_bo_man_get_node,
42178 + .put_node = ttm_bo_man_put_node,
42179 + .debug = ttm_bo_man_debug
42180 };
42181 EXPORT_SYMBOL(ttm_bo_manager_func);
42182 diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
42183 index dbc2def..0a9f710 100644
42184 --- a/drivers/gpu/drm/ttm/ttm_memory.c
42185 +++ b/drivers/gpu/drm/ttm/ttm_memory.c
42186 @@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
42187 zone->glob = glob;
42188 glob->zone_kernel = zone;
42189 ret = kobject_init_and_add(
42190 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
42191 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
42192 if (unlikely(ret != 0)) {
42193 kobject_put(&zone->kobj);
42194 return ret;
42195 @@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
42196 zone->glob = glob;
42197 glob->zone_dma32 = zone;
42198 ret = kobject_init_and_add(
42199 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
42200 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
42201 if (unlikely(ret != 0)) {
42202 kobject_put(&zone->kobj);
42203 return ret;
42204 diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
42205 index d1da339..829235e 100644
42206 --- a/drivers/gpu/drm/udl/udl_fb.c
42207 +++ b/drivers/gpu/drm/udl/udl_fb.c
42208 @@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
42209 fb_deferred_io_cleanup(info);
42210 kfree(info->fbdefio);
42211 info->fbdefio = NULL;
42212 - info->fbops->fb_mmap = udl_fb_mmap;
42213 }
42214
42215 pr_warn("released /dev/fb%d user=%d count=%d\n",
42216 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
42217 index ad02732..144f5ed 100644
42218 --- a/drivers/gpu/drm/via/via_drv.h
42219 +++ b/drivers/gpu/drm/via/via_drv.h
42220 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
42221 typedef uint32_t maskarray_t[5];
42222
42223 typedef struct drm_via_irq {
42224 - atomic_t irq_received;
42225 + atomic_unchecked_t irq_received;
42226 uint32_t pending_mask;
42227 uint32_t enable_mask;
42228 wait_queue_head_t irq_queue;
42229 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
42230 struct timeval last_vblank;
42231 int last_vblank_valid;
42232 unsigned usec_per_vblank;
42233 - atomic_t vbl_received;
42234 + atomic_unchecked_t vbl_received;
42235 drm_via_state_t hc_state;
42236 char pci_buf[VIA_PCI_BUF_SIZE];
42237 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
42238 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
42239 index 1319433..a993b0c 100644
42240 --- a/drivers/gpu/drm/via/via_irq.c
42241 +++ b/drivers/gpu/drm/via/via_irq.c
42242 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
42243 if (crtc != 0)
42244 return 0;
42245
42246 - return atomic_read(&dev_priv->vbl_received);
42247 + return atomic_read_unchecked(&dev_priv->vbl_received);
42248 }
42249
42250 irqreturn_t via_driver_irq_handler(int irq, void *arg)
42251 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
42252
42253 status = VIA_READ(VIA_REG_INTERRUPT);
42254 if (status & VIA_IRQ_VBLANK_PENDING) {
42255 - atomic_inc(&dev_priv->vbl_received);
42256 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
42257 + atomic_inc_unchecked(&dev_priv->vbl_received);
42258 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
42259 do_gettimeofday(&cur_vblank);
42260 if (dev_priv->last_vblank_valid) {
42261 dev_priv->usec_per_vblank =
42262 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
42263 dev_priv->last_vblank = cur_vblank;
42264 dev_priv->last_vblank_valid = 1;
42265 }
42266 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
42267 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
42268 DRM_DEBUG("US per vblank is: %u\n",
42269 dev_priv->usec_per_vblank);
42270 }
42271 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
42272
42273 for (i = 0; i < dev_priv->num_irqs; ++i) {
42274 if (status & cur_irq->pending_mask) {
42275 - atomic_inc(&cur_irq->irq_received);
42276 + atomic_inc_unchecked(&cur_irq->irq_received);
42277 wake_up(&cur_irq->irq_queue);
42278 handled = 1;
42279 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
42280 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
42281 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
42282 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
42283 masks[irq][4]));
42284 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
42285 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
42286 } else {
42287 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
42288 (((cur_irq_sequence =
42289 - atomic_read(&cur_irq->irq_received)) -
42290 + atomic_read_unchecked(&cur_irq->irq_received)) -
42291 *sequence) <= (1 << 23)));
42292 }
42293 *sequence = cur_irq_sequence;
42294 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
42295 }
42296
42297 for (i = 0; i < dev_priv->num_irqs; ++i) {
42298 - atomic_set(&cur_irq->irq_received, 0);
42299 + atomic_set_unchecked(&cur_irq->irq_received, 0);
42300 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
42301 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
42302 init_waitqueue_head(&cur_irq->irq_queue);
42303 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
42304 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
42305 case VIA_IRQ_RELATIVE:
42306 irqwait->request.sequence +=
42307 - atomic_read(&cur_irq->irq_received);
42308 + atomic_read_unchecked(&cur_irq->irq_received);
42309 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
42310 case VIA_IRQ_ABSOLUTE:
42311 break;
42312 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
42313 index 99f7317..33a835b 100644
42314 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
42315 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
42316 @@ -447,7 +447,7 @@ struct vmw_private {
42317 * Fencing and IRQs.
42318 */
42319
42320 - atomic_t marker_seq;
42321 + atomic_unchecked_t marker_seq;
42322 wait_queue_head_t fence_queue;
42323 wait_queue_head_t fifo_queue;
42324 int fence_queue_waiters; /* Protected by hw_mutex */
42325 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
42326 index 6eae14d..aa311b3 100644
42327 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
42328 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
42329 @@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
42330 (unsigned int) min,
42331 (unsigned int) fifo->capabilities);
42332
42333 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
42334 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
42335 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
42336 vmw_marker_queue_init(&fifo->marker_queue);
42337 return vmw_fifo_send_fence(dev_priv, &dummy);
42338 @@ -373,7 +373,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
42339 if (reserveable)
42340 iowrite32(bytes, fifo_mem +
42341 SVGA_FIFO_RESERVED);
42342 - return fifo_mem + (next_cmd >> 2);
42343 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
42344 } else {
42345 need_bounce = true;
42346 }
42347 @@ -493,7 +493,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
42348
42349 fm = vmw_fifo_reserve(dev_priv, bytes);
42350 if (unlikely(fm == NULL)) {
42351 - *seqno = atomic_read(&dev_priv->marker_seq);
42352 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
42353 ret = -ENOMEM;
42354 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
42355 false, 3*HZ);
42356 @@ -501,7 +501,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
42357 }
42358
42359 do {
42360 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
42361 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
42362 } while (*seqno == 0);
42363
42364 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
42365 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
42366 index 26f8bdd..90a0008 100644
42367 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
42368 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
42369 @@ -165,9 +165,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
42370 }
42371
42372 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
42373 - vmw_gmrid_man_init,
42374 - vmw_gmrid_man_takedown,
42375 - vmw_gmrid_man_get_node,
42376 - vmw_gmrid_man_put_node,
42377 - vmw_gmrid_man_debug
42378 + .init = vmw_gmrid_man_init,
42379 + .takedown = vmw_gmrid_man_takedown,
42380 + .get_node = vmw_gmrid_man_get_node,
42381 + .put_node = vmw_gmrid_man_put_node,
42382 + .debug = vmw_gmrid_man_debug
42383 };
42384 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
42385 index 37881ec..319065d 100644
42386 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
42387 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
42388 @@ -235,7 +235,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
42389 int ret;
42390
42391 num_clips = arg->num_clips;
42392 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
42393 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
42394
42395 if (unlikely(num_clips == 0))
42396 return 0;
42397 @@ -318,7 +318,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
42398 int ret;
42399
42400 num_clips = arg->num_clips;
42401 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
42402 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
42403
42404 if (unlikely(num_clips == 0))
42405 return 0;
42406 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
42407 index 0c42376..6febe77 100644
42408 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
42409 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
42410 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
42411 * emitted. Then the fence is stale and signaled.
42412 */
42413
42414 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
42415 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
42416 > VMW_FENCE_WRAP);
42417
42418 return ret;
42419 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
42420
42421 if (fifo_idle)
42422 down_read(&fifo_state->rwsem);
42423 - signal_seq = atomic_read(&dev_priv->marker_seq);
42424 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
42425 ret = 0;
42426
42427 for (;;) {
42428 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
42429 index efd1ffd..0ae13ca 100644
42430 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
42431 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
42432 @@ -135,7 +135,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
42433 while (!vmw_lag_lt(queue, us)) {
42434 spin_lock(&queue->lock);
42435 if (list_empty(&queue->head))
42436 - seqno = atomic_read(&dev_priv->marker_seq);
42437 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
42438 else {
42439 marker = list_first_entry(&queue->head,
42440 struct vmw_marker, head);
42441 diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
42442 index 37ac7b5..d52a5c9 100644
42443 --- a/drivers/gpu/vga/vga_switcheroo.c
42444 +++ b/drivers/gpu/vga/vga_switcheroo.c
42445 @@ -644,7 +644,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
42446
42447 /* this version is for the case where the power switch is separate
42448 to the device being powered down. */
42449 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
42450 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
42451 {
42452 /* copy over all the bus versions */
42453 if (dev->bus && dev->bus->pm) {
42454 @@ -695,7 +695,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
42455 return ret;
42456 }
42457
42458 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
42459 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
42460 {
42461 /* copy over all the bus versions */
42462 if (dev->bus && dev->bus->pm) {
42463 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
42464 index 12b6e67..ddd983c 100644
42465 --- a/drivers/hid/hid-core.c
42466 +++ b/drivers/hid/hid-core.c
42467 @@ -2500,7 +2500,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
42468
42469 int hid_add_device(struct hid_device *hdev)
42470 {
42471 - static atomic_t id = ATOMIC_INIT(0);
42472 + static atomic_unchecked_t id = ATOMIC_INIT(0);
42473 int ret;
42474
42475 if (WARN_ON(hdev->status & HID_STAT_ADDED))
42476 @@ -2542,7 +2542,7 @@ int hid_add_device(struct hid_device *hdev)
42477 /* XXX hack, any other cleaner solution after the driver core
42478 * is converted to allow more than 20 bytes as the device name? */
42479 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
42480 - hdev->vendor, hdev->product, atomic_inc_return(&id));
42481 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
42482
42483 hid_debug_register(hdev, dev_name(&hdev->dev));
42484 ret = device_add(&hdev->dev);
42485 diff --git a/drivers/hid/hid-logitech-dj.c b/drivers/hid/hid-logitech-dj.c
42486 index 9bf8637..f462416 100644
42487 --- a/drivers/hid/hid-logitech-dj.c
42488 +++ b/drivers/hid/hid-logitech-dj.c
42489 @@ -682,6 +682,12 @@ static int logi_dj_raw_event(struct hid_device *hdev,
42490 * device (via hid_input_report() ) and return 1 so hid-core does not do
42491 * anything else with it.
42492 */
42493 + if ((dj_report->device_index < DJ_DEVICE_INDEX_MIN) ||
42494 + (dj_report->device_index > DJ_DEVICE_INDEX_MAX)) {
42495 + dev_err(&hdev->dev, "%s: invalid device index:%d\n",
42496 + __func__, dj_report->device_index);
42497 + return false;
42498 + }
42499
42500 /* case 1) */
42501 if (data[0] != REPORT_ID_DJ_SHORT)
42502 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
42503 index c13fb5b..55a3802 100644
42504 --- a/drivers/hid/hid-wiimote-debug.c
42505 +++ b/drivers/hid/hid-wiimote-debug.c
42506 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
42507 else if (size == 0)
42508 return -EIO;
42509
42510 - if (copy_to_user(u, buf, size))
42511 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
42512 return -EFAULT;
42513
42514 *off += size;
42515 diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
42516 index 0cb92e3..c7d453d 100644
42517 --- a/drivers/hid/uhid.c
42518 +++ b/drivers/hid/uhid.c
42519 @@ -47,7 +47,7 @@ struct uhid_device {
42520 struct mutex report_lock;
42521 wait_queue_head_t report_wait;
42522 atomic_t report_done;
42523 - atomic_t report_id;
42524 + atomic_unchecked_t report_id;
42525 struct uhid_event report_buf;
42526 };
42527
42528 @@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
42529
42530 spin_lock_irqsave(&uhid->qlock, flags);
42531 ev->type = UHID_FEATURE;
42532 - ev->u.feature.id = atomic_inc_return(&uhid->report_id);
42533 + ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
42534 ev->u.feature.rnum = rnum;
42535 ev->u.feature.rtype = report_type;
42536
42537 @@ -538,7 +538,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
42538 spin_lock_irqsave(&uhid->qlock, flags);
42539
42540 /* id for old report; drop it silently */
42541 - if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
42542 + if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
42543 goto unlock;
42544 if (atomic_read(&uhid->report_done))
42545 goto unlock;
42546 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
42547 index 19bad59..ca24eaf 100644
42548 --- a/drivers/hv/channel.c
42549 +++ b/drivers/hv/channel.c
42550 @@ -366,8 +366,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
42551 unsigned long flags;
42552 int ret = 0;
42553
42554 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
42555 - atomic_inc(&vmbus_connection.next_gpadl_handle);
42556 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
42557 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
42558
42559 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
42560 if (ret)
42561 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
42562 index 3e4235c..877d0e5 100644
42563 --- a/drivers/hv/hv.c
42564 +++ b/drivers/hv/hv.c
42565 @@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
42566 u64 output_address = (output) ? virt_to_phys(output) : 0;
42567 u32 output_address_hi = output_address >> 32;
42568 u32 output_address_lo = output_address & 0xFFFFFFFF;
42569 - void *hypercall_page = hv_context.hypercall_page;
42570 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
42571
42572 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
42573 "=a"(hv_status_lo) : "d" (control_hi),
42574 @@ -156,7 +156,7 @@ int hv_init(void)
42575 /* See if the hypercall page is already set */
42576 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
42577
42578 - virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
42579 + virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
42580
42581 if (!virtaddr)
42582 goto cleanup;
42583 diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
42584 index 5e90c5d..d8fcefb 100644
42585 --- a/drivers/hv/hv_balloon.c
42586 +++ b/drivers/hv/hv_balloon.c
42587 @@ -470,7 +470,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
42588
42589 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
42590 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
42591 -static atomic_t trans_id = ATOMIC_INIT(0);
42592 +static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
42593
42594 static int dm_ring_size = (5 * PAGE_SIZE);
42595
42596 @@ -893,7 +893,7 @@ static void hot_add_req(struct work_struct *dummy)
42597 pr_info("Memory hot add failed\n");
42598
42599 dm->state = DM_INITIALIZED;
42600 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
42601 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42602 vmbus_sendpacket(dm->dev->channel, &resp,
42603 sizeof(struct dm_hot_add_response),
42604 (unsigned long)NULL,
42605 @@ -973,7 +973,7 @@ static void post_status(struct hv_dynmem_device *dm)
42606 memset(&status, 0, sizeof(struct dm_status));
42607 status.hdr.type = DM_STATUS_REPORT;
42608 status.hdr.size = sizeof(struct dm_status);
42609 - status.hdr.trans_id = atomic_inc_return(&trans_id);
42610 + status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42611
42612 /*
42613 * The host expects the guest to report free memory.
42614 @@ -993,7 +993,7 @@ static void post_status(struct hv_dynmem_device *dm)
42615 * send the status. This can happen if we were interrupted
42616 * after we picked our transaction ID.
42617 */
42618 - if (status.hdr.trans_id != atomic_read(&trans_id))
42619 + if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
42620 return;
42621
42622 /*
42623 @@ -1129,7 +1129,7 @@ static void balloon_up(struct work_struct *dummy)
42624 */
42625
42626 do {
42627 - bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
42628 + bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42629 ret = vmbus_sendpacket(dm_device.dev->channel,
42630 bl_resp,
42631 bl_resp->hdr.size,
42632 @@ -1175,7 +1175,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
42633
42634 memset(&resp, 0, sizeof(struct dm_unballoon_response));
42635 resp.hdr.type = DM_UNBALLOON_RESPONSE;
42636 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
42637 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42638 resp.hdr.size = sizeof(struct dm_unballoon_response);
42639
42640 vmbus_sendpacket(dm_device.dev->channel, &resp,
42641 @@ -1239,7 +1239,7 @@ static void version_resp(struct hv_dynmem_device *dm,
42642 memset(&version_req, 0, sizeof(struct dm_version_request));
42643 version_req.hdr.type = DM_VERSION_REQUEST;
42644 version_req.hdr.size = sizeof(struct dm_version_request);
42645 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
42646 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42647 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
42648 version_req.is_last_attempt = 1;
42649
42650 @@ -1409,7 +1409,7 @@ static int balloon_probe(struct hv_device *dev,
42651 memset(&version_req, 0, sizeof(struct dm_version_request));
42652 version_req.hdr.type = DM_VERSION_REQUEST;
42653 version_req.hdr.size = sizeof(struct dm_version_request);
42654 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
42655 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42656 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
42657 version_req.is_last_attempt = 0;
42658
42659 @@ -1440,7 +1440,7 @@ static int balloon_probe(struct hv_device *dev,
42660 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
42661 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
42662 cap_msg.hdr.size = sizeof(struct dm_capabilities);
42663 - cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
42664 + cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42665
42666 cap_msg.caps.cap_bits.balloon = 1;
42667 cap_msg.caps.cap_bits.hot_add = 1;
42668 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
42669 index c386d8d..d6004c4 100644
42670 --- a/drivers/hv/hyperv_vmbus.h
42671 +++ b/drivers/hv/hyperv_vmbus.h
42672 @@ -611,7 +611,7 @@ enum vmbus_connect_state {
42673 struct vmbus_connection {
42674 enum vmbus_connect_state conn_state;
42675
42676 - atomic_t next_gpadl_handle;
42677 + atomic_unchecked_t next_gpadl_handle;
42678
42679 /*
42680 * Represents channel interrupts. Each bit position represents a
42681 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
42682 index 4d6b269..2e23b86 100644
42683 --- a/drivers/hv/vmbus_drv.c
42684 +++ b/drivers/hv/vmbus_drv.c
42685 @@ -807,10 +807,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
42686 {
42687 int ret = 0;
42688
42689 - static atomic_t device_num = ATOMIC_INIT(0);
42690 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
42691
42692 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
42693 - atomic_inc_return(&device_num));
42694 + atomic_inc_return_unchecked(&device_num));
42695
42696 child_device_obj->device.bus = &hv_bus;
42697 child_device_obj->device.parent = &hv_acpi_dev->dev;
42698 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
42699 index 579bdf9..75118b5 100644
42700 --- a/drivers/hwmon/acpi_power_meter.c
42701 +++ b/drivers/hwmon/acpi_power_meter.c
42702 @@ -116,7 +116,7 @@ struct sensor_template {
42703 struct device_attribute *devattr,
42704 const char *buf, size_t count);
42705 int index;
42706 -};
42707 +} __do_const;
42708
42709 /* Averaging interval */
42710 static int update_avg_interval(struct acpi_power_meter_resource *resource)
42711 @@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
42712 struct sensor_template *attrs)
42713 {
42714 struct device *dev = &resource->acpi_dev->dev;
42715 - struct sensor_device_attribute *sensors =
42716 + sensor_device_attribute_no_const *sensors =
42717 &resource->sensors[resource->num_sensors];
42718 int res = 0;
42719
42720 diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
42721 index 3288f13..71cfb4e 100644
42722 --- a/drivers/hwmon/applesmc.c
42723 +++ b/drivers/hwmon/applesmc.c
42724 @@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
42725 {
42726 struct applesmc_node_group *grp;
42727 struct applesmc_dev_attr *node;
42728 - struct attribute *attr;
42729 + attribute_no_const *attr;
42730 int ret, i;
42731
42732 for (grp = groups; grp->format; grp++) {
42733 diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
42734 index cccef87..06ce8ec 100644
42735 --- a/drivers/hwmon/asus_atk0110.c
42736 +++ b/drivers/hwmon/asus_atk0110.c
42737 @@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
42738 struct atk_sensor_data {
42739 struct list_head list;
42740 struct atk_data *data;
42741 - struct device_attribute label_attr;
42742 - struct device_attribute input_attr;
42743 - struct device_attribute limit1_attr;
42744 - struct device_attribute limit2_attr;
42745 + device_attribute_no_const label_attr;
42746 + device_attribute_no_const input_attr;
42747 + device_attribute_no_const limit1_attr;
42748 + device_attribute_no_const limit2_attr;
42749 char label_attr_name[ATTR_NAME_SIZE];
42750 char input_attr_name[ATTR_NAME_SIZE];
42751 char limit1_attr_name[ATTR_NAME_SIZE];
42752 @@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
42753 static struct device_attribute atk_name_attr =
42754 __ATTR(name, 0444, atk_name_show, NULL);
42755
42756 -static void atk_init_attribute(struct device_attribute *attr, char *name,
42757 +static void atk_init_attribute(device_attribute_no_const *attr, char *name,
42758 sysfs_show_func show)
42759 {
42760 sysfs_attr_init(&attr->attr);
42761 diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
42762 index d76f0b7..55ae976 100644
42763 --- a/drivers/hwmon/coretemp.c
42764 +++ b/drivers/hwmon/coretemp.c
42765 @@ -784,7 +784,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
42766 return NOTIFY_OK;
42767 }
42768
42769 -static struct notifier_block coretemp_cpu_notifier __refdata = {
42770 +static struct notifier_block coretemp_cpu_notifier = {
42771 .notifier_call = coretemp_cpu_callback,
42772 };
42773
42774 diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
42775 index 7a8a6fb..015c1fd 100644
42776 --- a/drivers/hwmon/ibmaem.c
42777 +++ b/drivers/hwmon/ibmaem.c
42778 @@ -924,7 +924,7 @@ static int aem_register_sensors(struct aem_data *data,
42779 struct aem_rw_sensor_template *rw)
42780 {
42781 struct device *dev = &data->pdev->dev;
42782 - struct sensor_device_attribute *sensors = data->sensors;
42783 + sensor_device_attribute_no_const *sensors = data->sensors;
42784 int err;
42785
42786 /* Set up read-only sensors */
42787 diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
42788 index 14c82da..09b25d7 100644
42789 --- a/drivers/hwmon/iio_hwmon.c
42790 +++ b/drivers/hwmon/iio_hwmon.c
42791 @@ -61,7 +61,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
42792 {
42793 struct device *dev = &pdev->dev;
42794 struct iio_hwmon_state *st;
42795 - struct sensor_device_attribute *a;
42796 + sensor_device_attribute_no_const *a;
42797 int ret, i;
42798 int in_i = 1, temp_i = 1, curr_i = 1;
42799 enum iio_chan_type type;
42800 diff --git a/drivers/hwmon/nct6683.c b/drivers/hwmon/nct6683.c
42801 index 7710f46..427a28d 100644
42802 --- a/drivers/hwmon/nct6683.c
42803 +++ b/drivers/hwmon/nct6683.c
42804 @@ -397,11 +397,11 @@ static struct attribute_group *
42805 nct6683_create_attr_group(struct device *dev, struct sensor_template_group *tg,
42806 int repeat)
42807 {
42808 - struct sensor_device_attribute_2 *a2;
42809 - struct sensor_device_attribute *a;
42810 + sensor_device_attribute_2_no_const *a2;
42811 + sensor_device_attribute_no_const *a;
42812 struct sensor_device_template **t;
42813 struct sensor_device_attr_u *su;
42814 - struct attribute_group *group;
42815 + attribute_group_no_const *group;
42816 struct attribute **attrs;
42817 int i, j, count;
42818
42819 diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
42820 index 504cbdd..35d6f25 100644
42821 --- a/drivers/hwmon/nct6775.c
42822 +++ b/drivers/hwmon/nct6775.c
42823 @@ -943,10 +943,10 @@ static struct attribute_group *
42824 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
42825 int repeat)
42826 {
42827 - struct attribute_group *group;
42828 + attribute_group_no_const *group;
42829 struct sensor_device_attr_u *su;
42830 - struct sensor_device_attribute *a;
42831 - struct sensor_device_attribute_2 *a2;
42832 + sensor_device_attribute_no_const *a;
42833 + sensor_device_attribute_2_no_const *a2;
42834 struct attribute **attrs;
42835 struct sensor_device_template **t;
42836 int i, count;
42837 diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
42838 index 291d11f..3f0dbbd 100644
42839 --- a/drivers/hwmon/pmbus/pmbus_core.c
42840 +++ b/drivers/hwmon/pmbus/pmbus_core.c
42841 @@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
42842 return 0;
42843 }
42844
42845 -static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
42846 +static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
42847 const char *name,
42848 umode_t mode,
42849 ssize_t (*show)(struct device *dev,
42850 @@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
42851 dev_attr->store = store;
42852 }
42853
42854 -static void pmbus_attr_init(struct sensor_device_attribute *a,
42855 +static void pmbus_attr_init(sensor_device_attribute_no_const *a,
42856 const char *name,
42857 umode_t mode,
42858 ssize_t (*show)(struct device *dev,
42859 @@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
42860 u16 reg, u8 mask)
42861 {
42862 struct pmbus_boolean *boolean;
42863 - struct sensor_device_attribute *a;
42864 + sensor_device_attribute_no_const *a;
42865
42866 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
42867 if (!boolean)
42868 @@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
42869 bool update, bool readonly)
42870 {
42871 struct pmbus_sensor *sensor;
42872 - struct device_attribute *a;
42873 + device_attribute_no_const *a;
42874
42875 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
42876 if (!sensor)
42877 @@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
42878 const char *lstring, int index)
42879 {
42880 struct pmbus_label *label;
42881 - struct device_attribute *a;
42882 + device_attribute_no_const *a;
42883
42884 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
42885 if (!label)
42886 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
42887 index 97cd45a..ac54d8b 100644
42888 --- a/drivers/hwmon/sht15.c
42889 +++ b/drivers/hwmon/sht15.c
42890 @@ -169,7 +169,7 @@ struct sht15_data {
42891 int supply_uv;
42892 bool supply_uv_valid;
42893 struct work_struct update_supply_work;
42894 - atomic_t interrupt_handled;
42895 + atomic_unchecked_t interrupt_handled;
42896 };
42897
42898 /**
42899 @@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
42900 ret = gpio_direction_input(data->pdata->gpio_data);
42901 if (ret)
42902 return ret;
42903 - atomic_set(&data->interrupt_handled, 0);
42904 + atomic_set_unchecked(&data->interrupt_handled, 0);
42905
42906 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42907 if (gpio_get_value(data->pdata->gpio_data) == 0) {
42908 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
42909 /* Only relevant if the interrupt hasn't occurred. */
42910 - if (!atomic_read(&data->interrupt_handled))
42911 + if (!atomic_read_unchecked(&data->interrupt_handled))
42912 schedule_work(&data->read_work);
42913 }
42914 ret = wait_event_timeout(data->wait_queue,
42915 @@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
42916
42917 /* First disable the interrupt */
42918 disable_irq_nosync(irq);
42919 - atomic_inc(&data->interrupt_handled);
42920 + atomic_inc_unchecked(&data->interrupt_handled);
42921 /* Then schedule a reading work struct */
42922 if (data->state != SHT15_READING_NOTHING)
42923 schedule_work(&data->read_work);
42924 @@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
42925 * If not, then start the interrupt again - care here as could
42926 * have gone low in meantime so verify it hasn't!
42927 */
42928 - atomic_set(&data->interrupt_handled, 0);
42929 + atomic_set_unchecked(&data->interrupt_handled, 0);
42930 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42931 /* If still not occurred or another handler was scheduled */
42932 if (gpio_get_value(data->pdata->gpio_data)
42933 - || atomic_read(&data->interrupt_handled))
42934 + || atomic_read_unchecked(&data->interrupt_handled))
42935 return;
42936 }
42937
42938 diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
42939 index 8df43c5..b07b91d 100644
42940 --- a/drivers/hwmon/via-cputemp.c
42941 +++ b/drivers/hwmon/via-cputemp.c
42942 @@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
42943 return NOTIFY_OK;
42944 }
42945
42946 -static struct notifier_block via_cputemp_cpu_notifier __refdata = {
42947 +static struct notifier_block via_cputemp_cpu_notifier = {
42948 .notifier_call = via_cputemp_cpu_callback,
42949 };
42950
42951 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
42952 index 41fc683..a39cfea 100644
42953 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
42954 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
42955 @@ -43,7 +43,7 @@
42956 extern struct i2c_adapter amd756_smbus;
42957
42958 static struct i2c_adapter *s4882_adapter;
42959 -static struct i2c_algorithm *s4882_algo;
42960 +static i2c_algorithm_no_const *s4882_algo;
42961
42962 /* Wrapper access functions for multiplexed SMBus */
42963 static DEFINE_MUTEX(amd756_lock);
42964 diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
42965 index b19a310..d6eece0 100644
42966 --- a/drivers/i2c/busses/i2c-diolan-u2c.c
42967 +++ b/drivers/i2c/busses/i2c-diolan-u2c.c
42968 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
42969 /* usb layer */
42970
42971 /* Send command to device, and get response. */
42972 -static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42973 +static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42974 {
42975 int ret = 0;
42976 int actual;
42977 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
42978 index b170bdf..3c76427 100644
42979 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
42980 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
42981 @@ -41,7 +41,7 @@
42982 extern struct i2c_adapter *nforce2_smbus;
42983
42984 static struct i2c_adapter *s4985_adapter;
42985 -static struct i2c_algorithm *s4985_algo;
42986 +static i2c_algorithm_no_const *s4985_algo;
42987
42988 /* Wrapper access functions for multiplexed SMBus */
42989 static DEFINE_MUTEX(nforce2_lock);
42990 diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
42991 index 80b47e8..1a6040d9 100644
42992 --- a/drivers/i2c/i2c-dev.c
42993 +++ b/drivers/i2c/i2c-dev.c
42994 @@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
42995 break;
42996 }
42997
42998 - data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
42999 + data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
43000 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
43001 if (IS_ERR(rdwr_pa[i].buf)) {
43002 res = PTR_ERR(rdwr_pa[i].buf);
43003 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
43004 index 0b510ba..4fbb5085 100644
43005 --- a/drivers/ide/ide-cd.c
43006 +++ b/drivers/ide/ide-cd.c
43007 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
43008 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
43009 if ((unsigned long)buf & alignment
43010 || blk_rq_bytes(rq) & q->dma_pad_mask
43011 - || object_is_on_stack(buf))
43012 + || object_starts_on_stack(buf))
43013 drive->dma = 0;
43014 }
43015 }
43016 diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
43017 index af3e76d..96dfe5e 100644
43018 --- a/drivers/iio/industrialio-core.c
43019 +++ b/drivers/iio/industrialio-core.c
43020 @@ -555,7 +555,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
43021 }
43022
43023 static
43024 -int __iio_device_attr_init(struct device_attribute *dev_attr,
43025 +int __iio_device_attr_init(device_attribute_no_const *dev_attr,
43026 const char *postfix,
43027 struct iio_chan_spec const *chan,
43028 ssize_t (*readfunc)(struct device *dev,
43029 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
43030 index e28a494..f7c2671 100644
43031 --- a/drivers/infiniband/core/cm.c
43032 +++ b/drivers/infiniband/core/cm.c
43033 @@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
43034
43035 struct cm_counter_group {
43036 struct kobject obj;
43037 - atomic_long_t counter[CM_ATTR_COUNT];
43038 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
43039 };
43040
43041 struct cm_counter_attribute {
43042 @@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
43043 struct ib_mad_send_buf *msg = NULL;
43044 int ret;
43045
43046 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43047 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43048 counter[CM_REQ_COUNTER]);
43049
43050 /* Quick state check to discard duplicate REQs. */
43051 @@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
43052 if (!cm_id_priv)
43053 return;
43054
43055 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43056 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43057 counter[CM_REP_COUNTER]);
43058 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
43059 if (ret)
43060 @@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
43061 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
43062 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
43063 spin_unlock_irq(&cm_id_priv->lock);
43064 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43065 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43066 counter[CM_RTU_COUNTER]);
43067 goto out;
43068 }
43069 @@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
43070 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
43071 dreq_msg->local_comm_id);
43072 if (!cm_id_priv) {
43073 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43074 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43075 counter[CM_DREQ_COUNTER]);
43076 cm_issue_drep(work->port, work->mad_recv_wc);
43077 return -EINVAL;
43078 @@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
43079 case IB_CM_MRA_REP_RCVD:
43080 break;
43081 case IB_CM_TIMEWAIT:
43082 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43083 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43084 counter[CM_DREQ_COUNTER]);
43085 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
43086 goto unlock;
43087 @@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
43088 cm_free_msg(msg);
43089 goto deref;
43090 case IB_CM_DREQ_RCVD:
43091 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43092 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43093 counter[CM_DREQ_COUNTER]);
43094 goto unlock;
43095 default:
43096 @@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
43097 ib_modify_mad(cm_id_priv->av.port->mad_agent,
43098 cm_id_priv->msg, timeout)) {
43099 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
43100 - atomic_long_inc(&work->port->
43101 + atomic_long_inc_unchecked(&work->port->
43102 counter_group[CM_RECV_DUPLICATES].
43103 counter[CM_MRA_COUNTER]);
43104 goto out;
43105 @@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
43106 break;
43107 case IB_CM_MRA_REQ_RCVD:
43108 case IB_CM_MRA_REP_RCVD:
43109 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43110 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43111 counter[CM_MRA_COUNTER]);
43112 /* fall through */
43113 default:
43114 @@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
43115 case IB_CM_LAP_IDLE:
43116 break;
43117 case IB_CM_MRA_LAP_SENT:
43118 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43119 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43120 counter[CM_LAP_COUNTER]);
43121 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
43122 goto unlock;
43123 @@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
43124 cm_free_msg(msg);
43125 goto deref;
43126 case IB_CM_LAP_RCVD:
43127 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43128 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43129 counter[CM_LAP_COUNTER]);
43130 goto unlock;
43131 default:
43132 @@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
43133 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
43134 if (cur_cm_id_priv) {
43135 spin_unlock_irq(&cm.lock);
43136 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43137 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43138 counter[CM_SIDR_REQ_COUNTER]);
43139 goto out; /* Duplicate message. */
43140 }
43141 @@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
43142 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
43143 msg->retries = 1;
43144
43145 - atomic_long_add(1 + msg->retries,
43146 + atomic_long_add_unchecked(1 + msg->retries,
43147 &port->counter_group[CM_XMIT].counter[attr_index]);
43148 if (msg->retries)
43149 - atomic_long_add(msg->retries,
43150 + atomic_long_add_unchecked(msg->retries,
43151 &port->counter_group[CM_XMIT_RETRIES].
43152 counter[attr_index]);
43153
43154 @@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
43155 }
43156
43157 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
43158 - atomic_long_inc(&port->counter_group[CM_RECV].
43159 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
43160 counter[attr_id - CM_ATTR_ID_OFFSET]);
43161
43162 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
43163 @@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
43164 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
43165
43166 return sprintf(buf, "%ld\n",
43167 - atomic_long_read(&group->counter[cm_attr->index]));
43168 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
43169 }
43170
43171 static const struct sysfs_ops cm_counter_ops = {
43172 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
43173 index 9f5ad7c..588cd84 100644
43174 --- a/drivers/infiniband/core/fmr_pool.c
43175 +++ b/drivers/infiniband/core/fmr_pool.c
43176 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
43177
43178 struct task_struct *thread;
43179
43180 - atomic_t req_ser;
43181 - atomic_t flush_ser;
43182 + atomic_unchecked_t req_ser;
43183 + atomic_unchecked_t flush_ser;
43184
43185 wait_queue_head_t force_wait;
43186 };
43187 @@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
43188 struct ib_fmr_pool *pool = pool_ptr;
43189
43190 do {
43191 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
43192 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
43193 ib_fmr_batch_release(pool);
43194
43195 - atomic_inc(&pool->flush_ser);
43196 + atomic_inc_unchecked(&pool->flush_ser);
43197 wake_up_interruptible(&pool->force_wait);
43198
43199 if (pool->flush_function)
43200 @@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
43201 }
43202
43203 set_current_state(TASK_INTERRUPTIBLE);
43204 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
43205 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
43206 !kthread_should_stop())
43207 schedule();
43208 __set_current_state(TASK_RUNNING);
43209 @@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
43210 pool->dirty_watermark = params->dirty_watermark;
43211 pool->dirty_len = 0;
43212 spin_lock_init(&pool->pool_lock);
43213 - atomic_set(&pool->req_ser, 0);
43214 - atomic_set(&pool->flush_ser, 0);
43215 + atomic_set_unchecked(&pool->req_ser, 0);
43216 + atomic_set_unchecked(&pool->flush_ser, 0);
43217 init_waitqueue_head(&pool->force_wait);
43218
43219 pool->thread = kthread_run(ib_fmr_cleanup_thread,
43220 @@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
43221 }
43222 spin_unlock_irq(&pool->pool_lock);
43223
43224 - serial = atomic_inc_return(&pool->req_ser);
43225 + serial = atomic_inc_return_unchecked(&pool->req_ser);
43226 wake_up_process(pool->thread);
43227
43228 if (wait_event_interruptible(pool->force_wait,
43229 - atomic_read(&pool->flush_ser) - serial >= 0))
43230 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
43231 return -EINTR;
43232
43233 return 0;
43234 @@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
43235 } else {
43236 list_add_tail(&fmr->list, &pool->dirty_list);
43237 if (++pool->dirty_len >= pool->dirty_watermark) {
43238 - atomic_inc(&pool->req_ser);
43239 + atomic_inc_unchecked(&pool->req_ser);
43240 wake_up_process(pool->thread);
43241 }
43242 }
43243 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
43244 index ec7a298..8742e59 100644
43245 --- a/drivers/infiniband/hw/cxgb4/mem.c
43246 +++ b/drivers/infiniband/hw/cxgb4/mem.c
43247 @@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
43248 int err;
43249 struct fw_ri_tpte tpt;
43250 u32 stag_idx;
43251 - static atomic_t key;
43252 + static atomic_unchecked_t key;
43253
43254 if (c4iw_fatal_error(rdev))
43255 return -EIO;
43256 @@ -270,7 +270,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
43257 if (rdev->stats.stag.cur > rdev->stats.stag.max)
43258 rdev->stats.stag.max = rdev->stats.stag.cur;
43259 mutex_unlock(&rdev->stats.lock);
43260 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
43261 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
43262 }
43263 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
43264 __func__, stag_state, type, pdid, stag_idx);
43265 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
43266 index 79b3dbc..96e5fcc 100644
43267 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
43268 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
43269 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
43270 struct ib_atomic_eth *ateth;
43271 struct ipath_ack_entry *e;
43272 u64 vaddr;
43273 - atomic64_t *maddr;
43274 + atomic64_unchecked_t *maddr;
43275 u64 sdata;
43276 u32 rkey;
43277 u8 next;
43278 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
43279 IB_ACCESS_REMOTE_ATOMIC)))
43280 goto nack_acc_unlck;
43281 /* Perform atomic OP and save result. */
43282 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
43283 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
43284 sdata = be64_to_cpu(ateth->swap_data);
43285 e = &qp->s_ack_queue[qp->r_head_ack_queue];
43286 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
43287 - (u64) atomic64_add_return(sdata, maddr) - sdata :
43288 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
43289 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
43290 be64_to_cpu(ateth->compare_data),
43291 sdata);
43292 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
43293 index 1f95bba..9530f87 100644
43294 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
43295 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
43296 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
43297 unsigned long flags;
43298 struct ib_wc wc;
43299 u64 sdata;
43300 - atomic64_t *maddr;
43301 + atomic64_unchecked_t *maddr;
43302 enum ib_wc_status send_status;
43303
43304 /*
43305 @@ -382,11 +382,11 @@ again:
43306 IB_ACCESS_REMOTE_ATOMIC)))
43307 goto acc_err;
43308 /* Perform atomic OP and save result. */
43309 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
43310 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
43311 sdata = wqe->wr.wr.atomic.compare_add;
43312 *(u64 *) sqp->s_sge.sge.vaddr =
43313 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
43314 - (u64) atomic64_add_return(sdata, maddr) - sdata :
43315 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
43316 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
43317 sdata, wqe->wr.wr.atomic.swap);
43318 goto send_comp;
43319 diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
43320 index 82a7dd8..8fb6ba6 100644
43321 --- a/drivers/infiniband/hw/mlx4/mad.c
43322 +++ b/drivers/infiniband/hw/mlx4/mad.c
43323 @@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
43324
43325 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
43326 {
43327 - return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
43328 + return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
43329 cpu_to_be64(0xff00000000000000LL);
43330 }
43331
43332 diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
43333 index ed327e6..ca1739e0 100644
43334 --- a/drivers/infiniband/hw/mlx4/mcg.c
43335 +++ b/drivers/infiniband/hw/mlx4/mcg.c
43336 @@ -1041,7 +1041,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
43337 {
43338 char name[20];
43339
43340 - atomic_set(&ctx->tid, 0);
43341 + atomic_set_unchecked(&ctx->tid, 0);
43342 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
43343 ctx->mcg_wq = create_singlethread_workqueue(name);
43344 if (!ctx->mcg_wq)
43345 diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
43346 index 6eb743f..a7b0f6d 100644
43347 --- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
43348 +++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
43349 @@ -426,7 +426,7 @@ struct mlx4_ib_demux_ctx {
43350 struct list_head mcg_mgid0_list;
43351 struct workqueue_struct *mcg_wq;
43352 struct mlx4_ib_demux_pv_ctx **tun;
43353 - atomic_t tid;
43354 + atomic_unchecked_t tid;
43355 int flushing; /* flushing the work queue */
43356 };
43357
43358 diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
43359 index 9d3e5c1..6f166df 100644
43360 --- a/drivers/infiniband/hw/mthca/mthca_cmd.c
43361 +++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
43362 @@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
43363 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
43364 }
43365
43366 -int mthca_QUERY_FW(struct mthca_dev *dev)
43367 +int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
43368 {
43369 struct mthca_mailbox *mailbox;
43370 u32 *outbox;
43371 @@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43372 CMD_TIME_CLASS_B);
43373 }
43374
43375 -int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43376 +int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43377 int num_mtt)
43378 {
43379 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
43380 @@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
43381 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
43382 }
43383
43384 -int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43385 +int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43386 int eq_num)
43387 {
43388 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
43389 @@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
43390 CMD_TIME_CLASS_B);
43391 }
43392
43393 -int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
43394 +int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
43395 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
43396 void *in_mad, void *response_mad)
43397 {
43398 diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
43399 index ded76c1..0cf0a08 100644
43400 --- a/drivers/infiniband/hw/mthca/mthca_main.c
43401 +++ b/drivers/infiniband/hw/mthca/mthca_main.c
43402 @@ -692,7 +692,7 @@ err_close:
43403 return err;
43404 }
43405
43406 -static int mthca_setup_hca(struct mthca_dev *dev)
43407 +static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
43408 {
43409 int err;
43410
43411 diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
43412 index ed9a989..6aa5dc2 100644
43413 --- a/drivers/infiniband/hw/mthca/mthca_mr.c
43414 +++ b/drivers/infiniband/hw/mthca/mthca_mr.c
43415 @@ -81,7 +81,7 @@ struct mthca_mpt_entry {
43416 * through the bitmaps)
43417 */
43418
43419 -static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
43420 +static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
43421 {
43422 int o;
43423 int m;
43424 @@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
43425 return key;
43426 }
43427
43428 -int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
43429 +int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
43430 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
43431 {
43432 struct mthca_mailbox *mailbox;
43433 @@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
43434 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
43435 }
43436
43437 -int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
43438 +int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
43439 u64 *buffer_list, int buffer_size_shift,
43440 int list_len, u64 iova, u64 total_size,
43441 u32 access, struct mthca_mr *mr)
43442 diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
43443 index 415f8e1..e34214e 100644
43444 --- a/drivers/infiniband/hw/mthca/mthca_provider.c
43445 +++ b/drivers/infiniband/hw/mthca/mthca_provider.c
43446 @@ -764,7 +764,7 @@ unlock:
43447 return 0;
43448 }
43449
43450 -static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
43451 +static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
43452 {
43453 struct mthca_dev *dev = to_mdev(ibcq->device);
43454 struct mthca_cq *cq = to_mcq(ibcq);
43455 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
43456 index 3b2a6dc..bce26ff 100644
43457 --- a/drivers/infiniband/hw/nes/nes.c
43458 +++ b/drivers/infiniband/hw/nes/nes.c
43459 @@ -97,7 +97,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
43460 LIST_HEAD(nes_adapter_list);
43461 static LIST_HEAD(nes_dev_list);
43462
43463 -atomic_t qps_destroyed;
43464 +atomic_unchecked_t qps_destroyed;
43465
43466 static unsigned int ee_flsh_adapter;
43467 static unsigned int sysfs_nonidx_addr;
43468 @@ -278,7 +278,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
43469 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
43470 struct nes_adapter *nesadapter = nesdev->nesadapter;
43471
43472 - atomic_inc(&qps_destroyed);
43473 + atomic_inc_unchecked(&qps_destroyed);
43474
43475 /* Free the control structures */
43476
43477 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
43478 index bd9d132..70d84f4 100644
43479 --- a/drivers/infiniband/hw/nes/nes.h
43480 +++ b/drivers/infiniband/hw/nes/nes.h
43481 @@ -180,17 +180,17 @@ extern unsigned int nes_debug_level;
43482 extern unsigned int wqm_quanta;
43483 extern struct list_head nes_adapter_list;
43484
43485 -extern atomic_t cm_connects;
43486 -extern atomic_t cm_accepts;
43487 -extern atomic_t cm_disconnects;
43488 -extern atomic_t cm_closes;
43489 -extern atomic_t cm_connecteds;
43490 -extern atomic_t cm_connect_reqs;
43491 -extern atomic_t cm_rejects;
43492 -extern atomic_t mod_qp_timouts;
43493 -extern atomic_t qps_created;
43494 -extern atomic_t qps_destroyed;
43495 -extern atomic_t sw_qps_destroyed;
43496 +extern atomic_unchecked_t cm_connects;
43497 +extern atomic_unchecked_t cm_accepts;
43498 +extern atomic_unchecked_t cm_disconnects;
43499 +extern atomic_unchecked_t cm_closes;
43500 +extern atomic_unchecked_t cm_connecteds;
43501 +extern atomic_unchecked_t cm_connect_reqs;
43502 +extern atomic_unchecked_t cm_rejects;
43503 +extern atomic_unchecked_t mod_qp_timouts;
43504 +extern atomic_unchecked_t qps_created;
43505 +extern atomic_unchecked_t qps_destroyed;
43506 +extern atomic_unchecked_t sw_qps_destroyed;
43507 extern u32 mh_detected;
43508 extern u32 mh_pauses_sent;
43509 extern u32 cm_packets_sent;
43510 @@ -199,16 +199,16 @@ extern u32 cm_packets_created;
43511 extern u32 cm_packets_received;
43512 extern u32 cm_packets_dropped;
43513 extern u32 cm_packets_retrans;
43514 -extern atomic_t cm_listens_created;
43515 -extern atomic_t cm_listens_destroyed;
43516 +extern atomic_unchecked_t cm_listens_created;
43517 +extern atomic_unchecked_t cm_listens_destroyed;
43518 extern u32 cm_backlog_drops;
43519 -extern atomic_t cm_loopbacks;
43520 -extern atomic_t cm_nodes_created;
43521 -extern atomic_t cm_nodes_destroyed;
43522 -extern atomic_t cm_accel_dropped_pkts;
43523 -extern atomic_t cm_resets_recvd;
43524 -extern atomic_t pau_qps_created;
43525 -extern atomic_t pau_qps_destroyed;
43526 +extern atomic_unchecked_t cm_loopbacks;
43527 +extern atomic_unchecked_t cm_nodes_created;
43528 +extern atomic_unchecked_t cm_nodes_destroyed;
43529 +extern atomic_unchecked_t cm_accel_dropped_pkts;
43530 +extern atomic_unchecked_t cm_resets_recvd;
43531 +extern atomic_unchecked_t pau_qps_created;
43532 +extern atomic_unchecked_t pau_qps_destroyed;
43533
43534 extern u32 int_mod_timer_init;
43535 extern u32 int_mod_cq_depth_256;
43536 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
43537 index 6f09a72..cf4399d 100644
43538 --- a/drivers/infiniband/hw/nes/nes_cm.c
43539 +++ b/drivers/infiniband/hw/nes/nes_cm.c
43540 @@ -69,14 +69,14 @@ u32 cm_packets_dropped;
43541 u32 cm_packets_retrans;
43542 u32 cm_packets_created;
43543 u32 cm_packets_received;
43544 -atomic_t cm_listens_created;
43545 -atomic_t cm_listens_destroyed;
43546 +atomic_unchecked_t cm_listens_created;
43547 +atomic_unchecked_t cm_listens_destroyed;
43548 u32 cm_backlog_drops;
43549 -atomic_t cm_loopbacks;
43550 -atomic_t cm_nodes_created;
43551 -atomic_t cm_nodes_destroyed;
43552 -atomic_t cm_accel_dropped_pkts;
43553 -atomic_t cm_resets_recvd;
43554 +atomic_unchecked_t cm_loopbacks;
43555 +atomic_unchecked_t cm_nodes_created;
43556 +atomic_unchecked_t cm_nodes_destroyed;
43557 +atomic_unchecked_t cm_accel_dropped_pkts;
43558 +atomic_unchecked_t cm_resets_recvd;
43559
43560 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
43561 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
43562 @@ -135,28 +135,28 @@ static void record_ird_ord(struct nes_cm_node *, u16, u16);
43563 /* instance of function pointers for client API */
43564 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
43565 static struct nes_cm_ops nes_cm_api = {
43566 - mini_cm_accelerated,
43567 - mini_cm_listen,
43568 - mini_cm_del_listen,
43569 - mini_cm_connect,
43570 - mini_cm_close,
43571 - mini_cm_accept,
43572 - mini_cm_reject,
43573 - mini_cm_recv_pkt,
43574 - mini_cm_dealloc_core,
43575 - mini_cm_get,
43576 - mini_cm_set
43577 + .accelerated = mini_cm_accelerated,
43578 + .listen = mini_cm_listen,
43579 + .stop_listener = mini_cm_del_listen,
43580 + .connect = mini_cm_connect,
43581 + .close = mini_cm_close,
43582 + .accept = mini_cm_accept,
43583 + .reject = mini_cm_reject,
43584 + .recv_pkt = mini_cm_recv_pkt,
43585 + .destroy_cm_core = mini_cm_dealloc_core,
43586 + .get = mini_cm_get,
43587 + .set = mini_cm_set
43588 };
43589
43590 static struct nes_cm_core *g_cm_core;
43591
43592 -atomic_t cm_connects;
43593 -atomic_t cm_accepts;
43594 -atomic_t cm_disconnects;
43595 -atomic_t cm_closes;
43596 -atomic_t cm_connecteds;
43597 -atomic_t cm_connect_reqs;
43598 -atomic_t cm_rejects;
43599 +atomic_unchecked_t cm_connects;
43600 +atomic_unchecked_t cm_accepts;
43601 +atomic_unchecked_t cm_disconnects;
43602 +atomic_unchecked_t cm_closes;
43603 +atomic_unchecked_t cm_connecteds;
43604 +atomic_unchecked_t cm_connect_reqs;
43605 +atomic_unchecked_t cm_rejects;
43606
43607 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
43608 {
43609 @@ -1436,7 +1436,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
43610 kfree(listener);
43611 listener = NULL;
43612 ret = 0;
43613 - atomic_inc(&cm_listens_destroyed);
43614 + atomic_inc_unchecked(&cm_listens_destroyed);
43615 } else {
43616 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
43617 }
43618 @@ -1637,7 +1637,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
43619 cm_node->rem_mac);
43620
43621 add_hte_node(cm_core, cm_node);
43622 - atomic_inc(&cm_nodes_created);
43623 + atomic_inc_unchecked(&cm_nodes_created);
43624
43625 return cm_node;
43626 }
43627 @@ -1698,7 +1698,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
43628 }
43629
43630 atomic_dec(&cm_core->node_cnt);
43631 - atomic_inc(&cm_nodes_destroyed);
43632 + atomic_inc_unchecked(&cm_nodes_destroyed);
43633 nesqp = cm_node->nesqp;
43634 if (nesqp) {
43635 nesqp->cm_node = NULL;
43636 @@ -1762,7 +1762,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
43637
43638 static void drop_packet(struct sk_buff *skb)
43639 {
43640 - atomic_inc(&cm_accel_dropped_pkts);
43641 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
43642 dev_kfree_skb_any(skb);
43643 }
43644
43645 @@ -1825,7 +1825,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
43646 {
43647
43648 int reset = 0; /* whether to send reset in case of err.. */
43649 - atomic_inc(&cm_resets_recvd);
43650 + atomic_inc_unchecked(&cm_resets_recvd);
43651 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
43652 " refcnt=%d\n", cm_node, cm_node->state,
43653 atomic_read(&cm_node->ref_count));
43654 @@ -2492,7 +2492,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
43655 rem_ref_cm_node(cm_node->cm_core, cm_node);
43656 return NULL;
43657 }
43658 - atomic_inc(&cm_loopbacks);
43659 + atomic_inc_unchecked(&cm_loopbacks);
43660 loopbackremotenode->loopbackpartner = cm_node;
43661 loopbackremotenode->tcp_cntxt.rcv_wscale =
43662 NES_CM_DEFAULT_RCV_WND_SCALE;
43663 @@ -2773,7 +2773,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
43664 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
43665 else {
43666 rem_ref_cm_node(cm_core, cm_node);
43667 - atomic_inc(&cm_accel_dropped_pkts);
43668 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
43669 dev_kfree_skb_any(skb);
43670 }
43671 break;
43672 @@ -3081,7 +3081,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43673
43674 if ((cm_id) && (cm_id->event_handler)) {
43675 if (issue_disconn) {
43676 - atomic_inc(&cm_disconnects);
43677 + atomic_inc_unchecked(&cm_disconnects);
43678 cm_event.event = IW_CM_EVENT_DISCONNECT;
43679 cm_event.status = disconn_status;
43680 cm_event.local_addr = cm_id->local_addr;
43681 @@ -3103,7 +3103,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43682 }
43683
43684 if (issue_close) {
43685 - atomic_inc(&cm_closes);
43686 + atomic_inc_unchecked(&cm_closes);
43687 nes_disconnect(nesqp, 1);
43688
43689 cm_id->provider_data = nesqp;
43690 @@ -3241,7 +3241,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43691
43692 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
43693 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
43694 - atomic_inc(&cm_accepts);
43695 + atomic_inc_unchecked(&cm_accepts);
43696
43697 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
43698 netdev_refcnt_read(nesvnic->netdev));
43699 @@ -3439,7 +3439,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
43700 struct nes_cm_core *cm_core;
43701 u8 *start_buff;
43702
43703 - atomic_inc(&cm_rejects);
43704 + atomic_inc_unchecked(&cm_rejects);
43705 cm_node = (struct nes_cm_node *)cm_id->provider_data;
43706 loopback = cm_node->loopbackpartner;
43707 cm_core = cm_node->cm_core;
43708 @@ -3504,7 +3504,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43709 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
43710 ntohs(laddr->sin_port));
43711
43712 - atomic_inc(&cm_connects);
43713 + atomic_inc_unchecked(&cm_connects);
43714 nesqp->active_conn = 1;
43715
43716 /* cache the cm_id in the qp */
43717 @@ -3649,7 +3649,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
43718 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
43719 return err;
43720 }
43721 - atomic_inc(&cm_listens_created);
43722 + atomic_inc_unchecked(&cm_listens_created);
43723 }
43724
43725 cm_id->add_ref(cm_id);
43726 @@ -3756,7 +3756,7 @@ static void cm_event_connected(struct nes_cm_event *event)
43727
43728 if (nesqp->destroyed)
43729 return;
43730 - atomic_inc(&cm_connecteds);
43731 + atomic_inc_unchecked(&cm_connecteds);
43732 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
43733 " local port 0x%04X. jiffies = %lu.\n",
43734 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
43735 @@ -3941,7 +3941,7 @@ static void cm_event_reset(struct nes_cm_event *event)
43736
43737 cm_id->add_ref(cm_id);
43738 ret = cm_id->event_handler(cm_id, &cm_event);
43739 - atomic_inc(&cm_closes);
43740 + atomic_inc_unchecked(&cm_closes);
43741 cm_event.event = IW_CM_EVENT_CLOSE;
43742 cm_event.status = 0;
43743 cm_event.provider_data = cm_id->provider_data;
43744 @@ -3981,7 +3981,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
43745 return;
43746 cm_id = cm_node->cm_id;
43747
43748 - atomic_inc(&cm_connect_reqs);
43749 + atomic_inc_unchecked(&cm_connect_reqs);
43750 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43751 cm_node, cm_id, jiffies);
43752
43753 @@ -4030,7 +4030,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
43754 return;
43755 cm_id = cm_node->cm_id;
43756
43757 - atomic_inc(&cm_connect_reqs);
43758 + atomic_inc_unchecked(&cm_connect_reqs);
43759 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43760 cm_node, cm_id, jiffies);
43761
43762 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
43763 index 4166452..fc952c3 100644
43764 --- a/drivers/infiniband/hw/nes/nes_mgt.c
43765 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
43766 @@ -40,8 +40,8 @@
43767 #include "nes.h"
43768 #include "nes_mgt.h"
43769
43770 -atomic_t pau_qps_created;
43771 -atomic_t pau_qps_destroyed;
43772 +atomic_unchecked_t pau_qps_created;
43773 +atomic_unchecked_t pau_qps_destroyed;
43774
43775 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
43776 {
43777 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
43778 {
43779 struct sk_buff *skb;
43780 unsigned long flags;
43781 - atomic_inc(&pau_qps_destroyed);
43782 + atomic_inc_unchecked(&pau_qps_destroyed);
43783
43784 /* Free packets that have not yet been forwarded */
43785 /* Lock is acquired by skb_dequeue when removing the skb */
43786 @@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
43787 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
43788 skb_queue_head_init(&nesqp->pau_list);
43789 spin_lock_init(&nesqp->pau_lock);
43790 - atomic_inc(&pau_qps_created);
43791 + atomic_inc_unchecked(&pau_qps_created);
43792 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
43793 }
43794
43795 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
43796 index 49eb511..a774366 100644
43797 --- a/drivers/infiniband/hw/nes/nes_nic.c
43798 +++ b/drivers/infiniband/hw/nes/nes_nic.c
43799 @@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
43800 target_stat_values[++index] = mh_detected;
43801 target_stat_values[++index] = mh_pauses_sent;
43802 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
43803 - target_stat_values[++index] = atomic_read(&cm_connects);
43804 - target_stat_values[++index] = atomic_read(&cm_accepts);
43805 - target_stat_values[++index] = atomic_read(&cm_disconnects);
43806 - target_stat_values[++index] = atomic_read(&cm_connecteds);
43807 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
43808 - target_stat_values[++index] = atomic_read(&cm_rejects);
43809 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
43810 - target_stat_values[++index] = atomic_read(&qps_created);
43811 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
43812 - target_stat_values[++index] = atomic_read(&qps_destroyed);
43813 - target_stat_values[++index] = atomic_read(&cm_closes);
43814 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
43815 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
43816 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
43817 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
43818 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
43819 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
43820 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
43821 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
43822 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
43823 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
43824 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
43825 target_stat_values[++index] = cm_packets_sent;
43826 target_stat_values[++index] = cm_packets_bounced;
43827 target_stat_values[++index] = cm_packets_created;
43828 target_stat_values[++index] = cm_packets_received;
43829 target_stat_values[++index] = cm_packets_dropped;
43830 target_stat_values[++index] = cm_packets_retrans;
43831 - target_stat_values[++index] = atomic_read(&cm_listens_created);
43832 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
43833 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
43834 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
43835 target_stat_values[++index] = cm_backlog_drops;
43836 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
43837 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
43838 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
43839 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
43840 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
43841 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
43842 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
43843 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
43844 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
43845 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
43846 target_stat_values[++index] = nesadapter->free_4kpbl;
43847 target_stat_values[++index] = nesadapter->free_256pbl;
43848 target_stat_values[++index] = int_mod_timer_init;
43849 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
43850 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
43851 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
43852 - target_stat_values[++index] = atomic_read(&pau_qps_created);
43853 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
43854 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
43855 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
43856 }
43857
43858 /**
43859 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
43860 index fef067c..6a25ccd 100644
43861 --- a/drivers/infiniband/hw/nes/nes_verbs.c
43862 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
43863 @@ -46,9 +46,9 @@
43864
43865 #include <rdma/ib_umem.h>
43866
43867 -atomic_t mod_qp_timouts;
43868 -atomic_t qps_created;
43869 -atomic_t sw_qps_destroyed;
43870 +atomic_unchecked_t mod_qp_timouts;
43871 +atomic_unchecked_t qps_created;
43872 +atomic_unchecked_t sw_qps_destroyed;
43873
43874 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
43875
43876 @@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
43877 if (init_attr->create_flags)
43878 return ERR_PTR(-EINVAL);
43879
43880 - atomic_inc(&qps_created);
43881 + atomic_inc_unchecked(&qps_created);
43882 switch (init_attr->qp_type) {
43883 case IB_QPT_RC:
43884 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
43885 @@ -1468,7 +1468,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
43886 struct iw_cm_event cm_event;
43887 int ret = 0;
43888
43889 - atomic_inc(&sw_qps_destroyed);
43890 + atomic_inc_unchecked(&sw_qps_destroyed);
43891 nesqp->destroyed = 1;
43892
43893 /* Blow away the connection if it exists. */
43894 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
43895 index c00ae09..04e91be 100644
43896 --- a/drivers/infiniband/hw/qib/qib.h
43897 +++ b/drivers/infiniband/hw/qib/qib.h
43898 @@ -52,6 +52,7 @@
43899 #include <linux/kref.h>
43900 #include <linux/sched.h>
43901 #include <linux/kthread.h>
43902 +#include <linux/slab.h>
43903
43904 #include "qib_common.h"
43905 #include "qib_verbs.h"
43906 diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
43907 index de05545..b535322 100644
43908 --- a/drivers/input/evdev.c
43909 +++ b/drivers/input/evdev.c
43910 @@ -421,7 +421,7 @@ static int evdev_open(struct inode *inode, struct file *file)
43911
43912 err_free_client:
43913 evdev_detach_client(evdev, client);
43914 - kfree(client);
43915 + kvfree(client);
43916 return error;
43917 }
43918
43919 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
43920 index 24c41ba..102d71f 100644
43921 --- a/drivers/input/gameport/gameport.c
43922 +++ b/drivers/input/gameport/gameport.c
43923 @@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
43924 */
43925 static void gameport_init_port(struct gameport *gameport)
43926 {
43927 - static atomic_t gameport_no = ATOMIC_INIT(0);
43928 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
43929
43930 __module_get(THIS_MODULE);
43931
43932 mutex_init(&gameport->drv_mutex);
43933 device_initialize(&gameport->dev);
43934 dev_set_name(&gameport->dev, "gameport%lu",
43935 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
43936 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
43937 gameport->dev.bus = &gameport_bus;
43938 gameport->dev.release = gameport_release_port;
43939 if (gameport->parent)
43940 diff --git a/drivers/input/input.c b/drivers/input/input.c
43941 index 29ca0bb..f4bc2e3 100644
43942 --- a/drivers/input/input.c
43943 +++ b/drivers/input/input.c
43944 @@ -1774,7 +1774,7 @@ EXPORT_SYMBOL_GPL(input_class);
43945 */
43946 struct input_dev *input_allocate_device(void)
43947 {
43948 - static atomic_t input_no = ATOMIC_INIT(0);
43949 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
43950 struct input_dev *dev;
43951
43952 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
43953 @@ -1789,7 +1789,7 @@ struct input_dev *input_allocate_device(void)
43954 INIT_LIST_HEAD(&dev->node);
43955
43956 dev_set_name(&dev->dev, "input%ld",
43957 - (unsigned long) atomic_inc_return(&input_no) - 1);
43958 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
43959
43960 __module_get(THIS_MODULE);
43961 }
43962 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
43963 index 4a95b22..874c182 100644
43964 --- a/drivers/input/joystick/sidewinder.c
43965 +++ b/drivers/input/joystick/sidewinder.c
43966 @@ -30,6 +30,7 @@
43967 #include <linux/kernel.h>
43968 #include <linux/module.h>
43969 #include <linux/slab.h>
43970 +#include <linux/sched.h>
43971 #include <linux/input.h>
43972 #include <linux/gameport.h>
43973 #include <linux/jiffies.h>
43974 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
43975 index 177602c..ec78499 100644
43976 --- a/drivers/input/joystick/xpad.c
43977 +++ b/drivers/input/joystick/xpad.c
43978 @@ -850,7 +850,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
43979
43980 static int xpad_led_probe(struct usb_xpad *xpad)
43981 {
43982 - static atomic_t led_seq = ATOMIC_INIT(0);
43983 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
43984 long led_no;
43985 struct xpad_led *led;
43986 struct led_classdev *led_cdev;
43987 @@ -863,7 +863,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
43988 if (!led)
43989 return -ENOMEM;
43990
43991 - led_no = (long)atomic_inc_return(&led_seq) - 1;
43992 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
43993
43994 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
43995 led->xpad = xpad;
43996 diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
43997 index 719410f..1896169 100644
43998 --- a/drivers/input/misc/ims-pcu.c
43999 +++ b/drivers/input/misc/ims-pcu.c
44000 @@ -1851,7 +1851,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
44001
44002 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
44003 {
44004 - static atomic_t device_no = ATOMIC_INIT(0);
44005 + static atomic_unchecked_t device_no = ATOMIC_INIT(0);
44006
44007 const struct ims_pcu_device_info *info;
44008 int error;
44009 @@ -1882,7 +1882,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
44010 }
44011
44012 /* Device appears to be operable, complete initialization */
44013 - pcu->device_no = atomic_inc_return(&device_no) - 1;
44014 + pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
44015
44016 /*
44017 * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor
44018 diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
44019 index 2f0b39d..7370f13 100644
44020 --- a/drivers/input/mouse/psmouse.h
44021 +++ b/drivers/input/mouse/psmouse.h
44022 @@ -116,7 +116,7 @@ struct psmouse_attribute {
44023 ssize_t (*set)(struct psmouse *psmouse, void *data,
44024 const char *buf, size_t count);
44025 bool protect;
44026 -};
44027 +} __do_const;
44028 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
44029
44030 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
44031 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
44032 index b604564..3f14ae4 100644
44033 --- a/drivers/input/mousedev.c
44034 +++ b/drivers/input/mousedev.c
44035 @@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
44036
44037 spin_unlock_irq(&client->packet_lock);
44038
44039 - if (copy_to_user(buffer, data, count))
44040 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
44041 return -EFAULT;
44042
44043 return count;
44044 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
44045 index b29134d..394deb0 100644
44046 --- a/drivers/input/serio/serio.c
44047 +++ b/drivers/input/serio/serio.c
44048 @@ -514,7 +514,7 @@ static void serio_release_port(struct device *dev)
44049 */
44050 static void serio_init_port(struct serio *serio)
44051 {
44052 - static atomic_t serio_no = ATOMIC_INIT(0);
44053 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
44054
44055 __module_get(THIS_MODULE);
44056
44057 @@ -525,7 +525,7 @@ static void serio_init_port(struct serio *serio)
44058 mutex_init(&serio->drv_mutex);
44059 device_initialize(&serio->dev);
44060 dev_set_name(&serio->dev, "serio%ld",
44061 - (long)atomic_inc_return(&serio_no) - 1);
44062 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
44063 serio->dev.bus = &serio_bus;
44064 serio->dev.release = serio_release_port;
44065 serio->dev.groups = serio_device_attr_groups;
44066 diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
44067 index c9a02fe..0debc75 100644
44068 --- a/drivers/input/serio/serio_raw.c
44069 +++ b/drivers/input/serio/serio_raw.c
44070 @@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
44071
44072 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
44073 {
44074 - static atomic_t serio_raw_no = ATOMIC_INIT(0);
44075 + static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
44076 struct serio_raw *serio_raw;
44077 int err;
44078
44079 @@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
44080 }
44081
44082 snprintf(serio_raw->name, sizeof(serio_raw->name),
44083 - "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
44084 + "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
44085 kref_init(&serio_raw->kref);
44086 INIT_LIST_HEAD(&serio_raw->client_list);
44087 init_waitqueue_head(&serio_raw->wait);
44088 diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
44089 index a83cc2a..64462e6 100644
44090 --- a/drivers/iommu/arm-smmu.c
44091 +++ b/drivers/iommu/arm-smmu.c
44092 @@ -921,7 +921,7 @@ static int arm_smmu_init_domain_context(struct iommu_domain *domain,
44093 cfg->irptndx = cfg->cbndx;
44094 }
44095
44096 - ACCESS_ONCE(smmu_domain->smmu) = smmu;
44097 + ACCESS_ONCE_RW(smmu_domain->smmu) = smmu;
44098 arm_smmu_init_context_bank(smmu_domain);
44099 spin_unlock_irqrestore(&smmu_domain->lock, flags);
44100
44101 diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
44102 index 33c4395..e06447e 100644
44103 --- a/drivers/iommu/irq_remapping.c
44104 +++ b/drivers/iommu/irq_remapping.c
44105 @@ -354,7 +354,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
44106 void panic_if_irq_remap(const char *msg)
44107 {
44108 if (irq_remapping_enabled)
44109 - panic(msg);
44110 + panic("%s", msg);
44111 }
44112
44113 static void ir_ack_apic_edge(struct irq_data *data)
44114 @@ -375,10 +375,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
44115
44116 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
44117 {
44118 - chip->irq_print_chip = ir_print_prefix;
44119 - chip->irq_ack = ir_ack_apic_edge;
44120 - chip->irq_eoi = ir_ack_apic_level;
44121 - chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
44122 + pax_open_kernel();
44123 + *(void **)&chip->irq_print_chip = ir_print_prefix;
44124 + *(void **)&chip->irq_ack = ir_ack_apic_edge;
44125 + *(void **)&chip->irq_eoi = ir_ack_apic_level;
44126 + *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
44127 + pax_close_kernel();
44128 }
44129
44130 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
44131 diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
44132 index dda6dbc..f9adebb 100644
44133 --- a/drivers/irqchip/irq-gic.c
44134 +++ b/drivers/irqchip/irq-gic.c
44135 @@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
44136 * Supported arch specific GIC irq extension.
44137 * Default make them NULL.
44138 */
44139 -struct irq_chip gic_arch_extn = {
44140 +irq_chip_no_const gic_arch_extn = {
44141 .irq_eoi = NULL,
44142 .irq_mask = NULL,
44143 .irq_unmask = NULL,
44144 @@ -312,7 +312,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
44145 chained_irq_exit(chip, desc);
44146 }
44147
44148 -static struct irq_chip gic_chip = {
44149 +static irq_chip_no_const gic_chip __read_only = {
44150 .name = "GIC",
44151 .irq_mask = gic_mask_irq,
44152 .irq_unmask = gic_unmask_irq,
44153 diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
44154 index 8777065..a4a9967 100644
44155 --- a/drivers/irqchip/irq-renesas-irqc.c
44156 +++ b/drivers/irqchip/irq-renesas-irqc.c
44157 @@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
44158 struct irqc_priv *p;
44159 struct resource *io;
44160 struct resource *irq;
44161 - struct irq_chip *irq_chip;
44162 + irq_chip_no_const *irq_chip;
44163 const char *name = dev_name(&pdev->dev);
44164 int ret;
44165 int k;
44166 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
44167 index 6a2df32..dc962f1 100644
44168 --- a/drivers/isdn/capi/capi.c
44169 +++ b/drivers/isdn/capi/capi.c
44170 @@ -81,8 +81,8 @@ struct capiminor {
44171
44172 struct capi20_appl *ap;
44173 u32 ncci;
44174 - atomic_t datahandle;
44175 - atomic_t msgid;
44176 + atomic_unchecked_t datahandle;
44177 + atomic_unchecked_t msgid;
44178
44179 struct tty_port port;
44180 int ttyinstop;
44181 @@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
44182 capimsg_setu16(s, 2, mp->ap->applid);
44183 capimsg_setu8 (s, 4, CAPI_DATA_B3);
44184 capimsg_setu8 (s, 5, CAPI_RESP);
44185 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
44186 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
44187 capimsg_setu32(s, 8, mp->ncci);
44188 capimsg_setu16(s, 12, datahandle);
44189 }
44190 @@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
44191 mp->outbytes -= len;
44192 spin_unlock_bh(&mp->outlock);
44193
44194 - datahandle = atomic_inc_return(&mp->datahandle);
44195 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
44196 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
44197 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
44198 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
44199 capimsg_setu16(skb->data, 2, mp->ap->applid);
44200 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
44201 capimsg_setu8 (skb->data, 5, CAPI_REQ);
44202 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
44203 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
44204 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
44205 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
44206 capimsg_setu16(skb->data, 16, len); /* Data length */
44207 diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
44208 index b7ae0a0..04590fa 100644
44209 --- a/drivers/isdn/gigaset/bas-gigaset.c
44210 +++ b/drivers/isdn/gigaset/bas-gigaset.c
44211 @@ -2565,22 +2565,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
44212
44213
44214 static const struct gigaset_ops gigops = {
44215 - gigaset_write_cmd,
44216 - gigaset_write_room,
44217 - gigaset_chars_in_buffer,
44218 - gigaset_brkchars,
44219 - gigaset_init_bchannel,
44220 - gigaset_close_bchannel,
44221 - gigaset_initbcshw,
44222 - gigaset_freebcshw,
44223 - gigaset_reinitbcshw,
44224 - gigaset_initcshw,
44225 - gigaset_freecshw,
44226 - gigaset_set_modem_ctrl,
44227 - gigaset_baud_rate,
44228 - gigaset_set_line_ctrl,
44229 - gigaset_isoc_send_skb,
44230 - gigaset_isoc_input,
44231 + .write_cmd = gigaset_write_cmd,
44232 + .write_room = gigaset_write_room,
44233 + .chars_in_buffer = gigaset_chars_in_buffer,
44234 + .brkchars = gigaset_brkchars,
44235 + .init_bchannel = gigaset_init_bchannel,
44236 + .close_bchannel = gigaset_close_bchannel,
44237 + .initbcshw = gigaset_initbcshw,
44238 + .freebcshw = gigaset_freebcshw,
44239 + .reinitbcshw = gigaset_reinitbcshw,
44240 + .initcshw = gigaset_initcshw,
44241 + .freecshw = gigaset_freecshw,
44242 + .set_modem_ctrl = gigaset_set_modem_ctrl,
44243 + .baud_rate = gigaset_baud_rate,
44244 + .set_line_ctrl = gigaset_set_line_ctrl,
44245 + .send_skb = gigaset_isoc_send_skb,
44246 + .handle_input = gigaset_isoc_input,
44247 };
44248
44249 /* bas_gigaset_init
44250 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
44251 index 600c79b..3752bab 100644
44252 --- a/drivers/isdn/gigaset/interface.c
44253 +++ b/drivers/isdn/gigaset/interface.c
44254 @@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
44255 }
44256 tty->driver_data = cs;
44257
44258 - ++cs->port.count;
44259 + atomic_inc(&cs->port.count);
44260
44261 - if (cs->port.count == 1) {
44262 + if (atomic_read(&cs->port.count) == 1) {
44263 tty_port_tty_set(&cs->port, tty);
44264 cs->port.low_latency = 1;
44265 }
44266 @@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
44267
44268 if (!cs->connected)
44269 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
44270 - else if (!cs->port.count)
44271 + else if (!atomic_read(&cs->port.count))
44272 dev_warn(cs->dev, "%s: device not opened\n", __func__);
44273 - else if (!--cs->port.count)
44274 + else if (!atomic_dec_return(&cs->port.count))
44275 tty_port_tty_set(&cs->port, NULL);
44276
44277 mutex_unlock(&cs->mutex);
44278 diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
44279 index 8c91fd5..14f13ce 100644
44280 --- a/drivers/isdn/gigaset/ser-gigaset.c
44281 +++ b/drivers/isdn/gigaset/ser-gigaset.c
44282 @@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
44283 }
44284
44285 static const struct gigaset_ops ops = {
44286 - gigaset_write_cmd,
44287 - gigaset_write_room,
44288 - gigaset_chars_in_buffer,
44289 - gigaset_brkchars,
44290 - gigaset_init_bchannel,
44291 - gigaset_close_bchannel,
44292 - gigaset_initbcshw,
44293 - gigaset_freebcshw,
44294 - gigaset_reinitbcshw,
44295 - gigaset_initcshw,
44296 - gigaset_freecshw,
44297 - gigaset_set_modem_ctrl,
44298 - gigaset_baud_rate,
44299 - gigaset_set_line_ctrl,
44300 - gigaset_m10x_send_skb, /* asyncdata.c */
44301 - gigaset_m10x_input, /* asyncdata.c */
44302 + .write_cmd = gigaset_write_cmd,
44303 + .write_room = gigaset_write_room,
44304 + .chars_in_buffer = gigaset_chars_in_buffer,
44305 + .brkchars = gigaset_brkchars,
44306 + .init_bchannel = gigaset_init_bchannel,
44307 + .close_bchannel = gigaset_close_bchannel,
44308 + .initbcshw = gigaset_initbcshw,
44309 + .freebcshw = gigaset_freebcshw,
44310 + .reinitbcshw = gigaset_reinitbcshw,
44311 + .initcshw = gigaset_initcshw,
44312 + .freecshw = gigaset_freecshw,
44313 + .set_modem_ctrl = gigaset_set_modem_ctrl,
44314 + .baud_rate = gigaset_baud_rate,
44315 + .set_line_ctrl = gigaset_set_line_ctrl,
44316 + .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
44317 + .handle_input = gigaset_m10x_input, /* asyncdata.c */
44318 };
44319
44320
44321 diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
44322 index d0a41cb..b953e50 100644
44323 --- a/drivers/isdn/gigaset/usb-gigaset.c
44324 +++ b/drivers/isdn/gigaset/usb-gigaset.c
44325 @@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
44326 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
44327 memcpy(cs->hw.usb->bchars, buf, 6);
44328 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
44329 - 0, 0, &buf, 6, 2000);
44330 + 0, 0, buf, 6, 2000);
44331 }
44332
44333 static void gigaset_freebcshw(struct bc_state *bcs)
44334 @@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
44335 }
44336
44337 static const struct gigaset_ops ops = {
44338 - gigaset_write_cmd,
44339 - gigaset_write_room,
44340 - gigaset_chars_in_buffer,
44341 - gigaset_brkchars,
44342 - gigaset_init_bchannel,
44343 - gigaset_close_bchannel,
44344 - gigaset_initbcshw,
44345 - gigaset_freebcshw,
44346 - gigaset_reinitbcshw,
44347 - gigaset_initcshw,
44348 - gigaset_freecshw,
44349 - gigaset_set_modem_ctrl,
44350 - gigaset_baud_rate,
44351 - gigaset_set_line_ctrl,
44352 - gigaset_m10x_send_skb,
44353 - gigaset_m10x_input,
44354 + .write_cmd = gigaset_write_cmd,
44355 + .write_room = gigaset_write_room,
44356 + .chars_in_buffer = gigaset_chars_in_buffer,
44357 + .brkchars = gigaset_brkchars,
44358 + .init_bchannel = gigaset_init_bchannel,
44359 + .close_bchannel = gigaset_close_bchannel,
44360 + .initbcshw = gigaset_initbcshw,
44361 + .freebcshw = gigaset_freebcshw,
44362 + .reinitbcshw = gigaset_reinitbcshw,
44363 + .initcshw = gigaset_initcshw,
44364 + .freecshw = gigaset_freecshw,
44365 + .set_modem_ctrl = gigaset_set_modem_ctrl,
44366 + .baud_rate = gigaset_baud_rate,
44367 + .set_line_ctrl = gigaset_set_line_ctrl,
44368 + .send_skb = gigaset_m10x_send_skb,
44369 + .handle_input = gigaset_m10x_input,
44370 };
44371
44372 /*
44373 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
44374 index 4d9b195..455075c 100644
44375 --- a/drivers/isdn/hardware/avm/b1.c
44376 +++ b/drivers/isdn/hardware/avm/b1.c
44377 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
44378 }
44379 if (left) {
44380 if (t4file->user) {
44381 - if (copy_from_user(buf, dp, left))
44382 + if (left > sizeof buf || copy_from_user(buf, dp, left))
44383 return -EFAULT;
44384 } else {
44385 memcpy(buf, dp, left);
44386 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
44387 }
44388 if (left) {
44389 if (config->user) {
44390 - if (copy_from_user(buf, dp, left))
44391 + if (left > sizeof buf || copy_from_user(buf, dp, left))
44392 return -EFAULT;
44393 } else {
44394 memcpy(buf, dp, left);
44395 diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
44396 index 9b856e1..fa03c92 100644
44397 --- a/drivers/isdn/i4l/isdn_common.c
44398 +++ b/drivers/isdn/i4l/isdn_common.c
44399 @@ -1654,6 +1654,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
44400 } else
44401 return -EINVAL;
44402 case IIOCDBGVAR:
44403 + if (!capable(CAP_SYS_RAWIO))
44404 + return -EPERM;
44405 if (arg) {
44406 if (copy_to_user(argp, &dev, sizeof(ulong)))
44407 return -EFAULT;
44408 diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
44409 index 91d5730..336523e 100644
44410 --- a/drivers/isdn/i4l/isdn_concap.c
44411 +++ b/drivers/isdn/i4l/isdn_concap.c
44412 @@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
44413 }
44414
44415 struct concap_device_ops isdn_concap_reliable_dl_dops = {
44416 - &isdn_concap_dl_data_req,
44417 - &isdn_concap_dl_connect_req,
44418 - &isdn_concap_dl_disconn_req
44419 + .data_req = &isdn_concap_dl_data_req,
44420 + .connect_req = &isdn_concap_dl_connect_req,
44421 + .disconn_req = &isdn_concap_dl_disconn_req
44422 };
44423
44424 /* The following should better go into a dedicated source file such that
44425 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
44426 index 3c5f249..5fac4d0 100644
44427 --- a/drivers/isdn/i4l/isdn_tty.c
44428 +++ b/drivers/isdn/i4l/isdn_tty.c
44429 @@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
44430
44431 #ifdef ISDN_DEBUG_MODEM_OPEN
44432 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
44433 - port->count);
44434 + atomic_read(&port->count));
44435 #endif
44436 - port->count++;
44437 + atomic_inc(&port->count);
44438 port->tty = tty;
44439 /*
44440 * Start up serial port
44441 @@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
44442 #endif
44443 return;
44444 }
44445 - if ((tty->count == 1) && (port->count != 1)) {
44446 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
44447 /*
44448 * Uh, oh. tty->count is 1, which means that the tty
44449 * structure will be freed. Info->count should always
44450 @@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
44451 * serial port won't be shutdown.
44452 */
44453 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
44454 - "info->count is %d\n", port->count);
44455 - port->count = 1;
44456 + "info->count is %d\n", atomic_read(&port->count));
44457 + atomic_set(&port->count, 1);
44458 }
44459 - if (--port->count < 0) {
44460 + if (atomic_dec_return(&port->count) < 0) {
44461 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
44462 - info->line, port->count);
44463 - port->count = 0;
44464 + info->line, atomic_read(&port->count));
44465 + atomic_set(&port->count, 0);
44466 }
44467 - if (port->count) {
44468 + if (atomic_read(&port->count)) {
44469 #ifdef ISDN_DEBUG_MODEM_OPEN
44470 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
44471 #endif
44472 @@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
44473 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
44474 return;
44475 isdn_tty_shutdown(info);
44476 - port->count = 0;
44477 + atomic_set(&port->count, 0);
44478 port->flags &= ~ASYNC_NORMAL_ACTIVE;
44479 port->tty = NULL;
44480 wake_up_interruptible(&port->open_wait);
44481 @@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
44482 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
44483 modem_info *info = &dev->mdm.info[i];
44484
44485 - if (info->port.count == 0)
44486 + if (atomic_read(&info->port.count) == 0)
44487 continue;
44488 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
44489 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
44490 diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
44491 index e2d4e58..40cd045 100644
44492 --- a/drivers/isdn/i4l/isdn_x25iface.c
44493 +++ b/drivers/isdn/i4l/isdn_x25iface.c
44494 @@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
44495
44496
44497 static struct concap_proto_ops ix25_pops = {
44498 - &isdn_x25iface_proto_new,
44499 - &isdn_x25iface_proto_del,
44500 - &isdn_x25iface_proto_restart,
44501 - &isdn_x25iface_proto_close,
44502 - &isdn_x25iface_xmit,
44503 - &isdn_x25iface_receive,
44504 - &isdn_x25iface_connect_ind,
44505 - &isdn_x25iface_disconn_ind
44506 + .proto_new = &isdn_x25iface_proto_new,
44507 + .proto_del = &isdn_x25iface_proto_del,
44508 + .restart = &isdn_x25iface_proto_restart,
44509 + .close = &isdn_x25iface_proto_close,
44510 + .encap_and_xmit = &isdn_x25iface_xmit,
44511 + .data_ind = &isdn_x25iface_receive,
44512 + .connect_ind = &isdn_x25iface_connect_ind,
44513 + .disconn_ind = &isdn_x25iface_disconn_ind
44514 };
44515
44516 /* error message helper function */
44517 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
44518 index 6a7447c..cae33fe 100644
44519 --- a/drivers/isdn/icn/icn.c
44520 +++ b/drivers/isdn/icn/icn.c
44521 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
44522 if (count > len)
44523 count = len;
44524 if (user) {
44525 - if (copy_from_user(msg, buf, count))
44526 + if (count > sizeof msg || copy_from_user(msg, buf, count))
44527 return -EFAULT;
44528 } else
44529 memcpy(msg, buf, count);
44530 diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
44531 index a4f05c5..1433bc5 100644
44532 --- a/drivers/isdn/mISDN/dsp_cmx.c
44533 +++ b/drivers/isdn/mISDN/dsp_cmx.c
44534 @@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
44535 static u16 dsp_count; /* last sample count */
44536 static int dsp_count_valid; /* if we have last sample count */
44537
44538 -void
44539 +void __intentional_overflow(-1)
44540 dsp_cmx_send(void *arg)
44541 {
44542 struct dsp_conf *conf;
44543 diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
44544 index f58a354..fbae176 100644
44545 --- a/drivers/leds/leds-clevo-mail.c
44546 +++ b/drivers/leds/leds-clevo-mail.c
44547 @@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
44548 * detected as working, but in reality it is not) as low as
44549 * possible.
44550 */
44551 -static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
44552 +static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
44553 {
44554 .callback = clevo_mail_led_dmi_callback,
44555 .ident = "Clevo D410J",
44556 diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
44557 index 046cb70..6b20d39 100644
44558 --- a/drivers/leds/leds-ss4200.c
44559 +++ b/drivers/leds/leds-ss4200.c
44560 @@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
44561 * detected as working, but in reality it is not) as low as
44562 * possible.
44563 */
44564 -static struct dmi_system_id nas_led_whitelist[] __initdata = {
44565 +static struct dmi_system_id nas_led_whitelist[] __initconst = {
44566 {
44567 .callback = ss4200_led_dmi_callback,
44568 .ident = "Intel SS4200-E",
44569 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
44570 index 6590558..a74c5dd 100644
44571 --- a/drivers/lguest/core.c
44572 +++ b/drivers/lguest/core.c
44573 @@ -96,9 +96,17 @@ static __init int map_switcher(void)
44574 * The end address needs +1 because __get_vm_area allocates an
44575 * extra guard page, so we need space for that.
44576 */
44577 +
44578 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
44579 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
44580 + VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
44581 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
44582 +#else
44583 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
44584 VM_ALLOC, switcher_addr, switcher_addr
44585 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
44586 +#endif
44587 +
44588 if (!switcher_vma) {
44589 err = -ENOMEM;
44590 printk("lguest: could not map switcher pages high\n");
44591 @@ -121,7 +129,7 @@ static __init int map_switcher(void)
44592 * Now the Switcher is mapped at the right address, we can't fail!
44593 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
44594 */
44595 - memcpy(switcher_vma->addr, start_switcher_text,
44596 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
44597 end_switcher_text - start_switcher_text);
44598
44599 printk(KERN_INFO "lguest: mapped switcher at %p\n",
44600 diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
44601 index e8b55c3..3514c37 100644
44602 --- a/drivers/lguest/page_tables.c
44603 +++ b/drivers/lguest/page_tables.c
44604 @@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
44605 /*:*/
44606
44607 #ifdef CONFIG_X86_PAE
44608 -static void release_pmd(pmd_t *spmd)
44609 +static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
44610 {
44611 /* If the entry's not present, there's nothing to release. */
44612 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
44613 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
44614 index 922a1ac..9dd0c2a 100644
44615 --- a/drivers/lguest/x86/core.c
44616 +++ b/drivers/lguest/x86/core.c
44617 @@ -59,7 +59,7 @@ static struct {
44618 /* Offset from where switcher.S was compiled to where we've copied it */
44619 static unsigned long switcher_offset(void)
44620 {
44621 - return switcher_addr - (unsigned long)start_switcher_text;
44622 + return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
44623 }
44624
44625 /* This cpu's struct lguest_pages (after the Switcher text page) */
44626 @@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
44627 * These copies are pretty cheap, so we do them unconditionally: */
44628 /* Save the current Host top-level page directory.
44629 */
44630 +
44631 +#ifdef CONFIG_PAX_PER_CPU_PGD
44632 + pages->state.host_cr3 = read_cr3();
44633 +#else
44634 pages->state.host_cr3 = __pa(current->mm->pgd);
44635 +#endif
44636 +
44637 /*
44638 * Set up the Guest's page tables to see this CPU's pages (and no
44639 * other CPU's pages).
44640 @@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
44641 * compiled-in switcher code and the high-mapped copy we just made.
44642 */
44643 for (i = 0; i < IDT_ENTRIES; i++)
44644 - default_idt_entries[i] += switcher_offset();
44645 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
44646
44647 /*
44648 * Set up the Switcher's per-cpu areas.
44649 @@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
44650 * it will be undisturbed when we switch. To change %cs and jump we
44651 * need this structure to feed to Intel's "lcall" instruction.
44652 */
44653 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
44654 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
44655 lguest_entry.segment = LGUEST_CS;
44656
44657 /*
44658 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
44659 index 40634b0..4f5855e 100644
44660 --- a/drivers/lguest/x86/switcher_32.S
44661 +++ b/drivers/lguest/x86/switcher_32.S
44662 @@ -87,6 +87,7 @@
44663 #include <asm/page.h>
44664 #include <asm/segment.h>
44665 #include <asm/lguest.h>
44666 +#include <asm/processor-flags.h>
44667
44668 // We mark the start of the code to copy
44669 // It's placed in .text tho it's never run here
44670 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
44671 // Changes type when we load it: damn Intel!
44672 // For after we switch over our page tables
44673 // That entry will be read-only: we'd crash.
44674 +
44675 +#ifdef CONFIG_PAX_KERNEXEC
44676 + mov %cr0, %edx
44677 + xor $X86_CR0_WP, %edx
44678 + mov %edx, %cr0
44679 +#endif
44680 +
44681 movl $(GDT_ENTRY_TSS*8), %edx
44682 ltr %dx
44683
44684 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
44685 // Let's clear it again for our return.
44686 // The GDT descriptor of the Host
44687 // Points to the table after two "size" bytes
44688 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
44689 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
44690 // Clear "used" from type field (byte 5, bit 2)
44691 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
44692 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
44693 +
44694 +#ifdef CONFIG_PAX_KERNEXEC
44695 + mov %cr0, %eax
44696 + xor $X86_CR0_WP, %eax
44697 + mov %eax, %cr0
44698 +#endif
44699
44700 // Once our page table's switched, the Guest is live!
44701 // The Host fades as we run this final step.
44702 @@ -295,13 +309,12 @@ deliver_to_host:
44703 // I consulted gcc, and it gave
44704 // These instructions, which I gladly credit:
44705 leal (%edx,%ebx,8), %eax
44706 - movzwl (%eax),%edx
44707 - movl 4(%eax), %eax
44708 - xorw %ax, %ax
44709 - orl %eax, %edx
44710 + movl 4(%eax), %edx
44711 + movw (%eax), %dx
44712 // Now the address of the handler's in %edx
44713 // We call it now: its "iret" drops us home.
44714 - jmp *%edx
44715 + ljmp $__KERNEL_CS, $1f
44716 +1: jmp *%edx
44717
44718 // Every interrupt can come to us here
44719 // But we must truly tell each apart.
44720 diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
44721 index a08e3ee..df8ade2 100644
44722 --- a/drivers/md/bcache/closure.h
44723 +++ b/drivers/md/bcache/closure.h
44724 @@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
44725 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
44726 struct workqueue_struct *wq)
44727 {
44728 - BUG_ON(object_is_on_stack(cl));
44729 + BUG_ON(object_starts_on_stack(cl));
44730 closure_set_ip(cl);
44731 cl->fn = fn;
44732 cl->wq = wq;
44733 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
44734 index 67f8b31..9418f2b 100644
44735 --- a/drivers/md/bitmap.c
44736 +++ b/drivers/md/bitmap.c
44737 @@ -1775,7 +1775,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
44738 chunk_kb ? "KB" : "B");
44739 if (bitmap->storage.file) {
44740 seq_printf(seq, ", file: ");
44741 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
44742 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
44743 }
44744
44745 seq_printf(seq, "\n");
44746 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
44747 index 5152142..623d141 100644
44748 --- a/drivers/md/dm-ioctl.c
44749 +++ b/drivers/md/dm-ioctl.c
44750 @@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
44751 cmd == DM_LIST_VERSIONS_CMD)
44752 return 0;
44753
44754 - if ((cmd == DM_DEV_CREATE_CMD)) {
44755 + if (cmd == DM_DEV_CREATE_CMD) {
44756 if (!*param->name) {
44757 DMWARN("name not supplied when creating device");
44758 return -EINVAL;
44759 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
44760 index 7dfdb5c..4caada6 100644
44761 --- a/drivers/md/dm-raid1.c
44762 +++ b/drivers/md/dm-raid1.c
44763 @@ -40,7 +40,7 @@ enum dm_raid1_error {
44764
44765 struct mirror {
44766 struct mirror_set *ms;
44767 - atomic_t error_count;
44768 + atomic_unchecked_t error_count;
44769 unsigned long error_type;
44770 struct dm_dev *dev;
44771 sector_t offset;
44772 @@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
44773 struct mirror *m;
44774
44775 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
44776 - if (!atomic_read(&m->error_count))
44777 + if (!atomic_read_unchecked(&m->error_count))
44778 return m;
44779
44780 return NULL;
44781 @@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
44782 * simple way to tell if a device has encountered
44783 * errors.
44784 */
44785 - atomic_inc(&m->error_count);
44786 + atomic_inc_unchecked(&m->error_count);
44787
44788 if (test_and_set_bit(error_type, &m->error_type))
44789 return;
44790 @@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
44791 struct mirror *m = get_default_mirror(ms);
44792
44793 do {
44794 - if (likely(!atomic_read(&m->error_count)))
44795 + if (likely(!atomic_read_unchecked(&m->error_count)))
44796 return m;
44797
44798 if (m-- == ms->mirror)
44799 @@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
44800 {
44801 struct mirror *default_mirror = get_default_mirror(m->ms);
44802
44803 - return !atomic_read(&default_mirror->error_count);
44804 + return !atomic_read_unchecked(&default_mirror->error_count);
44805 }
44806
44807 static int mirror_available(struct mirror_set *ms, struct bio *bio)
44808 @@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
44809 */
44810 if (likely(region_in_sync(ms, region, 1)))
44811 m = choose_mirror(ms, bio->bi_iter.bi_sector);
44812 - else if (m && atomic_read(&m->error_count))
44813 + else if (m && atomic_read_unchecked(&m->error_count))
44814 m = NULL;
44815
44816 if (likely(m))
44817 @@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
44818 }
44819
44820 ms->mirror[mirror].ms = ms;
44821 - atomic_set(&(ms->mirror[mirror].error_count), 0);
44822 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
44823 ms->mirror[mirror].error_type = 0;
44824 ms->mirror[mirror].offset = offset;
44825
44826 @@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
44827 */
44828 static char device_status_char(struct mirror *m)
44829 {
44830 - if (!atomic_read(&(m->error_count)))
44831 + if (!atomic_read_unchecked(&(m->error_count)))
44832 return 'A';
44833
44834 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
44835 diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
44836 index 28a9012..9c0f6a5 100644
44837 --- a/drivers/md/dm-stats.c
44838 +++ b/drivers/md/dm-stats.c
44839 @@ -382,7 +382,7 @@ do_sync_free:
44840 synchronize_rcu_expedited();
44841 dm_stat_free(&s->rcu_head);
44842 } else {
44843 - ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
44844 + ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
44845 call_rcu(&s->rcu_head, dm_stat_free);
44846 }
44847 return 0;
44848 @@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
44849 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
44850 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
44851 ));
44852 - ACCESS_ONCE(last->last_sector) = end_sector;
44853 - ACCESS_ONCE(last->last_rw) = bi_rw;
44854 + ACCESS_ONCE_RW(last->last_sector) = end_sector;
44855 + ACCESS_ONCE_RW(last->last_rw) = bi_rw;
44856 }
44857
44858 rcu_read_lock();
44859 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
44860 index d1600d2..4c3af3a 100644
44861 --- a/drivers/md/dm-stripe.c
44862 +++ b/drivers/md/dm-stripe.c
44863 @@ -21,7 +21,7 @@ struct stripe {
44864 struct dm_dev *dev;
44865 sector_t physical_start;
44866
44867 - atomic_t error_count;
44868 + atomic_unchecked_t error_count;
44869 };
44870
44871 struct stripe_c {
44872 @@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
44873 kfree(sc);
44874 return r;
44875 }
44876 - atomic_set(&(sc->stripe[i].error_count), 0);
44877 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
44878 }
44879
44880 ti->private = sc;
44881 @@ -330,7 +330,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
44882 DMEMIT("%d ", sc->stripes);
44883 for (i = 0; i < sc->stripes; i++) {
44884 DMEMIT("%s ", sc->stripe[i].dev->name);
44885 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
44886 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
44887 'D' : 'A';
44888 }
44889 buffer[i] = '\0';
44890 @@ -375,8 +375,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
44891 */
44892 for (i = 0; i < sc->stripes; i++)
44893 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
44894 - atomic_inc(&(sc->stripe[i].error_count));
44895 - if (atomic_read(&(sc->stripe[i].error_count)) <
44896 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
44897 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
44898 DM_IO_ERROR_THRESHOLD)
44899 schedule_work(&sc->trigger_event);
44900 }
44901 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
44902 index f9c6cb8..e272df6 100644
44903 --- a/drivers/md/dm-table.c
44904 +++ b/drivers/md/dm-table.c
44905 @@ -274,7 +274,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
44906 static int open_dev(struct dm_dev_internal *d, dev_t dev,
44907 struct mapped_device *md)
44908 {
44909 - static char *_claim_ptr = "I belong to device-mapper";
44910 + static char _claim_ptr[] = "I belong to device-mapper";
44911 struct block_device *bdev;
44912
44913 int r;
44914 @@ -342,7 +342,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
44915 if (!dev_size)
44916 return 0;
44917
44918 - if ((start >= dev_size) || (start + len > dev_size)) {
44919 + if ((start >= dev_size) || (len > dev_size - start)) {
44920 DMWARN("%s: %s too small for target: "
44921 "start=%llu, len=%llu, dev_size=%llu",
44922 dm_device_name(ti->table->md), bdevname(bdev, b),
44923 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
44924 index e9d33ad..dae9880d 100644
44925 --- a/drivers/md/dm-thin-metadata.c
44926 +++ b/drivers/md/dm-thin-metadata.c
44927 @@ -404,7 +404,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44928 {
44929 pmd->info.tm = pmd->tm;
44930 pmd->info.levels = 2;
44931 - pmd->info.value_type.context = pmd->data_sm;
44932 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44933 pmd->info.value_type.size = sizeof(__le64);
44934 pmd->info.value_type.inc = data_block_inc;
44935 pmd->info.value_type.dec = data_block_dec;
44936 @@ -423,7 +423,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44937
44938 pmd->bl_info.tm = pmd->tm;
44939 pmd->bl_info.levels = 1;
44940 - pmd->bl_info.value_type.context = pmd->data_sm;
44941 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44942 pmd->bl_info.value_type.size = sizeof(__le64);
44943 pmd->bl_info.value_type.inc = data_block_inc;
44944 pmd->bl_info.value_type.dec = data_block_dec;
44945 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
44946 index 32b958d..34011e8 100644
44947 --- a/drivers/md/dm.c
44948 +++ b/drivers/md/dm.c
44949 @@ -180,9 +180,9 @@ struct mapped_device {
44950 /*
44951 * Event handling.
44952 */
44953 - atomic_t event_nr;
44954 + atomic_unchecked_t event_nr;
44955 wait_queue_head_t eventq;
44956 - atomic_t uevent_seq;
44957 + atomic_unchecked_t uevent_seq;
44958 struct list_head uevent_list;
44959 spinlock_t uevent_lock; /* Protect access to uevent_list */
44960
44961 @@ -1952,8 +1952,8 @@ static struct mapped_device *alloc_dev(int minor)
44962 spin_lock_init(&md->deferred_lock);
44963 atomic_set(&md->holders, 1);
44964 atomic_set(&md->open_count, 0);
44965 - atomic_set(&md->event_nr, 0);
44966 - atomic_set(&md->uevent_seq, 0);
44967 + atomic_set_unchecked(&md->event_nr, 0);
44968 + atomic_set_unchecked(&md->uevent_seq, 0);
44969 INIT_LIST_HEAD(&md->uevent_list);
44970 spin_lock_init(&md->uevent_lock);
44971
44972 @@ -2107,7 +2107,7 @@ static void event_callback(void *context)
44973
44974 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
44975
44976 - atomic_inc(&md->event_nr);
44977 + atomic_inc_unchecked(&md->event_nr);
44978 wake_up(&md->eventq);
44979 }
44980
44981 @@ -2800,18 +2800,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
44982
44983 uint32_t dm_next_uevent_seq(struct mapped_device *md)
44984 {
44985 - return atomic_add_return(1, &md->uevent_seq);
44986 + return atomic_add_return_unchecked(1, &md->uevent_seq);
44987 }
44988
44989 uint32_t dm_get_event_nr(struct mapped_device *md)
44990 {
44991 - return atomic_read(&md->event_nr);
44992 + return atomic_read_unchecked(&md->event_nr);
44993 }
44994
44995 int dm_wait_event(struct mapped_device *md, int event_nr)
44996 {
44997 return wait_event_interruptible(md->eventq,
44998 - (event_nr != atomic_read(&md->event_nr)));
44999 + (event_nr != atomic_read_unchecked(&md->event_nr)));
45000 }
45001
45002 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
45003 diff --git a/drivers/md/md.c b/drivers/md/md.c
45004 index b7f603c..723d2bd 100644
45005 --- a/drivers/md/md.c
45006 +++ b/drivers/md/md.c
45007 @@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
45008 * start build, activate spare
45009 */
45010 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
45011 -static atomic_t md_event_count;
45012 +static atomic_unchecked_t md_event_count;
45013 void md_new_event(struct mddev *mddev)
45014 {
45015 - atomic_inc(&md_event_count);
45016 + atomic_inc_unchecked(&md_event_count);
45017 wake_up(&md_event_waiters);
45018 }
45019 EXPORT_SYMBOL_GPL(md_new_event);
45020 @@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
45021 */
45022 static void md_new_event_inintr(struct mddev *mddev)
45023 {
45024 - atomic_inc(&md_event_count);
45025 + atomic_inc_unchecked(&md_event_count);
45026 wake_up(&md_event_waiters);
45027 }
45028
45029 @@ -1462,7 +1462,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
45030 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
45031 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
45032 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
45033 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
45034 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
45035
45036 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
45037 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
45038 @@ -1713,7 +1713,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
45039 else
45040 sb->resync_offset = cpu_to_le64(0);
45041
45042 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
45043 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
45044
45045 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
45046 sb->size = cpu_to_le64(mddev->dev_sectors);
45047 @@ -2725,7 +2725,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
45048 static ssize_t
45049 errors_show(struct md_rdev *rdev, char *page)
45050 {
45051 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
45052 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
45053 }
45054
45055 static ssize_t
45056 @@ -2734,7 +2734,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
45057 char *e;
45058 unsigned long n = simple_strtoul(buf, &e, 10);
45059 if (*buf && (*e == 0 || *e == '\n')) {
45060 - atomic_set(&rdev->corrected_errors, n);
45061 + atomic_set_unchecked(&rdev->corrected_errors, n);
45062 return len;
45063 }
45064 return -EINVAL;
45065 @@ -3183,8 +3183,8 @@ int md_rdev_init(struct md_rdev *rdev)
45066 rdev->sb_loaded = 0;
45067 rdev->bb_page = NULL;
45068 atomic_set(&rdev->nr_pending, 0);
45069 - atomic_set(&rdev->read_errors, 0);
45070 - atomic_set(&rdev->corrected_errors, 0);
45071 + atomic_set_unchecked(&rdev->read_errors, 0);
45072 + atomic_set_unchecked(&rdev->corrected_errors, 0);
45073
45074 INIT_LIST_HEAD(&rdev->same_set);
45075 init_waitqueue_head(&rdev->blocked_wait);
45076 @@ -7072,7 +7072,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
45077
45078 spin_unlock(&pers_lock);
45079 seq_printf(seq, "\n");
45080 - seq->poll_event = atomic_read(&md_event_count);
45081 + seq->poll_event = atomic_read_unchecked(&md_event_count);
45082 return 0;
45083 }
45084 if (v == (void*)2) {
45085 @@ -7175,7 +7175,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
45086 return error;
45087
45088 seq = file->private_data;
45089 - seq->poll_event = atomic_read(&md_event_count);
45090 + seq->poll_event = atomic_read_unchecked(&md_event_count);
45091 return error;
45092 }
45093
45094 @@ -7192,7 +7192,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
45095 /* always allow read */
45096 mask = POLLIN | POLLRDNORM;
45097
45098 - if (seq->poll_event != atomic_read(&md_event_count))
45099 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
45100 mask |= POLLERR | POLLPRI;
45101 return mask;
45102 }
45103 @@ -7236,7 +7236,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
45104 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
45105 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
45106 (int)part_stat_read(&disk->part0, sectors[1]) -
45107 - atomic_read(&disk->sync_io);
45108 + atomic_read_unchecked(&disk->sync_io);
45109 /* sync IO will cause sync_io to increase before the disk_stats
45110 * as sync_io is counted when a request starts, and
45111 * disk_stats is counted when it completes.
45112 diff --git a/drivers/md/md.h b/drivers/md/md.h
45113 index a49d991..3582bb7 100644
45114 --- a/drivers/md/md.h
45115 +++ b/drivers/md/md.h
45116 @@ -94,13 +94,13 @@ struct md_rdev {
45117 * only maintained for arrays that
45118 * support hot removal
45119 */
45120 - atomic_t read_errors; /* number of consecutive read errors that
45121 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
45122 * we have tried to ignore.
45123 */
45124 struct timespec last_read_error; /* monotonic time since our
45125 * last read error
45126 */
45127 - atomic_t corrected_errors; /* number of corrected read errors,
45128 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
45129 * for reporting to userspace and storing
45130 * in superblock.
45131 */
45132 @@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
45133
45134 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
45135 {
45136 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
45137 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
45138 }
45139
45140 struct md_personality
45141 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
45142 index 786b689..ea8c956 100644
45143 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
45144 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
45145 @@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
45146 * Flick into a mode where all blocks get allocated in the new area.
45147 */
45148 smm->begin = old_len;
45149 - memcpy(sm, &bootstrap_ops, sizeof(*sm));
45150 + memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
45151
45152 /*
45153 * Extend.
45154 @@ -710,7 +710,7 @@ out:
45155 /*
45156 * Switch back to normal behaviour.
45157 */
45158 - memcpy(sm, &ops, sizeof(*sm));
45159 + memcpy((void *)sm, &ops, sizeof(*sm));
45160 return r;
45161 }
45162
45163 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
45164 index 3e6d115..ffecdeb 100644
45165 --- a/drivers/md/persistent-data/dm-space-map.h
45166 +++ b/drivers/md/persistent-data/dm-space-map.h
45167 @@ -71,6 +71,7 @@ struct dm_space_map {
45168 dm_sm_threshold_fn fn,
45169 void *context);
45170 };
45171 +typedef struct dm_space_map __no_const dm_space_map_no_const;
45172
45173 /*----------------------------------------------------------------*/
45174
45175 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
45176 index 55de4f6..b1c57fe 100644
45177 --- a/drivers/md/raid1.c
45178 +++ b/drivers/md/raid1.c
45179 @@ -1936,7 +1936,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
45180 if (r1_sync_page_io(rdev, sect, s,
45181 bio->bi_io_vec[idx].bv_page,
45182 READ) != 0)
45183 - atomic_add(s, &rdev->corrected_errors);
45184 + atomic_add_unchecked(s, &rdev->corrected_errors);
45185 }
45186 sectors -= s;
45187 sect += s;
45188 @@ -2170,7 +2170,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
45189 !test_bit(Faulty, &rdev->flags)) {
45190 if (r1_sync_page_io(rdev, sect, s,
45191 conf->tmppage, READ)) {
45192 - atomic_add(s, &rdev->corrected_errors);
45193 + atomic_add_unchecked(s, &rdev->corrected_errors);
45194 printk(KERN_INFO
45195 "md/raid1:%s: read error corrected "
45196 "(%d sectors at %llu on %s)\n",
45197 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
45198 index 6703751..187af1e 100644
45199 --- a/drivers/md/raid10.c
45200 +++ b/drivers/md/raid10.c
45201 @@ -1948,7 +1948,7 @@ static void end_sync_read(struct bio *bio, int error)
45202 /* The write handler will notice the lack of
45203 * R10BIO_Uptodate and record any errors etc
45204 */
45205 - atomic_add(r10_bio->sectors,
45206 + atomic_add_unchecked(r10_bio->sectors,
45207 &conf->mirrors[d].rdev->corrected_errors);
45208
45209 /* for reconstruct, we always reschedule after a read.
45210 @@ -2306,7 +2306,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
45211 {
45212 struct timespec cur_time_mon;
45213 unsigned long hours_since_last;
45214 - unsigned int read_errors = atomic_read(&rdev->read_errors);
45215 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
45216
45217 ktime_get_ts(&cur_time_mon);
45218
45219 @@ -2328,9 +2328,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
45220 * overflowing the shift of read_errors by hours_since_last.
45221 */
45222 if (hours_since_last >= 8 * sizeof(read_errors))
45223 - atomic_set(&rdev->read_errors, 0);
45224 + atomic_set_unchecked(&rdev->read_errors, 0);
45225 else
45226 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
45227 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
45228 }
45229
45230 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
45231 @@ -2384,8 +2384,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
45232 return;
45233
45234 check_decay_read_errors(mddev, rdev);
45235 - atomic_inc(&rdev->read_errors);
45236 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
45237 + atomic_inc_unchecked(&rdev->read_errors);
45238 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
45239 char b[BDEVNAME_SIZE];
45240 bdevname(rdev->bdev, b);
45241
45242 @@ -2393,7 +2393,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
45243 "md/raid10:%s: %s: Raid device exceeded "
45244 "read_error threshold [cur %d:max %d]\n",
45245 mdname(mddev), b,
45246 - atomic_read(&rdev->read_errors), max_read_errors);
45247 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
45248 printk(KERN_NOTICE
45249 "md/raid10:%s: %s: Failing raid device\n",
45250 mdname(mddev), b);
45251 @@ -2548,7 +2548,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
45252 sect +
45253 choose_data_offset(r10_bio, rdev)),
45254 bdevname(rdev->bdev, b));
45255 - atomic_add(s, &rdev->corrected_errors);
45256 + atomic_add_unchecked(s, &rdev->corrected_errors);
45257 }
45258
45259 rdev_dec_pending(rdev, mddev);
45260 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
45261 index 9f0fbec..991e7a1 100644
45262 --- a/drivers/md/raid5.c
45263 +++ b/drivers/md/raid5.c
45264 @@ -1735,6 +1735,10 @@ static int grow_one_stripe(struct r5conf *conf, int hash)
45265 return 1;
45266 }
45267
45268 +#ifdef CONFIG_GRKERNSEC_HIDESYM
45269 +static atomic_unchecked_t raid5_cache_id = ATOMIC_INIT(0);
45270 +#endif
45271 +
45272 static int grow_stripes(struct r5conf *conf, int num)
45273 {
45274 struct kmem_cache *sc;
45275 @@ -1746,7 +1750,11 @@ static int grow_stripes(struct r5conf *conf, int num)
45276 "raid%d-%s", conf->level, mdname(conf->mddev));
45277 else
45278 sprintf(conf->cache_name[0],
45279 +#ifdef CONFIG_GRKERNSEC_HIDESYM
45280 + "raid%d-%08lx", conf->level, atomic_inc_return_unchecked(&raid5_cache_id));
45281 +#else
45282 "raid%d-%p", conf->level, conf->mddev);
45283 +#endif
45284 sprintf(conf->cache_name[1], "%s-alt", conf->cache_name[0]);
45285
45286 conf->active_name = 0;
45287 @@ -2022,21 +2030,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
45288 mdname(conf->mddev), STRIPE_SECTORS,
45289 (unsigned long long)s,
45290 bdevname(rdev->bdev, b));
45291 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
45292 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
45293 clear_bit(R5_ReadError, &sh->dev[i].flags);
45294 clear_bit(R5_ReWrite, &sh->dev[i].flags);
45295 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
45296 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
45297
45298 - if (atomic_read(&rdev->read_errors))
45299 - atomic_set(&rdev->read_errors, 0);
45300 + if (atomic_read_unchecked(&rdev->read_errors))
45301 + atomic_set_unchecked(&rdev->read_errors, 0);
45302 } else {
45303 const char *bdn = bdevname(rdev->bdev, b);
45304 int retry = 0;
45305 int set_bad = 0;
45306
45307 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
45308 - atomic_inc(&rdev->read_errors);
45309 + atomic_inc_unchecked(&rdev->read_errors);
45310 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
45311 printk_ratelimited(
45312 KERN_WARNING
45313 @@ -2064,7 +2072,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
45314 mdname(conf->mddev),
45315 (unsigned long long)s,
45316 bdn);
45317 - } else if (atomic_read(&rdev->read_errors)
45318 + } else if (atomic_read_unchecked(&rdev->read_errors)
45319 > conf->max_nr_stripes)
45320 printk(KERN_WARNING
45321 "md/raid:%s: Too many read errors, failing device %s.\n",
45322 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
45323 index 983db75..ef9248c 100644
45324 --- a/drivers/media/dvb-core/dvbdev.c
45325 +++ b/drivers/media/dvb-core/dvbdev.c
45326 @@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
45327 const struct dvb_device *template, void *priv, int type)
45328 {
45329 struct dvb_device *dvbdev;
45330 - struct file_operations *dvbdevfops;
45331 + file_operations_no_const *dvbdevfops;
45332 struct device *clsdev;
45333 int minor;
45334 int id;
45335 diff --git a/drivers/media/dvb-frontends/af9033.h b/drivers/media/dvb-frontends/af9033.h
45336 index 539f4db..cdd403b 100644
45337 --- a/drivers/media/dvb-frontends/af9033.h
45338 +++ b/drivers/media/dvb-frontends/af9033.h
45339 @@ -82,7 +82,7 @@ struct af9033_ops {
45340 int (*pid_filter_ctrl)(struct dvb_frontend *fe, int onoff);
45341 int (*pid_filter)(struct dvb_frontend *fe, int index, u16 pid,
45342 int onoff);
45343 -};
45344 +} __no_const;
45345
45346
45347 #if IS_ENABLED(CONFIG_DVB_AF9033)
45348 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
45349 index 9b6c3bb..baeb5c7 100644
45350 --- a/drivers/media/dvb-frontends/dib3000.h
45351 +++ b/drivers/media/dvb-frontends/dib3000.h
45352 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
45353 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
45354 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
45355 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
45356 -};
45357 +} __no_const;
45358
45359 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
45360 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
45361 diff --git a/drivers/media/dvb-frontends/dib7000p.h b/drivers/media/dvb-frontends/dib7000p.h
45362 index 1fea0e9..321ce8f 100644
45363 --- a/drivers/media/dvb-frontends/dib7000p.h
45364 +++ b/drivers/media/dvb-frontends/dib7000p.h
45365 @@ -64,7 +64,7 @@ struct dib7000p_ops {
45366 int (*get_adc_power)(struct dvb_frontend *fe);
45367 int (*slave_reset)(struct dvb_frontend *fe);
45368 struct dvb_frontend *(*init)(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib7000p_config *cfg);
45369 -};
45370 +} __no_const;
45371
45372 #if IS_ENABLED(CONFIG_DVB_DIB7000P)
45373 void *dib7000p_attach(struct dib7000p_ops *ops);
45374 diff --git a/drivers/media/dvb-frontends/dib8000.h b/drivers/media/dvb-frontends/dib8000.h
45375 index 84cc103..5780c54 100644
45376 --- a/drivers/media/dvb-frontends/dib8000.h
45377 +++ b/drivers/media/dvb-frontends/dib8000.h
45378 @@ -61,7 +61,7 @@ struct dib8000_ops {
45379 int (*pid_filter_ctrl)(struct dvb_frontend *fe, u8 onoff);
45380 int (*pid_filter)(struct dvb_frontend *fe, u8 id, u16 pid, u8 onoff);
45381 struct dvb_frontend *(*init)(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib8000_config *cfg);
45382 -};
45383 +} __no_const;
45384
45385 #if IS_ENABLED(CONFIG_DVB_DIB8000)
45386 void *dib8000_attach(struct dib8000_ops *ops);
45387 diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
45388 index ed8cb90..5ef7f79 100644
45389 --- a/drivers/media/pci/cx88/cx88-video.c
45390 +++ b/drivers/media/pci/cx88/cx88-video.c
45391 @@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
45392
45393 /* ------------------------------------------------------------------ */
45394
45395 -static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45396 -static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45397 -static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45398 +static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45399 +static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45400 +static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45401
45402 module_param_array(video_nr, int, NULL, 0444);
45403 module_param_array(vbi_nr, int, NULL, 0444);
45404 diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
45405 index 802642d..5534900 100644
45406 --- a/drivers/media/pci/ivtv/ivtv-driver.c
45407 +++ b/drivers/media/pci/ivtv/ivtv-driver.c
45408 @@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
45409 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
45410
45411 /* ivtv instance counter */
45412 -static atomic_t ivtv_instance = ATOMIC_INIT(0);
45413 +static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
45414
45415 /* Parameter declarations */
45416 static int cardtype[IVTV_MAX_CARDS];
45417 diff --git a/drivers/media/pci/solo6x10/solo6x10-core.c b/drivers/media/pci/solo6x10/solo6x10-core.c
45418 index 172583d..0f806f4 100644
45419 --- a/drivers/media/pci/solo6x10/solo6x10-core.c
45420 +++ b/drivers/media/pci/solo6x10/solo6x10-core.c
45421 @@ -430,7 +430,7 @@ static void solo_device_release(struct device *dev)
45422
45423 static int solo_sysfs_init(struct solo_dev *solo_dev)
45424 {
45425 - struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
45426 + bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
45427 struct device *dev = &solo_dev->dev;
45428 const char *driver;
45429 int i;
45430 diff --git a/drivers/media/pci/solo6x10/solo6x10-g723.c b/drivers/media/pci/solo6x10/solo6x10-g723.c
45431 index c7141f2..5301fec 100644
45432 --- a/drivers/media/pci/solo6x10/solo6x10-g723.c
45433 +++ b/drivers/media/pci/solo6x10/solo6x10-g723.c
45434 @@ -351,7 +351,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
45435
45436 int solo_g723_init(struct solo_dev *solo_dev)
45437 {
45438 - static struct snd_device_ops ops = { NULL };
45439 + static struct snd_device_ops ops = { };
45440 struct snd_card *card;
45441 struct snd_kcontrol_new kctl;
45442 char name[32];
45443 diff --git a/drivers/media/pci/solo6x10/solo6x10-p2m.c b/drivers/media/pci/solo6x10/solo6x10-p2m.c
45444 index 8c84846..27b4f83 100644
45445 --- a/drivers/media/pci/solo6x10/solo6x10-p2m.c
45446 +++ b/drivers/media/pci/solo6x10/solo6x10-p2m.c
45447 @@ -73,7 +73,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
45448
45449 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
45450 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
45451 - p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
45452 + p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
45453 if (p2m_id < 0)
45454 p2m_id = -p2m_id;
45455 }
45456 diff --git a/drivers/media/pci/solo6x10/solo6x10.h b/drivers/media/pci/solo6x10/solo6x10.h
45457 index c6154b0..73e4ae9 100644
45458 --- a/drivers/media/pci/solo6x10/solo6x10.h
45459 +++ b/drivers/media/pci/solo6x10/solo6x10.h
45460 @@ -219,7 +219,7 @@ struct solo_dev {
45461
45462 /* P2M DMA Engine */
45463 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
45464 - atomic_t p2m_count;
45465 + atomic_unchecked_t p2m_count;
45466 int p2m_jiffies;
45467 unsigned int p2m_timeouts;
45468
45469 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
45470 index 2d177fa..5b925a1 100644
45471 --- a/drivers/media/platform/omap/omap_vout.c
45472 +++ b/drivers/media/platform/omap/omap_vout.c
45473 @@ -63,7 +63,6 @@ enum omap_vout_channels {
45474 OMAP_VIDEO2,
45475 };
45476
45477 -static struct videobuf_queue_ops video_vbq_ops;
45478 /* Variables configurable through module params*/
45479 static u32 video1_numbuffers = 3;
45480 static u32 video2_numbuffers = 3;
45481 @@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
45482 {
45483 struct videobuf_queue *q;
45484 struct omap_vout_device *vout = NULL;
45485 + static struct videobuf_queue_ops video_vbq_ops = {
45486 + .buf_setup = omap_vout_buffer_setup,
45487 + .buf_prepare = omap_vout_buffer_prepare,
45488 + .buf_release = omap_vout_buffer_release,
45489 + .buf_queue = omap_vout_buffer_queue,
45490 + };
45491
45492 vout = video_drvdata(file);
45493 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
45494 @@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
45495 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
45496
45497 q = &vout->vbq;
45498 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
45499 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
45500 - video_vbq_ops.buf_release = omap_vout_buffer_release;
45501 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
45502 spin_lock_init(&vout->vbq_lock);
45503
45504 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
45505 diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
45506 index fb2acc5..a2fcbdc4 100644
45507 --- a/drivers/media/platform/s5p-tv/mixer.h
45508 +++ b/drivers/media/platform/s5p-tv/mixer.h
45509 @@ -156,7 +156,7 @@ struct mxr_layer {
45510 /** layer index (unique identifier) */
45511 int idx;
45512 /** callbacks for layer methods */
45513 - struct mxr_layer_ops ops;
45514 + struct mxr_layer_ops *ops;
45515 /** format array */
45516 const struct mxr_format **fmt_array;
45517 /** size of format array */
45518 diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45519 index 74344c7..a39e70e 100644
45520 --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45521 +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45522 @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
45523 {
45524 struct mxr_layer *layer;
45525 int ret;
45526 - struct mxr_layer_ops ops = {
45527 + static struct mxr_layer_ops ops = {
45528 .release = mxr_graph_layer_release,
45529 .buffer_set = mxr_graph_buffer_set,
45530 .stream_set = mxr_graph_stream_set,
45531 diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
45532 index b713403..53cb5ad 100644
45533 --- a/drivers/media/platform/s5p-tv/mixer_reg.c
45534 +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
45535 @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
45536 layer->update_buf = next;
45537 }
45538
45539 - layer->ops.buffer_set(layer, layer->update_buf);
45540 + layer->ops->buffer_set(layer, layer->update_buf);
45541
45542 if (done && done != layer->shadow_buf)
45543 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
45544 diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
45545 index b4d2696..91df48e 100644
45546 --- a/drivers/media/platform/s5p-tv/mixer_video.c
45547 +++ b/drivers/media/platform/s5p-tv/mixer_video.c
45548 @@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
45549 layer->geo.src.height = layer->geo.src.full_height;
45550
45551 mxr_geometry_dump(mdev, &layer->geo);
45552 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45553 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45554 mxr_geometry_dump(mdev, &layer->geo);
45555 }
45556
45557 @@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
45558 layer->geo.dst.full_width = mbus_fmt.width;
45559 layer->geo.dst.full_height = mbus_fmt.height;
45560 layer->geo.dst.field = mbus_fmt.field;
45561 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45562 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45563
45564 mxr_geometry_dump(mdev, &layer->geo);
45565 }
45566 @@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
45567 /* set source size to highest accepted value */
45568 geo->src.full_width = max(geo->dst.full_width, pix->width);
45569 geo->src.full_height = max(geo->dst.full_height, pix->height);
45570 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45571 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45572 mxr_geometry_dump(mdev, &layer->geo);
45573 /* set cropping to total visible screen */
45574 geo->src.width = pix->width;
45575 @@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
45576 geo->src.x_offset = 0;
45577 geo->src.y_offset = 0;
45578 /* assure consistency of geometry */
45579 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
45580 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
45581 mxr_geometry_dump(mdev, &layer->geo);
45582 /* set full size to lowest possible value */
45583 geo->src.full_width = 0;
45584 geo->src.full_height = 0;
45585 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45586 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45587 mxr_geometry_dump(mdev, &layer->geo);
45588
45589 /* returning results */
45590 @@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
45591 target->width = s->r.width;
45592 target->height = s->r.height;
45593
45594 - layer->ops.fix_geometry(layer, stage, s->flags);
45595 + layer->ops->fix_geometry(layer, stage, s->flags);
45596
45597 /* retrieve update selection rectangle */
45598 res.left = target->x_offset;
45599 @@ -954,13 +954,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
45600 mxr_output_get(mdev);
45601
45602 mxr_layer_update_output(layer);
45603 - layer->ops.format_set(layer);
45604 + layer->ops->format_set(layer);
45605 /* enabling layer in hardware */
45606 spin_lock_irqsave(&layer->enq_slock, flags);
45607 layer->state = MXR_LAYER_STREAMING;
45608 spin_unlock_irqrestore(&layer->enq_slock, flags);
45609
45610 - layer->ops.stream_set(layer, MXR_ENABLE);
45611 + layer->ops->stream_set(layer, MXR_ENABLE);
45612 mxr_streamer_get(mdev);
45613
45614 return 0;
45615 @@ -1030,7 +1030,7 @@ static void stop_streaming(struct vb2_queue *vq)
45616 spin_unlock_irqrestore(&layer->enq_slock, flags);
45617
45618 /* disabling layer in hardware */
45619 - layer->ops.stream_set(layer, MXR_DISABLE);
45620 + layer->ops->stream_set(layer, MXR_DISABLE);
45621 /* remove one streamer */
45622 mxr_streamer_put(mdev);
45623 /* allow changes in output configuration */
45624 @@ -1068,8 +1068,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
45625
45626 void mxr_layer_release(struct mxr_layer *layer)
45627 {
45628 - if (layer->ops.release)
45629 - layer->ops.release(layer);
45630 + if (layer->ops->release)
45631 + layer->ops->release(layer);
45632 }
45633
45634 void mxr_base_layer_release(struct mxr_layer *layer)
45635 @@ -1095,7 +1095,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
45636
45637 layer->mdev = mdev;
45638 layer->idx = idx;
45639 - layer->ops = *ops;
45640 + layer->ops = ops;
45641
45642 spin_lock_init(&layer->enq_slock);
45643 INIT_LIST_HEAD(&layer->enq_list);
45644 diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45645 index c9388c4..ce71ece 100644
45646 --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45647 +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45648 @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
45649 {
45650 struct mxr_layer *layer;
45651 int ret;
45652 - struct mxr_layer_ops ops = {
45653 + static struct mxr_layer_ops ops = {
45654 .release = mxr_vp_layer_release,
45655 .buffer_set = mxr_vp_buffer_set,
45656 .stream_set = mxr_vp_stream_set,
45657 diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
45658 index 8033371..de5bca0 100644
45659 --- a/drivers/media/platform/vivi.c
45660 +++ b/drivers/media/platform/vivi.c
45661 @@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
45662 MODULE_LICENSE("Dual BSD/GPL");
45663 MODULE_VERSION(VIVI_VERSION);
45664
45665 -static unsigned video_nr = -1;
45666 -module_param(video_nr, uint, 0644);
45667 +static int video_nr = -1;
45668 +module_param(video_nr, int, 0644);
45669 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
45670
45671 static unsigned n_devs = 1;
45672 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
45673 index 82affae..42833ec 100644
45674 --- a/drivers/media/radio/radio-cadet.c
45675 +++ b/drivers/media/radio/radio-cadet.c
45676 @@ -333,6 +333,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
45677 unsigned char readbuf[RDS_BUFFER];
45678 int i = 0;
45679
45680 + if (count > RDS_BUFFER)
45681 + return -EFAULT;
45682 mutex_lock(&dev->lock);
45683 if (dev->rdsstat == 0)
45684 cadet_start_rds(dev);
45685 @@ -349,8 +351,9 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
45686 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
45687 mutex_unlock(&dev->lock);
45688
45689 - if (i && copy_to_user(data, readbuf, i))
45690 - return -EFAULT;
45691 + if (i > sizeof(readbuf) || (i && copy_to_user(data, readbuf, i)))
45692 + i = -EFAULT;
45693 +
45694 return i;
45695 }
45696
45697 diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
45698 index 5236035..c622c74 100644
45699 --- a/drivers/media/radio/radio-maxiradio.c
45700 +++ b/drivers/media/radio/radio-maxiradio.c
45701 @@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
45702 /* TEA5757 pin mappings */
45703 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
45704
45705 -static atomic_t maxiradio_instance = ATOMIC_INIT(0);
45706 +static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
45707
45708 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
45709 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
45710 diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
45711 index 050b3bb..79f62b9 100644
45712 --- a/drivers/media/radio/radio-shark.c
45713 +++ b/drivers/media/radio/radio-shark.c
45714 @@ -79,7 +79,7 @@ struct shark_device {
45715 u32 last_val;
45716 };
45717
45718 -static atomic_t shark_instance = ATOMIC_INIT(0);
45719 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
45720
45721 static void shark_write_val(struct snd_tea575x *tea, u32 val)
45722 {
45723 diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
45724 index 8654e0d..0608a64 100644
45725 --- a/drivers/media/radio/radio-shark2.c
45726 +++ b/drivers/media/radio/radio-shark2.c
45727 @@ -74,7 +74,7 @@ struct shark_device {
45728 u8 *transfer_buffer;
45729 };
45730
45731 -static atomic_t shark_instance = ATOMIC_INIT(0);
45732 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
45733
45734 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
45735 {
45736 diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
45737 index 633022b..7f10754 100644
45738 --- a/drivers/media/radio/radio-si476x.c
45739 +++ b/drivers/media/radio/radio-si476x.c
45740 @@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
45741 struct si476x_radio *radio;
45742 struct v4l2_ctrl *ctrl;
45743
45744 - static atomic_t instance = ATOMIC_INIT(0);
45745 + static atomic_unchecked_t instance = ATOMIC_INIT(0);
45746
45747 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
45748 if (!radio)
45749 diff --git a/drivers/media/usb/dvb-usb/cinergyT2-core.c b/drivers/media/usb/dvb-usb/cinergyT2-core.c
45750 index 9fd1527..8927230 100644
45751 --- a/drivers/media/usb/dvb-usb/cinergyT2-core.c
45752 +++ b/drivers/media/usb/dvb-usb/cinergyT2-core.c
45753 @@ -50,29 +50,73 @@ static struct dvb_usb_device_properties cinergyt2_properties;
45754
45755 static int cinergyt2_streaming_ctrl(struct dvb_usb_adapter *adap, int enable)
45756 {
45757 - char buf[] = { CINERGYT2_EP1_CONTROL_STREAM_TRANSFER, enable ? 1 : 0 };
45758 - char result[64];
45759 - return dvb_usb_generic_rw(adap->dev, buf, sizeof(buf), result,
45760 - sizeof(result), 0);
45761 + char *buf;
45762 + char *result;
45763 + int retval;
45764 +
45765 + buf = kmalloc(2, GFP_KERNEL);
45766 + if (buf == NULL)
45767 + return -ENOMEM;
45768 + result = kmalloc(64, GFP_KERNEL);
45769 + if (result == NULL) {
45770 + kfree(buf);
45771 + return -ENOMEM;
45772 + }
45773 +
45774 + buf[0] = CINERGYT2_EP1_CONTROL_STREAM_TRANSFER;
45775 + buf[1] = enable ? 1 : 0;
45776 +
45777 + retval = dvb_usb_generic_rw(adap->dev, buf, 2, result, 64, 0);
45778 +
45779 + kfree(buf);
45780 + kfree(result);
45781 + return retval;
45782 }
45783
45784 static int cinergyt2_power_ctrl(struct dvb_usb_device *d, int enable)
45785 {
45786 - char buf[] = { CINERGYT2_EP1_SLEEP_MODE, enable ? 0 : 1 };
45787 - char state[3];
45788 - return dvb_usb_generic_rw(d, buf, sizeof(buf), state, sizeof(state), 0);
45789 + char *buf;
45790 + char *state;
45791 + int retval;
45792 +
45793 + buf = kmalloc(2, GFP_KERNEL);
45794 + if (buf == NULL)
45795 + return -ENOMEM;
45796 + state = kmalloc(3, GFP_KERNEL);
45797 + if (state == NULL) {
45798 + kfree(buf);
45799 + return -ENOMEM;
45800 + }
45801 +
45802 + buf[0] = CINERGYT2_EP1_SLEEP_MODE;
45803 + buf[1] = enable ? 1 : 0;
45804 +
45805 + retval = dvb_usb_generic_rw(d, buf, 2, state, 3, 0);
45806 +
45807 + kfree(buf);
45808 + kfree(state);
45809 + return retval;
45810 }
45811
45812 static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
45813 {
45814 - char query[] = { CINERGYT2_EP1_GET_FIRMWARE_VERSION };
45815 - char state[3];
45816 + char *query;
45817 + char *state;
45818 int ret;
45819 + query = kmalloc(1, GFP_KERNEL);
45820 + if (query == NULL)
45821 + return -ENOMEM;
45822 + state = kmalloc(3, GFP_KERNEL);
45823 + if (state == NULL) {
45824 + kfree(query);
45825 + return -ENOMEM;
45826 + }
45827 +
45828 + query[0] = CINERGYT2_EP1_GET_FIRMWARE_VERSION;
45829
45830 adap->fe_adap[0].fe = cinergyt2_fe_attach(adap->dev);
45831
45832 - ret = dvb_usb_generic_rw(adap->dev, query, sizeof(query), state,
45833 - sizeof(state), 0);
45834 + ret = dvb_usb_generic_rw(adap->dev, query, 1, state, 3, 0);
45835 if (ret < 0) {
45836 deb_rc("cinergyt2_power_ctrl() Failed to retrieve sleep "
45837 "state info\n");
45838 @@ -80,7 +124,8 @@ static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
45839
45840 /* Copy this pointer as we are gonna need it in the release phase */
45841 cinergyt2_usb_device = adap->dev;
45842 -
45843 + kfree(query);
45844 + kfree(state);
45845 return 0;
45846 }
45847
45848 @@ -141,12 +186,23 @@ static int repeatable_keys[] = {
45849 static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
45850 {
45851 struct cinergyt2_state *st = d->priv;
45852 - u8 key[5] = {0, 0, 0, 0, 0}, cmd = CINERGYT2_EP1_GET_RC_EVENTS;
45853 + u8 *key, *cmd;
45854 int i;
45855
45856 + cmd = kmalloc(1, GFP_KERNEL);
45857 + if (cmd == NULL)
45858 + return -EINVAL;
45859 + key = kzalloc(5, GFP_KERNEL);
45860 + if (key == NULL) {
45861 + kfree(cmd);
45862 + return -EINVAL;
45863 + }
45864 +
45865 + cmd[0] = CINERGYT2_EP1_GET_RC_EVENTS;
45866 +
45867 *state = REMOTE_NO_KEY_PRESSED;
45868
45869 - dvb_usb_generic_rw(d, &cmd, 1, key, sizeof(key), 0);
45870 + dvb_usb_generic_rw(d, cmd, 1, key, 5, 0);
45871 if (key[4] == 0xff) {
45872 /* key repeat */
45873 st->rc_counter++;
45874 @@ -157,12 +213,12 @@ static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
45875 *event = d->last_event;
45876 deb_rc("repeat key, event %x\n",
45877 *event);
45878 - return 0;
45879 + goto out;
45880 }
45881 }
45882 deb_rc("repeated key (non repeatable)\n");
45883 }
45884 - return 0;
45885 + goto out;
45886 }
45887
45888 /* hack to pass checksum on the custom field */
45889 @@ -174,6 +230,9 @@ static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
45890
45891 deb_rc("key: %*ph\n", 5, key);
45892 }
45893 +out:
45894 + kfree(cmd);
45895 + kfree(key);
45896 return 0;
45897 }
45898
45899 diff --git a/drivers/media/usb/dvb-usb/cinergyT2-fe.c b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
45900 index c890fe4..f9b2ae6 100644
45901 --- a/drivers/media/usb/dvb-usb/cinergyT2-fe.c
45902 +++ b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
45903 @@ -145,103 +145,176 @@ static int cinergyt2_fe_read_status(struct dvb_frontend *fe,
45904 fe_status_t *status)
45905 {
45906 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45907 - struct dvbt_get_status_msg result;
45908 - u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45909 + struct dvbt_get_status_msg *result;
45910 + u8 *cmd;
45911 int ret;
45912
45913 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&result,
45914 - sizeof(result), 0);
45915 + cmd = kmalloc(1, GFP_KERNEL);
45916 + if (cmd == NULL)
45917 + return -ENOMEM;
45918 + result = kmalloc(sizeof(*result), GFP_KERNEL);
45919 + if (result == NULL) {
45920 + kfree(cmd);
45921 + return -ENOMEM;
45922 + }
45923 +
45924 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45925 +
45926 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (u8 *)result,
45927 + sizeof(*result), 0);
45928 if (ret < 0)
45929 - return ret;
45930 + goto out;
45931
45932 *status = 0;
45933
45934 - if (0xffff - le16_to_cpu(result.gain) > 30)
45935 + if (0xffff - le16_to_cpu(result->gain) > 30)
45936 *status |= FE_HAS_SIGNAL;
45937 - if (result.lock_bits & (1 << 6))
45938 + if (result->lock_bits & (1 << 6))
45939 *status |= FE_HAS_LOCK;
45940 - if (result.lock_bits & (1 << 5))
45941 + if (result->lock_bits & (1 << 5))
45942 *status |= FE_HAS_SYNC;
45943 - if (result.lock_bits & (1 << 4))
45944 + if (result->lock_bits & (1 << 4))
45945 *status |= FE_HAS_CARRIER;
45946 - if (result.lock_bits & (1 << 1))
45947 + if (result->lock_bits & (1 << 1))
45948 *status |= FE_HAS_VITERBI;
45949
45950 if ((*status & (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC)) !=
45951 (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC))
45952 *status &= ~FE_HAS_LOCK;
45953
45954 - return 0;
45955 +out:
45956 + kfree(cmd);
45957 + kfree(result);
45958 + return ret;
45959 }
45960
45961 static int cinergyt2_fe_read_ber(struct dvb_frontend *fe, u32 *ber)
45962 {
45963 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45964 - struct dvbt_get_status_msg status;
45965 - char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45966 + struct dvbt_get_status_msg *status;
45967 + char *cmd;
45968 int ret;
45969
45970 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
45971 - sizeof(status), 0);
45972 + cmd = kmalloc(1, GFP_KERNEL);
45973 + if (cmd == NULL)
45974 + return -ENOMEM;
45975 + status = kmalloc(sizeof(*status), GFP_KERNEL);
45976 + if (status == NULL) {
45977 + kfree(cmd);
45978 + return -ENOMEM;
45979 + }
45980 +
45981 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45982 +
45983 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
45984 + sizeof(*status), 0);
45985 if (ret < 0)
45986 - return ret;
45987 + goto out;
45988
45989 - *ber = le32_to_cpu(status.viterbi_error_rate);
45990 + *ber = le32_to_cpu(status->viterbi_error_rate);
45991 +out:
45992 + kfree(cmd);
45993 + kfree(status);
45994 return 0;
45995 }
45996
45997 static int cinergyt2_fe_read_unc_blocks(struct dvb_frontend *fe, u32 *unc)
45998 {
45999 struct cinergyt2_fe_state *state = fe->demodulator_priv;
46000 - struct dvbt_get_status_msg status;
46001 - u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
46002 + struct dvbt_get_status_msg *status;
46003 + u8 *cmd;
46004 int ret;
46005
46006 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&status,
46007 - sizeof(status), 0);
46008 + cmd = kmalloc(1, GFP_KERNEL);
46009 + if (cmd == NULL)
46010 + return -ENOMEM;
46011 + status = kmalloc(sizeof(*status), GFP_KERNEL);
46012 + if (status == NULL) {
46013 + kfree(cmd);
46014 + return -ENOMEM;
46015 + }
46016 +
46017 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
46018 +
46019 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (u8 *)status,
46020 + sizeof(*status), 0);
46021 if (ret < 0) {
46022 err("cinergyt2_fe_read_unc_blocks() Failed! (Error=%d)\n",
46023 ret);
46024 - return ret;
46025 + goto out;
46026 }
46027 - *unc = le32_to_cpu(status.uncorrected_block_count);
46028 - return 0;
46029 + *unc = le32_to_cpu(status->uncorrected_block_count);
46030 +
46031 +out:
46032 + kfree(cmd);
46033 + kfree(status);
46034 + return ret;
46035 }
46036
46037 static int cinergyt2_fe_read_signal_strength(struct dvb_frontend *fe,
46038 u16 *strength)
46039 {
46040 struct cinergyt2_fe_state *state = fe->demodulator_priv;
46041 - struct dvbt_get_status_msg status;
46042 - char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
46043 + struct dvbt_get_status_msg *status;
46044 + char *cmd;
46045 int ret;
46046
46047 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
46048 - sizeof(status), 0);
46049 + cmd = kmalloc(1, GFP_KERNEL);
46050 + if (cmd == NULL)
46051 + return -ENOMEM;
46052 + status = kmalloc(sizeof(*status), GFP_KERNEL);
46053 + if (status == NULL) {
46054 + kfree(cmd);
46055 + return -ENOMEM;
46056 + }
46057 +
46058 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
46059 +
46060 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
46061 + sizeof(*status), 0);
46062 if (ret < 0) {
46063 err("cinergyt2_fe_read_signal_strength() Failed!"
46064 " (Error=%d)\n", ret);
46065 - return ret;
46066 + goto out;
46067 }
46068 - *strength = (0xffff - le16_to_cpu(status.gain));
46069 + *strength = (0xffff - le16_to_cpu(status->gain));
46070 +
46071 +out:
46072 + kfree(cmd);
46073 + kfree(status);
46074 return 0;
46075 }
46076
46077 static int cinergyt2_fe_read_snr(struct dvb_frontend *fe, u16 *snr)
46078 {
46079 struct cinergyt2_fe_state *state = fe->demodulator_priv;
46080 - struct dvbt_get_status_msg status;
46081 - char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
46082 + struct dvbt_get_status_msg *status;
46083 + char *cmd;
46084 int ret;
46085
46086 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
46087 - sizeof(status), 0);
46088 + cmd = kmalloc(1, GFP_KERNEL);
46089 + if (cmd == NULL)
46090 + return -ENOMEM;
46091 + status = kmalloc(sizeof(*status), GFP_KERNEL);
46092 + if (status == NULL) {
46093 + kfree(cmd);
46094 + return -ENOMEM;
46095 + }
46096 +
46097 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
46098 +
46099 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
46100 + sizeof(*status), 0);
46101 if (ret < 0) {
46102 err("cinergyt2_fe_read_snr() Failed! (Error=%d)\n", ret);
46103 - return ret;
46104 + goto out;
46105 }
46106 - *snr = (status.snr << 8) | status.snr;
46107 - return 0;
46108 + *snr = (status->snr << 8) | status->snr;
46109 +
46110 +out:
46111 + kfree(cmd);
46112 + kfree(status);
46113 + return ret;
46114 }
46115
46116 static int cinergyt2_fe_init(struct dvb_frontend *fe)
46117 @@ -266,35 +339,46 @@ static int cinergyt2_fe_set_frontend(struct dvb_frontend *fe)
46118 {
46119 struct dtv_frontend_properties *fep = &fe->dtv_property_cache;
46120 struct cinergyt2_fe_state *state = fe->demodulator_priv;
46121 - struct dvbt_set_parameters_msg param;
46122 - char result[2];
46123 + struct dvbt_set_parameters_msg *param;
46124 + char *result;
46125 int err;
46126
46127 - param.cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
46128 - param.tps = cpu_to_le16(compute_tps(fep));
46129 - param.freq = cpu_to_le32(fep->frequency / 1000);
46130 - param.flags = 0;
46131 + result = kmalloc(2, GFP_KERNEL);
46132 + if (result == NULL)
46133 + return -ENOMEM;
46134 + param = kmalloc(sizeof(*param), GFP_KERNEL);
46135 + if (param == NULL) {
46136 + kfree(result);
46137 + return -ENOMEM;
46138 + }
46139 +
46140 + param->cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
46141 + param->tps = cpu_to_le16(compute_tps(fep));
46142 + param->freq = cpu_to_le32(fep->frequency / 1000);
46143 + param->flags = 0;
46144
46145 switch (fep->bandwidth_hz) {
46146 default:
46147 case 8000000:
46148 - param.bandwidth = 8;
46149 + param->bandwidth = 8;
46150 break;
46151 case 7000000:
46152 - param.bandwidth = 7;
46153 + param->bandwidth = 7;
46154 break;
46155 case 6000000:
46156 - param.bandwidth = 6;
46157 + param->bandwidth = 6;
46158 break;
46159 }
46160
46161 err = dvb_usb_generic_rw(state->d,
46162 - (char *)&param, sizeof(param),
46163 - result, sizeof(result), 0);
46164 + (char *)param, sizeof(*param),
46165 + result, 2, 0);
46166 if (err < 0)
46167 err("cinergyt2_fe_set_frontend() Failed! err=%d\n", err);
46168
46169 - return (err < 0) ? err : 0;
46170 + kfree(result);
46171 + kfree(param);
46172 + return err;
46173 }
46174
46175 static void cinergyt2_fe_release(struct dvb_frontend *fe)
46176 diff --git a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
46177 index 733a7ff..f8b52e3 100644
46178 --- a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
46179 +++ b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
46180 @@ -35,42 +35,57 @@ static int usb_cypress_writemem(struct usb_device *udev,u16 addr,u8 *data, u8 le
46181
46182 int usb_cypress_load_firmware(struct usb_device *udev, const struct firmware *fw, int type)
46183 {
46184 - struct hexline hx;
46185 - u8 reset;
46186 + struct hexline *hx;
46187 + u8 *reset;
46188 int ret,pos=0;
46189
46190 + reset = kmalloc(1, GFP_KERNEL);
46191 + if (reset == NULL)
46192 + return -ENOMEM;
46193 +
46194 + hx = kmalloc(sizeof(struct hexline), GFP_KERNEL);
46195 + if (hx == NULL) {
46196 + kfree(reset);
46197 + return -ENOMEM;
46198 + }
46199 +
46200 /* stop the CPU */
46201 - reset = 1;
46202 - if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1)) != 1)
46203 + reset[0] = 1;
46204 + if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1)) != 1)
46205 err("could not stop the USB controller CPU.");
46206
46207 - while ((ret = dvb_usb_get_hexline(fw,&hx,&pos)) > 0) {
46208 - deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx.addr,hx.len,hx.chk);
46209 - ret = usb_cypress_writemem(udev,hx.addr,hx.data,hx.len);
46210 + while ((ret = dvb_usb_get_hexline(fw,hx,&pos)) > 0) {
46211 + deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx->addr,hx->len,hx->chk);
46212 + ret = usb_cypress_writemem(udev,hx->addr,hx->data,hx->len);
46213
46214 - if (ret != hx.len) {
46215 + if (ret != hx->len) {
46216 err("error while transferring firmware "
46217 "(transferred size: %d, block size: %d)",
46218 - ret,hx.len);
46219 + ret,hx->len);
46220 ret = -EINVAL;
46221 break;
46222 }
46223 }
46224 if (ret < 0) {
46225 err("firmware download failed at %d with %d",pos,ret);
46226 + kfree(reset);
46227 + kfree(hx);
46228 return ret;
46229 }
46230
46231 if (ret == 0) {
46232 /* restart the CPU */
46233 - reset = 0;
46234 - if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1) != 1) {
46235 + reset[0] = 0;
46236 + if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1) != 1) {
46237 err("could not restart the USB controller CPU.");
46238 ret = -EINVAL;
46239 }
46240 } else
46241 ret = -EIO;
46242
46243 + kfree(reset);
46244 + kfree(hx);
46245 +
46246 return ret;
46247 }
46248 EXPORT_SYMBOL(usb_cypress_load_firmware);
46249 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
46250 index 2add8c5..c33b854 100644
46251 --- a/drivers/media/usb/dvb-usb/dw2102.c
46252 +++ b/drivers/media/usb/dvb-usb/dw2102.c
46253 @@ -118,7 +118,7 @@ struct su3000_state {
46254
46255 struct s6x0_state {
46256 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
46257 -};
46258 +} __no_const;
46259
46260 /* debug */
46261 static int dvb_usb_dw2102_debug;
46262 diff --git a/drivers/media/usb/dvb-usb/technisat-usb2.c b/drivers/media/usb/dvb-usb/technisat-usb2.c
46263 index 6b0b8b6b..4038398 100644
46264 --- a/drivers/media/usb/dvb-usb/technisat-usb2.c
46265 +++ b/drivers/media/usb/dvb-usb/technisat-usb2.c
46266 @@ -87,8 +87,11 @@ struct technisat_usb2_state {
46267 static int technisat_usb2_i2c_access(struct usb_device *udev,
46268 u8 device_addr, u8 *tx, u8 txlen, u8 *rx, u8 rxlen)
46269 {
46270 - u8 b[64];
46271 - int ret, actual_length;
46272 + u8 *b = kmalloc(64, GFP_KERNEL);
46273 + int ret, actual_length, error = 0;
46274 +
46275 + if (b == NULL)
46276 + return -ENOMEM;
46277
46278 deb_i2c("i2c-access: %02x, tx: ", device_addr);
46279 debug_dump(tx, txlen, deb_i2c);
46280 @@ -121,7 +124,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46281
46282 if (ret < 0) {
46283 err("i2c-error: out failed %02x = %d", device_addr, ret);
46284 - return -ENODEV;
46285 + error = -ENODEV;
46286 + goto out;
46287 }
46288
46289 ret = usb_bulk_msg(udev,
46290 @@ -129,7 +133,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46291 b, 64, &actual_length, 1000);
46292 if (ret < 0) {
46293 err("i2c-error: in failed %02x = %d", device_addr, ret);
46294 - return -ENODEV;
46295 + error = -ENODEV;
46296 + goto out;
46297 }
46298
46299 if (b[0] != I2C_STATUS_OK) {
46300 @@ -137,8 +142,10 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46301 /* handle tuner-i2c-nak */
46302 if (!(b[0] == I2C_STATUS_NAK &&
46303 device_addr == 0x60
46304 - /* && device_is_technisat_usb2 */))
46305 - return -ENODEV;
46306 + /* && device_is_technisat_usb2 */)) {
46307 + error = -ENODEV;
46308 + goto out;
46309 + }
46310 }
46311
46312 deb_i2c("status: %d, ", b[0]);
46313 @@ -152,7 +159,9 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46314
46315 deb_i2c("\n");
46316
46317 - return 0;
46318 +out:
46319 + kfree(b);
46320 + return error;
46321 }
46322
46323 static int technisat_usb2_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
46324 @@ -224,14 +233,16 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
46325 {
46326 int ret;
46327
46328 - u8 led[8] = {
46329 - red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
46330 - 0
46331 - };
46332 + u8 *led = kzalloc(8, GFP_KERNEL);
46333 +
46334 + if (led == NULL)
46335 + return -ENOMEM;
46336
46337 if (disable_led_control && state != TECH_LED_OFF)
46338 return 0;
46339
46340 + led[0] = red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST;
46341 +
46342 switch (state) {
46343 case TECH_LED_ON:
46344 led[1] = 0x82;
46345 @@ -263,16 +274,22 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
46346 red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
46347 USB_TYPE_VENDOR | USB_DIR_OUT,
46348 0, 0,
46349 - led, sizeof(led), 500);
46350 + led, 8, 500);
46351
46352 mutex_unlock(&d->i2c_mutex);
46353 +
46354 + kfree(led);
46355 +
46356 return ret;
46357 }
46358
46359 static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 green)
46360 {
46361 int ret;
46362 - u8 b = 0;
46363 + u8 *b = kzalloc(1, GFP_KERNEL);
46364 +
46365 + if (b == NULL)
46366 + return -ENOMEM;
46367
46368 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
46369 return -EAGAIN;
46370 @@ -281,10 +298,12 @@ static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 gre
46371 SET_LED_TIMER_DIVIDER_VENDOR_REQUEST,
46372 USB_TYPE_VENDOR | USB_DIR_OUT,
46373 (red << 8) | green, 0,
46374 - &b, 1, 500);
46375 + b, 1, 500);
46376
46377 mutex_unlock(&d->i2c_mutex);
46378
46379 + kfree(b);
46380 +
46381 return ret;
46382 }
46383
46384 @@ -328,7 +347,7 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46385 struct dvb_usb_device_description **desc, int *cold)
46386 {
46387 int ret;
46388 - u8 version[3];
46389 + u8 *version = kmalloc(3, GFP_KERNEL);
46390
46391 /* first select the interface */
46392 if (usb_set_interface(udev, 0, 1) != 0)
46393 @@ -338,11 +357,14 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46394
46395 *cold = 0; /* by default do not download a firmware - just in case something is wrong */
46396
46397 + if (version == NULL)
46398 + return 0;
46399 +
46400 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
46401 GET_VERSION_INFO_VENDOR_REQUEST,
46402 USB_TYPE_VENDOR | USB_DIR_IN,
46403 0, 0,
46404 - version, sizeof(version), 500);
46405 + version, 3, 500);
46406
46407 if (ret < 0)
46408 *cold = 1;
46409 @@ -351,6 +373,8 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46410 *cold = 0;
46411 }
46412
46413 + kfree(version);
46414 +
46415 return 0;
46416 }
46417
46418 @@ -591,10 +615,15 @@ static int technisat_usb2_frontend_attach(struct dvb_usb_adapter *a)
46419
46420 static int technisat_usb2_get_ir(struct dvb_usb_device *d)
46421 {
46422 - u8 buf[62], *b;
46423 + u8 *buf, *b;
46424 int ret;
46425 struct ir_raw_event ev;
46426
46427 + buf = kmalloc(62, GFP_KERNEL);
46428 +
46429 + if (buf == NULL)
46430 + return -ENOMEM;
46431 +
46432 buf[0] = GET_IR_DATA_VENDOR_REQUEST;
46433 buf[1] = 0x08;
46434 buf[2] = 0x8f;
46435 @@ -617,16 +646,20 @@ static int technisat_usb2_get_ir(struct dvb_usb_device *d)
46436 GET_IR_DATA_VENDOR_REQUEST,
46437 USB_TYPE_VENDOR | USB_DIR_IN,
46438 0x8080, 0,
46439 - buf, sizeof(buf), 500);
46440 + buf, 62, 500);
46441
46442 unlock:
46443 mutex_unlock(&d->i2c_mutex);
46444
46445 - if (ret < 0)
46446 + if (ret < 0) {
46447 + kfree(buf);
46448 return ret;
46449 + }
46450
46451 - if (ret == 1)
46452 + if (ret == 1) {
46453 + kfree(buf);
46454 return 0; /* no key pressed */
46455 + }
46456
46457 /* decoding */
46458 b = buf+1;
46459 @@ -653,6 +686,8 @@ unlock:
46460
46461 ir_raw_event_handle(d->rc_dev);
46462
46463 + kfree(buf);
46464 +
46465 return 1;
46466 }
46467
46468 diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46469 index cca6c2f..77b9a18 100644
46470 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46471 +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46472 @@ -328,7 +328,7 @@ struct v4l2_buffer32 {
46473 __u32 reserved;
46474 };
46475
46476 -static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
46477 +static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
46478 enum v4l2_memory memory)
46479 {
46480 void __user *up_pln;
46481 @@ -357,7 +357,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
46482 return 0;
46483 }
46484
46485 -static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
46486 +static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
46487 enum v4l2_memory memory)
46488 {
46489 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
46490 @@ -427,7 +427,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
46491 * by passing a very big num_planes value */
46492 uplane = compat_alloc_user_space(num_planes *
46493 sizeof(struct v4l2_plane));
46494 - kp->m.planes = uplane;
46495 + kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
46496
46497 while (--num_planes >= 0) {
46498 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
46499 @@ -498,7 +498,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
46500 if (num_planes == 0)
46501 return 0;
46502
46503 - uplane = kp->m.planes;
46504 + uplane = (struct v4l2_plane __force_user *)kp->m.planes;
46505 if (get_user(p, &up->m.planes))
46506 return -EFAULT;
46507 uplane32 = compat_ptr(p);
46508 @@ -562,7 +562,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
46509 get_user(kp->flags, &up->flags) ||
46510 copy_from_user(&kp->fmt, &up->fmt, sizeof(up->fmt)))
46511 return -EFAULT;
46512 - kp->base = compat_ptr(tmp);
46513 + kp->base = (void __force_kernel *)compat_ptr(tmp);
46514 return 0;
46515 }
46516
46517 @@ -667,7 +667,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
46518 n * sizeof(struct v4l2_ext_control32)))
46519 return -EFAULT;
46520 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
46521 - kp->controls = kcontrols;
46522 + kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
46523 while (--n >= 0) {
46524 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
46525 return -EFAULT;
46526 @@ -689,7 +689,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
46527 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
46528 {
46529 struct v4l2_ext_control32 __user *ucontrols;
46530 - struct v4l2_ext_control __user *kcontrols = kp->controls;
46531 + struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
46532 int n = kp->count;
46533 compat_caddr_t p;
46534
46535 @@ -783,7 +783,7 @@ static int put_v4l2_edid32(struct v4l2_edid *kp, struct v4l2_edid32 __user *up)
46536 put_user(kp->start_block, &up->start_block) ||
46537 put_user(kp->blocks, &up->blocks) ||
46538 put_user(tmp, &up->edid) ||
46539 - copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
46540 + copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
46541 return -EFAULT;
46542 return 0;
46543 }
46544 diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
46545 index 015f92a..59e311e 100644
46546 --- a/drivers/media/v4l2-core/v4l2-device.c
46547 +++ b/drivers/media/v4l2-core/v4l2-device.c
46548 @@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
46549 EXPORT_SYMBOL_GPL(v4l2_device_put);
46550
46551 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
46552 - atomic_t *instance)
46553 + atomic_unchecked_t *instance)
46554 {
46555 - int num = atomic_inc_return(instance) - 1;
46556 + int num = atomic_inc_return_unchecked(instance) - 1;
46557 int len = strlen(basename);
46558
46559 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
46560 diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
46561 index d15e167..337f374 100644
46562 --- a/drivers/media/v4l2-core/v4l2-ioctl.c
46563 +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
46564 @@ -2142,7 +2142,8 @@ struct v4l2_ioctl_info {
46565 struct file *file, void *fh, void *p);
46566 } u;
46567 void (*debug)(const void *arg, bool write_only);
46568 -};
46569 +} __do_const;
46570 +typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
46571
46572 /* This control needs a priority check */
46573 #define INFO_FL_PRIO (1 << 0)
46574 @@ -2326,7 +2327,7 @@ static long __video_do_ioctl(struct file *file,
46575 struct video_device *vfd = video_devdata(file);
46576 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
46577 bool write_only = false;
46578 - struct v4l2_ioctl_info default_info;
46579 + v4l2_ioctl_info_no_const default_info;
46580 const struct v4l2_ioctl_info *info;
46581 void *fh = file->private_data;
46582 struct v4l2_fh *vfh = NULL;
46583 @@ -2413,7 +2414,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46584 ret = -EINVAL;
46585 break;
46586 }
46587 - *user_ptr = (void __user *)buf->m.planes;
46588 + *user_ptr = (void __force_user *)buf->m.planes;
46589 *kernel_ptr = (void **)&buf->m.planes;
46590 *array_size = sizeof(struct v4l2_plane) * buf->length;
46591 ret = 1;
46592 @@ -2430,7 +2431,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46593 ret = -EINVAL;
46594 break;
46595 }
46596 - *user_ptr = (void __user *)edid->edid;
46597 + *user_ptr = (void __force_user *)edid->edid;
46598 *kernel_ptr = (void **)&edid->edid;
46599 *array_size = edid->blocks * 128;
46600 ret = 1;
46601 @@ -2448,7 +2449,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46602 ret = -EINVAL;
46603 break;
46604 }
46605 - *user_ptr = (void __user *)ctrls->controls;
46606 + *user_ptr = (void __force_user *)ctrls->controls;
46607 *kernel_ptr = (void **)&ctrls->controls;
46608 *array_size = sizeof(struct v4l2_ext_control)
46609 * ctrls->count;
46610 @@ -2549,7 +2550,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
46611 }
46612
46613 if (has_array_args) {
46614 - *kernel_ptr = (void __force *)user_ptr;
46615 + *kernel_ptr = (void __force_kernel *)user_ptr;
46616 if (copy_to_user(user_ptr, mbuf, array_size))
46617 err = -EFAULT;
46618 goto out_array_args;
46619 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
46620 index a896d94..a5d56b1 100644
46621 --- a/drivers/message/fusion/mptbase.c
46622 +++ b/drivers/message/fusion/mptbase.c
46623 @@ -6752,8 +6752,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
46624 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
46625 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
46626
46627 +#ifdef CONFIG_GRKERNSEC_HIDESYM
46628 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
46629 +#else
46630 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
46631 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
46632 +#endif
46633 +
46634 /*
46635 * Rounding UP to nearest 4-kB boundary here...
46636 */
46637 @@ -6766,7 +6771,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
46638 ioc->facts.GlobalCredits);
46639
46640 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
46641 +#ifdef CONFIG_GRKERNSEC_HIDESYM
46642 + NULL, NULL);
46643 +#else
46644 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
46645 +#endif
46646 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
46647 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
46648 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
46649 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
46650 index 0707fa2..70ca794 100644
46651 --- a/drivers/message/fusion/mptsas.c
46652 +++ b/drivers/message/fusion/mptsas.c
46653 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
46654 return 0;
46655 }
46656
46657 +static inline void
46658 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
46659 +{
46660 + if (phy_info->port_details) {
46661 + phy_info->port_details->rphy = rphy;
46662 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
46663 + ioc->name, rphy));
46664 + }
46665 +
46666 + if (rphy) {
46667 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
46668 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
46669 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
46670 + ioc->name, rphy, rphy->dev.release));
46671 + }
46672 +}
46673 +
46674 /* no mutex */
46675 static void
46676 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
46677 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
46678 return NULL;
46679 }
46680
46681 -static inline void
46682 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
46683 -{
46684 - if (phy_info->port_details) {
46685 - phy_info->port_details->rphy = rphy;
46686 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
46687 - ioc->name, rphy));
46688 - }
46689 -
46690 - if (rphy) {
46691 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
46692 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
46693 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
46694 - ioc->name, rphy, rphy->dev.release));
46695 - }
46696 -}
46697 -
46698 static inline struct sas_port *
46699 mptsas_get_port(struct mptsas_phyinfo *phy_info)
46700 {
46701 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
46702 index b7d87cd..3fb36da 100644
46703 --- a/drivers/message/i2o/i2o_proc.c
46704 +++ b/drivers/message/i2o/i2o_proc.c
46705 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
46706 "Array Controller Device"
46707 };
46708
46709 -static char *chtostr(char *tmp, u8 *chars, int n)
46710 -{
46711 - tmp[0] = 0;
46712 - return strncat(tmp, (char *)chars, n);
46713 -}
46714 -
46715 static int i2o_report_query_status(struct seq_file *seq, int block_status,
46716 char *group)
46717 {
46718 @@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
46719 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
46720 {
46721 struct i2o_controller *c = (struct i2o_controller *)seq->private;
46722 - static u32 work32[5];
46723 - static u8 *work8 = (u8 *) work32;
46724 - static u16 *work16 = (u16 *) work32;
46725 + u32 work32[5];
46726 + u8 *work8 = (u8 *) work32;
46727 + u16 *work16 = (u16 *) work32;
46728 int token;
46729 u32 hwcap;
46730
46731 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
46732 } *result;
46733
46734 i2o_exec_execute_ddm_table ddm_table;
46735 - char tmp[28 + 1];
46736
46737 result = kmalloc(sizeof(*result), GFP_KERNEL);
46738 if (!result)
46739 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
46740
46741 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
46742 seq_printf(seq, "%-#8x", ddm_table.module_id);
46743 - seq_printf(seq, "%-29s",
46744 - chtostr(tmp, ddm_table.module_name_version, 28));
46745 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
46746 seq_printf(seq, "%9d ", ddm_table.data_size);
46747 seq_printf(seq, "%8d", ddm_table.code_size);
46748
46749 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
46750
46751 i2o_driver_result_table *result;
46752 i2o_driver_store_table *dst;
46753 - char tmp[28 + 1];
46754
46755 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
46756 if (result == NULL)
46757 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
46758
46759 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
46760 seq_printf(seq, "%-#8x", dst->module_id);
46761 - seq_printf(seq, "%-29s",
46762 - chtostr(tmp, dst->module_name_version, 28));
46763 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
46764 + seq_printf(seq, "%-.28s", dst->module_name_version);
46765 + seq_printf(seq, "%-.8s", dst->date);
46766 seq_printf(seq, "%8d ", dst->module_size);
46767 seq_printf(seq, "%8d ", dst->mpb_size);
46768 seq_printf(seq, "0x%04x", dst->module_flags);
46769 @@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
46770 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
46771 {
46772 struct i2o_device *d = (struct i2o_device *)seq->private;
46773 - static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
46774 + u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
46775 // == (allow) 512d bytes (max)
46776 - static u16 *work16 = (u16 *) work32;
46777 + u16 *work16 = (u16 *) work32;
46778 int token;
46779 - char tmp[16 + 1];
46780
46781 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
46782
46783 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
46784 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
46785 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
46786 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
46787 - seq_printf(seq, "Vendor info : %s\n",
46788 - chtostr(tmp, (u8 *) (work32 + 2), 16));
46789 - seq_printf(seq, "Product info : %s\n",
46790 - chtostr(tmp, (u8 *) (work32 + 6), 16));
46791 - seq_printf(seq, "Description : %s\n",
46792 - chtostr(tmp, (u8 *) (work32 + 10), 16));
46793 - seq_printf(seq, "Product rev. : %s\n",
46794 - chtostr(tmp, (u8 *) (work32 + 14), 8));
46795 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
46796 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
46797 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
46798 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
46799
46800 seq_printf(seq, "Serial number : ");
46801 print_serial_number(seq, (u8 *) (work32 + 16),
46802 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
46803 u8 pad[256]; // allow up to 256 byte (max) serial number
46804 } result;
46805
46806 - char tmp[24 + 1];
46807 -
46808 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
46809
46810 if (token < 0) {
46811 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
46812 }
46813
46814 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
46815 - seq_printf(seq, "Module name : %s\n",
46816 - chtostr(tmp, result.module_name, 24));
46817 - seq_printf(seq, "Module revision : %s\n",
46818 - chtostr(tmp, result.module_rev, 8));
46819 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
46820 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
46821
46822 seq_printf(seq, "Serial number : ");
46823 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
46824 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
46825 u8 instance_number[4];
46826 } result;
46827
46828 - char tmp[64 + 1];
46829 -
46830 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
46831
46832 if (token < 0) {
46833 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
46834 return 0;
46835 }
46836
46837 - seq_printf(seq, "Device name : %s\n",
46838 - chtostr(tmp, result.device_name, 64));
46839 - seq_printf(seq, "Service name : %s\n",
46840 - chtostr(tmp, result.service_name, 64));
46841 - seq_printf(seq, "Physical name : %s\n",
46842 - chtostr(tmp, result.physical_location, 64));
46843 - seq_printf(seq, "Instance number : %s\n",
46844 - chtostr(tmp, result.instance_number, 4));
46845 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
46846 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
46847 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
46848 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
46849
46850 return 0;
46851 }
46852 @@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
46853 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
46854 {
46855 struct i2o_device *d = (struct i2o_device *)seq->private;
46856 - static u32 work32[12];
46857 - static u16 *work16 = (u16 *) work32;
46858 - static u8 *work8 = (u8 *) work32;
46859 + u32 work32[12];
46860 + u16 *work16 = (u16 *) work32;
46861 + u8 *work8 = (u8 *) work32;
46862 int token;
46863
46864 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
46865 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
46866 index 92752fb..a7494f6 100644
46867 --- a/drivers/message/i2o/iop.c
46868 +++ b/drivers/message/i2o/iop.c
46869 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
46870
46871 spin_lock_irqsave(&c->context_list_lock, flags);
46872
46873 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
46874 - atomic_inc(&c->context_list_counter);
46875 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
46876 + atomic_inc_unchecked(&c->context_list_counter);
46877
46878 - entry->context = atomic_read(&c->context_list_counter);
46879 + entry->context = atomic_read_unchecked(&c->context_list_counter);
46880
46881 list_add(&entry->list, &c->context_list);
46882
46883 @@ -1076,7 +1076,7 @@ struct i2o_controller *i2o_iop_alloc(void)
46884
46885 #if BITS_PER_LONG == 64
46886 spin_lock_init(&c->context_list_lock);
46887 - atomic_set(&c->context_list_counter, 0);
46888 + atomic_set_unchecked(&c->context_list_counter, 0);
46889 INIT_LIST_HEAD(&c->context_list);
46890 #endif
46891
46892 diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
46893 index b2c7e3b..85aa4764 100644
46894 --- a/drivers/mfd/ab8500-debugfs.c
46895 +++ b/drivers/mfd/ab8500-debugfs.c
46896 @@ -100,7 +100,7 @@ static int irq_last;
46897 static u32 *irq_count;
46898 static int num_irqs;
46899
46900 -static struct device_attribute **dev_attr;
46901 +static device_attribute_no_const **dev_attr;
46902 static char **event_name;
46903
46904 static u8 avg_sample = SAMPLE_16;
46905 diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
46906 index ecbe78e..b2ca870 100644
46907 --- a/drivers/mfd/max8925-i2c.c
46908 +++ b/drivers/mfd/max8925-i2c.c
46909 @@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
46910 const struct i2c_device_id *id)
46911 {
46912 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
46913 - static struct max8925_chip *chip;
46914 + struct max8925_chip *chip;
46915 struct device_node *node = client->dev.of_node;
46916
46917 if (node && !pdata) {
46918 diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
46919 index f243e75..322176c 100644
46920 --- a/drivers/mfd/tps65910.c
46921 +++ b/drivers/mfd/tps65910.c
46922 @@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
46923 struct tps65910_platform_data *pdata)
46924 {
46925 int ret = 0;
46926 - static struct regmap_irq_chip *tps6591x_irqs_chip;
46927 + struct regmap_irq_chip *tps6591x_irqs_chip;
46928
46929 if (!irq) {
46930 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
46931 diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
46932 index b1dabba..24a88f2 100644
46933 --- a/drivers/mfd/twl4030-irq.c
46934 +++ b/drivers/mfd/twl4030-irq.c
46935 @@ -34,6 +34,7 @@
46936 #include <linux/of.h>
46937 #include <linux/irqdomain.h>
46938 #include <linux/i2c/twl.h>
46939 +#include <asm/pgtable.h>
46940
46941 #include "twl-core.h"
46942
46943 @@ -725,10 +726,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
46944 * Install an irq handler for each of the SIH modules;
46945 * clone dummy irq_chip since PIH can't *do* anything
46946 */
46947 - twl4030_irq_chip = dummy_irq_chip;
46948 - twl4030_irq_chip.name = "twl4030";
46949 + pax_open_kernel();
46950 + memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
46951 + *(const char **)&twl4030_irq_chip.name = "twl4030";
46952
46953 - twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
46954 + *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
46955 + pax_close_kernel();
46956
46957 for (i = irq_base; i < irq_end; i++) {
46958 irq_set_chip_and_handler(i, &twl4030_irq_chip,
46959 diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
46960 index 464419b..64bae8d 100644
46961 --- a/drivers/misc/c2port/core.c
46962 +++ b/drivers/misc/c2port/core.c
46963 @@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
46964 goto error_idr_alloc;
46965 c2dev->id = ret;
46966
46967 - bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
46968 + pax_open_kernel();
46969 + *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
46970 + pax_close_kernel();
46971
46972 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
46973 "c2port%d", c2dev->id);
46974 diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
46975 index 3f2b625..945e179 100644
46976 --- a/drivers/misc/eeprom/sunxi_sid.c
46977 +++ b/drivers/misc/eeprom/sunxi_sid.c
46978 @@ -126,7 +126,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
46979
46980 platform_set_drvdata(pdev, sid_data);
46981
46982 - sid_bin_attr.size = sid_data->keysize;
46983 + pax_open_kernel();
46984 + *(size_t *)&sid_bin_attr.size = sid_data->keysize;
46985 + pax_close_kernel();
46986 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
46987 return -ENODEV;
46988
46989 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
46990 index 36f5d52..32311c3 100644
46991 --- a/drivers/misc/kgdbts.c
46992 +++ b/drivers/misc/kgdbts.c
46993 @@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
46994 char before[BREAK_INSTR_SIZE];
46995 char after[BREAK_INSTR_SIZE];
46996
46997 - probe_kernel_read(before, (char *)kgdbts_break_test,
46998 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
46999 BREAK_INSTR_SIZE);
47000 init_simple_test();
47001 ts.tst = plant_and_detach_test;
47002 @@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
47003 /* Activate test with initial breakpoint */
47004 if (!is_early)
47005 kgdb_breakpoint();
47006 - probe_kernel_read(after, (char *)kgdbts_break_test,
47007 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
47008 BREAK_INSTR_SIZE);
47009 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
47010 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
47011 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
47012 index 3ef4627..8d00486 100644
47013 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
47014 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
47015 @@ -497,7 +497,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
47016 * the lid is closed. This leads to interrupts as soon as a little move
47017 * is done.
47018 */
47019 - atomic_inc(&lis3->count);
47020 + atomic_inc_unchecked(&lis3->count);
47021
47022 wake_up_interruptible(&lis3->misc_wait);
47023 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
47024 @@ -583,7 +583,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
47025 if (lis3->pm_dev)
47026 pm_runtime_get_sync(lis3->pm_dev);
47027
47028 - atomic_set(&lis3->count, 0);
47029 + atomic_set_unchecked(&lis3->count, 0);
47030 return 0;
47031 }
47032
47033 @@ -615,7 +615,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
47034 add_wait_queue(&lis3->misc_wait, &wait);
47035 while (true) {
47036 set_current_state(TASK_INTERRUPTIBLE);
47037 - data = atomic_xchg(&lis3->count, 0);
47038 + data = atomic_xchg_unchecked(&lis3->count, 0);
47039 if (data)
47040 break;
47041
47042 @@ -656,7 +656,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
47043 struct lis3lv02d, miscdev);
47044
47045 poll_wait(file, &lis3->misc_wait, wait);
47046 - if (atomic_read(&lis3->count))
47047 + if (atomic_read_unchecked(&lis3->count))
47048 return POLLIN | POLLRDNORM;
47049 return 0;
47050 }
47051 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
47052 index c439c82..1f20f57 100644
47053 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
47054 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
47055 @@ -297,7 +297,7 @@ struct lis3lv02d {
47056 struct input_polled_dev *idev; /* input device */
47057 struct platform_device *pdev; /* platform device */
47058 struct regulator_bulk_data regulators[2];
47059 - atomic_t count; /* interrupt count after last read */
47060 + atomic_unchecked_t count; /* interrupt count after last read */
47061 union axis_conversion ac; /* hw -> logical axis */
47062 int mapped_btns[3];
47063
47064 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
47065 index 2f30bad..c4c13d0 100644
47066 --- a/drivers/misc/sgi-gru/gruhandles.c
47067 +++ b/drivers/misc/sgi-gru/gruhandles.c
47068 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
47069 unsigned long nsec;
47070
47071 nsec = CLKS2NSEC(clks);
47072 - atomic_long_inc(&mcs_op_statistics[op].count);
47073 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
47074 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
47075 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
47076 if (mcs_op_statistics[op].max < nsec)
47077 mcs_op_statistics[op].max = nsec;
47078 }
47079 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
47080 index 4f76359..cdfcb2e 100644
47081 --- a/drivers/misc/sgi-gru/gruprocfs.c
47082 +++ b/drivers/misc/sgi-gru/gruprocfs.c
47083 @@ -32,9 +32,9 @@
47084
47085 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
47086
47087 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
47088 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
47089 {
47090 - unsigned long val = atomic_long_read(v);
47091 + unsigned long val = atomic_long_read_unchecked(v);
47092
47093 seq_printf(s, "%16lu %s\n", val, id);
47094 }
47095 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
47096
47097 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
47098 for (op = 0; op < mcsop_last; op++) {
47099 - count = atomic_long_read(&mcs_op_statistics[op].count);
47100 - total = atomic_long_read(&mcs_op_statistics[op].total);
47101 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
47102 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
47103 max = mcs_op_statistics[op].max;
47104 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
47105 count ? total / count : 0, max);
47106 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
47107 index 5c3ce24..4915ccb 100644
47108 --- a/drivers/misc/sgi-gru/grutables.h
47109 +++ b/drivers/misc/sgi-gru/grutables.h
47110 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
47111 * GRU statistics.
47112 */
47113 struct gru_stats_s {
47114 - atomic_long_t vdata_alloc;
47115 - atomic_long_t vdata_free;
47116 - atomic_long_t gts_alloc;
47117 - atomic_long_t gts_free;
47118 - atomic_long_t gms_alloc;
47119 - atomic_long_t gms_free;
47120 - atomic_long_t gts_double_allocate;
47121 - atomic_long_t assign_context;
47122 - atomic_long_t assign_context_failed;
47123 - atomic_long_t free_context;
47124 - atomic_long_t load_user_context;
47125 - atomic_long_t load_kernel_context;
47126 - atomic_long_t lock_kernel_context;
47127 - atomic_long_t unlock_kernel_context;
47128 - atomic_long_t steal_user_context;
47129 - atomic_long_t steal_kernel_context;
47130 - atomic_long_t steal_context_failed;
47131 - atomic_long_t nopfn;
47132 - atomic_long_t asid_new;
47133 - atomic_long_t asid_next;
47134 - atomic_long_t asid_wrap;
47135 - atomic_long_t asid_reuse;
47136 - atomic_long_t intr;
47137 - atomic_long_t intr_cbr;
47138 - atomic_long_t intr_tfh;
47139 - atomic_long_t intr_spurious;
47140 - atomic_long_t intr_mm_lock_failed;
47141 - atomic_long_t call_os;
47142 - atomic_long_t call_os_wait_queue;
47143 - atomic_long_t user_flush_tlb;
47144 - atomic_long_t user_unload_context;
47145 - atomic_long_t user_exception;
47146 - atomic_long_t set_context_option;
47147 - atomic_long_t check_context_retarget_intr;
47148 - atomic_long_t check_context_unload;
47149 - atomic_long_t tlb_dropin;
47150 - atomic_long_t tlb_preload_page;
47151 - atomic_long_t tlb_dropin_fail_no_asid;
47152 - atomic_long_t tlb_dropin_fail_upm;
47153 - atomic_long_t tlb_dropin_fail_invalid;
47154 - atomic_long_t tlb_dropin_fail_range_active;
47155 - atomic_long_t tlb_dropin_fail_idle;
47156 - atomic_long_t tlb_dropin_fail_fmm;
47157 - atomic_long_t tlb_dropin_fail_no_exception;
47158 - atomic_long_t tfh_stale_on_fault;
47159 - atomic_long_t mmu_invalidate_range;
47160 - atomic_long_t mmu_invalidate_page;
47161 - atomic_long_t flush_tlb;
47162 - atomic_long_t flush_tlb_gru;
47163 - atomic_long_t flush_tlb_gru_tgh;
47164 - atomic_long_t flush_tlb_gru_zero_asid;
47165 + atomic_long_unchecked_t vdata_alloc;
47166 + atomic_long_unchecked_t vdata_free;
47167 + atomic_long_unchecked_t gts_alloc;
47168 + atomic_long_unchecked_t gts_free;
47169 + atomic_long_unchecked_t gms_alloc;
47170 + atomic_long_unchecked_t gms_free;
47171 + atomic_long_unchecked_t gts_double_allocate;
47172 + atomic_long_unchecked_t assign_context;
47173 + atomic_long_unchecked_t assign_context_failed;
47174 + atomic_long_unchecked_t free_context;
47175 + atomic_long_unchecked_t load_user_context;
47176 + atomic_long_unchecked_t load_kernel_context;
47177 + atomic_long_unchecked_t lock_kernel_context;
47178 + atomic_long_unchecked_t unlock_kernel_context;
47179 + atomic_long_unchecked_t steal_user_context;
47180 + atomic_long_unchecked_t steal_kernel_context;
47181 + atomic_long_unchecked_t steal_context_failed;
47182 + atomic_long_unchecked_t nopfn;
47183 + atomic_long_unchecked_t asid_new;
47184 + atomic_long_unchecked_t asid_next;
47185 + atomic_long_unchecked_t asid_wrap;
47186 + atomic_long_unchecked_t asid_reuse;
47187 + atomic_long_unchecked_t intr;
47188 + atomic_long_unchecked_t intr_cbr;
47189 + atomic_long_unchecked_t intr_tfh;
47190 + atomic_long_unchecked_t intr_spurious;
47191 + atomic_long_unchecked_t intr_mm_lock_failed;
47192 + atomic_long_unchecked_t call_os;
47193 + atomic_long_unchecked_t call_os_wait_queue;
47194 + atomic_long_unchecked_t user_flush_tlb;
47195 + atomic_long_unchecked_t user_unload_context;
47196 + atomic_long_unchecked_t user_exception;
47197 + atomic_long_unchecked_t set_context_option;
47198 + atomic_long_unchecked_t check_context_retarget_intr;
47199 + atomic_long_unchecked_t check_context_unload;
47200 + atomic_long_unchecked_t tlb_dropin;
47201 + atomic_long_unchecked_t tlb_preload_page;
47202 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
47203 + atomic_long_unchecked_t tlb_dropin_fail_upm;
47204 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
47205 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
47206 + atomic_long_unchecked_t tlb_dropin_fail_idle;
47207 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
47208 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
47209 + atomic_long_unchecked_t tfh_stale_on_fault;
47210 + atomic_long_unchecked_t mmu_invalidate_range;
47211 + atomic_long_unchecked_t mmu_invalidate_page;
47212 + atomic_long_unchecked_t flush_tlb;
47213 + atomic_long_unchecked_t flush_tlb_gru;
47214 + atomic_long_unchecked_t flush_tlb_gru_tgh;
47215 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
47216
47217 - atomic_long_t copy_gpa;
47218 - atomic_long_t read_gpa;
47219 + atomic_long_unchecked_t copy_gpa;
47220 + atomic_long_unchecked_t read_gpa;
47221
47222 - atomic_long_t mesq_receive;
47223 - atomic_long_t mesq_receive_none;
47224 - atomic_long_t mesq_send;
47225 - atomic_long_t mesq_send_failed;
47226 - atomic_long_t mesq_noop;
47227 - atomic_long_t mesq_send_unexpected_error;
47228 - atomic_long_t mesq_send_lb_overflow;
47229 - atomic_long_t mesq_send_qlimit_reached;
47230 - atomic_long_t mesq_send_amo_nacked;
47231 - atomic_long_t mesq_send_put_nacked;
47232 - atomic_long_t mesq_page_overflow;
47233 - atomic_long_t mesq_qf_locked;
47234 - atomic_long_t mesq_qf_noop_not_full;
47235 - atomic_long_t mesq_qf_switch_head_failed;
47236 - atomic_long_t mesq_qf_unexpected_error;
47237 - atomic_long_t mesq_noop_unexpected_error;
47238 - atomic_long_t mesq_noop_lb_overflow;
47239 - atomic_long_t mesq_noop_qlimit_reached;
47240 - atomic_long_t mesq_noop_amo_nacked;
47241 - atomic_long_t mesq_noop_put_nacked;
47242 - atomic_long_t mesq_noop_page_overflow;
47243 + atomic_long_unchecked_t mesq_receive;
47244 + atomic_long_unchecked_t mesq_receive_none;
47245 + atomic_long_unchecked_t mesq_send;
47246 + atomic_long_unchecked_t mesq_send_failed;
47247 + atomic_long_unchecked_t mesq_noop;
47248 + atomic_long_unchecked_t mesq_send_unexpected_error;
47249 + atomic_long_unchecked_t mesq_send_lb_overflow;
47250 + atomic_long_unchecked_t mesq_send_qlimit_reached;
47251 + atomic_long_unchecked_t mesq_send_amo_nacked;
47252 + atomic_long_unchecked_t mesq_send_put_nacked;
47253 + atomic_long_unchecked_t mesq_page_overflow;
47254 + atomic_long_unchecked_t mesq_qf_locked;
47255 + atomic_long_unchecked_t mesq_qf_noop_not_full;
47256 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
47257 + atomic_long_unchecked_t mesq_qf_unexpected_error;
47258 + atomic_long_unchecked_t mesq_noop_unexpected_error;
47259 + atomic_long_unchecked_t mesq_noop_lb_overflow;
47260 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
47261 + atomic_long_unchecked_t mesq_noop_amo_nacked;
47262 + atomic_long_unchecked_t mesq_noop_put_nacked;
47263 + atomic_long_unchecked_t mesq_noop_page_overflow;
47264
47265 };
47266
47267 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
47268 tghop_invalidate, mcsop_last};
47269
47270 struct mcs_op_statistic {
47271 - atomic_long_t count;
47272 - atomic_long_t total;
47273 + atomic_long_unchecked_t count;
47274 + atomic_long_unchecked_t total;
47275 unsigned long max;
47276 };
47277
47278 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
47279
47280 #define STAT(id) do { \
47281 if (gru_options & OPT_STATS) \
47282 - atomic_long_inc(&gru_stats.id); \
47283 + atomic_long_inc_unchecked(&gru_stats.id); \
47284 } while (0)
47285
47286 #ifdef CONFIG_SGI_GRU_DEBUG
47287 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
47288 index c862cd4..0d176fe 100644
47289 --- a/drivers/misc/sgi-xp/xp.h
47290 +++ b/drivers/misc/sgi-xp/xp.h
47291 @@ -288,7 +288,7 @@ struct xpc_interface {
47292 xpc_notify_func, void *);
47293 void (*received) (short, int, void *);
47294 enum xp_retval (*partid_to_nasids) (short, void *);
47295 -};
47296 +} __no_const;
47297
47298 extern struct xpc_interface xpc_interface;
47299
47300 diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
47301 index 01be66d..e3a0c7e 100644
47302 --- a/drivers/misc/sgi-xp/xp_main.c
47303 +++ b/drivers/misc/sgi-xp/xp_main.c
47304 @@ -78,13 +78,13 @@ xpc_notloaded(void)
47305 }
47306
47307 struct xpc_interface xpc_interface = {
47308 - (void (*)(int))xpc_notloaded,
47309 - (void (*)(int))xpc_notloaded,
47310 - (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
47311 - (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
47312 + .connect = (void (*)(int))xpc_notloaded,
47313 + .disconnect = (void (*)(int))xpc_notloaded,
47314 + .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
47315 + .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
47316 void *))xpc_notloaded,
47317 - (void (*)(short, int, void *))xpc_notloaded,
47318 - (enum xp_retval(*)(short, void *))xpc_notloaded
47319 + .received = (void (*)(short, int, void *))xpc_notloaded,
47320 + .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
47321 };
47322 EXPORT_SYMBOL_GPL(xpc_interface);
47323
47324 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
47325 index b94d5f7..7f494c5 100644
47326 --- a/drivers/misc/sgi-xp/xpc.h
47327 +++ b/drivers/misc/sgi-xp/xpc.h
47328 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
47329 void (*received_payload) (struct xpc_channel *, void *);
47330 void (*notify_senders_of_disconnect) (struct xpc_channel *);
47331 };
47332 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
47333
47334 /* struct xpc_partition act_state values (for XPC HB) */
47335
47336 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
47337 /* found in xpc_main.c */
47338 extern struct device *xpc_part;
47339 extern struct device *xpc_chan;
47340 -extern struct xpc_arch_operations xpc_arch_ops;
47341 +extern xpc_arch_operations_no_const xpc_arch_ops;
47342 extern int xpc_disengage_timelimit;
47343 extern int xpc_disengage_timedout;
47344 extern int xpc_activate_IRQ_rcvd;
47345 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
47346 index 82dc574..8539ab2 100644
47347 --- a/drivers/misc/sgi-xp/xpc_main.c
47348 +++ b/drivers/misc/sgi-xp/xpc_main.c
47349 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
47350 .notifier_call = xpc_system_die,
47351 };
47352
47353 -struct xpc_arch_operations xpc_arch_ops;
47354 +xpc_arch_operations_no_const xpc_arch_ops;
47355
47356 /*
47357 * Timer function to enforce the timelimit on the partition disengage.
47358 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
47359
47360 if (((die_args->trapnr == X86_TRAP_MF) ||
47361 (die_args->trapnr == X86_TRAP_XF)) &&
47362 - !user_mode_vm(die_args->regs))
47363 + !user_mode(die_args->regs))
47364 xpc_die_deactivate();
47365
47366 break;
47367 diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
47368 index ede41f0..744fbd9 100644
47369 --- a/drivers/mmc/card/block.c
47370 +++ b/drivers/mmc/card/block.c
47371 @@ -574,7 +574,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
47372 if (idata->ic.postsleep_min_us)
47373 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
47374
47375 - if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
47376 + if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
47377 err = -EFAULT;
47378 goto cmd_rel_host;
47379 }
47380 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
47381 index f51b5ba..86614a7 100644
47382 --- a/drivers/mmc/core/mmc_ops.c
47383 +++ b/drivers/mmc/core/mmc_ops.c
47384 @@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
47385 void *data_buf;
47386 int is_on_stack;
47387
47388 - is_on_stack = object_is_on_stack(buf);
47389 + is_on_stack = object_starts_on_stack(buf);
47390 if (is_on_stack) {
47391 /*
47392 * dma onto stack is unsafe/nonportable, but callers to this
47393 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
47394 index 08fd956..370487a 100644
47395 --- a/drivers/mmc/host/dw_mmc.h
47396 +++ b/drivers/mmc/host/dw_mmc.h
47397 @@ -262,5 +262,5 @@ struct dw_mci_drv_data {
47398 int (*parse_dt)(struct dw_mci *host);
47399 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
47400 struct dw_mci_tuning_data *tuning_data);
47401 -};
47402 +} __do_const;
47403 #endif /* _DW_MMC_H_ */
47404 diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
47405 index e4d4707..28262a3 100644
47406 --- a/drivers/mmc/host/mmci.c
47407 +++ b/drivers/mmc/host/mmci.c
47408 @@ -1612,7 +1612,9 @@ static int mmci_probe(struct amba_device *dev,
47409 mmc->caps |= MMC_CAP_CMD23;
47410
47411 if (variant->busy_detect) {
47412 - mmci_ops.card_busy = mmci_card_busy;
47413 + pax_open_kernel();
47414 + *(void **)&mmci_ops.card_busy = mmci_card_busy;
47415 + pax_close_kernel();
47416 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
47417 mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY;
47418 mmc->max_busy_timeout = 0;
47419 diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
47420 index ccec0e3..199f9ce 100644
47421 --- a/drivers/mmc/host/sdhci-esdhc-imx.c
47422 +++ b/drivers/mmc/host/sdhci-esdhc-imx.c
47423 @@ -1034,9 +1034,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
47424 host->mmc->caps |= MMC_CAP_1_8V_DDR;
47425 }
47426
47427 - if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
47428 - sdhci_esdhc_ops.platform_execute_tuning =
47429 + if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
47430 + pax_open_kernel();
47431 + *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
47432 esdhc_executing_tuning;
47433 + pax_close_kernel();
47434 + }
47435
47436 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
47437 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
47438 diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
47439 index 1e47903..7683916 100644
47440 --- a/drivers/mmc/host/sdhci-s3c.c
47441 +++ b/drivers/mmc/host/sdhci-s3c.c
47442 @@ -584,9 +584,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
47443 * we can use overriding functions instead of default.
47444 */
47445 if (sc->no_divider) {
47446 - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
47447 - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
47448 - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
47449 + pax_open_kernel();
47450 + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
47451 + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
47452 + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
47453 + pax_close_kernel();
47454 }
47455
47456 /* It supports additional host capabilities if needed */
47457 diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
47458 index 423666b..81ff5eb 100644
47459 --- a/drivers/mtd/chips/cfi_cmdset_0020.c
47460 +++ b/drivers/mtd/chips/cfi_cmdset_0020.c
47461 @@ -666,7 +666,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
47462 size_t totlen = 0, thislen;
47463 int ret = 0;
47464 size_t buflen = 0;
47465 - static char *buffer;
47466 + char *buffer;
47467
47468 if (!ECCBUF_SIZE) {
47469 /* We should fall back to a general writev implementation.
47470 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
47471 index 0b071a3..8ec3d5b 100644
47472 --- a/drivers/mtd/nand/denali.c
47473 +++ b/drivers/mtd/nand/denali.c
47474 @@ -24,6 +24,7 @@
47475 #include <linux/slab.h>
47476 #include <linux/mtd/mtd.h>
47477 #include <linux/module.h>
47478 +#include <linux/slab.h>
47479
47480 #include "denali.h"
47481
47482 diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47483 index 959cb9b..8520fe5 100644
47484 --- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47485 +++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47486 @@ -386,7 +386,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
47487
47488 /* first try to map the upper buffer directly */
47489 if (virt_addr_valid(this->upper_buf) &&
47490 - !object_is_on_stack(this->upper_buf)) {
47491 + !object_starts_on_stack(this->upper_buf)) {
47492 sg_init_one(sgl, this->upper_buf, this->upper_len);
47493 ret = dma_map_sg(this->dev, sgl, 1, dr);
47494 if (ret == 0)
47495 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
47496 index 51b9d6a..52af9a7 100644
47497 --- a/drivers/mtd/nftlmount.c
47498 +++ b/drivers/mtd/nftlmount.c
47499 @@ -24,6 +24,7 @@
47500 #include <asm/errno.h>
47501 #include <linux/delay.h>
47502 #include <linux/slab.h>
47503 +#include <linux/sched.h>
47504 #include <linux/mtd/mtd.h>
47505 #include <linux/mtd/nand.h>
47506 #include <linux/mtd/nftl.h>
47507 diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
47508 index cf49c22..971b133 100644
47509 --- a/drivers/mtd/sm_ftl.c
47510 +++ b/drivers/mtd/sm_ftl.c
47511 @@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
47512 #define SM_CIS_VENDOR_OFFSET 0x59
47513 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
47514 {
47515 - struct attribute_group *attr_group;
47516 + attribute_group_no_const *attr_group;
47517 struct attribute **attributes;
47518 struct sm_sysfs_attribute *vendor_attribute;
47519 char *vendor;
47520 diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
47521 index d163e11..f517018 100644
47522 --- a/drivers/net/bonding/bond_netlink.c
47523 +++ b/drivers/net/bonding/bond_netlink.c
47524 @@ -548,7 +548,7 @@ nla_put_failure:
47525 return -EMSGSIZE;
47526 }
47527
47528 -struct rtnl_link_ops bond_link_ops __read_mostly = {
47529 +struct rtnl_link_ops bond_link_ops = {
47530 .kind = "bond",
47531 .priv_size = sizeof(struct bonding),
47532 .setup = bond_setup,
47533 diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
47534 index 4168822..f38eeddf 100644
47535 --- a/drivers/net/can/Kconfig
47536 +++ b/drivers/net/can/Kconfig
47537 @@ -98,7 +98,7 @@ config CAN_JANZ_ICAN3
47538
47539 config CAN_FLEXCAN
47540 tristate "Support for Freescale FLEXCAN based chips"
47541 - depends on ARM || PPC
47542 + depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
47543 ---help---
47544 Say Y here if you want to support for Freescale FlexCAN.
47545
47546 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
47547 index 1d162cc..b546a75 100644
47548 --- a/drivers/net/ethernet/8390/ax88796.c
47549 +++ b/drivers/net/ethernet/8390/ax88796.c
47550 @@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
47551 if (ax->plat->reg_offsets)
47552 ei_local->reg_offset = ax->plat->reg_offsets;
47553 else {
47554 + resource_size_t _mem_size = mem_size;
47555 + do_div(_mem_size, 0x18);
47556 ei_local->reg_offset = ax->reg_offsets;
47557 for (ret = 0; ret < 0x18; ret++)
47558 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
47559 + ax->reg_offsets[ret] = _mem_size * ret;
47560 }
47561
47562 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
47563 diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
47564 index 7330681..7e9e463 100644
47565 --- a/drivers/net/ethernet/altera/altera_tse_main.c
47566 +++ b/drivers/net/ethernet/altera/altera_tse_main.c
47567 @@ -1182,7 +1182,7 @@ static int tse_shutdown(struct net_device *dev)
47568 return 0;
47569 }
47570
47571 -static struct net_device_ops altera_tse_netdev_ops = {
47572 +static net_device_ops_no_const altera_tse_netdev_ops __read_only = {
47573 .ndo_open = tse_open,
47574 .ndo_stop = tse_shutdown,
47575 .ndo_start_xmit = tse_start_xmit,
47576 @@ -1439,11 +1439,13 @@ static int altera_tse_probe(struct platform_device *pdev)
47577 ndev->netdev_ops = &altera_tse_netdev_ops;
47578 altera_tse_set_ethtool_ops(ndev);
47579
47580 + pax_open_kernel();
47581 altera_tse_netdev_ops.ndo_set_rx_mode = tse_set_rx_mode;
47582
47583 if (priv->hash_filter)
47584 altera_tse_netdev_ops.ndo_set_rx_mode =
47585 tse_set_rx_mode_hashfilter;
47586 + pax_close_kernel();
47587
47588 /* Scatter/gather IO is not supported,
47589 * so it is turned off
47590 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-common.h b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47591 index cc25a3a..c8d72d3 100644
47592 --- a/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47593 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47594 @@ -1083,14 +1083,14 @@ do { \
47595 * operations, everything works on mask values.
47596 */
47597 #define XMDIO_READ(_pdata, _mmd, _reg) \
47598 - ((_pdata)->hw_if.read_mmd_regs((_pdata), 0, \
47599 + ((_pdata)->hw_if->read_mmd_regs((_pdata), 0, \
47600 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff)))
47601
47602 #define XMDIO_READ_BITS(_pdata, _mmd, _reg, _mask) \
47603 (XMDIO_READ((_pdata), _mmd, _reg) & _mask)
47604
47605 #define XMDIO_WRITE(_pdata, _mmd, _reg, _val) \
47606 - ((_pdata)->hw_if.write_mmd_regs((_pdata), 0, \
47607 + ((_pdata)->hw_if->write_mmd_regs((_pdata), 0, \
47608 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff), (_val)))
47609
47610 #define XMDIO_WRITE_BITS(_pdata, _mmd, _reg, _mask, _val) \
47611 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c b/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47612 index 7d6a49b..e6d403b 100644
47613 --- a/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47614 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47615 @@ -188,7 +188,7 @@ static int xgbe_dcb_ieee_setets(struct net_device *netdev,
47616
47617 memcpy(pdata->ets, ets, sizeof(*pdata->ets));
47618
47619 - pdata->hw_if.config_dcb_tc(pdata);
47620 + pdata->hw_if->config_dcb_tc(pdata);
47621
47622 return 0;
47623 }
47624 @@ -227,7 +227,7 @@ static int xgbe_dcb_ieee_setpfc(struct net_device *netdev,
47625
47626 memcpy(pdata->pfc, pfc, sizeof(*pdata->pfc));
47627
47628 - pdata->hw_if.config_dcb_pfc(pdata);
47629 + pdata->hw_if->config_dcb_pfc(pdata);
47630
47631 return 0;
47632 }
47633 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47634 index 1c5d62e..8e14d54 100644
47635 --- a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47636 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47637 @@ -236,7 +236,7 @@ err_ring:
47638
47639 static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
47640 {
47641 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47642 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47643 struct xgbe_channel *channel;
47644 struct xgbe_ring *ring;
47645 struct xgbe_ring_data *rdata;
47646 @@ -277,7 +277,7 @@ static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
47647
47648 static void xgbe_wrapper_rx_descriptor_init(struct xgbe_prv_data *pdata)
47649 {
47650 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47651 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47652 struct xgbe_channel *channel;
47653 struct xgbe_ring *ring;
47654 struct xgbe_ring_desc *rdesc;
47655 @@ -506,7 +506,7 @@ err_out:
47656 static void xgbe_realloc_skb(struct xgbe_channel *channel)
47657 {
47658 struct xgbe_prv_data *pdata = channel->pdata;
47659 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47660 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47661 struct xgbe_ring *ring = channel->rx_ring;
47662 struct xgbe_ring_data *rdata;
47663 struct sk_buff *skb = NULL;
47664 @@ -550,17 +550,12 @@ static void xgbe_realloc_skb(struct xgbe_channel *channel)
47665 DBGPR("<--xgbe_realloc_skb\n");
47666 }
47667
47668 -void xgbe_init_function_ptrs_desc(struct xgbe_desc_if *desc_if)
47669 -{
47670 - DBGPR("-->xgbe_init_function_ptrs_desc\n");
47671 -
47672 - desc_if->alloc_ring_resources = xgbe_alloc_ring_resources;
47673 - desc_if->free_ring_resources = xgbe_free_ring_resources;
47674 - desc_if->map_tx_skb = xgbe_map_tx_skb;
47675 - desc_if->realloc_skb = xgbe_realloc_skb;
47676 - desc_if->unmap_skb = xgbe_unmap_skb;
47677 - desc_if->wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init;
47678 - desc_if->wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init;
47679 -
47680 - DBGPR("<--xgbe_init_function_ptrs_desc\n");
47681 -}
47682 +const struct xgbe_desc_if default_xgbe_desc_if = {
47683 + .alloc_ring_resources = xgbe_alloc_ring_resources,
47684 + .free_ring_resources = xgbe_free_ring_resources,
47685 + .map_tx_skb = xgbe_map_tx_skb,
47686 + .realloc_skb = xgbe_realloc_skb,
47687 + .unmap_skb = xgbe_unmap_skb,
47688 + .wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init,
47689 + .wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init,
47690 +};
47691 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
47692 index ea27383..faa8936 100644
47693 --- a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
47694 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
47695 @@ -2463,7 +2463,7 @@ static void xgbe_powerdown_rx(struct xgbe_prv_data *pdata)
47696
47697 static int xgbe_init(struct xgbe_prv_data *pdata)
47698 {
47699 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47700 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47701 int ret;
47702
47703 DBGPR("-->xgbe_init\n");
47704 @@ -2525,101 +2525,96 @@ static int xgbe_init(struct xgbe_prv_data *pdata)
47705 return 0;
47706 }
47707
47708 -void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if)
47709 -{
47710 - DBGPR("-->xgbe_init_function_ptrs\n");
47711 -
47712 - hw_if->tx_complete = xgbe_tx_complete;
47713 -
47714 - hw_if->set_promiscuous_mode = xgbe_set_promiscuous_mode;
47715 - hw_if->set_all_multicast_mode = xgbe_set_all_multicast_mode;
47716 - hw_if->add_mac_addresses = xgbe_add_mac_addresses;
47717 - hw_if->set_mac_address = xgbe_set_mac_address;
47718 -
47719 - hw_if->enable_rx_csum = xgbe_enable_rx_csum;
47720 - hw_if->disable_rx_csum = xgbe_disable_rx_csum;
47721 -
47722 - hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping;
47723 - hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping;
47724 - hw_if->enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering;
47725 - hw_if->disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering;
47726 - hw_if->update_vlan_hash_table = xgbe_update_vlan_hash_table;
47727 -
47728 - hw_if->read_mmd_regs = xgbe_read_mmd_regs;
47729 - hw_if->write_mmd_regs = xgbe_write_mmd_regs;
47730 -
47731 - hw_if->set_gmii_speed = xgbe_set_gmii_speed;
47732 - hw_if->set_gmii_2500_speed = xgbe_set_gmii_2500_speed;
47733 - hw_if->set_xgmii_speed = xgbe_set_xgmii_speed;
47734 -
47735 - hw_if->enable_tx = xgbe_enable_tx;
47736 - hw_if->disable_tx = xgbe_disable_tx;
47737 - hw_if->enable_rx = xgbe_enable_rx;
47738 - hw_if->disable_rx = xgbe_disable_rx;
47739 -
47740 - hw_if->powerup_tx = xgbe_powerup_tx;
47741 - hw_if->powerdown_tx = xgbe_powerdown_tx;
47742 - hw_if->powerup_rx = xgbe_powerup_rx;
47743 - hw_if->powerdown_rx = xgbe_powerdown_rx;
47744 -
47745 - hw_if->pre_xmit = xgbe_pre_xmit;
47746 - hw_if->dev_read = xgbe_dev_read;
47747 - hw_if->enable_int = xgbe_enable_int;
47748 - hw_if->disable_int = xgbe_disable_int;
47749 - hw_if->init = xgbe_init;
47750 - hw_if->exit = xgbe_exit;
47751 +const struct xgbe_hw_if default_xgbe_hw_if = {
47752 + .tx_complete = xgbe_tx_complete,
47753 +
47754 + .set_promiscuous_mode = xgbe_set_promiscuous_mode,
47755 + .set_all_multicast_mode = xgbe_set_all_multicast_mode,
47756 + .add_mac_addresses = xgbe_add_mac_addresses,
47757 + .set_mac_address = xgbe_set_mac_address,
47758 +
47759 + .enable_rx_csum = xgbe_enable_rx_csum,
47760 + .disable_rx_csum = xgbe_disable_rx_csum,
47761 +
47762 + .enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping,
47763 + .disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping,
47764 + .enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering,
47765 + .disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering,
47766 + .update_vlan_hash_table = xgbe_update_vlan_hash_table,
47767 +
47768 + .read_mmd_regs = xgbe_read_mmd_regs,
47769 + .write_mmd_regs = xgbe_write_mmd_regs,
47770 +
47771 + .set_gmii_speed = xgbe_set_gmii_speed,
47772 + .set_gmii_2500_speed = xgbe_set_gmii_2500_speed,
47773 + .set_xgmii_speed = xgbe_set_xgmii_speed,
47774 +
47775 + .enable_tx = xgbe_enable_tx,
47776 + .disable_tx = xgbe_disable_tx,
47777 + .enable_rx = xgbe_enable_rx,
47778 + .disable_rx = xgbe_disable_rx,
47779 +
47780 + .powerup_tx = xgbe_powerup_tx,
47781 + .powerdown_tx = xgbe_powerdown_tx,
47782 + .powerup_rx = xgbe_powerup_rx,
47783 + .powerdown_rx = xgbe_powerdown_rx,
47784 +
47785 + .pre_xmit = xgbe_pre_xmit,
47786 + .dev_read = xgbe_dev_read,
47787 + .enable_int = xgbe_enable_int,
47788 + .disable_int = xgbe_disable_int,
47789 + .init = xgbe_init,
47790 + .exit = xgbe_exit,
47791
47792 /* Descriptor related Sequences have to be initialized here */
47793 - hw_if->tx_desc_init = xgbe_tx_desc_init;
47794 - hw_if->rx_desc_init = xgbe_rx_desc_init;
47795 - hw_if->tx_desc_reset = xgbe_tx_desc_reset;
47796 - hw_if->rx_desc_reset = xgbe_rx_desc_reset;
47797 - hw_if->is_last_desc = xgbe_is_last_desc;
47798 - hw_if->is_context_desc = xgbe_is_context_desc;
47799 + .tx_desc_init = xgbe_tx_desc_init,
47800 + .rx_desc_init = xgbe_rx_desc_init,
47801 + .tx_desc_reset = xgbe_tx_desc_reset,
47802 + .rx_desc_reset = xgbe_rx_desc_reset,
47803 + .is_last_desc = xgbe_is_last_desc,
47804 + .is_context_desc = xgbe_is_context_desc,
47805
47806 /* For FLOW ctrl */
47807 - hw_if->config_tx_flow_control = xgbe_config_tx_flow_control;
47808 - hw_if->config_rx_flow_control = xgbe_config_rx_flow_control;
47809 + .config_tx_flow_control = xgbe_config_tx_flow_control,
47810 + .config_rx_flow_control = xgbe_config_rx_flow_control,
47811
47812 /* For RX coalescing */
47813 - hw_if->config_rx_coalesce = xgbe_config_rx_coalesce;
47814 - hw_if->config_tx_coalesce = xgbe_config_tx_coalesce;
47815 - hw_if->usec_to_riwt = xgbe_usec_to_riwt;
47816 - hw_if->riwt_to_usec = xgbe_riwt_to_usec;
47817 + .config_rx_coalesce = xgbe_config_rx_coalesce,
47818 + .config_tx_coalesce = xgbe_config_tx_coalesce,
47819 + .usec_to_riwt = xgbe_usec_to_riwt,
47820 + .riwt_to_usec = xgbe_riwt_to_usec,
47821
47822 /* For RX and TX threshold config */
47823 - hw_if->config_rx_threshold = xgbe_config_rx_threshold;
47824 - hw_if->config_tx_threshold = xgbe_config_tx_threshold;
47825 + .config_rx_threshold = xgbe_config_rx_threshold,
47826 + .config_tx_threshold = xgbe_config_tx_threshold,
47827
47828 /* For RX and TX Store and Forward Mode config */
47829 - hw_if->config_rsf_mode = xgbe_config_rsf_mode;
47830 - hw_if->config_tsf_mode = xgbe_config_tsf_mode;
47831 + .config_rsf_mode = xgbe_config_rsf_mode,
47832 + .config_tsf_mode = xgbe_config_tsf_mode,
47833
47834 /* For TX DMA Operating on Second Frame config */
47835 - hw_if->config_osp_mode = xgbe_config_osp_mode;
47836 + .config_osp_mode = xgbe_config_osp_mode,
47837
47838 /* For RX and TX PBL config */
47839 - hw_if->config_rx_pbl_val = xgbe_config_rx_pbl_val;
47840 - hw_if->get_rx_pbl_val = xgbe_get_rx_pbl_val;
47841 - hw_if->config_tx_pbl_val = xgbe_config_tx_pbl_val;
47842 - hw_if->get_tx_pbl_val = xgbe_get_tx_pbl_val;
47843 - hw_if->config_pblx8 = xgbe_config_pblx8;
47844 + .config_rx_pbl_val = xgbe_config_rx_pbl_val,
47845 + .get_rx_pbl_val = xgbe_get_rx_pbl_val,
47846 + .config_tx_pbl_val = xgbe_config_tx_pbl_val,
47847 + .get_tx_pbl_val = xgbe_get_tx_pbl_val,
47848 + .config_pblx8 = xgbe_config_pblx8,
47849
47850 /* For MMC statistics support */
47851 - hw_if->tx_mmc_int = xgbe_tx_mmc_int;
47852 - hw_if->rx_mmc_int = xgbe_rx_mmc_int;
47853 - hw_if->read_mmc_stats = xgbe_read_mmc_stats;
47854 + .tx_mmc_int = xgbe_tx_mmc_int,
47855 + .rx_mmc_int = xgbe_rx_mmc_int,
47856 + .read_mmc_stats = xgbe_read_mmc_stats,
47857
47858 /* For PTP config */
47859 - hw_if->config_tstamp = xgbe_config_tstamp;
47860 - hw_if->update_tstamp_addend = xgbe_update_tstamp_addend;
47861 - hw_if->set_tstamp_time = xgbe_set_tstamp_time;
47862 - hw_if->get_tstamp_time = xgbe_get_tstamp_time;
47863 - hw_if->get_tx_tstamp = xgbe_get_tx_tstamp;
47864 + .config_tstamp = xgbe_config_tstamp,
47865 + .update_tstamp_addend = xgbe_update_tstamp_addend,
47866 + .set_tstamp_time = xgbe_set_tstamp_time,
47867 + .get_tstamp_time = xgbe_get_tstamp_time,
47868 + .get_tx_tstamp = xgbe_get_tx_tstamp,
47869
47870 /* For Data Center Bridging config */
47871 - hw_if->config_dcb_tc = xgbe_config_dcb_tc;
47872 - hw_if->config_dcb_pfc = xgbe_config_dcb_pfc;
47873 -
47874 - DBGPR("<--xgbe_init_function_ptrs\n");
47875 -}
47876 + .config_dcb_tc = xgbe_config_dcb_tc,
47877 + .config_dcb_pfc = xgbe_config_dcb_pfc,
47878 +};
47879 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
47880 index b26d758..b0d1c3b 100644
47881 --- a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
47882 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
47883 @@ -155,7 +155,7 @@ static int xgbe_calc_rx_buf_size(struct net_device *netdev, unsigned int mtu)
47884
47885 static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
47886 {
47887 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47888 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47889 struct xgbe_channel *channel;
47890 enum xgbe_int int_id;
47891 unsigned int i;
47892 @@ -177,7 +177,7 @@ static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
47893
47894 static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
47895 {
47896 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47897 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47898 struct xgbe_channel *channel;
47899 enum xgbe_int int_id;
47900 unsigned int i;
47901 @@ -200,7 +200,7 @@ static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
47902 static irqreturn_t xgbe_isr(int irq, void *data)
47903 {
47904 struct xgbe_prv_data *pdata = data;
47905 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47906 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47907 struct xgbe_channel *channel;
47908 unsigned int dma_isr, dma_ch_isr;
47909 unsigned int mac_isr, mac_tssr;
47910 @@ -447,7 +447,7 @@ static void xgbe_napi_disable(struct xgbe_prv_data *pdata, unsigned int del)
47911
47912 void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
47913 {
47914 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47915 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47916
47917 DBGPR("-->xgbe_init_tx_coalesce\n");
47918
47919 @@ -461,7 +461,7 @@ void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
47920
47921 void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
47922 {
47923 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47924 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47925
47926 DBGPR("-->xgbe_init_rx_coalesce\n");
47927
47928 @@ -475,7 +475,7 @@ void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
47929
47930 static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
47931 {
47932 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47933 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47934 struct xgbe_channel *channel;
47935 struct xgbe_ring *ring;
47936 struct xgbe_ring_data *rdata;
47937 @@ -500,7 +500,7 @@ static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
47938
47939 static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
47940 {
47941 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47942 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47943 struct xgbe_channel *channel;
47944 struct xgbe_ring *ring;
47945 struct xgbe_ring_data *rdata;
47946 @@ -526,7 +526,7 @@ static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
47947 static void xgbe_adjust_link(struct net_device *netdev)
47948 {
47949 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47950 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47951 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47952 struct phy_device *phydev = pdata->phydev;
47953 int new_state = 0;
47954
47955 @@ -634,7 +634,7 @@ static void xgbe_phy_exit(struct xgbe_prv_data *pdata)
47956 int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
47957 {
47958 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47959 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47960 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47961 unsigned long flags;
47962
47963 DBGPR("-->xgbe_powerdown\n");
47964 @@ -672,7 +672,7 @@ int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
47965 int xgbe_powerup(struct net_device *netdev, unsigned int caller)
47966 {
47967 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47968 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47969 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47970 unsigned long flags;
47971
47972 DBGPR("-->xgbe_powerup\n");
47973 @@ -709,7 +709,7 @@ int xgbe_powerup(struct net_device *netdev, unsigned int caller)
47974
47975 static int xgbe_start(struct xgbe_prv_data *pdata)
47976 {
47977 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47978 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47979 struct net_device *netdev = pdata->netdev;
47980
47981 DBGPR("-->xgbe_start\n");
47982 @@ -735,7 +735,7 @@ static int xgbe_start(struct xgbe_prv_data *pdata)
47983
47984 static void xgbe_stop(struct xgbe_prv_data *pdata)
47985 {
47986 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47987 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47988 struct net_device *netdev = pdata->netdev;
47989
47990 DBGPR("-->xgbe_stop\n");
47991 @@ -755,7 +755,7 @@ static void xgbe_stop(struct xgbe_prv_data *pdata)
47992
47993 static void xgbe_restart_dev(struct xgbe_prv_data *pdata, unsigned int reset)
47994 {
47995 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47996 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47997
47998 DBGPR("-->xgbe_restart_dev\n");
47999
48000 @@ -952,7 +952,7 @@ static int xgbe_set_hwtstamp_settings(struct xgbe_prv_data *pdata,
48001 return -ERANGE;
48002 }
48003
48004 - pdata->hw_if.config_tstamp(pdata, mac_tscr);
48005 + pdata->hw_if->config_tstamp(pdata, mac_tscr);
48006
48007 memcpy(&pdata->tstamp_config, &config, sizeof(config));
48008
48009 @@ -1090,8 +1090,8 @@ static void xgbe_packet_info(struct xgbe_prv_data *pdata,
48010 static int xgbe_open(struct net_device *netdev)
48011 {
48012 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48013 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48014 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48015 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48016 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48017 int ret;
48018
48019 DBGPR("-->xgbe_open\n");
48020 @@ -1171,8 +1171,8 @@ err_phy_init:
48021 static int xgbe_close(struct net_device *netdev)
48022 {
48023 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48024 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48025 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48026 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48027 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48028
48029 DBGPR("-->xgbe_close\n");
48030
48031 @@ -1206,8 +1206,8 @@ static int xgbe_close(struct net_device *netdev)
48032 static int xgbe_xmit(struct sk_buff *skb, struct net_device *netdev)
48033 {
48034 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48035 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48036 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48037 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48038 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48039 struct xgbe_channel *channel;
48040 struct xgbe_ring *ring;
48041 struct xgbe_packet_data *packet;
48042 @@ -1276,7 +1276,7 @@ tx_netdev_return:
48043 static void xgbe_set_rx_mode(struct net_device *netdev)
48044 {
48045 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48046 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48047 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48048 unsigned int pr_mode, am_mode;
48049
48050 DBGPR("-->xgbe_set_rx_mode\n");
48051 @@ -1295,7 +1295,7 @@ static void xgbe_set_rx_mode(struct net_device *netdev)
48052 static int xgbe_set_mac_address(struct net_device *netdev, void *addr)
48053 {
48054 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48055 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48056 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48057 struct sockaddr *saddr = addr;
48058
48059 DBGPR("-->xgbe_set_mac_address\n");
48060 @@ -1362,7 +1362,7 @@ static struct rtnl_link_stats64 *xgbe_get_stats64(struct net_device *netdev,
48061
48062 DBGPR("-->%s\n", __func__);
48063
48064 - pdata->hw_if.read_mmc_stats(pdata);
48065 + pdata->hw_if->read_mmc_stats(pdata);
48066
48067 s->rx_packets = pstats->rxframecount_gb;
48068 s->rx_bytes = pstats->rxoctetcount_gb;
48069 @@ -1389,7 +1389,7 @@ static int xgbe_vlan_rx_add_vid(struct net_device *netdev, __be16 proto,
48070 u16 vid)
48071 {
48072 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48073 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48074 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48075
48076 DBGPR("-->%s\n", __func__);
48077
48078 @@ -1405,7 +1405,7 @@ static int xgbe_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto,
48079 u16 vid)
48080 {
48081 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48082 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48083 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48084
48085 DBGPR("-->%s\n", __func__);
48086
48087 @@ -1465,7 +1465,7 @@ static int xgbe_set_features(struct net_device *netdev,
48088 netdev_features_t features)
48089 {
48090 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48091 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48092 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48093 unsigned int rxcsum, rxvlan, rxvlan_filter;
48094
48095 rxcsum = pdata->netdev_features & NETIF_F_RXCSUM;
48096 @@ -1521,7 +1521,7 @@ struct net_device_ops *xgbe_get_netdev_ops(void)
48097 static void xgbe_rx_refresh(struct xgbe_channel *channel)
48098 {
48099 struct xgbe_prv_data *pdata = channel->pdata;
48100 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48101 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48102 struct xgbe_ring *ring = channel->rx_ring;
48103 struct xgbe_ring_data *rdata;
48104
48105 @@ -1537,8 +1537,8 @@ static void xgbe_rx_refresh(struct xgbe_channel *channel)
48106 static int xgbe_tx_poll(struct xgbe_channel *channel)
48107 {
48108 struct xgbe_prv_data *pdata = channel->pdata;
48109 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48110 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
48111 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48112 + struct xgbe_desc_if *desc_if = pdata->desc_if;
48113 struct xgbe_ring *ring = channel->tx_ring;
48114 struct xgbe_ring_data *rdata;
48115 struct xgbe_ring_desc *rdesc;
48116 @@ -1590,7 +1590,7 @@ static int xgbe_tx_poll(struct xgbe_channel *channel)
48117 static int xgbe_rx_poll(struct xgbe_channel *channel, int budget)
48118 {
48119 struct xgbe_prv_data *pdata = channel->pdata;
48120 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48121 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48122 struct xgbe_ring *ring = channel->rx_ring;
48123 struct xgbe_ring_data *rdata;
48124 struct xgbe_packet_data *packet;
48125 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
48126 index 46f6130..f37dde3 100644
48127 --- a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
48128 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
48129 @@ -203,7 +203,7 @@ static void xgbe_get_ethtool_stats(struct net_device *netdev,
48130
48131 DBGPR("-->%s\n", __func__);
48132
48133 - pdata->hw_if.read_mmc_stats(pdata);
48134 + pdata->hw_if->read_mmc_stats(pdata);
48135 for (i = 0; i < XGBE_STATS_COUNT; i++) {
48136 stat = (u8 *)pdata + xgbe_gstring_stats[i].stat_offset;
48137 *data++ = *(u64 *)stat;
48138 @@ -378,7 +378,7 @@ static int xgbe_get_coalesce(struct net_device *netdev,
48139 struct ethtool_coalesce *ec)
48140 {
48141 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48142 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48143 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48144 unsigned int riwt;
48145
48146 DBGPR("-->xgbe_get_coalesce\n");
48147 @@ -401,7 +401,7 @@ static int xgbe_set_coalesce(struct net_device *netdev,
48148 struct ethtool_coalesce *ec)
48149 {
48150 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48151 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48152 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48153 unsigned int rx_frames, rx_riwt, rx_usecs;
48154 unsigned int tx_frames, tx_usecs;
48155
48156 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-main.c b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
48157 index bdf9cfa..340aea1 100644
48158 --- a/drivers/net/ethernet/amd/xgbe/xgbe-main.c
48159 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
48160 @@ -210,12 +210,6 @@ static void xgbe_default_config(struct xgbe_prv_data *pdata)
48161 DBGPR("<--xgbe_default_config\n");
48162 }
48163
48164 -static void xgbe_init_all_fptrs(struct xgbe_prv_data *pdata)
48165 -{
48166 - xgbe_init_function_ptrs_dev(&pdata->hw_if);
48167 - xgbe_init_function_ptrs_desc(&pdata->desc_if);
48168 -}
48169 -
48170 static int xgbe_probe(struct platform_device *pdev)
48171 {
48172 struct xgbe_prv_data *pdata;
48173 @@ -328,9 +322,8 @@ static int xgbe_probe(struct platform_device *pdev)
48174 netdev->base_addr = (unsigned long)pdata->xgmac_regs;
48175
48176 /* Set all the function pointers */
48177 - xgbe_init_all_fptrs(pdata);
48178 - hw_if = &pdata->hw_if;
48179 - desc_if = &pdata->desc_if;
48180 + hw_if = pdata->hw_if = &default_xgbe_hw_if;
48181 + desc_if = pdata->desc_if = &default_xgbe_desc_if;
48182
48183 /* Issue software reset to device */
48184 hw_if->exit(pdata);
48185 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
48186 index 6d2221e..47d1325 100644
48187 --- a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
48188 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
48189 @@ -127,7 +127,7 @@
48190 static int xgbe_mdio_read(struct mii_bus *mii, int prtad, int mmd_reg)
48191 {
48192 struct xgbe_prv_data *pdata = mii->priv;
48193 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48194 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48195 int mmd_data;
48196
48197 DBGPR_MDIO("-->xgbe_mdio_read: prtad=%#x mmd_reg=%#x\n",
48198 @@ -144,7 +144,7 @@ static int xgbe_mdio_write(struct mii_bus *mii, int prtad, int mmd_reg,
48199 u16 mmd_val)
48200 {
48201 struct xgbe_prv_data *pdata = mii->priv;
48202 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
48203 + struct xgbe_hw_if *hw_if = pdata->hw_if;
48204 int mmd_data = mmd_val;
48205
48206 DBGPR_MDIO("-->xgbe_mdio_write: prtad=%#x mmd_reg=%#x mmd_data=%#x\n",
48207 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
48208 index 37e64cf..c3b61cf 100644
48209 --- a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
48210 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
48211 @@ -130,7 +130,7 @@ static cycle_t xgbe_cc_read(const struct cyclecounter *cc)
48212 tstamp_cc);
48213 u64 nsec;
48214
48215 - nsec = pdata->hw_if.get_tstamp_time(pdata);
48216 + nsec = pdata->hw_if->get_tstamp_time(pdata);
48217
48218 return nsec;
48219 }
48220 @@ -159,7 +159,7 @@ static int xgbe_adjfreq(struct ptp_clock_info *info, s32 delta)
48221
48222 spin_lock_irqsave(&pdata->tstamp_lock, flags);
48223
48224 - pdata->hw_if.update_tstamp_addend(pdata, addend);
48225 + pdata->hw_if->update_tstamp_addend(pdata, addend);
48226
48227 spin_unlock_irqrestore(&pdata->tstamp_lock, flags);
48228
48229 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe.h b/drivers/net/ethernet/amd/xgbe/xgbe.h
48230 index e9fe6e6..875fbaf 100644
48231 --- a/drivers/net/ethernet/amd/xgbe/xgbe.h
48232 +++ b/drivers/net/ethernet/amd/xgbe/xgbe.h
48233 @@ -585,8 +585,8 @@ struct xgbe_prv_data {
48234
48235 int irq_number;
48236
48237 - struct xgbe_hw_if hw_if;
48238 - struct xgbe_desc_if desc_if;
48239 + const struct xgbe_hw_if *hw_if;
48240 + const struct xgbe_desc_if *desc_if;
48241
48242 /* AXI DMA settings */
48243 unsigned int axdomain;
48244 @@ -699,6 +699,9 @@ struct xgbe_prv_data {
48245 #endif
48246 };
48247
48248 +extern const struct xgbe_hw_if default_xgbe_hw_if;
48249 +extern const struct xgbe_desc_if default_xgbe_desc_if;
48250 +
48251 /* Function prototypes*/
48252
48253 void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *);
48254 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
48255 index 571427c..e9fe9e7 100644
48256 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
48257 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
48258 @@ -1058,7 +1058,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
48259 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
48260 {
48261 /* RX_MODE controlling object */
48262 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
48263 + bnx2x_init_rx_mode_obj(bp);
48264
48265 /* multicast configuration controlling object */
48266 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
48267 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
48268 index b193604..8873bfd 100644
48269 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
48270 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
48271 @@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
48272 return rc;
48273 }
48274
48275 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
48276 - struct bnx2x_rx_mode_obj *o)
48277 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
48278 {
48279 if (CHIP_IS_E1x(bp)) {
48280 - o->wait_comp = bnx2x_empty_rx_mode_wait;
48281 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
48282 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
48283 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
48284 } else {
48285 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
48286 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
48287 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
48288 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
48289 }
48290 }
48291
48292 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48293 index 718ecd2..2183b2f 100644
48294 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48295 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48296 @@ -1340,8 +1340,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
48297
48298 /********************* RX MODE ****************/
48299
48300 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
48301 - struct bnx2x_rx_mode_obj *o);
48302 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
48303
48304 /**
48305 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
48306 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
48307 index 31c9f82..e65e986 100644
48308 --- a/drivers/net/ethernet/broadcom/tg3.h
48309 +++ b/drivers/net/ethernet/broadcom/tg3.h
48310 @@ -150,6 +150,7 @@
48311 #define CHIPREV_ID_5750_A0 0x4000
48312 #define CHIPREV_ID_5750_A1 0x4001
48313 #define CHIPREV_ID_5750_A3 0x4003
48314 +#define CHIPREV_ID_5750_C1 0x4201
48315 #define CHIPREV_ID_5750_C2 0x4202
48316 #define CHIPREV_ID_5752_A0_HW 0x5000
48317 #define CHIPREV_ID_5752_A0 0x6000
48318 diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
48319 index 13f9636..228040f 100644
48320 --- a/drivers/net/ethernet/brocade/bna/bna_enet.c
48321 +++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
48322 @@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
48323 }
48324
48325 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
48326 - bna_cb_ioceth_enable,
48327 - bna_cb_ioceth_disable,
48328 - bna_cb_ioceth_hbfail,
48329 - bna_cb_ioceth_reset
48330 + .enable_cbfn = bna_cb_ioceth_enable,
48331 + .disable_cbfn = bna_cb_ioceth_disable,
48332 + .hbfail_cbfn = bna_cb_ioceth_hbfail,
48333 + .reset_cbfn = bna_cb_ioceth_reset
48334 };
48335
48336 static void bna_attr_init(struct bna_ioceth *ioceth)
48337 diff --git a/drivers/net/ethernet/brocade/bna/bnad.c b/drivers/net/ethernet/brocade/bna/bnad.c
48338 index ffc92a4..40edc77 100644
48339 --- a/drivers/net/ethernet/brocade/bna/bnad.c
48340 +++ b/drivers/net/ethernet/brocade/bna/bnad.c
48341 @@ -552,6 +552,7 @@ bnad_cq_setup_skb_frags(struct bna_rcb *rcb, struct sk_buff *skb,
48342
48343 len = (vec == nvecs) ?
48344 last_fraglen : unmap->vector.len;
48345 + skb->truesize += unmap->vector.len;
48346 totlen += len;
48347
48348 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
48349 @@ -563,7 +564,6 @@ bnad_cq_setup_skb_frags(struct bna_rcb *rcb, struct sk_buff *skb,
48350
48351 skb->len += totlen;
48352 skb->data_len += totlen;
48353 - skb->truesize += totlen;
48354 }
48355
48356 static inline void
48357 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48358 index 8cffcdf..aadf043 100644
48359 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48360 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48361 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
48362 */
48363 struct l2t_skb_cb {
48364 arp_failure_handler_func arp_failure_handler;
48365 -};
48366 +} __no_const;
48367
48368 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
48369
48370 diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48371 index 9f5f3c3..86d21a6 100644
48372 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48373 +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48374 @@ -2359,7 +2359,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
48375
48376 int i;
48377 struct adapter *ap = netdev2adap(dev);
48378 - static const unsigned int *reg_ranges;
48379 + const unsigned int *reg_ranges;
48380 int arr_size = 0, buf_size = 0;
48381
48382 if (is_t4(ap->params.chip)) {
48383 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
48384 index cf8b6ff..274271e 100644
48385 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
48386 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
48387 @@ -5387,7 +5387,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
48388 for (i=0; i<ETH_ALEN; i++) {
48389 tmp.addr[i] = dev->dev_addr[i];
48390 }
48391 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
48392 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
48393 break;
48394
48395 case DE4X5_SET_HWADDR: /* Set the hardware address */
48396 @@ -5427,7 +5427,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
48397 spin_lock_irqsave(&lp->lock, flags);
48398 memcpy(&statbuf, &lp->pktStats, ioc->len);
48399 spin_unlock_irqrestore(&lp->lock, flags);
48400 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
48401 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
48402 return -EFAULT;
48403 break;
48404 }
48405 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
48406 index 93ff8ef..39c64dd 100644
48407 --- a/drivers/net/ethernet/emulex/benet/be_main.c
48408 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
48409 @@ -533,7 +533,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
48410
48411 if (wrapped)
48412 newacc += 65536;
48413 - ACCESS_ONCE(*acc) = newacc;
48414 + ACCESS_ONCE_RW(*acc) = newacc;
48415 }
48416
48417 static void populate_erx_stats(struct be_adapter *adapter,
48418 @@ -4286,6 +4286,9 @@ static int be_ndo_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh)
48419 if (nla_type(attr) != IFLA_BRIDGE_MODE)
48420 continue;
48421
48422 + if (nla_len(attr) < sizeof(mode))
48423 + return -EINVAL;
48424 +
48425 mode = nla_get_u16(attr);
48426 if (mode != BRIDGE_MODE_VEPA && mode != BRIDGE_MODE_VEB)
48427 return -EINVAL;
48428 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
48429 index c77fa4a..7fd42fc 100644
48430 --- a/drivers/net/ethernet/faraday/ftgmac100.c
48431 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
48432 @@ -30,6 +30,8 @@
48433 #include <linux/netdevice.h>
48434 #include <linux/phy.h>
48435 #include <linux/platform_device.h>
48436 +#include <linux/interrupt.h>
48437 +#include <linux/irqreturn.h>
48438 #include <net/ip.h>
48439
48440 #include "ftgmac100.h"
48441 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
48442 index 4ff1adc..0ea6bf4 100644
48443 --- a/drivers/net/ethernet/faraday/ftmac100.c
48444 +++ b/drivers/net/ethernet/faraday/ftmac100.c
48445 @@ -31,6 +31,8 @@
48446 #include <linux/module.h>
48447 #include <linux/netdevice.h>
48448 #include <linux/platform_device.h>
48449 +#include <linux/interrupt.h>
48450 +#include <linux/irqreturn.h>
48451
48452 #include "ftmac100.h"
48453
48454 diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48455 index 537b621..07f87ce 100644
48456 --- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48457 +++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48458 @@ -401,7 +401,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
48459 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
48460
48461 /* Update the base adjustement value. */
48462 - ACCESS_ONCE(pf->ptp_base_adj) = incval;
48463 + ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
48464 smp_mb(); /* Force the above update. */
48465 }
48466
48467 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
48468 index 87bd53f..a0b97ec 100644
48469 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
48470 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
48471 @@ -7789,6 +7789,9 @@ static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
48472 if (nla_type(attr) != IFLA_BRIDGE_MODE)
48473 continue;
48474
48475 + if (nla_len(attr) < sizeof(mode))
48476 + return -EINVAL;
48477 +
48478 mode = nla_get_u16(attr);
48479 if (mode == BRIDGE_MODE_VEPA) {
48480 reg = 0;
48481 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48482 index 5fd4b52..87aa34b 100644
48483 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48484 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48485 @@ -794,7 +794,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
48486 }
48487
48488 /* update the base incval used to calculate frequency adjustment */
48489 - ACCESS_ONCE(adapter->base_incval) = incval;
48490 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
48491 smp_mb();
48492
48493 /* need lock to prevent incorrect read while modifying cyclecounter */
48494 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c
48495 index c14d4d8..66da603 100644
48496 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c
48497 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c
48498 @@ -1259,6 +1259,9 @@ int ixgbe_ndo_set_vf_spoofchk(struct net_device *netdev, int vf, bool setting)
48499 struct ixgbe_hw *hw = &adapter->hw;
48500 u32 regval;
48501
48502 + if (vf >= adapter->num_vfs)
48503 + return -EINVAL;
48504 +
48505 adapter->vfinfo[vf].spoofchk_enabled = setting;
48506
48507 regval = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg));
48508 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
48509 index 2bbd01f..e8baa64 100644
48510 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
48511 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
48512 @@ -3457,7 +3457,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
48513 struct __vxge_hw_fifo *fifo;
48514 struct vxge_hw_fifo_config *config;
48515 u32 txdl_size, txdl_per_memblock;
48516 - struct vxge_hw_mempool_cbs fifo_mp_callback;
48517 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
48518 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
48519 + };
48520 +
48521 struct __vxge_hw_virtualpath *vpath;
48522
48523 if ((vp == NULL) || (attr == NULL)) {
48524 @@ -3540,8 +3543,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
48525 goto exit;
48526 }
48527
48528 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
48529 -
48530 fifo->mempool =
48531 __vxge_hw_mempool_create(vpath->hldev,
48532 fifo->config->memblock_size,
48533 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48534 index 3172cdf..d01ab34 100644
48535 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48536 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48537 @@ -2190,7 +2190,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
48538 max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
48539 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
48540 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
48541 - adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
48542 + pax_open_kernel();
48543 + *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
48544 + pax_close_kernel();
48545 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48546 max_sds_rings = QLCNIC_MAX_SDS_RINGS;
48547 max_tx_rings = QLCNIC_MAX_TX_RINGS;
48548 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48549 index be7d7a6..a8983f8 100644
48550 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48551 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48552 @@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
48553 case QLCNIC_NON_PRIV_FUNC:
48554 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
48555 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48556 - nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
48557 + pax_open_kernel();
48558 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
48559 + pax_close_kernel();
48560 break;
48561 case QLCNIC_PRIV_FUNC:
48562 ahw->op_mode = QLCNIC_PRIV_FUNC;
48563 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
48564 - nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
48565 + pax_open_kernel();
48566 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
48567 + pax_close_kernel();
48568 break;
48569 case QLCNIC_MGMT_FUNC:
48570 ahw->op_mode = QLCNIC_MGMT_FUNC;
48571 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48572 - nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
48573 + pax_open_kernel();
48574 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
48575 + pax_close_kernel();
48576 break;
48577 default:
48578 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
48579 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48580 index c9f57fb..208bdc1 100644
48581 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48582 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48583 @@ -1285,7 +1285,7 @@ flash_temp:
48584 int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
48585 {
48586 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
48587 - static const struct qlcnic_dump_operations *fw_dump_ops;
48588 + const struct qlcnic_dump_operations *fw_dump_ops;
48589 struct qlcnic_83xx_dump_template_hdr *hdr_83xx;
48590 u32 entry_offset, dump, no_entries, buf_offset = 0;
48591 int i, k, ops_cnt, ops_index, dump_size = 0;
48592 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
48593 index 0921302..927f761 100644
48594 --- a/drivers/net/ethernet/realtek/r8169.c
48595 +++ b/drivers/net/ethernet/realtek/r8169.c
48596 @@ -744,22 +744,22 @@ struct rtl8169_private {
48597 struct mdio_ops {
48598 void (*write)(struct rtl8169_private *, int, int);
48599 int (*read)(struct rtl8169_private *, int);
48600 - } mdio_ops;
48601 + } __no_const mdio_ops;
48602
48603 struct pll_power_ops {
48604 void (*down)(struct rtl8169_private *);
48605 void (*up)(struct rtl8169_private *);
48606 - } pll_power_ops;
48607 + } __no_const pll_power_ops;
48608
48609 struct jumbo_ops {
48610 void (*enable)(struct rtl8169_private *);
48611 void (*disable)(struct rtl8169_private *);
48612 - } jumbo_ops;
48613 + } __no_const jumbo_ops;
48614
48615 struct csi_ops {
48616 void (*write)(struct rtl8169_private *, int, int);
48617 u32 (*read)(struct rtl8169_private *, int);
48618 - } csi_ops;
48619 + } __no_const csi_ops;
48620
48621 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
48622 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
48623 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
48624 index 6b861e3..204ac86 100644
48625 --- a/drivers/net/ethernet/sfc/ptp.c
48626 +++ b/drivers/net/ethernet/sfc/ptp.c
48627 @@ -822,7 +822,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
48628 ptp->start.dma_addr);
48629
48630 /* Clear flag that signals MC ready */
48631 - ACCESS_ONCE(*start) = 0;
48632 + ACCESS_ONCE_RW(*start) = 0;
48633 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
48634 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
48635 EFX_BUG_ON_PARANOID(rc);
48636 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48637 index 08c483b..2c4a553 100644
48638 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48639 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48640 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
48641
48642 writel(value, ioaddr + MMC_CNTRL);
48643
48644 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
48645 - MMC_CNTRL, value);
48646 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
48647 +// MMC_CNTRL, value);
48648 }
48649
48650 /* To mask all all interrupts.*/
48651 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
48652 index d5e07de..e3bf20a 100644
48653 --- a/drivers/net/hyperv/hyperv_net.h
48654 +++ b/drivers/net/hyperv/hyperv_net.h
48655 @@ -171,7 +171,7 @@ struct rndis_device {
48656 enum rndis_device_state state;
48657 bool link_state;
48658 bool link_change;
48659 - atomic_t new_req_id;
48660 + atomic_unchecked_t new_req_id;
48661
48662 spinlock_t request_lock;
48663 struct list_head req_list;
48664 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
48665 index 2b86f0b..ecc996f 100644
48666 --- a/drivers/net/hyperv/rndis_filter.c
48667 +++ b/drivers/net/hyperv/rndis_filter.c
48668 @@ -102,7 +102,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
48669 * template
48670 */
48671 set = &rndis_msg->msg.set_req;
48672 - set->req_id = atomic_inc_return(&dev->new_req_id);
48673 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
48674
48675 /* Add to the request list */
48676 spin_lock_irqsave(&dev->request_lock, flags);
48677 @@ -911,7 +911,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
48678
48679 /* Setup the rndis set */
48680 halt = &request->request_msg.msg.halt_req;
48681 - halt->req_id = atomic_inc_return(&dev->new_req_id);
48682 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
48683
48684 /* Ignore return since this msg is optional. */
48685 rndis_filter_send_request(dev, request);
48686 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
48687 index 9ce854f..e43fa17 100644
48688 --- a/drivers/net/ieee802154/fakehard.c
48689 +++ b/drivers/net/ieee802154/fakehard.c
48690 @@ -365,7 +365,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
48691 phy->transmit_power = 0xbf;
48692
48693 dev->netdev_ops = &fake_ops;
48694 - dev->ml_priv = &fake_mlme;
48695 + dev->ml_priv = (void *)&fake_mlme;
48696
48697 priv = netdev_priv(dev);
48698 priv->phy = phy;
48699 diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
48700 index 5f17ad0..e0463c8 100644
48701 --- a/drivers/net/macvlan.c
48702 +++ b/drivers/net/macvlan.c
48703 @@ -264,7 +264,7 @@ static void macvlan_broadcast_enqueue(struct macvlan_port *port,
48704 free_nskb:
48705 kfree_skb(nskb);
48706 err:
48707 - atomic_long_inc(&skb->dev->rx_dropped);
48708 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
48709 }
48710
48711 /* called under rcu_read_lock() from netif_receive_skb */
48712 @@ -1150,13 +1150,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
48713 int macvlan_link_register(struct rtnl_link_ops *ops)
48714 {
48715 /* common fields */
48716 - ops->priv_size = sizeof(struct macvlan_dev);
48717 - ops->validate = macvlan_validate;
48718 - ops->maxtype = IFLA_MACVLAN_MAX;
48719 - ops->policy = macvlan_policy;
48720 - ops->changelink = macvlan_changelink;
48721 - ops->get_size = macvlan_get_size;
48722 - ops->fill_info = macvlan_fill_info;
48723 + pax_open_kernel();
48724 + *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
48725 + *(void **)&ops->validate = macvlan_validate;
48726 + *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
48727 + *(const void **)&ops->policy = macvlan_policy;
48728 + *(void **)&ops->changelink = macvlan_changelink;
48729 + *(void **)&ops->get_size = macvlan_get_size;
48730 + *(void **)&ops->fill_info = macvlan_fill_info;
48731 + pax_close_kernel();
48732
48733 return rtnl_link_register(ops);
48734 };
48735 @@ -1236,7 +1238,7 @@ static int macvlan_device_event(struct notifier_block *unused,
48736 return NOTIFY_DONE;
48737 }
48738
48739 -static struct notifier_block macvlan_notifier_block __read_mostly = {
48740 +static struct notifier_block macvlan_notifier_block = {
48741 .notifier_call = macvlan_device_event,
48742 };
48743
48744 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
48745 index 07c942b..2d8b073 100644
48746 --- a/drivers/net/macvtap.c
48747 +++ b/drivers/net/macvtap.c
48748 @@ -1023,7 +1023,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
48749 }
48750
48751 ret = 0;
48752 - if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
48753 + if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
48754 put_user(q->flags, &ifr->ifr_flags))
48755 ret = -EFAULT;
48756 macvtap_put_vlan(vlan);
48757 @@ -1193,7 +1193,7 @@ static int macvtap_device_event(struct notifier_block *unused,
48758 return NOTIFY_DONE;
48759 }
48760
48761 -static struct notifier_block macvtap_notifier_block __read_mostly = {
48762 +static struct notifier_block macvtap_notifier_block = {
48763 .notifier_call = macvtap_device_event,
48764 };
48765
48766 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
48767 index 17ecdd6..79ad848 100644
48768 --- a/drivers/net/ppp/ppp_generic.c
48769 +++ b/drivers/net/ppp/ppp_generic.c
48770 @@ -1020,7 +1020,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48771 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
48772 struct ppp_stats stats;
48773 struct ppp_comp_stats cstats;
48774 - char *vers;
48775
48776 switch (cmd) {
48777 case SIOCGPPPSTATS:
48778 @@ -1042,8 +1041,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48779 break;
48780
48781 case SIOCGPPPVER:
48782 - vers = PPP_VERSION;
48783 - if (copy_to_user(addr, vers, strlen(vers) + 1))
48784 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
48785 break;
48786 err = 0;
48787 break;
48788 diff --git a/drivers/net/ppp/pptp.c b/drivers/net/ppp/pptp.c
48789 index 1aff970..cc2ee29 100644
48790 --- a/drivers/net/ppp/pptp.c
48791 +++ b/drivers/net/ppp/pptp.c
48792 @@ -506,7 +506,9 @@ static int pptp_getname(struct socket *sock, struct sockaddr *uaddr,
48793 int len = sizeof(struct sockaddr_pppox);
48794 struct sockaddr_pppox sp;
48795
48796 - sp.sa_family = AF_PPPOX;
48797 + memset(&sp.sa_addr, 0, sizeof(sp.sa_addr));
48798 +
48799 + sp.sa_family = AF_PPPOX;
48800 sp.sa_protocol = PX_PROTO_PPTP;
48801 sp.sa_addr.pptp = pppox_sk(sock->sk)->proto.pptp.src_addr;
48802
48803 diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
48804 index 079f7ad..b2a2bfa7 100644
48805 --- a/drivers/net/slip/slhc.c
48806 +++ b/drivers/net/slip/slhc.c
48807 @@ -487,7 +487,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
48808 register struct tcphdr *thp;
48809 register struct iphdr *ip;
48810 register struct cstate *cs;
48811 - int len, hdrlen;
48812 + long len, hdrlen;
48813 unsigned char *cp = icp;
48814
48815 /* We've got a compressed packet; read the change byte */
48816 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
48817 index 1f76c2ea..9681171 100644
48818 --- a/drivers/net/team/team.c
48819 +++ b/drivers/net/team/team.c
48820 @@ -2862,7 +2862,7 @@ static int team_device_event(struct notifier_block *unused,
48821 return NOTIFY_DONE;
48822 }
48823
48824 -static struct notifier_block team_notifier_block __read_mostly = {
48825 +static struct notifier_block team_notifier_block = {
48826 .notifier_call = team_device_event,
48827 };
48828
48829 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
48830 index d965e8a..f119e64 100644
48831 --- a/drivers/net/tun.c
48832 +++ b/drivers/net/tun.c
48833 @@ -1861,7 +1861,7 @@ unlock:
48834 }
48835
48836 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
48837 - unsigned long arg, int ifreq_len)
48838 + unsigned long arg, size_t ifreq_len)
48839 {
48840 struct tun_file *tfile = file->private_data;
48841 struct tun_struct *tun;
48842 @@ -1874,6 +1874,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
48843 unsigned int ifindex;
48844 int ret;
48845
48846 + if (ifreq_len > sizeof ifr)
48847 + return -EFAULT;
48848 +
48849 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
48850 if (copy_from_user(&ifr, argp, ifreq_len))
48851 return -EFAULT;
48852 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
48853 index babda7d..e40c90a 100644
48854 --- a/drivers/net/usb/hso.c
48855 +++ b/drivers/net/usb/hso.c
48856 @@ -71,7 +71,7 @@
48857 #include <asm/byteorder.h>
48858 #include <linux/serial_core.h>
48859 #include <linux/serial.h>
48860 -
48861 +#include <asm/local.h>
48862
48863 #define MOD_AUTHOR "Option Wireless"
48864 #define MOD_DESCRIPTION "USB High Speed Option driver"
48865 @@ -1178,7 +1178,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
48866 struct urb *urb;
48867
48868 urb = serial->rx_urb[0];
48869 - if (serial->port.count > 0) {
48870 + if (atomic_read(&serial->port.count) > 0) {
48871 count = put_rxbuf_data(urb, serial);
48872 if (count == -1)
48873 return;
48874 @@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
48875 DUMP1(urb->transfer_buffer, urb->actual_length);
48876
48877 /* Anyone listening? */
48878 - if (serial->port.count == 0)
48879 + if (atomic_read(&serial->port.count) == 0)
48880 return;
48881
48882 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
48883 @@ -1278,8 +1278,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
48884 tty_port_tty_set(&serial->port, tty);
48885
48886 /* check for port already opened, if not set the termios */
48887 - serial->port.count++;
48888 - if (serial->port.count == 1) {
48889 + if (atomic_inc_return(&serial->port.count) == 1) {
48890 serial->rx_state = RX_IDLE;
48891 /* Force default termio settings */
48892 _hso_serial_set_termios(tty, NULL);
48893 @@ -1289,7 +1288,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
48894 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
48895 if (result) {
48896 hso_stop_serial_device(serial->parent);
48897 - serial->port.count--;
48898 + atomic_dec(&serial->port.count);
48899 kref_put(&serial->parent->ref, hso_serial_ref_free);
48900 }
48901 } else {
48902 @@ -1326,10 +1325,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
48903
48904 /* reset the rts and dtr */
48905 /* do the actual close */
48906 - serial->port.count--;
48907 + atomic_dec(&serial->port.count);
48908
48909 - if (serial->port.count <= 0) {
48910 - serial->port.count = 0;
48911 + if (atomic_read(&serial->port.count) <= 0) {
48912 + atomic_set(&serial->port.count, 0);
48913 tty_port_tty_set(&serial->port, NULL);
48914 if (!usb_gone)
48915 hso_stop_serial_device(serial->parent);
48916 @@ -1404,7 +1403,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
48917
48918 /* the actual setup */
48919 spin_lock_irqsave(&serial->serial_lock, flags);
48920 - if (serial->port.count)
48921 + if (atomic_read(&serial->port.count))
48922 _hso_serial_set_termios(tty, old);
48923 else
48924 tty->termios = *old;
48925 @@ -1873,7 +1872,7 @@ static void intr_callback(struct urb *urb)
48926 D1("Pending read interrupt on port %d\n", i);
48927 spin_lock(&serial->serial_lock);
48928 if (serial->rx_state == RX_IDLE &&
48929 - serial->port.count > 0) {
48930 + atomic_read(&serial->port.count) > 0) {
48931 /* Setup and send a ctrl req read on
48932 * port i */
48933 if (!serial->rx_urb_filled[0]) {
48934 @@ -3047,7 +3046,7 @@ static int hso_resume(struct usb_interface *iface)
48935 /* Start all serial ports */
48936 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
48937 if (serial_table[i] && (serial_table[i]->interface == iface)) {
48938 - if (dev2ser(serial_table[i])->port.count) {
48939 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
48940 result =
48941 hso_start_serial_device(serial_table[i], GFP_NOIO);
48942 hso_kick_transmit(dev2ser(serial_table[i]));
48943 diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
48944 index 604ef21..d1f49a1 100644
48945 --- a/drivers/net/usb/r8152.c
48946 +++ b/drivers/net/usb/r8152.c
48947 @@ -575,7 +575,7 @@ struct r8152 {
48948 void (*up)(struct r8152 *);
48949 void (*down)(struct r8152 *);
48950 void (*unload)(struct r8152 *);
48951 - } rtl_ops;
48952 + } __no_const rtl_ops;
48953
48954 int intr_interval;
48955 u32 saved_wolopts;
48956 diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
48957 index a2515887..6d13233 100644
48958 --- a/drivers/net/usb/sierra_net.c
48959 +++ b/drivers/net/usb/sierra_net.c
48960 @@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
48961 /* atomic counter partially included in MAC address to make sure 2 devices
48962 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
48963 */
48964 -static atomic_t iface_counter = ATOMIC_INIT(0);
48965 +static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
48966
48967 /*
48968 * SYNC Timer Delay definition used to set the expiry time
48969 @@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
48970 dev->net->netdev_ops = &sierra_net_device_ops;
48971
48972 /* change MAC addr to include, ifacenum, and to be unique */
48973 - dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
48974 + dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
48975 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
48976
48977 /* we will have to manufacture ethernet headers, prepare template */
48978 diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
48979 index 59caa06..de191b3 100644
48980 --- a/drivers/net/virtio_net.c
48981 +++ b/drivers/net/virtio_net.c
48982 @@ -48,7 +48,7 @@ module_param(gso, bool, 0444);
48983 #define RECEIVE_AVG_WEIGHT 64
48984
48985 /* Minimum alignment for mergeable packet buffers. */
48986 -#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256)
48987 +#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256UL)
48988
48989 #define VIRTNET_DRIVER_VERSION "1.0.0"
48990
48991 diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
48992 index 81a8a29..ae60a58 100644
48993 --- a/drivers/net/vxlan.c
48994 +++ b/drivers/net/vxlan.c
48995 @@ -2762,7 +2762,7 @@ nla_put_failure:
48996 return -EMSGSIZE;
48997 }
48998
48999 -static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
49000 +static struct rtnl_link_ops vxlan_link_ops = {
49001 .kind = "vxlan",
49002 .maxtype = IFLA_VXLAN_MAX,
49003 .policy = vxlan_policy,
49004 @@ -2809,7 +2809,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
49005 return NOTIFY_DONE;
49006 }
49007
49008 -static struct notifier_block vxlan_notifier_block __read_mostly = {
49009 +static struct notifier_block vxlan_notifier_block = {
49010 .notifier_call = vxlan_lowerdev_event,
49011 };
49012
49013 diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
49014 index 5920c99..ff2e4a5 100644
49015 --- a/drivers/net/wan/lmc/lmc_media.c
49016 +++ b/drivers/net/wan/lmc/lmc_media.c
49017 @@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
49018 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
49019
49020 lmc_media_t lmc_ds3_media = {
49021 - lmc_ds3_init, /* special media init stuff */
49022 - lmc_ds3_default, /* reset to default state */
49023 - lmc_ds3_set_status, /* reset status to state provided */
49024 - lmc_dummy_set_1, /* set clock source */
49025 - lmc_dummy_set2_1, /* set line speed */
49026 - lmc_ds3_set_100ft, /* set cable length */
49027 - lmc_ds3_set_scram, /* set scrambler */
49028 - lmc_ds3_get_link_status, /* get link status */
49029 - lmc_dummy_set_1, /* set link status */
49030 - lmc_ds3_set_crc_length, /* set CRC length */
49031 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
49032 - lmc_ds3_watchdog
49033 + .init = lmc_ds3_init, /* special media init stuff */
49034 + .defaults = lmc_ds3_default, /* reset to default state */
49035 + .set_status = lmc_ds3_set_status, /* reset status to state provided */
49036 + .set_clock_source = lmc_dummy_set_1, /* set clock source */
49037 + .set_speed = lmc_dummy_set2_1, /* set line speed */
49038 + .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
49039 + .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
49040 + .get_link_status = lmc_ds3_get_link_status, /* get link status */
49041 + .set_link_status = lmc_dummy_set_1, /* set link status */
49042 + .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
49043 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
49044 + .watchdog = lmc_ds3_watchdog
49045 };
49046
49047 lmc_media_t lmc_hssi_media = {
49048 - lmc_hssi_init, /* special media init stuff */
49049 - lmc_hssi_default, /* reset to default state */
49050 - lmc_hssi_set_status, /* reset status to state provided */
49051 - lmc_hssi_set_clock, /* set clock source */
49052 - lmc_dummy_set2_1, /* set line speed */
49053 - lmc_dummy_set_1, /* set cable length */
49054 - lmc_dummy_set_1, /* set scrambler */
49055 - lmc_hssi_get_link_status, /* get link status */
49056 - lmc_hssi_set_link_status, /* set link status */
49057 - lmc_hssi_set_crc_length, /* set CRC length */
49058 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
49059 - lmc_hssi_watchdog
49060 + .init = lmc_hssi_init, /* special media init stuff */
49061 + .defaults = lmc_hssi_default, /* reset to default state */
49062 + .set_status = lmc_hssi_set_status, /* reset status to state provided */
49063 + .set_clock_source = lmc_hssi_set_clock, /* set clock source */
49064 + .set_speed = lmc_dummy_set2_1, /* set line speed */
49065 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
49066 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
49067 + .get_link_status = lmc_hssi_get_link_status, /* get link status */
49068 + .set_link_status = lmc_hssi_set_link_status, /* set link status */
49069 + .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
49070 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
49071 + .watchdog = lmc_hssi_watchdog
49072 };
49073
49074 -lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
49075 - lmc_ssi_default, /* reset to default state */
49076 - lmc_ssi_set_status, /* reset status to state provided */
49077 - lmc_ssi_set_clock, /* set clock source */
49078 - lmc_ssi_set_speed, /* set line speed */
49079 - lmc_dummy_set_1, /* set cable length */
49080 - lmc_dummy_set_1, /* set scrambler */
49081 - lmc_ssi_get_link_status, /* get link status */
49082 - lmc_ssi_set_link_status, /* set link status */
49083 - lmc_ssi_set_crc_length, /* set CRC length */
49084 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
49085 - lmc_ssi_watchdog
49086 +lmc_media_t lmc_ssi_media = {
49087 + .init = lmc_ssi_init, /* special media init stuff */
49088 + .defaults = lmc_ssi_default, /* reset to default state */
49089 + .set_status = lmc_ssi_set_status, /* reset status to state provided */
49090 + .set_clock_source = lmc_ssi_set_clock, /* set clock source */
49091 + .set_speed = lmc_ssi_set_speed, /* set line speed */
49092 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
49093 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
49094 + .get_link_status = lmc_ssi_get_link_status, /* get link status */
49095 + .set_link_status = lmc_ssi_set_link_status, /* set link status */
49096 + .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
49097 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
49098 + .watchdog = lmc_ssi_watchdog
49099 };
49100
49101 lmc_media_t lmc_t1_media = {
49102 - lmc_t1_init, /* special media init stuff */
49103 - lmc_t1_default, /* reset to default state */
49104 - lmc_t1_set_status, /* reset status to state provided */
49105 - lmc_t1_set_clock, /* set clock source */
49106 - lmc_dummy_set2_1, /* set line speed */
49107 - lmc_dummy_set_1, /* set cable length */
49108 - lmc_dummy_set_1, /* set scrambler */
49109 - lmc_t1_get_link_status, /* get link status */
49110 - lmc_dummy_set_1, /* set link status */
49111 - lmc_t1_set_crc_length, /* set CRC length */
49112 - lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
49113 - lmc_t1_watchdog
49114 + .init = lmc_t1_init, /* special media init stuff */
49115 + .defaults = lmc_t1_default, /* reset to default state */
49116 + .set_status = lmc_t1_set_status, /* reset status to state provided */
49117 + .set_clock_source = lmc_t1_set_clock, /* set clock source */
49118 + .set_speed = lmc_dummy_set2_1, /* set line speed */
49119 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
49120 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
49121 + .get_link_status = lmc_t1_get_link_status, /* get link status */
49122 + .set_link_status = lmc_dummy_set_1, /* set link status */
49123 + .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
49124 + .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
49125 + .watchdog = lmc_t1_watchdog
49126 };
49127
49128 static void
49129 diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
49130 index feacc3b..5bac0de 100644
49131 --- a/drivers/net/wan/z85230.c
49132 +++ b/drivers/net/wan/z85230.c
49133 @@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
49134
49135 struct z8530_irqhandler z8530_sync =
49136 {
49137 - z8530_rx,
49138 - z8530_tx,
49139 - z8530_status
49140 + .rx = z8530_rx,
49141 + .tx = z8530_tx,
49142 + .status = z8530_status
49143 };
49144
49145 EXPORT_SYMBOL(z8530_sync);
49146 @@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
49147 }
49148
49149 static struct z8530_irqhandler z8530_dma_sync = {
49150 - z8530_dma_rx,
49151 - z8530_dma_tx,
49152 - z8530_dma_status
49153 + .rx = z8530_dma_rx,
49154 + .tx = z8530_dma_tx,
49155 + .status = z8530_dma_status
49156 };
49157
49158 static struct z8530_irqhandler z8530_txdma_sync = {
49159 - z8530_rx,
49160 - z8530_dma_tx,
49161 - z8530_dma_status
49162 + .rx = z8530_rx,
49163 + .tx = z8530_dma_tx,
49164 + .status = z8530_dma_status
49165 };
49166
49167 /**
49168 @@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
49169
49170 struct z8530_irqhandler z8530_nop=
49171 {
49172 - z8530_rx_clear,
49173 - z8530_tx_clear,
49174 - z8530_status_clear
49175 + .rx = z8530_rx_clear,
49176 + .tx = z8530_tx_clear,
49177 + .status = z8530_status_clear
49178 };
49179
49180
49181 diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
49182 index 0b60295..b8bfa5b 100644
49183 --- a/drivers/net/wimax/i2400m/rx.c
49184 +++ b/drivers/net/wimax/i2400m/rx.c
49185 @@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
49186 if (i2400m->rx_roq == NULL)
49187 goto error_roq_alloc;
49188
49189 - rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
49190 + rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
49191 GFP_KERNEL);
49192 if (rd == NULL) {
49193 result = -ENOMEM;
49194 diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
49195 index e71a2ce..2268d61 100644
49196 --- a/drivers/net/wireless/airo.c
49197 +++ b/drivers/net/wireless/airo.c
49198 @@ -7846,7 +7846,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
49199 struct airo_info *ai = dev->ml_priv;
49200 int ridcode;
49201 int enabled;
49202 - static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
49203 + int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
49204 unsigned char *iobuf;
49205
49206 /* Only super-user can write RIDs */
49207 diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
49208 index da92bfa..5a9001a 100644
49209 --- a/drivers/net/wireless/at76c50x-usb.c
49210 +++ b/drivers/net/wireless/at76c50x-usb.c
49211 @@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
49212 }
49213
49214 /* Convert timeout from the DFU status to jiffies */
49215 -static inline unsigned long at76_get_timeout(struct dfu_status *s)
49216 +static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
49217 {
49218 return msecs_to_jiffies((s->poll_timeout[2] << 16)
49219 | (s->poll_timeout[1] << 8)
49220 diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
49221 index 5fdc40d..3975205 100644
49222 --- a/drivers/net/wireless/ath/ath10k/htc.c
49223 +++ b/drivers/net/wireless/ath/ath10k/htc.c
49224 @@ -856,7 +856,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
49225 /* registered target arrival callback from the HIF layer */
49226 int ath10k_htc_init(struct ath10k *ar)
49227 {
49228 - struct ath10k_hif_cb htc_callbacks;
49229 + static struct ath10k_hif_cb htc_callbacks = {
49230 + .rx_completion = ath10k_htc_rx_completion_handler,
49231 + .tx_completion = ath10k_htc_tx_completion_handler,
49232 + };
49233 struct ath10k_htc_ep *ep = NULL;
49234 struct ath10k_htc *htc = &ar->htc;
49235
49236 @@ -866,8 +869,6 @@ int ath10k_htc_init(struct ath10k *ar)
49237 ath10k_htc_reset_endpoint_states(htc);
49238
49239 /* setup HIF layer callbacks */
49240 - htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
49241 - htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
49242 htc->ar = ar;
49243
49244 /* Get HIF default pipe for HTC message exchange */
49245 diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
49246 index 4716d33..a688310 100644
49247 --- a/drivers/net/wireless/ath/ath10k/htc.h
49248 +++ b/drivers/net/wireless/ath/ath10k/htc.h
49249 @@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
49250
49251 struct ath10k_htc_ops {
49252 void (*target_send_suspend_complete)(struct ath10k *ar);
49253 -};
49254 +} __no_const;
49255
49256 struct ath10k_htc_ep_ops {
49257 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
49258 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
49259 void (*ep_tx_credits)(struct ath10k *);
49260 -};
49261 +} __no_const;
49262
49263 /* service connection information */
49264 struct ath10k_htc_svc_conn_req {
49265 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
49266 index 59af9f9..5f3564f 100644
49267 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
49268 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
49269 @@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49270 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
49271 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
49272
49273 - ACCESS_ONCE(ads->ds_link) = i->link;
49274 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
49275 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
49276 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
49277
49278 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
49279 ctl6 = SM(i->keytype, AR_EncrType);
49280 @@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49281
49282 if ((i->is_first || i->is_last) &&
49283 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
49284 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
49285 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
49286 | set11nTries(i->rates, 1)
49287 | set11nTries(i->rates, 2)
49288 | set11nTries(i->rates, 3)
49289 | (i->dur_update ? AR_DurUpdateEna : 0)
49290 | SM(0, AR_BurstDur);
49291
49292 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
49293 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
49294 | set11nRate(i->rates, 1)
49295 | set11nRate(i->rates, 2)
49296 | set11nRate(i->rates, 3);
49297 } else {
49298 - ACCESS_ONCE(ads->ds_ctl2) = 0;
49299 - ACCESS_ONCE(ads->ds_ctl3) = 0;
49300 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
49301 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
49302 }
49303
49304 if (!i->is_first) {
49305 - ACCESS_ONCE(ads->ds_ctl0) = 0;
49306 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
49307 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
49308 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
49309 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
49310 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
49311 return;
49312 }
49313
49314 @@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49315 break;
49316 }
49317
49318 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
49319 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
49320 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
49321 | SM(i->txpower, AR_XmitPower0)
49322 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
49323 @@ -289,27 +289,27 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49324 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
49325 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
49326
49327 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
49328 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
49329 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
49330 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
49331
49332 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
49333 return;
49334
49335 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
49336 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
49337 | set11nPktDurRTSCTS(i->rates, 1);
49338
49339 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
49340 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
49341 | set11nPktDurRTSCTS(i->rates, 3);
49342
49343 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
49344 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
49345 | set11nRateFlags(i->rates, 1)
49346 | set11nRateFlags(i->rates, 2)
49347 | set11nRateFlags(i->rates, 3)
49348 | SM(i->rtscts_rate, AR_RTSCTSRate);
49349
49350 - ACCESS_ONCE(ads->ds_ctl9) = SM(i->txpower, AR_XmitPower1);
49351 - ACCESS_ONCE(ads->ds_ctl10) = SM(i->txpower, AR_XmitPower2);
49352 - ACCESS_ONCE(ads->ds_ctl11) = SM(i->txpower, AR_XmitPower3);
49353 + ACCESS_ONCE_RW(ads->ds_ctl9) = SM(i->txpower, AR_XmitPower1);
49354 + ACCESS_ONCE_RW(ads->ds_ctl10) = SM(i->txpower, AR_XmitPower2);
49355 + ACCESS_ONCE_RW(ads->ds_ctl11) = SM(i->txpower, AR_XmitPower3);
49356 }
49357
49358 static int ar9002_hw_proc_txdesc(struct ath_hw *ah, void *ds,
49359 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49360 index 71e38e8..5ac96ca 100644
49361 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49362 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49363 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49364 (i->qcu << AR_TxQcuNum_S) | desc_len;
49365
49366 checksum += val;
49367 - ACCESS_ONCE(ads->info) = val;
49368 + ACCESS_ONCE_RW(ads->info) = val;
49369
49370 checksum += i->link;
49371 - ACCESS_ONCE(ads->link) = i->link;
49372 + ACCESS_ONCE_RW(ads->link) = i->link;
49373
49374 checksum += i->buf_addr[0];
49375 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
49376 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
49377 checksum += i->buf_addr[1];
49378 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
49379 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
49380 checksum += i->buf_addr[2];
49381 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
49382 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
49383 checksum += i->buf_addr[3];
49384 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
49385 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
49386
49387 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
49388 - ACCESS_ONCE(ads->ctl3) = val;
49389 + ACCESS_ONCE_RW(ads->ctl3) = val;
49390 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
49391 - ACCESS_ONCE(ads->ctl5) = val;
49392 + ACCESS_ONCE_RW(ads->ctl5) = val;
49393 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
49394 - ACCESS_ONCE(ads->ctl7) = val;
49395 + ACCESS_ONCE_RW(ads->ctl7) = val;
49396 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
49397 - ACCESS_ONCE(ads->ctl9) = val;
49398 + ACCESS_ONCE_RW(ads->ctl9) = val;
49399
49400 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
49401 - ACCESS_ONCE(ads->ctl10) = checksum;
49402 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
49403
49404 if (i->is_first || i->is_last) {
49405 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
49406 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
49407 | set11nTries(i->rates, 1)
49408 | set11nTries(i->rates, 2)
49409 | set11nTries(i->rates, 3)
49410 | (i->dur_update ? AR_DurUpdateEna : 0)
49411 | SM(0, AR_BurstDur);
49412
49413 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
49414 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
49415 | set11nRate(i->rates, 1)
49416 | set11nRate(i->rates, 2)
49417 | set11nRate(i->rates, 3);
49418 } else {
49419 - ACCESS_ONCE(ads->ctl13) = 0;
49420 - ACCESS_ONCE(ads->ctl14) = 0;
49421 + ACCESS_ONCE_RW(ads->ctl13) = 0;
49422 + ACCESS_ONCE_RW(ads->ctl14) = 0;
49423 }
49424
49425 ads->ctl20 = 0;
49426 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49427
49428 ctl17 = SM(i->keytype, AR_EncrType);
49429 if (!i->is_first) {
49430 - ACCESS_ONCE(ads->ctl11) = 0;
49431 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
49432 - ACCESS_ONCE(ads->ctl15) = 0;
49433 - ACCESS_ONCE(ads->ctl16) = 0;
49434 - ACCESS_ONCE(ads->ctl17) = ctl17;
49435 - ACCESS_ONCE(ads->ctl18) = 0;
49436 - ACCESS_ONCE(ads->ctl19) = 0;
49437 + ACCESS_ONCE_RW(ads->ctl11) = 0;
49438 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
49439 + ACCESS_ONCE_RW(ads->ctl15) = 0;
49440 + ACCESS_ONCE_RW(ads->ctl16) = 0;
49441 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
49442 + ACCESS_ONCE_RW(ads->ctl18) = 0;
49443 + ACCESS_ONCE_RW(ads->ctl19) = 0;
49444 return;
49445 }
49446
49447 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
49448 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
49449 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
49450 | SM(i->txpower, AR_XmitPower0)
49451 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
49452 @@ -135,26 +135,26 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49453 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
49454 ctl12 |= SM(val, AR_PAPRDChainMask);
49455
49456 - ACCESS_ONCE(ads->ctl12) = ctl12;
49457 - ACCESS_ONCE(ads->ctl17) = ctl17;
49458 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
49459 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
49460
49461 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
49462 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
49463 | set11nPktDurRTSCTS(i->rates, 1);
49464
49465 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
49466 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
49467 | set11nPktDurRTSCTS(i->rates, 3);
49468
49469 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
49470 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
49471 | set11nRateFlags(i->rates, 1)
49472 | set11nRateFlags(i->rates, 2)
49473 | set11nRateFlags(i->rates, 3)
49474 | SM(i->rtscts_rate, AR_RTSCTSRate);
49475
49476 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
49477 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
49478
49479 - ACCESS_ONCE(ads->ctl20) = SM(i->txpower, AR_XmitPower1);
49480 - ACCESS_ONCE(ads->ctl21) = SM(i->txpower, AR_XmitPower2);
49481 - ACCESS_ONCE(ads->ctl22) = SM(i->txpower, AR_XmitPower3);
49482 + ACCESS_ONCE_RW(ads->ctl20) = SM(i->txpower, AR_XmitPower1);
49483 + ACCESS_ONCE_RW(ads->ctl21) = SM(i->txpower, AR_XmitPower2);
49484 + ACCESS_ONCE_RW(ads->ctl22) = SM(i->txpower, AR_XmitPower3);
49485 }
49486
49487 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
49488 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
49489 index 51b4ebe..d1929dd 100644
49490 --- a/drivers/net/wireless/ath/ath9k/hw.h
49491 +++ b/drivers/net/wireless/ath/ath9k/hw.h
49492 @@ -629,7 +629,7 @@ struct ath_hw_private_ops {
49493
49494 /* ANI */
49495 void (*ani_cache_ini_regs)(struct ath_hw *ah);
49496 -};
49497 +} __no_const;
49498
49499 /**
49500 * struct ath_spec_scan - parameters for Atheros spectral scan
49501 @@ -706,7 +706,7 @@ struct ath_hw_ops {
49502 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
49503 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
49504 #endif
49505 -};
49506 +} __no_const;
49507
49508 struct ath_nf_limits {
49509 s16 max;
49510 diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c
49511 index 4b148bb..ac738fa 100644
49512 --- a/drivers/net/wireless/ath/ath9k/main.c
49513 +++ b/drivers/net/wireless/ath/ath9k/main.c
49514 @@ -2592,16 +2592,18 @@ void ath9k_fill_chanctx_ops(void)
49515 if (!ath9k_use_chanctx)
49516 return;
49517
49518 - ath9k_ops.hw_scan = ath9k_hw_scan;
49519 - ath9k_ops.cancel_hw_scan = ath9k_cancel_hw_scan;
49520 - ath9k_ops.remain_on_channel = ath9k_remain_on_channel;
49521 - ath9k_ops.cancel_remain_on_channel = ath9k_cancel_remain_on_channel;
49522 - ath9k_ops.add_chanctx = ath9k_add_chanctx;
49523 - ath9k_ops.remove_chanctx = ath9k_remove_chanctx;
49524 - ath9k_ops.change_chanctx = ath9k_change_chanctx;
49525 - ath9k_ops.assign_vif_chanctx = ath9k_assign_vif_chanctx;
49526 - ath9k_ops.unassign_vif_chanctx = ath9k_unassign_vif_chanctx;
49527 - ath9k_ops.mgd_prepare_tx = ath9k_chanctx_force_active;
49528 + pax_open_kernel();
49529 + *(void **)&ath9k_ops.hw_scan = ath9k_hw_scan;
49530 + *(void **)&ath9k_ops.cancel_hw_scan = ath9k_cancel_hw_scan;
49531 + *(void **)&ath9k_ops.remain_on_channel = ath9k_remain_on_channel;
49532 + *(void **)&ath9k_ops.cancel_remain_on_channel = ath9k_cancel_remain_on_channel;
49533 + *(void **)&ath9k_ops.add_chanctx = ath9k_add_chanctx;
49534 + *(void **)&ath9k_ops.remove_chanctx = ath9k_remove_chanctx;
49535 + *(void **)&ath9k_ops.change_chanctx = ath9k_change_chanctx;
49536 + *(void **)&ath9k_ops.assign_vif_chanctx = ath9k_assign_vif_chanctx;
49537 + *(void **)&ath9k_ops.unassign_vif_chanctx = ath9k_unassign_vif_chanctx;
49538 + *(void **)&ath9k_ops.mgd_prepare_tx = ath9k_chanctx_force_active;
49539 + pax_close_kernel();
49540 }
49541
49542 struct ieee80211_ops ath9k_ops = {
49543 diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
49544 index 92190da..f3a4c4c 100644
49545 --- a/drivers/net/wireless/b43/phy_lp.c
49546 +++ b/drivers/net/wireless/b43/phy_lp.c
49547 @@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
49548 {
49549 struct ssb_bus *bus = dev->dev->sdev->bus;
49550
49551 - static const struct b206x_channel *chandata = NULL;
49552 + const struct b206x_channel *chandata = NULL;
49553 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
49554 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
49555 u16 old_comm15, scale;
49556 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
49557 index dc1d20c..f7a4f06 100644
49558 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
49559 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
49560 @@ -3633,7 +3633,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
49561 */
49562 if (il3945_mod_params.disable_hw_scan) {
49563 D_INFO("Disabling hw_scan\n");
49564 - il3945_mac_ops.hw_scan = NULL;
49565 + pax_open_kernel();
49566 + *(void **)&il3945_mac_ops.hw_scan = NULL;
49567 + pax_close_kernel();
49568 }
49569
49570 D_INFO("*** LOAD DRIVER ***\n");
49571 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49572 index 0ffb6ff..c0b7f0e 100644
49573 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49574 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49575 @@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
49576 {
49577 struct iwl_priv *priv = file->private_data;
49578 char buf[64];
49579 - int buf_size;
49580 + size_t buf_size;
49581 u32 offset, len;
49582
49583 memset(buf, 0, sizeof(buf));
49584 @@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
49585 struct iwl_priv *priv = file->private_data;
49586
49587 char buf[8];
49588 - int buf_size;
49589 + size_t buf_size;
49590 u32 reset_flag;
49591
49592 memset(buf, 0, sizeof(buf));
49593 @@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
49594 {
49595 struct iwl_priv *priv = file->private_data;
49596 char buf[8];
49597 - int buf_size;
49598 + size_t buf_size;
49599 int ht40;
49600
49601 memset(buf, 0, sizeof(buf));
49602 @@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
49603 {
49604 struct iwl_priv *priv = file->private_data;
49605 char buf[8];
49606 - int buf_size;
49607 + size_t buf_size;
49608 int value;
49609
49610 memset(buf, 0, sizeof(buf));
49611 @@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
49612 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
49613 DEBUGFS_READ_FILE_OPS(current_sleep_command);
49614
49615 -static const char *fmt_value = " %-30s %10u\n";
49616 -static const char *fmt_hex = " %-30s 0x%02X\n";
49617 -static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
49618 -static const char *fmt_header =
49619 +static const char fmt_value[] = " %-30s %10u\n";
49620 +static const char fmt_hex[] = " %-30s 0x%02X\n";
49621 +static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
49622 +static const char fmt_header[] =
49623 "%-32s current cumulative delta max\n";
49624
49625 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
49626 @@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
49627 {
49628 struct iwl_priv *priv = file->private_data;
49629 char buf[8];
49630 - int buf_size;
49631 + size_t buf_size;
49632 int clear;
49633
49634 memset(buf, 0, sizeof(buf));
49635 @@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
49636 {
49637 struct iwl_priv *priv = file->private_data;
49638 char buf[8];
49639 - int buf_size;
49640 + size_t buf_size;
49641 int trace;
49642
49643 memset(buf, 0, sizeof(buf));
49644 @@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
49645 {
49646 struct iwl_priv *priv = file->private_data;
49647 char buf[8];
49648 - int buf_size;
49649 + size_t buf_size;
49650 int missed;
49651
49652 memset(buf, 0, sizeof(buf));
49653 @@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
49654
49655 struct iwl_priv *priv = file->private_data;
49656 char buf[8];
49657 - int buf_size;
49658 + size_t buf_size;
49659 int plcp;
49660
49661 memset(buf, 0, sizeof(buf));
49662 @@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
49663
49664 struct iwl_priv *priv = file->private_data;
49665 char buf[8];
49666 - int buf_size;
49667 + size_t buf_size;
49668 int flush;
49669
49670 memset(buf, 0, sizeof(buf));
49671 @@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
49672
49673 struct iwl_priv *priv = file->private_data;
49674 char buf[8];
49675 - int buf_size;
49676 + size_t buf_size;
49677 int rts;
49678
49679 if (!priv->cfg->ht_params)
49680 @@ -2204,7 +2204,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
49681 {
49682 struct iwl_priv *priv = file->private_data;
49683 char buf[8];
49684 - int buf_size;
49685 + size_t buf_size;
49686
49687 memset(buf, 0, sizeof(buf));
49688 buf_size = min(count, sizeof(buf) - 1);
49689 @@ -2238,7 +2238,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
49690 struct iwl_priv *priv = file->private_data;
49691 u32 event_log_flag;
49692 char buf[8];
49693 - int buf_size;
49694 + size_t buf_size;
49695
49696 /* check that the interface is up */
49697 if (!iwl_is_ready(priv))
49698 @@ -2292,7 +2292,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
49699 struct iwl_priv *priv = file->private_data;
49700 char buf[8];
49701 u32 calib_disabled;
49702 - int buf_size;
49703 + size_t buf_size;
49704
49705 memset(buf, 0, sizeof(buf));
49706 buf_size = min(count, sizeof(buf) - 1);
49707 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
49708 index 6c02467..771bb8a 100644
49709 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
49710 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
49711 @@ -1686,7 +1686,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
49712 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
49713
49714 char buf[8];
49715 - int buf_size;
49716 + size_t buf_size;
49717 u32 reset_flag;
49718
49719 memset(buf, 0, sizeof(buf));
49720 @@ -1707,7 +1707,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
49721 {
49722 struct iwl_trans *trans = file->private_data;
49723 char buf[8];
49724 - int buf_size;
49725 + size_t buf_size;
49726 int csr;
49727
49728 memset(buf, 0, sizeof(buf));
49729 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
49730 index 6b48c865..19646a7 100644
49731 --- a/drivers/net/wireless/mac80211_hwsim.c
49732 +++ b/drivers/net/wireless/mac80211_hwsim.c
49733 @@ -2577,20 +2577,20 @@ static int __init init_mac80211_hwsim(void)
49734 if (channels < 1)
49735 return -EINVAL;
49736
49737 - mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
49738 - mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
49739 - mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
49740 - mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
49741 - mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
49742 - mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
49743 - mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
49744 - mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
49745 - mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
49746 - mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
49747 - mac80211_hwsim_mchan_ops.assign_vif_chanctx =
49748 - mac80211_hwsim_assign_vif_chanctx;
49749 - mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
49750 - mac80211_hwsim_unassign_vif_chanctx;
49751 + pax_open_kernel();
49752 + memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
49753 + *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
49754 + *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
49755 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
49756 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
49757 + *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
49758 + *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
49759 + *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
49760 + *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
49761 + *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
49762 + *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
49763 + *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
49764 + pax_close_kernel();
49765
49766 spin_lock_init(&hwsim_radio_lock);
49767 INIT_LIST_HEAD(&hwsim_radios);
49768 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
49769 index d2a9a08..0cb175d 100644
49770 --- a/drivers/net/wireless/rndis_wlan.c
49771 +++ b/drivers/net/wireless/rndis_wlan.c
49772 @@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
49773
49774 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
49775
49776 - if (rts_threshold < 0 || rts_threshold > 2347)
49777 + if (rts_threshold > 2347)
49778 rts_threshold = 2347;
49779
49780 tmp = cpu_to_le32(rts_threshold);
49781 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
49782 index d13f25c..2573994 100644
49783 --- a/drivers/net/wireless/rt2x00/rt2x00.h
49784 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
49785 @@ -375,7 +375,7 @@ struct rt2x00_intf {
49786 * for hardware which doesn't support hardware
49787 * sequence counting.
49788 */
49789 - atomic_t seqno;
49790 + atomic_unchecked_t seqno;
49791 };
49792
49793 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
49794 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
49795 index 8e68f87..c35ba29 100644
49796 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
49797 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
49798 @@ -250,9 +250,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
49799 * sequence counter given by mac80211.
49800 */
49801 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
49802 - seqno = atomic_add_return(0x10, &intf->seqno);
49803 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
49804 else
49805 - seqno = atomic_read(&intf->seqno);
49806 + seqno = atomic_read_unchecked(&intf->seqno);
49807
49808 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
49809 hdr->seq_ctrl |= cpu_to_le16(seqno);
49810 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
49811 index b661f896..ddf7d2b 100644
49812 --- a/drivers/net/wireless/ti/wl1251/sdio.c
49813 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
49814 @@ -282,13 +282,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
49815
49816 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
49817
49818 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
49819 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
49820 + pax_open_kernel();
49821 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
49822 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
49823 + pax_close_kernel();
49824
49825 wl1251_info("using dedicated interrupt line");
49826 } else {
49827 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
49828 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
49829 + pax_open_kernel();
49830 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
49831 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
49832 + pax_close_kernel();
49833
49834 wl1251_info("using SDIO interrupt");
49835 }
49836 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
49837 index 0bccf12..3d95068 100644
49838 --- a/drivers/net/wireless/ti/wl12xx/main.c
49839 +++ b/drivers/net/wireless/ti/wl12xx/main.c
49840 @@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
49841 sizeof(wl->conf.mem));
49842
49843 /* read data preparation is only needed by wl127x */
49844 - wl->ops->prepare_read = wl127x_prepare_read;
49845 + pax_open_kernel();
49846 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
49847 + pax_close_kernel();
49848
49849 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
49850 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
49851 @@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
49852 sizeof(wl->conf.mem));
49853
49854 /* read data preparation is only needed by wl127x */
49855 - wl->ops->prepare_read = wl127x_prepare_read;
49856 + pax_open_kernel();
49857 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
49858 + pax_close_kernel();
49859
49860 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
49861 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
49862 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
49863 index 7af1936..128bb35 100644
49864 --- a/drivers/net/wireless/ti/wl18xx/main.c
49865 +++ b/drivers/net/wireless/ti/wl18xx/main.c
49866 @@ -1916,8 +1916,10 @@ static int wl18xx_setup(struct wl1271 *wl)
49867 }
49868
49869 if (!checksum_param) {
49870 - wl18xx_ops.set_rx_csum = NULL;
49871 - wl18xx_ops.init_vif = NULL;
49872 + pax_open_kernel();
49873 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
49874 + *(void **)&wl18xx_ops.init_vif = NULL;
49875 + pax_close_kernel();
49876 }
49877
49878 /* Enable 11a Band only if we have 5G antennas */
49879 diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
49880 index a912dc0..a8225ba 100644
49881 --- a/drivers/net/wireless/zd1211rw/zd_usb.c
49882 +++ b/drivers/net/wireless/zd1211rw/zd_usb.c
49883 @@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
49884 {
49885 struct zd_usb *usb = urb->context;
49886 struct zd_usb_interrupt *intr = &usb->intr;
49887 - int len;
49888 + unsigned int len;
49889 u16 int_num;
49890
49891 ZD_ASSERT(in_interrupt());
49892 diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
49893 index ca82f54..3767771 100644
49894 --- a/drivers/net/xen-netfront.c
49895 +++ b/drivers/net/xen-netfront.c
49896 @@ -496,9 +496,6 @@ static void xennet_make_frags(struct sk_buff *skb, struct netfront_queue *queue,
49897 len = skb_frag_size(frag);
49898 offset = frag->page_offset;
49899
49900 - /* Data must not cross a page boundary. */
49901 - BUG_ON(len + offset > PAGE_SIZE<<compound_order(page));
49902 -
49903 /* Skip unused frames from start of page */
49904 page += offset >> PAGE_SHIFT;
49905 offset &= ~PAGE_MASK;
49906 @@ -506,8 +503,6 @@ static void xennet_make_frags(struct sk_buff *skb, struct netfront_queue *queue,
49907 while (len > 0) {
49908 unsigned long bytes;
49909
49910 - BUG_ON(offset >= PAGE_SIZE);
49911 -
49912 bytes = PAGE_SIZE - offset;
49913 if (bytes > len)
49914 bytes = len;
49915 diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
49916 index 683671a..4519fc2 100644
49917 --- a/drivers/nfc/nfcwilink.c
49918 +++ b/drivers/nfc/nfcwilink.c
49919 @@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
49920
49921 static int nfcwilink_probe(struct platform_device *pdev)
49922 {
49923 - static struct nfcwilink *drv;
49924 + struct nfcwilink *drv;
49925 int rc;
49926 __u32 protocols;
49927
49928 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
49929 index d93b2b6..ae50401 100644
49930 --- a/drivers/oprofile/buffer_sync.c
49931 +++ b/drivers/oprofile/buffer_sync.c
49932 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
49933 if (cookie == NO_COOKIE)
49934 offset = pc;
49935 if (cookie == INVALID_COOKIE) {
49936 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
49937 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
49938 offset = pc;
49939 }
49940 if (cookie != last_cookie) {
49941 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
49942 /* add userspace sample */
49943
49944 if (!mm) {
49945 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
49946 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
49947 return 0;
49948 }
49949
49950 cookie = lookup_dcookie(mm, s->eip, &offset);
49951
49952 if (cookie == INVALID_COOKIE) {
49953 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
49954 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
49955 return 0;
49956 }
49957
49958 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
49959 /* ignore backtraces if failed to add a sample */
49960 if (state == sb_bt_start) {
49961 state = sb_bt_ignore;
49962 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
49963 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
49964 }
49965 }
49966 release_mm(mm);
49967 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
49968 index c0cc4e7..44d4e54 100644
49969 --- a/drivers/oprofile/event_buffer.c
49970 +++ b/drivers/oprofile/event_buffer.c
49971 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
49972 }
49973
49974 if (buffer_pos == buffer_size) {
49975 - atomic_inc(&oprofile_stats.event_lost_overflow);
49976 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
49977 return;
49978 }
49979
49980 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
49981 index ed2c3ec..deda85a 100644
49982 --- a/drivers/oprofile/oprof.c
49983 +++ b/drivers/oprofile/oprof.c
49984 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
49985 if (oprofile_ops.switch_events())
49986 return;
49987
49988 - atomic_inc(&oprofile_stats.multiplex_counter);
49989 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
49990 start_switch_worker();
49991 }
49992
49993 diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
49994 index ee2cfce..7f8f699 100644
49995 --- a/drivers/oprofile/oprofile_files.c
49996 +++ b/drivers/oprofile/oprofile_files.c
49997 @@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
49998
49999 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
50000
50001 -static ssize_t timeout_read(struct file *file, char __user *buf,
50002 +static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
50003 size_t count, loff_t *offset)
50004 {
50005 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
50006 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
50007 index 59659ce..6c860a0 100644
50008 --- a/drivers/oprofile/oprofile_stats.c
50009 +++ b/drivers/oprofile/oprofile_stats.c
50010 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
50011 cpu_buf->sample_invalid_eip = 0;
50012 }
50013
50014 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
50015 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
50016 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
50017 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
50018 - atomic_set(&oprofile_stats.multiplex_counter, 0);
50019 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
50020 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
50021 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
50022 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
50023 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
50024 }
50025
50026
50027 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
50028 index 1fc622b..8c48fc3 100644
50029 --- a/drivers/oprofile/oprofile_stats.h
50030 +++ b/drivers/oprofile/oprofile_stats.h
50031 @@ -13,11 +13,11 @@
50032 #include <linux/atomic.h>
50033
50034 struct oprofile_stat_struct {
50035 - atomic_t sample_lost_no_mm;
50036 - atomic_t sample_lost_no_mapping;
50037 - atomic_t bt_lost_no_mapping;
50038 - atomic_t event_lost_overflow;
50039 - atomic_t multiplex_counter;
50040 + atomic_unchecked_t sample_lost_no_mm;
50041 + atomic_unchecked_t sample_lost_no_mapping;
50042 + atomic_unchecked_t bt_lost_no_mapping;
50043 + atomic_unchecked_t event_lost_overflow;
50044 + atomic_unchecked_t multiplex_counter;
50045 };
50046
50047 extern struct oprofile_stat_struct oprofile_stats;
50048 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
50049 index 3f49345..c750d0b 100644
50050 --- a/drivers/oprofile/oprofilefs.c
50051 +++ b/drivers/oprofile/oprofilefs.c
50052 @@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
50053
50054 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
50055 {
50056 - atomic_t *val = file->private_data;
50057 - return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
50058 + atomic_unchecked_t *val = file->private_data;
50059 + return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
50060 }
50061
50062
50063 @@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
50064
50065
50066 int oprofilefs_create_ro_atomic(struct dentry *root,
50067 - char const *name, atomic_t *val)
50068 + char const *name, atomic_unchecked_t *val)
50069 {
50070 return __oprofilefs_create_file(root, name,
50071 &atomic_ro_fops, 0444, val);
50072 diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
50073 index 61be1d9..dec05d7 100644
50074 --- a/drivers/oprofile/timer_int.c
50075 +++ b/drivers/oprofile/timer_int.c
50076 @@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
50077 return NOTIFY_OK;
50078 }
50079
50080 -static struct notifier_block __refdata oprofile_cpu_notifier = {
50081 +static struct notifier_block oprofile_cpu_notifier = {
50082 .notifier_call = oprofile_cpu_notify,
50083 };
50084
50085 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
50086 index 3b47080..6cd05dd 100644
50087 --- a/drivers/parport/procfs.c
50088 +++ b/drivers/parport/procfs.c
50089 @@ -64,7 +64,7 @@ static int do_active_device(struct ctl_table *table, int write,
50090
50091 *ppos += len;
50092
50093 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
50094 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
50095 }
50096
50097 #ifdef CONFIG_PARPORT_1284
50098 @@ -106,7 +106,7 @@ static int do_autoprobe(struct ctl_table *table, int write,
50099
50100 *ppos += len;
50101
50102 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
50103 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
50104 }
50105 #endif /* IEEE1284.3 support. */
50106
50107 diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
50108 index 8dcccff..35d701d 100644
50109 --- a/drivers/pci/hotplug/acpiphp_ibm.c
50110 +++ b/drivers/pci/hotplug/acpiphp_ibm.c
50111 @@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
50112 goto init_cleanup;
50113 }
50114
50115 - ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
50116 + pax_open_kernel();
50117 + *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
50118 + pax_close_kernel();
50119 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
50120
50121 return retval;
50122 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
50123 index 04fcd78..39e83f1 100644
50124 --- a/drivers/pci/hotplug/cpcihp_generic.c
50125 +++ b/drivers/pci/hotplug/cpcihp_generic.c
50126 @@ -73,7 +73,6 @@ static u16 port;
50127 static unsigned int enum_bit;
50128 static u8 enum_mask;
50129
50130 -static struct cpci_hp_controller_ops generic_hpc_ops;
50131 static struct cpci_hp_controller generic_hpc;
50132
50133 static int __init validate_parameters(void)
50134 @@ -139,6 +138,10 @@ static int query_enum(void)
50135 return ((value & enum_mask) == enum_mask);
50136 }
50137
50138 +static struct cpci_hp_controller_ops generic_hpc_ops = {
50139 + .query_enum = query_enum,
50140 +};
50141 +
50142 static int __init cpcihp_generic_init(void)
50143 {
50144 int status;
50145 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
50146 pci_dev_put(dev);
50147
50148 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
50149 - generic_hpc_ops.query_enum = query_enum;
50150 generic_hpc.ops = &generic_hpc_ops;
50151
50152 status = cpci_hp_register_controller(&generic_hpc);
50153 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
50154 index 6757b3e..d3bad62 100644
50155 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
50156 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
50157 @@ -59,7 +59,6 @@
50158 /* local variables */
50159 static bool debug;
50160 static bool poll;
50161 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
50162 static struct cpci_hp_controller zt5550_hpc;
50163
50164 /* Primary cPCI bus bridge device */
50165 @@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
50166 return 0;
50167 }
50168
50169 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
50170 + .query_enum = zt5550_hc_query_enum,
50171 +};
50172 +
50173 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
50174 {
50175 int status;
50176 @@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
50177 dbg("returned from zt5550_hc_config");
50178
50179 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
50180 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
50181 zt5550_hpc.ops = &zt5550_hpc_ops;
50182 if(!poll) {
50183 zt5550_hpc.irq = hc_dev->irq;
50184 zt5550_hpc.irq_flags = IRQF_SHARED;
50185 zt5550_hpc.dev_id = hc_dev;
50186
50187 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
50188 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
50189 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
50190 + pax_open_kernel();
50191 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
50192 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
50193 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
50194 + pax_open_kernel();
50195 } else {
50196 info("using ENUM# polling mode");
50197 }
50198 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
50199 index 0968a9b..5a00edf 100644
50200 --- a/drivers/pci/hotplug/cpqphp_nvram.c
50201 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
50202 @@ -427,9 +427,13 @@ static u32 store_HRT (void __iomem *rom_start)
50203
50204 void compaq_nvram_init (void __iomem *rom_start)
50205 {
50206 +
50207 +#ifndef CONFIG_PAX_KERNEXEC
50208 if (rom_start) {
50209 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
50210 }
50211 +#endif
50212 +
50213 dbg("int15 entry = %p\n", compaq_int15_entry_point);
50214
50215 /* initialize our int15 lock */
50216 diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
50217 index 56d8486..f26113f 100644
50218 --- a/drivers/pci/hotplug/pci_hotplug_core.c
50219 +++ b/drivers/pci/hotplug/pci_hotplug_core.c
50220 @@ -436,8 +436,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
50221 return -EINVAL;
50222 }
50223
50224 - slot->ops->owner = owner;
50225 - slot->ops->mod_name = mod_name;
50226 + pax_open_kernel();
50227 + *(struct module **)&slot->ops->owner = owner;
50228 + *(const char **)&slot->ops->mod_name = mod_name;
50229 + pax_close_kernel();
50230
50231 mutex_lock(&pci_hp_mutex);
50232 /*
50233 diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
50234 index 07aa722..84514b4 100644
50235 --- a/drivers/pci/hotplug/pciehp_core.c
50236 +++ b/drivers/pci/hotplug/pciehp_core.c
50237 @@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
50238 struct slot *slot = ctrl->slot;
50239 struct hotplug_slot *hotplug = NULL;
50240 struct hotplug_slot_info *info = NULL;
50241 - struct hotplug_slot_ops *ops = NULL;
50242 + hotplug_slot_ops_no_const *ops = NULL;
50243 char name[SLOT_NAME_SIZE];
50244 int retval = -ENOMEM;
50245
50246 diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
50247 index 5a40516..136d5a7 100644
50248 --- a/drivers/pci/msi.c
50249 +++ b/drivers/pci/msi.c
50250 @@ -507,8 +507,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
50251 {
50252 struct attribute **msi_attrs;
50253 struct attribute *msi_attr;
50254 - struct device_attribute *msi_dev_attr;
50255 - struct attribute_group *msi_irq_group;
50256 + device_attribute_no_const *msi_dev_attr;
50257 + attribute_group_no_const *msi_irq_group;
50258 const struct attribute_group **msi_irq_groups;
50259 struct msi_desc *entry;
50260 int ret = -ENOMEM;
50261 @@ -568,7 +568,7 @@ error_attrs:
50262 count = 0;
50263 msi_attr = msi_attrs[count];
50264 while (msi_attr) {
50265 - msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
50266 + msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
50267 kfree(msi_attr->name);
50268 kfree(msi_dev_attr);
50269 ++count;
50270 diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
50271 index 6d04771..4126004 100644
50272 --- a/drivers/pci/pci-sysfs.c
50273 +++ b/drivers/pci/pci-sysfs.c
50274 @@ -1134,7 +1134,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
50275 {
50276 /* allocate attribute structure, piggyback attribute name */
50277 int name_len = write_combine ? 13 : 10;
50278 - struct bin_attribute *res_attr;
50279 + bin_attribute_no_const *res_attr;
50280 int retval;
50281
50282 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
50283 @@ -1311,7 +1311,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
50284 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
50285 {
50286 int retval;
50287 - struct bin_attribute *attr;
50288 + bin_attribute_no_const *attr;
50289
50290 /* If the device has VPD, try to expose it in sysfs. */
50291 if (dev->vpd) {
50292 @@ -1358,7 +1358,7 @@ int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev)
50293 {
50294 int retval;
50295 int rom_size = 0;
50296 - struct bin_attribute *attr;
50297 + bin_attribute_no_const *attr;
50298
50299 if (!sysfs_initialized)
50300 return -EACCES;
50301 diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
50302 index 0601890..dc15007 100644
50303 --- a/drivers/pci/pci.h
50304 +++ b/drivers/pci/pci.h
50305 @@ -91,7 +91,7 @@ struct pci_vpd_ops {
50306 struct pci_vpd {
50307 unsigned int len;
50308 const struct pci_vpd_ops *ops;
50309 - struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
50310 + bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
50311 };
50312
50313 int pci_vpd_pci22_init(struct pci_dev *dev);
50314 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
50315 index e1e7026..d28dd33 100644
50316 --- a/drivers/pci/pcie/aspm.c
50317 +++ b/drivers/pci/pcie/aspm.c
50318 @@ -27,9 +27,9 @@
50319 #define MODULE_PARAM_PREFIX "pcie_aspm."
50320
50321 /* Note: those are not register definitions */
50322 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
50323 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
50324 -#define ASPM_STATE_L1 (4) /* L1 state */
50325 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
50326 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
50327 +#define ASPM_STATE_L1 (4U) /* L1 state */
50328 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
50329 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
50330
50331 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
50332 index 4170113..7cc5339 100644
50333 --- a/drivers/pci/probe.c
50334 +++ b/drivers/pci/probe.c
50335 @@ -176,7 +176,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
50336 struct pci_bus_region region, inverted_region;
50337 bool bar_too_big = false, bar_too_high = false, bar_invalid = false;
50338
50339 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
50340 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
50341
50342 /* No printks while decoding is disabled! */
50343 if (!dev->mmio_always_on) {
50344 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
50345 index 3f155e7..0f4b1f0 100644
50346 --- a/drivers/pci/proc.c
50347 +++ b/drivers/pci/proc.c
50348 @@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
50349 static int __init pci_proc_init(void)
50350 {
50351 struct pci_dev *dev = NULL;
50352 +
50353 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
50354 +#ifdef CONFIG_GRKERNSEC_PROC_USER
50355 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
50356 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50357 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
50358 +#endif
50359 +#else
50360 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
50361 +#endif
50362 proc_create("devices", 0, proc_bus_pci_dir,
50363 &proc_bus_pci_dev_operations);
50364 proc_initialized = 1;
50365 diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
50366 index d866db8..c827d1f 100644
50367 --- a/drivers/platform/chrome/chromeos_laptop.c
50368 +++ b/drivers/platform/chrome/chromeos_laptop.c
50369 @@ -479,7 +479,7 @@ static struct chromeos_laptop cr48 = {
50370 .callback = chromeos_laptop_dmi_matched, \
50371 .driver_data = (void *)&board_
50372
50373 -static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
50374 +static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
50375 {
50376 .ident = "Samsung Series 5 550",
50377 .matches = {
50378 diff --git a/drivers/platform/x86/alienware-wmi.c b/drivers/platform/x86/alienware-wmi.c
50379 index c5af23b..3d62d5e 100644
50380 --- a/drivers/platform/x86/alienware-wmi.c
50381 +++ b/drivers/platform/x86/alienware-wmi.c
50382 @@ -150,7 +150,7 @@ struct wmax_led_args {
50383 } __packed;
50384
50385 static struct platform_device *platform_device;
50386 -static struct device_attribute *zone_dev_attrs;
50387 +static device_attribute_no_const *zone_dev_attrs;
50388 static struct attribute **zone_attrs;
50389 static struct platform_zone *zone_data;
50390
50391 @@ -161,7 +161,7 @@ static struct platform_driver platform_driver = {
50392 }
50393 };
50394
50395 -static struct attribute_group zone_attribute_group = {
50396 +static attribute_group_no_const zone_attribute_group = {
50397 .name = "rgb_zones",
50398 };
50399
50400 diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
50401 index 21fc932..ee9394a 100644
50402 --- a/drivers/platform/x86/asus-wmi.c
50403 +++ b/drivers/platform/x86/asus-wmi.c
50404 @@ -1590,6 +1590,10 @@ static int show_dsts(struct seq_file *m, void *data)
50405 int err;
50406 u32 retval = -1;
50407
50408 +#ifdef CONFIG_GRKERNSEC_KMEM
50409 + return -EPERM;
50410 +#endif
50411 +
50412 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
50413
50414 if (err < 0)
50415 @@ -1606,6 +1610,10 @@ static int show_devs(struct seq_file *m, void *data)
50416 int err;
50417 u32 retval = -1;
50418
50419 +#ifdef CONFIG_GRKERNSEC_KMEM
50420 + return -EPERM;
50421 +#endif
50422 +
50423 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
50424 &retval);
50425
50426 @@ -1630,6 +1638,10 @@ static int show_call(struct seq_file *m, void *data)
50427 union acpi_object *obj;
50428 acpi_status status;
50429
50430 +#ifdef CONFIG_GRKERNSEC_KMEM
50431 + return -EPERM;
50432 +#endif
50433 +
50434 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
50435 1, asus->debug.method_id,
50436 &input, &output);
50437 diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
50438 index 62f8030..c7f2a45 100644
50439 --- a/drivers/platform/x86/msi-laptop.c
50440 +++ b/drivers/platform/x86/msi-laptop.c
50441 @@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
50442
50443 if (!quirks->ec_read_only) {
50444 /* allow userland write sysfs file */
50445 - dev_attr_bluetooth.store = store_bluetooth;
50446 - dev_attr_wlan.store = store_wlan;
50447 - dev_attr_threeg.store = store_threeg;
50448 - dev_attr_bluetooth.attr.mode |= S_IWUSR;
50449 - dev_attr_wlan.attr.mode |= S_IWUSR;
50450 - dev_attr_threeg.attr.mode |= S_IWUSR;
50451 + pax_open_kernel();
50452 + *(void **)&dev_attr_bluetooth.store = store_bluetooth;
50453 + *(void **)&dev_attr_wlan.store = store_wlan;
50454 + *(void **)&dev_attr_threeg.store = store_threeg;
50455 + *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
50456 + *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
50457 + *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
50458 + pax_close_kernel();
50459 }
50460
50461 /* disable hardware control by fn key */
50462 diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
50463 index 70222f2..8c8ce66 100644
50464 --- a/drivers/platform/x86/msi-wmi.c
50465 +++ b/drivers/platform/x86/msi-wmi.c
50466 @@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
50467 static void msi_wmi_notify(u32 value, void *context)
50468 {
50469 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
50470 - static struct key_entry *key;
50471 + struct key_entry *key;
50472 union acpi_object *obj;
50473 acpi_status status;
50474
50475 diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
50476 index 26ad9ff..7c52909 100644
50477 --- a/drivers/platform/x86/sony-laptop.c
50478 +++ b/drivers/platform/x86/sony-laptop.c
50479 @@ -2527,7 +2527,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
50480 }
50481
50482 /* High speed charging function */
50483 -static struct device_attribute *hsc_handle;
50484 +static device_attribute_no_const *hsc_handle;
50485
50486 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
50487 struct device_attribute *attr,
50488 @@ -2601,7 +2601,7 @@ static void sony_nc_highspeed_charging_cleanup(struct platform_device *pd)
50489 }
50490
50491 /* low battery function */
50492 -static struct device_attribute *lowbatt_handle;
50493 +static device_attribute_no_const *lowbatt_handle;
50494
50495 static ssize_t sony_nc_lowbatt_store(struct device *dev,
50496 struct device_attribute *attr,
50497 @@ -2667,7 +2667,7 @@ static void sony_nc_lowbatt_cleanup(struct platform_device *pd)
50498 }
50499
50500 /* fan speed function */
50501 -static struct device_attribute *fan_handle, *hsf_handle;
50502 +static device_attribute_no_const *fan_handle, *hsf_handle;
50503
50504 static ssize_t sony_nc_hsfan_store(struct device *dev,
50505 struct device_attribute *attr,
50506 @@ -2774,7 +2774,7 @@ static void sony_nc_fanspeed_cleanup(struct platform_device *pd)
50507 }
50508
50509 /* USB charge function */
50510 -static struct device_attribute *uc_handle;
50511 +static device_attribute_no_const *uc_handle;
50512
50513 static ssize_t sony_nc_usb_charge_store(struct device *dev,
50514 struct device_attribute *attr,
50515 @@ -2848,7 +2848,7 @@ static void sony_nc_usb_charge_cleanup(struct platform_device *pd)
50516 }
50517
50518 /* Panel ID function */
50519 -static struct device_attribute *panel_handle;
50520 +static device_attribute_no_const *panel_handle;
50521
50522 static ssize_t sony_nc_panelid_show(struct device *dev,
50523 struct device_attribute *attr, char *buffer)
50524 @@ -2895,7 +2895,7 @@ static void sony_nc_panelid_cleanup(struct platform_device *pd)
50525 }
50526
50527 /* smart connect function */
50528 -static struct device_attribute *sc_handle;
50529 +static device_attribute_no_const *sc_handle;
50530
50531 static ssize_t sony_nc_smart_conn_store(struct device *dev,
50532 struct device_attribute *attr,
50533 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
50534 index 3bbc6eb..7760460 100644
50535 --- a/drivers/platform/x86/thinkpad_acpi.c
50536 +++ b/drivers/platform/x86/thinkpad_acpi.c
50537 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
50538 return 0;
50539 }
50540
50541 -void static hotkey_mask_warn_incomplete_mask(void)
50542 +static void hotkey_mask_warn_incomplete_mask(void)
50543 {
50544 /* log only what the user can fix... */
50545 const u32 wantedmask = hotkey_driver_mask &
50546 @@ -2438,10 +2438,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
50547 && !tp_features.bright_unkfw)
50548 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
50549 }
50550 +}
50551
50552 #undef TPACPI_COMPARE_KEY
50553 #undef TPACPI_MAY_SEND_KEY
50554 -}
50555
50556 /*
50557 * Polling driver
50558 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
50559 index 438d4c7..ca8a2fb 100644
50560 --- a/drivers/pnp/pnpbios/bioscalls.c
50561 +++ b/drivers/pnp/pnpbios/bioscalls.c
50562 @@ -59,7 +59,7 @@ do { \
50563 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
50564 } while(0)
50565
50566 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
50567 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
50568 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
50569
50570 /*
50571 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
50572
50573 cpu = get_cpu();
50574 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
50575 +
50576 + pax_open_kernel();
50577 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
50578 + pax_close_kernel();
50579
50580 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
50581 spin_lock_irqsave(&pnp_bios_lock, flags);
50582 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
50583 :"memory");
50584 spin_unlock_irqrestore(&pnp_bios_lock, flags);
50585
50586 + pax_open_kernel();
50587 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
50588 + pax_close_kernel();
50589 +
50590 put_cpu();
50591
50592 /* If we get here and this is set then the PnP BIOS faulted on us. */
50593 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
50594 return status;
50595 }
50596
50597 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
50598 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
50599 {
50600 int i;
50601
50602 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
50603 pnp_bios_callpoint.offset = header->fields.pm16offset;
50604 pnp_bios_callpoint.segment = PNP_CS16;
50605
50606 + pax_open_kernel();
50607 +
50608 for_each_possible_cpu(i) {
50609 struct desc_struct *gdt = get_cpu_gdt_table(i);
50610 if (!gdt)
50611 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
50612 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
50613 (unsigned long)__va(header->fields.pm16dseg));
50614 }
50615 +
50616 + pax_close_kernel();
50617 }
50618 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
50619 index 0c52e2a..3421ab7 100644
50620 --- a/drivers/power/pda_power.c
50621 +++ b/drivers/power/pda_power.c
50622 @@ -37,7 +37,11 @@ static int polling;
50623
50624 #if IS_ENABLED(CONFIG_USB_PHY)
50625 static struct usb_phy *transceiver;
50626 -static struct notifier_block otg_nb;
50627 +static int otg_handle_notification(struct notifier_block *nb,
50628 + unsigned long event, void *unused);
50629 +static struct notifier_block otg_nb = {
50630 + .notifier_call = otg_handle_notification
50631 +};
50632 #endif
50633
50634 static struct regulator *ac_draw;
50635 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
50636
50637 #if IS_ENABLED(CONFIG_USB_PHY)
50638 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
50639 - otg_nb.notifier_call = otg_handle_notification;
50640 ret = usb_register_notifier(transceiver, &otg_nb);
50641 if (ret) {
50642 dev_err(dev, "failure to register otg notifier\n");
50643 diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
50644 index cc439fd..8fa30df 100644
50645 --- a/drivers/power/power_supply.h
50646 +++ b/drivers/power/power_supply.h
50647 @@ -16,12 +16,12 @@ struct power_supply;
50648
50649 #ifdef CONFIG_SYSFS
50650
50651 -extern void power_supply_init_attrs(struct device_type *dev_type);
50652 +extern void power_supply_init_attrs(void);
50653 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
50654
50655 #else
50656
50657 -static inline void power_supply_init_attrs(struct device_type *dev_type) {}
50658 +static inline void power_supply_init_attrs(void) {}
50659 #define power_supply_uevent NULL
50660
50661 #endif /* CONFIG_SYSFS */
50662 diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
50663 index 078afd6..fbac9da 100644
50664 --- a/drivers/power/power_supply_core.c
50665 +++ b/drivers/power/power_supply_core.c
50666 @@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
50667 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
50668 EXPORT_SYMBOL_GPL(power_supply_notifier);
50669
50670 -static struct device_type power_supply_dev_type;
50671 +extern const struct attribute_group *power_supply_attr_groups[];
50672 +static struct device_type power_supply_dev_type = {
50673 + .groups = power_supply_attr_groups,
50674 +};
50675
50676 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
50677 struct power_supply *supply)
50678 @@ -640,7 +643,7 @@ static int __init power_supply_class_init(void)
50679 return PTR_ERR(power_supply_class);
50680
50681 power_supply_class->dev_uevent = power_supply_uevent;
50682 - power_supply_init_attrs(&power_supply_dev_type);
50683 + power_supply_init_attrs();
50684
50685 return 0;
50686 }
50687 diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
50688 index 750a202..99c8f4b 100644
50689 --- a/drivers/power/power_supply_sysfs.c
50690 +++ b/drivers/power/power_supply_sysfs.c
50691 @@ -234,17 +234,15 @@ static struct attribute_group power_supply_attr_group = {
50692 .is_visible = power_supply_attr_is_visible,
50693 };
50694
50695 -static const struct attribute_group *power_supply_attr_groups[] = {
50696 +const struct attribute_group *power_supply_attr_groups[] = {
50697 &power_supply_attr_group,
50698 NULL,
50699 };
50700
50701 -void power_supply_init_attrs(struct device_type *dev_type)
50702 +void power_supply_init_attrs(void)
50703 {
50704 int i;
50705
50706 - dev_type->groups = power_supply_attr_groups;
50707 -
50708 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
50709 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
50710 }
50711 diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
50712 index 84419af..268ede8 100644
50713 --- a/drivers/powercap/powercap_sys.c
50714 +++ b/drivers/powercap/powercap_sys.c
50715 @@ -154,8 +154,77 @@ struct powercap_constraint_attr {
50716 struct device_attribute name_attr;
50717 };
50718
50719 +static ssize_t show_constraint_name(struct device *dev,
50720 + struct device_attribute *dev_attr,
50721 + char *buf);
50722 +
50723 static struct powercap_constraint_attr
50724 - constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
50725 + constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
50726 + [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
50727 + .power_limit_attr = {
50728 + .attr = {
50729 + .name = NULL,
50730 + .mode = S_IWUSR | S_IRUGO
50731 + },
50732 + .show = show_constraint_power_limit_uw,
50733 + .store = store_constraint_power_limit_uw
50734 + },
50735 +
50736 + .time_window_attr = {
50737 + .attr = {
50738 + .name = NULL,
50739 + .mode = S_IWUSR | S_IRUGO
50740 + },
50741 + .show = show_constraint_time_window_us,
50742 + .store = store_constraint_time_window_us
50743 + },
50744 +
50745 + .max_power_attr = {
50746 + .attr = {
50747 + .name = NULL,
50748 + .mode = S_IRUGO
50749 + },
50750 + .show = show_constraint_max_power_uw,
50751 + .store = NULL
50752 + },
50753 +
50754 + .min_power_attr = {
50755 + .attr = {
50756 + .name = NULL,
50757 + .mode = S_IRUGO
50758 + },
50759 + .show = show_constraint_min_power_uw,
50760 + .store = NULL
50761 + },
50762 +
50763 + .max_time_window_attr = {
50764 + .attr = {
50765 + .name = NULL,
50766 + .mode = S_IRUGO
50767 + },
50768 + .show = show_constraint_max_time_window_us,
50769 + .store = NULL
50770 + },
50771 +
50772 + .min_time_window_attr = {
50773 + .attr = {
50774 + .name = NULL,
50775 + .mode = S_IRUGO
50776 + },
50777 + .show = show_constraint_min_time_window_us,
50778 + .store = NULL
50779 + },
50780 +
50781 + .name_attr = {
50782 + .attr = {
50783 + .name = NULL,
50784 + .mode = S_IRUGO
50785 + },
50786 + .show = show_constraint_name,
50787 + .store = NULL
50788 + }
50789 + }
50790 +};
50791
50792 /* A list of powercap control_types */
50793 static LIST_HEAD(powercap_cntrl_list);
50794 @@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
50795 }
50796
50797 static int create_constraint_attribute(int id, const char *name,
50798 - int mode,
50799 - struct device_attribute *dev_attr,
50800 - ssize_t (*show)(struct device *,
50801 - struct device_attribute *, char *),
50802 - ssize_t (*store)(struct device *,
50803 - struct device_attribute *,
50804 - const char *, size_t)
50805 - )
50806 + struct device_attribute *dev_attr)
50807 {
50808 + name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
50809
50810 - dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
50811 - id, name);
50812 - if (!dev_attr->attr.name)
50813 + if (!name)
50814 return -ENOMEM;
50815 - dev_attr->attr.mode = mode;
50816 - dev_attr->show = show;
50817 - dev_attr->store = store;
50818 +
50819 + pax_open_kernel();
50820 + *(const char **)&dev_attr->attr.name = name;
50821 + pax_close_kernel();
50822
50823 return 0;
50824 }
50825 @@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
50826
50827 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
50828 ret = create_constraint_attribute(i, "power_limit_uw",
50829 - S_IWUSR | S_IRUGO,
50830 - &constraint_attrs[i].power_limit_attr,
50831 - show_constraint_power_limit_uw,
50832 - store_constraint_power_limit_uw);
50833 + &constraint_attrs[i].power_limit_attr);
50834 if (ret)
50835 goto err_alloc;
50836 ret = create_constraint_attribute(i, "time_window_us",
50837 - S_IWUSR | S_IRUGO,
50838 - &constraint_attrs[i].time_window_attr,
50839 - show_constraint_time_window_us,
50840 - store_constraint_time_window_us);
50841 + &constraint_attrs[i].time_window_attr);
50842 if (ret)
50843 goto err_alloc;
50844 - ret = create_constraint_attribute(i, "name", S_IRUGO,
50845 - &constraint_attrs[i].name_attr,
50846 - show_constraint_name,
50847 - NULL);
50848 + ret = create_constraint_attribute(i, "name",
50849 + &constraint_attrs[i].name_attr);
50850 if (ret)
50851 goto err_alloc;
50852 - ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
50853 - &constraint_attrs[i].max_power_attr,
50854 - show_constraint_max_power_uw,
50855 - NULL);
50856 + ret = create_constraint_attribute(i, "max_power_uw",
50857 + &constraint_attrs[i].max_power_attr);
50858 if (ret)
50859 goto err_alloc;
50860 - ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
50861 - &constraint_attrs[i].min_power_attr,
50862 - show_constraint_min_power_uw,
50863 - NULL);
50864 + ret = create_constraint_attribute(i, "min_power_uw",
50865 + &constraint_attrs[i].min_power_attr);
50866 if (ret)
50867 goto err_alloc;
50868 ret = create_constraint_attribute(i, "max_time_window_us",
50869 - S_IRUGO,
50870 - &constraint_attrs[i].max_time_window_attr,
50871 - show_constraint_max_time_window_us,
50872 - NULL);
50873 + &constraint_attrs[i].max_time_window_attr);
50874 if (ret)
50875 goto err_alloc;
50876 ret = create_constraint_attribute(i, "min_time_window_us",
50877 - S_IRUGO,
50878 - &constraint_attrs[i].min_time_window_attr,
50879 - show_constraint_min_time_window_us,
50880 - NULL);
50881 + &constraint_attrs[i].min_time_window_attr);
50882 if (ret)
50883 goto err_alloc;
50884
50885 @@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
50886 power_zone->zone_dev_attrs[count++] =
50887 &dev_attr_max_energy_range_uj.attr;
50888 if (power_zone->ops->get_energy_uj) {
50889 + pax_open_kernel();
50890 if (power_zone->ops->reset_energy_uj)
50891 - dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
50892 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
50893 else
50894 - dev_attr_energy_uj.attr.mode = S_IRUGO;
50895 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
50896 + pax_close_kernel();
50897 power_zone->zone_dev_attrs[count++] =
50898 &dev_attr_energy_uj.attr;
50899 }
50900 diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h
50901 index 9c5d414..c7900ce 100644
50902 --- a/drivers/ptp/ptp_private.h
50903 +++ b/drivers/ptp/ptp_private.h
50904 @@ -51,7 +51,7 @@ struct ptp_clock {
50905 struct mutex pincfg_mux; /* protect concurrent info->pin_config access */
50906 wait_queue_head_t tsev_wq;
50907 int defunct; /* tells readers to go away when clock is being removed */
50908 - struct device_attribute *pin_dev_attr;
50909 + device_attribute_no_const *pin_dev_attr;
50910 struct attribute **pin_attr;
50911 struct attribute_group pin_attr_group;
50912 };
50913 diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c
50914 index 302e626..12579af 100644
50915 --- a/drivers/ptp/ptp_sysfs.c
50916 +++ b/drivers/ptp/ptp_sysfs.c
50917 @@ -280,7 +280,7 @@ static int ptp_populate_pins(struct ptp_clock *ptp)
50918 goto no_pin_attr;
50919
50920 for (i = 0; i < n_pins; i++) {
50921 - struct device_attribute *da = &ptp->pin_dev_attr[i];
50922 + device_attribute_no_const *da = &ptp->pin_dev_attr[i];
50923 sysfs_attr_init(&da->attr);
50924 da->attr.name = info->pin_config[i].name;
50925 da->attr.mode = 0644;
50926 diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
50927 index a3c3785..c901e3a 100644
50928 --- a/drivers/regulator/core.c
50929 +++ b/drivers/regulator/core.c
50930 @@ -3481,7 +3481,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
50931 {
50932 const struct regulation_constraints *constraints = NULL;
50933 const struct regulator_init_data *init_data;
50934 - static atomic_t regulator_no = ATOMIC_INIT(0);
50935 + static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
50936 struct regulator_dev *rdev;
50937 struct device *dev;
50938 int ret, i;
50939 @@ -3551,7 +3551,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
50940 rdev->dev.of_node = of_node_get(config->of_node);
50941 rdev->dev.parent = dev;
50942 dev_set_name(&rdev->dev, "regulator.%d",
50943 - atomic_inc_return(&regulator_no) - 1);
50944 + atomic_inc_return_unchecked(&regulator_no) - 1);
50945 ret = device_register(&rdev->dev);
50946 if (ret != 0) {
50947 put_device(&rdev->dev);
50948 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
50949 index 2fc4111..6aa88ca 100644
50950 --- a/drivers/regulator/max8660.c
50951 +++ b/drivers/regulator/max8660.c
50952 @@ -424,8 +424,10 @@ static int max8660_probe(struct i2c_client *client,
50953 max8660->shadow_regs[MAX8660_OVER1] = 5;
50954 } else {
50955 /* Otherwise devices can be toggled via software */
50956 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
50957 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
50958 + pax_open_kernel();
50959 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
50960 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
50961 + pax_close_kernel();
50962 }
50963
50964 /*
50965 diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
50966 index dbedf17..18ff6b7 100644
50967 --- a/drivers/regulator/max8973-regulator.c
50968 +++ b/drivers/regulator/max8973-regulator.c
50969 @@ -403,9 +403,11 @@ static int max8973_probe(struct i2c_client *client,
50970 if (!pdata || !pdata->enable_ext_control) {
50971 max->desc.enable_reg = MAX8973_VOUT;
50972 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
50973 - max->ops.enable = regulator_enable_regmap;
50974 - max->ops.disable = regulator_disable_regmap;
50975 - max->ops.is_enabled = regulator_is_enabled_regmap;
50976 + pax_open_kernel();
50977 + *(void **)&max->ops.enable = regulator_enable_regmap;
50978 + *(void **)&max->ops.disable = regulator_disable_regmap;
50979 + *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
50980 + pax_close_kernel();
50981 }
50982
50983 if (pdata) {
50984 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
50985 index f374fa5..26f0683 100644
50986 --- a/drivers/regulator/mc13892-regulator.c
50987 +++ b/drivers/regulator/mc13892-regulator.c
50988 @@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
50989 }
50990 mc13xxx_unlock(mc13892);
50991
50992 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
50993 + pax_open_kernel();
50994 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
50995 = mc13892_vcam_set_mode;
50996 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
50997 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
50998 = mc13892_vcam_get_mode;
50999 + pax_close_kernel();
51000
51001 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
51002 ARRAY_SIZE(mc13892_regulators));
51003 diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
51004 index 5b2e761..c8c8a4a 100644
51005 --- a/drivers/rtc/rtc-cmos.c
51006 +++ b/drivers/rtc/rtc-cmos.c
51007 @@ -789,7 +789,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
51008 hpet_rtc_timer_init();
51009
51010 /* export at least the first block of NVRAM */
51011 - nvram.size = address_space - NVRAM_OFFSET;
51012 + pax_open_kernel();
51013 + *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
51014 + pax_close_kernel();
51015 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
51016 if (retval < 0) {
51017 dev_dbg(dev, "can't create nvram file? %d\n", retval);
51018 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
51019 index d049393..bb20be0 100644
51020 --- a/drivers/rtc/rtc-dev.c
51021 +++ b/drivers/rtc/rtc-dev.c
51022 @@ -16,6 +16,7 @@
51023 #include <linux/module.h>
51024 #include <linux/rtc.h>
51025 #include <linux/sched.h>
51026 +#include <linux/grsecurity.h>
51027 #include "rtc-core.h"
51028
51029 static dev_t rtc_devt;
51030 @@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
51031 if (copy_from_user(&tm, uarg, sizeof(tm)))
51032 return -EFAULT;
51033
51034 + gr_log_timechange();
51035 +
51036 return rtc_set_time(rtc, &tm);
51037
51038 case RTC_PIE_ON:
51039 diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
51040 index f03d5ba..8325bf6 100644
51041 --- a/drivers/rtc/rtc-ds1307.c
51042 +++ b/drivers/rtc/rtc-ds1307.c
51043 @@ -107,7 +107,7 @@ struct ds1307 {
51044 u8 offset; /* register's offset */
51045 u8 regs[11];
51046 u16 nvram_offset;
51047 - struct bin_attribute *nvram;
51048 + bin_attribute_no_const *nvram;
51049 enum ds_type type;
51050 unsigned long flags;
51051 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
51052 diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
51053 index 11880c1..b823aa4 100644
51054 --- a/drivers/rtc/rtc-m48t59.c
51055 +++ b/drivers/rtc/rtc-m48t59.c
51056 @@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
51057 if (IS_ERR(m48t59->rtc))
51058 return PTR_ERR(m48t59->rtc);
51059
51060 - m48t59_nvram_attr.size = pdata->offset;
51061 + pax_open_kernel();
51062 + *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
51063 + pax_close_kernel();
51064
51065 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
51066 if (ret)
51067 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
51068 index e693af6..2e525b6 100644
51069 --- a/drivers/scsi/bfa/bfa_fcpim.h
51070 +++ b/drivers/scsi/bfa/bfa_fcpim.h
51071 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
51072
51073 struct bfa_itn_s {
51074 bfa_isr_func_t isr;
51075 -};
51076 +} __no_const;
51077
51078 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
51079 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
51080 diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
51081 index 0f19455..ef7adb5 100644
51082 --- a/drivers/scsi/bfa/bfa_fcs.c
51083 +++ b/drivers/scsi/bfa/bfa_fcs.c
51084 @@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
51085 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
51086
51087 static struct bfa_fcs_mod_s fcs_modules[] = {
51088 - { bfa_fcs_port_attach, NULL, NULL },
51089 - { bfa_fcs_uf_attach, NULL, NULL },
51090 - { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
51091 - bfa_fcs_fabric_modexit },
51092 + {
51093 + .attach = bfa_fcs_port_attach,
51094 + .modinit = NULL,
51095 + .modexit = NULL
51096 + },
51097 + {
51098 + .attach = bfa_fcs_uf_attach,
51099 + .modinit = NULL,
51100 + .modexit = NULL
51101 + },
51102 + {
51103 + .attach = bfa_fcs_fabric_attach,
51104 + .modinit = bfa_fcs_fabric_modinit,
51105 + .modexit = bfa_fcs_fabric_modexit
51106 + },
51107 };
51108
51109 /*
51110 diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
51111 index ff75ef8..2dfe00a 100644
51112 --- a/drivers/scsi/bfa/bfa_fcs_lport.c
51113 +++ b/drivers/scsi/bfa/bfa_fcs_lport.c
51114 @@ -89,15 +89,26 @@ static struct {
51115 void (*offline) (struct bfa_fcs_lport_s *port);
51116 } __port_action[] = {
51117 {
51118 - bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
51119 - bfa_fcs_lport_unknown_offline}, {
51120 - bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
51121 - bfa_fcs_lport_fab_offline}, {
51122 - bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
51123 - bfa_fcs_lport_n2n_offline}, {
51124 - bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
51125 - bfa_fcs_lport_loop_offline},
51126 - };
51127 + .init = bfa_fcs_lport_unknown_init,
51128 + .online = bfa_fcs_lport_unknown_online,
51129 + .offline = bfa_fcs_lport_unknown_offline
51130 + },
51131 + {
51132 + .init = bfa_fcs_lport_fab_init,
51133 + .online = bfa_fcs_lport_fab_online,
51134 + .offline = bfa_fcs_lport_fab_offline
51135 + },
51136 + {
51137 + .init = bfa_fcs_lport_n2n_init,
51138 + .online = bfa_fcs_lport_n2n_online,
51139 + .offline = bfa_fcs_lport_n2n_offline
51140 + },
51141 + {
51142 + .init = bfa_fcs_lport_loop_init,
51143 + .online = bfa_fcs_lport_loop_online,
51144 + .offline = bfa_fcs_lport_loop_offline
51145 + },
51146 +};
51147
51148 /*
51149 * fcs_port_sm FCS logical port state machine
51150 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
51151 index a38aafa0..fe8f03b 100644
51152 --- a/drivers/scsi/bfa/bfa_ioc.h
51153 +++ b/drivers/scsi/bfa/bfa_ioc.h
51154 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
51155 bfa_ioc_disable_cbfn_t disable_cbfn;
51156 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
51157 bfa_ioc_reset_cbfn_t reset_cbfn;
51158 -};
51159 +} __no_const;
51160
51161 /*
51162 * IOC event notification mechanism.
51163 @@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
51164 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
51165 enum bfi_ioc_state fwstate);
51166 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
51167 -};
51168 +} __no_const;
51169
51170 /*
51171 * Queue element to wait for room in request queue. FIFO order is
51172 diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
51173 index a14c784..6de6790 100644
51174 --- a/drivers/scsi/bfa/bfa_modules.h
51175 +++ b/drivers/scsi/bfa/bfa_modules.h
51176 @@ -78,12 +78,12 @@ enum {
51177 \
51178 extern struct bfa_module_s hal_mod_ ## __mod; \
51179 struct bfa_module_s hal_mod_ ## __mod = { \
51180 - bfa_ ## __mod ## _meminfo, \
51181 - bfa_ ## __mod ## _attach, \
51182 - bfa_ ## __mod ## _detach, \
51183 - bfa_ ## __mod ## _start, \
51184 - bfa_ ## __mod ## _stop, \
51185 - bfa_ ## __mod ## _iocdisable, \
51186 + .meminfo = bfa_ ## __mod ## _meminfo, \
51187 + .attach = bfa_ ## __mod ## _attach, \
51188 + .detach = bfa_ ## __mod ## _detach, \
51189 + .start = bfa_ ## __mod ## _start, \
51190 + .stop = bfa_ ## __mod ## _stop, \
51191 + .iocdisable = bfa_ ## __mod ## _iocdisable, \
51192 }
51193
51194 #define BFA_CACHELINE_SZ (256)
51195 diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
51196 index 045c4e1..13de803 100644
51197 --- a/drivers/scsi/fcoe/fcoe_sysfs.c
51198 +++ b/drivers/scsi/fcoe/fcoe_sysfs.c
51199 @@ -33,8 +33,8 @@
51200 */
51201 #include "libfcoe.h"
51202
51203 -static atomic_t ctlr_num;
51204 -static atomic_t fcf_num;
51205 +static atomic_unchecked_t ctlr_num;
51206 +static atomic_unchecked_t fcf_num;
51207
51208 /*
51209 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
51210 @@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
51211 if (!ctlr)
51212 goto out;
51213
51214 - ctlr->id = atomic_inc_return(&ctlr_num) - 1;
51215 + ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
51216 ctlr->f = f;
51217 ctlr->mode = FIP_CONN_TYPE_FABRIC;
51218 INIT_LIST_HEAD(&ctlr->fcfs);
51219 @@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
51220 fcf->dev.parent = &ctlr->dev;
51221 fcf->dev.bus = &fcoe_bus_type;
51222 fcf->dev.type = &fcoe_fcf_device_type;
51223 - fcf->id = atomic_inc_return(&fcf_num) - 1;
51224 + fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
51225 fcf->state = FCOE_FCF_STATE_UNKNOWN;
51226
51227 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
51228 @@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
51229 {
51230 int error;
51231
51232 - atomic_set(&ctlr_num, 0);
51233 - atomic_set(&fcf_num, 0);
51234 + atomic_set_unchecked(&ctlr_num, 0);
51235 + atomic_set_unchecked(&fcf_num, 0);
51236
51237 error = bus_register(&fcoe_bus_type);
51238 if (error)
51239 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
51240 index 6de80e3..a11e0ac 100644
51241 --- a/drivers/scsi/hosts.c
51242 +++ b/drivers/scsi/hosts.c
51243 @@ -42,7 +42,7 @@
51244 #include "scsi_logging.h"
51245
51246
51247 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
51248 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
51249
51250
51251 static void scsi_host_cls_release(struct device *dev)
51252 @@ -392,7 +392,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
51253 * subtract one because we increment first then return, but we need to
51254 * know what the next host number was before increment
51255 */
51256 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
51257 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
51258 shost->dma_channel = 0xff;
51259
51260 /* These three are default values which can be overridden */
51261 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
51262 index 6b35d0d..2880305 100644
51263 --- a/drivers/scsi/hpsa.c
51264 +++ b/drivers/scsi/hpsa.c
51265 @@ -701,10 +701,10 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
51266 unsigned long flags;
51267
51268 if (h->transMethod & CFGTBL_Trans_io_accel1)
51269 - return h->access.command_completed(h, q);
51270 + return h->access->command_completed(h, q);
51271
51272 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
51273 - return h->access.command_completed(h, q);
51274 + return h->access->command_completed(h, q);
51275
51276 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
51277 a = rq->head[rq->current_entry];
51278 @@ -5454,7 +5454,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
51279 while (!list_empty(&h->reqQ)) {
51280 c = list_entry(h->reqQ.next, struct CommandList, list);
51281 /* can't do anything if fifo is full */
51282 - if ((h->access.fifo_full(h))) {
51283 + if ((h->access->fifo_full(h))) {
51284 h->fifo_recently_full = 1;
51285 dev_warn(&h->pdev->dev, "fifo full\n");
51286 break;
51287 @@ -5476,7 +5476,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
51288
51289 /* Tell the controller execute command */
51290 spin_unlock_irqrestore(&h->lock, *flags);
51291 - h->access.submit_command(h, c);
51292 + h->access->submit_command(h, c);
51293 spin_lock_irqsave(&h->lock, *flags);
51294 }
51295 }
51296 @@ -5492,17 +5492,17 @@ static void lock_and_start_io(struct ctlr_info *h)
51297
51298 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
51299 {
51300 - return h->access.command_completed(h, q);
51301 + return h->access->command_completed(h, q);
51302 }
51303
51304 static inline bool interrupt_pending(struct ctlr_info *h)
51305 {
51306 - return h->access.intr_pending(h);
51307 + return h->access->intr_pending(h);
51308 }
51309
51310 static inline long interrupt_not_for_us(struct ctlr_info *h)
51311 {
51312 - return (h->access.intr_pending(h) == 0) ||
51313 + return (h->access->intr_pending(h) == 0) ||
51314 (h->interrupts_enabled == 0);
51315 }
51316
51317 @@ -6458,7 +6458,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
51318 if (prod_index < 0)
51319 return -ENODEV;
51320 h->product_name = products[prod_index].product_name;
51321 - h->access = *(products[prod_index].access);
51322 + h->access = products[prod_index].access;
51323
51324 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
51325 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
51326 @@ -6780,7 +6780,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
51327 unsigned long flags;
51328 u32 lockup_detected;
51329
51330 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51331 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51332 spin_lock_irqsave(&h->lock, flags);
51333 lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
51334 if (!lockup_detected) {
51335 @@ -7027,7 +7027,7 @@ reinit_after_soft_reset:
51336 }
51337
51338 /* make sure the board interrupts are off */
51339 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51340 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51341
51342 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
51343 goto clean2;
51344 @@ -7062,7 +7062,7 @@ reinit_after_soft_reset:
51345 * fake ones to scoop up any residual completions.
51346 */
51347 spin_lock_irqsave(&h->lock, flags);
51348 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51349 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51350 spin_unlock_irqrestore(&h->lock, flags);
51351 free_irqs(h);
51352 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
51353 @@ -7081,9 +7081,9 @@ reinit_after_soft_reset:
51354 dev_info(&h->pdev->dev, "Board READY.\n");
51355 dev_info(&h->pdev->dev,
51356 "Waiting for stale completions to drain.\n");
51357 - h->access.set_intr_mask(h, HPSA_INTR_ON);
51358 + h->access->set_intr_mask(h, HPSA_INTR_ON);
51359 msleep(10000);
51360 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51361 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51362
51363 rc = controller_reset_failed(h->cfgtable);
51364 if (rc)
51365 @@ -7109,7 +7109,7 @@ reinit_after_soft_reset:
51366 h->drv_req_rescan = 0;
51367
51368 /* Turn the interrupts on so we can service requests */
51369 - h->access.set_intr_mask(h, HPSA_INTR_ON);
51370 + h->access->set_intr_mask(h, HPSA_INTR_ON);
51371
51372 hpsa_hba_inquiry(h);
51373 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
51374 @@ -7174,7 +7174,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
51375 * To write all data in the battery backed cache to disks
51376 */
51377 hpsa_flush_cache(h);
51378 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51379 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51380 hpsa_free_irqs_and_disable_msix(h);
51381 }
51382
51383 @@ -7292,7 +7292,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51384 CFGTBL_Trans_enable_directed_msix |
51385 (trans_support & (CFGTBL_Trans_io_accel1 |
51386 CFGTBL_Trans_io_accel2));
51387 - struct access_method access = SA5_performant_access;
51388 + struct access_method *access = &SA5_performant_access;
51389
51390 /* This is a bit complicated. There are 8 registers on
51391 * the controller which we write to to tell it 8 different
51392 @@ -7334,7 +7334,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51393 * perform the superfluous readl() after each command submission.
51394 */
51395 if (trans_support & (CFGTBL_Trans_io_accel1 | CFGTBL_Trans_io_accel2))
51396 - access = SA5_performant_access_no_read;
51397 + access = &SA5_performant_access_no_read;
51398
51399 /* Controller spec: zero out this buffer. */
51400 for (i = 0; i < h->nreply_queues; i++)
51401 @@ -7364,12 +7364,12 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51402 * enable outbound interrupt coalescing in accelerator mode;
51403 */
51404 if (trans_support & CFGTBL_Trans_io_accel1) {
51405 - access = SA5_ioaccel_mode1_access;
51406 + access = &SA5_ioaccel_mode1_access;
51407 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
51408 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
51409 } else {
51410 if (trans_support & CFGTBL_Trans_io_accel2) {
51411 - access = SA5_ioaccel_mode2_access;
51412 + access = &SA5_ioaccel_mode2_access;
51413 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
51414 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
51415 }
51416 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
51417 index 24472ce..8782caf 100644
51418 --- a/drivers/scsi/hpsa.h
51419 +++ b/drivers/scsi/hpsa.h
51420 @@ -127,7 +127,7 @@ struct ctlr_info {
51421 unsigned int msix_vector;
51422 unsigned int msi_vector;
51423 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
51424 - struct access_method access;
51425 + struct access_method *access;
51426 char hba_mode_enabled;
51427
51428 /* queue and queue Info */
51429 @@ -536,43 +536,43 @@ static unsigned long SA5_ioaccel_mode1_completed(struct ctlr_info *h, u8 q)
51430 }
51431
51432 static struct access_method SA5_access = {
51433 - SA5_submit_command,
51434 - SA5_intr_mask,
51435 - SA5_fifo_full,
51436 - SA5_intr_pending,
51437 - SA5_completed,
51438 + .submit_command = SA5_submit_command,
51439 + .set_intr_mask = SA5_intr_mask,
51440 + .fifo_full = SA5_fifo_full,
51441 + .intr_pending = SA5_intr_pending,
51442 + .command_completed = SA5_completed,
51443 };
51444
51445 static struct access_method SA5_ioaccel_mode1_access = {
51446 - SA5_submit_command,
51447 - SA5_performant_intr_mask,
51448 - SA5_fifo_full,
51449 - SA5_ioaccel_mode1_intr_pending,
51450 - SA5_ioaccel_mode1_completed,
51451 + .submit_command = SA5_submit_command,
51452 + .set_intr_mask = SA5_performant_intr_mask,
51453 + .fifo_full = SA5_fifo_full,
51454 + .intr_pending = SA5_ioaccel_mode1_intr_pending,
51455 + .command_completed = SA5_ioaccel_mode1_completed,
51456 };
51457
51458 static struct access_method SA5_ioaccel_mode2_access = {
51459 - SA5_submit_command_ioaccel2,
51460 - SA5_performant_intr_mask,
51461 - SA5_fifo_full,
51462 - SA5_performant_intr_pending,
51463 - SA5_performant_completed,
51464 + .submit_command = SA5_submit_command_ioaccel2,
51465 + .set_intr_mask = SA5_performant_intr_mask,
51466 + .fifo_full = SA5_fifo_full,
51467 + .intr_pending = SA5_performant_intr_pending,
51468 + .command_completed = SA5_performant_completed,
51469 };
51470
51471 static struct access_method SA5_performant_access = {
51472 - SA5_submit_command,
51473 - SA5_performant_intr_mask,
51474 - SA5_fifo_full,
51475 - SA5_performant_intr_pending,
51476 - SA5_performant_completed,
51477 + .submit_command = SA5_submit_command,
51478 + .set_intr_mask = SA5_performant_intr_mask,
51479 + .fifo_full = SA5_fifo_full,
51480 + .intr_pending = SA5_performant_intr_pending,
51481 + .command_completed = SA5_performant_completed,
51482 };
51483
51484 static struct access_method SA5_performant_access_no_read = {
51485 - SA5_submit_command_no_read,
51486 - SA5_performant_intr_mask,
51487 - SA5_fifo_full,
51488 - SA5_performant_intr_pending,
51489 - SA5_performant_completed,
51490 + .submit_command = SA5_submit_command_no_read,
51491 + .set_intr_mask = SA5_performant_intr_mask,
51492 + .fifo_full = SA5_fifo_full,
51493 + .intr_pending = SA5_performant_intr_pending,
51494 + .command_completed = SA5_performant_completed,
51495 };
51496
51497 struct board_type {
51498 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
51499 index 1b3a094..068e683 100644
51500 --- a/drivers/scsi/libfc/fc_exch.c
51501 +++ b/drivers/scsi/libfc/fc_exch.c
51502 @@ -101,12 +101,12 @@ struct fc_exch_mgr {
51503 u16 pool_max_index;
51504
51505 struct {
51506 - atomic_t no_free_exch;
51507 - atomic_t no_free_exch_xid;
51508 - atomic_t xid_not_found;
51509 - atomic_t xid_busy;
51510 - atomic_t seq_not_found;
51511 - atomic_t non_bls_resp;
51512 + atomic_unchecked_t no_free_exch;
51513 + atomic_unchecked_t no_free_exch_xid;
51514 + atomic_unchecked_t xid_not_found;
51515 + atomic_unchecked_t xid_busy;
51516 + atomic_unchecked_t seq_not_found;
51517 + atomic_unchecked_t non_bls_resp;
51518 } stats;
51519 };
51520
51521 @@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
51522 /* allocate memory for exchange */
51523 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
51524 if (!ep) {
51525 - atomic_inc(&mp->stats.no_free_exch);
51526 + atomic_inc_unchecked(&mp->stats.no_free_exch);
51527 goto out;
51528 }
51529 memset(ep, 0, sizeof(*ep));
51530 @@ -874,7 +874,7 @@ out:
51531 return ep;
51532 err:
51533 spin_unlock_bh(&pool->lock);
51534 - atomic_inc(&mp->stats.no_free_exch_xid);
51535 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
51536 mempool_free(ep, mp->ep_pool);
51537 return NULL;
51538 }
51539 @@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51540 xid = ntohs(fh->fh_ox_id); /* we originated exch */
51541 ep = fc_exch_find(mp, xid);
51542 if (!ep) {
51543 - atomic_inc(&mp->stats.xid_not_found);
51544 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51545 reject = FC_RJT_OX_ID;
51546 goto out;
51547 }
51548 @@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51549 ep = fc_exch_find(mp, xid);
51550 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
51551 if (ep) {
51552 - atomic_inc(&mp->stats.xid_busy);
51553 + atomic_inc_unchecked(&mp->stats.xid_busy);
51554 reject = FC_RJT_RX_ID;
51555 goto rel;
51556 }
51557 @@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51558 }
51559 xid = ep->xid; /* get our XID */
51560 } else if (!ep) {
51561 - atomic_inc(&mp->stats.xid_not_found);
51562 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51563 reject = FC_RJT_RX_ID; /* XID not found */
51564 goto out;
51565 }
51566 @@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51567 } else {
51568 sp = &ep->seq;
51569 if (sp->id != fh->fh_seq_id) {
51570 - atomic_inc(&mp->stats.seq_not_found);
51571 + atomic_inc_unchecked(&mp->stats.seq_not_found);
51572 if (f_ctl & FC_FC_END_SEQ) {
51573 /*
51574 * Update sequence_id based on incoming last
51575 @@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51576
51577 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
51578 if (!ep) {
51579 - atomic_inc(&mp->stats.xid_not_found);
51580 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51581 goto out;
51582 }
51583 if (ep->esb_stat & ESB_ST_COMPLETE) {
51584 - atomic_inc(&mp->stats.xid_not_found);
51585 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51586 goto rel;
51587 }
51588 if (ep->rxid == FC_XID_UNKNOWN)
51589 ep->rxid = ntohs(fh->fh_rx_id);
51590 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
51591 - atomic_inc(&mp->stats.xid_not_found);
51592 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51593 goto rel;
51594 }
51595 if (ep->did != ntoh24(fh->fh_s_id) &&
51596 ep->did != FC_FID_FLOGI) {
51597 - atomic_inc(&mp->stats.xid_not_found);
51598 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51599 goto rel;
51600 }
51601 sof = fr_sof(fp);
51602 @@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51603 sp->ssb_stat |= SSB_ST_RESP;
51604 sp->id = fh->fh_seq_id;
51605 } else if (sp->id != fh->fh_seq_id) {
51606 - atomic_inc(&mp->stats.seq_not_found);
51607 + atomic_inc_unchecked(&mp->stats.seq_not_found);
51608 goto rel;
51609 }
51610
51611 @@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51612 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
51613
51614 if (!sp)
51615 - atomic_inc(&mp->stats.xid_not_found);
51616 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51617 else
51618 - atomic_inc(&mp->stats.non_bls_resp);
51619 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
51620
51621 fc_frame_free(fp);
51622 }
51623 @@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
51624
51625 list_for_each_entry(ema, &lport->ema_list, ema_list) {
51626 mp = ema->mp;
51627 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
51628 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
51629 st->fc_no_free_exch_xid +=
51630 - atomic_read(&mp->stats.no_free_exch_xid);
51631 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
51632 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
51633 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
51634 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
51635 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
51636 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
51637 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
51638 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
51639 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
51640 }
51641 }
51642 EXPORT_SYMBOL(fc_exch_update_stats);
51643 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
51644 index 766098a..1c6c971 100644
51645 --- a/drivers/scsi/libsas/sas_ata.c
51646 +++ b/drivers/scsi/libsas/sas_ata.c
51647 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
51648 .postreset = ata_std_postreset,
51649 .error_handler = ata_std_error_handler,
51650 .post_internal_cmd = sas_ata_post_internal,
51651 - .qc_defer = ata_std_qc_defer,
51652 + .qc_defer = ata_std_qc_defer,
51653 .qc_prep = ata_noop_qc_prep,
51654 .qc_issue = sas_ata_qc_issue,
51655 .qc_fill_rtf = sas_ata_qc_fill_rtf,
51656 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
51657 index 434e903..5a4a79b 100644
51658 --- a/drivers/scsi/lpfc/lpfc.h
51659 +++ b/drivers/scsi/lpfc/lpfc.h
51660 @@ -430,7 +430,7 @@ struct lpfc_vport {
51661 struct dentry *debug_nodelist;
51662 struct dentry *vport_debugfs_root;
51663 struct lpfc_debugfs_trc *disc_trc;
51664 - atomic_t disc_trc_cnt;
51665 + atomic_unchecked_t disc_trc_cnt;
51666 #endif
51667 uint8_t stat_data_enabled;
51668 uint8_t stat_data_blocked;
51669 @@ -880,8 +880,8 @@ struct lpfc_hba {
51670 struct timer_list fabric_block_timer;
51671 unsigned long bit_flags;
51672 #define FABRIC_COMANDS_BLOCKED 0
51673 - atomic_t num_rsrc_err;
51674 - atomic_t num_cmd_success;
51675 + atomic_unchecked_t num_rsrc_err;
51676 + atomic_unchecked_t num_cmd_success;
51677 unsigned long last_rsrc_error_time;
51678 unsigned long last_ramp_down_time;
51679 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
51680 @@ -916,7 +916,7 @@ struct lpfc_hba {
51681
51682 struct dentry *debug_slow_ring_trc;
51683 struct lpfc_debugfs_trc *slow_ring_trc;
51684 - atomic_t slow_ring_trc_cnt;
51685 + atomic_unchecked_t slow_ring_trc_cnt;
51686 /* iDiag debugfs sub-directory */
51687 struct dentry *idiag_root;
51688 struct dentry *idiag_pci_cfg;
51689 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
51690 index b0aedce..89c6ca6 100644
51691 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
51692 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
51693 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
51694
51695 #include <linux/debugfs.h>
51696
51697 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
51698 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
51699 static unsigned long lpfc_debugfs_start_time = 0L;
51700
51701 /* iDiag */
51702 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
51703 lpfc_debugfs_enable = 0;
51704
51705 len = 0;
51706 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
51707 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
51708 (lpfc_debugfs_max_disc_trc - 1);
51709 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
51710 dtp = vport->disc_trc + i;
51711 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
51712 lpfc_debugfs_enable = 0;
51713
51714 len = 0;
51715 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
51716 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
51717 (lpfc_debugfs_max_slow_ring_trc - 1);
51718 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
51719 dtp = phba->slow_ring_trc + i;
51720 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
51721 !vport || !vport->disc_trc)
51722 return;
51723
51724 - index = atomic_inc_return(&vport->disc_trc_cnt) &
51725 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
51726 (lpfc_debugfs_max_disc_trc - 1);
51727 dtp = vport->disc_trc + index;
51728 dtp->fmt = fmt;
51729 dtp->data1 = data1;
51730 dtp->data2 = data2;
51731 dtp->data3 = data3;
51732 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
51733 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
51734 dtp->jif = jiffies;
51735 #endif
51736 return;
51737 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
51738 !phba || !phba->slow_ring_trc)
51739 return;
51740
51741 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
51742 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
51743 (lpfc_debugfs_max_slow_ring_trc - 1);
51744 dtp = phba->slow_ring_trc + index;
51745 dtp->fmt = fmt;
51746 dtp->data1 = data1;
51747 dtp->data2 = data2;
51748 dtp->data3 = data3;
51749 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
51750 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
51751 dtp->jif = jiffies;
51752 #endif
51753 return;
51754 @@ -4268,7 +4268,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
51755 "slow_ring buffer\n");
51756 goto debug_failed;
51757 }
51758 - atomic_set(&phba->slow_ring_trc_cnt, 0);
51759 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
51760 memset(phba->slow_ring_trc, 0,
51761 (sizeof(struct lpfc_debugfs_trc) *
51762 lpfc_debugfs_max_slow_ring_trc));
51763 @@ -4314,7 +4314,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
51764 "buffer\n");
51765 goto debug_failed;
51766 }
51767 - atomic_set(&vport->disc_trc_cnt, 0);
51768 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
51769
51770 snprintf(name, sizeof(name), "discovery_trace");
51771 vport->debug_disc_trc =
51772 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
51773 index a5769a9..718ecc7 100644
51774 --- a/drivers/scsi/lpfc/lpfc_init.c
51775 +++ b/drivers/scsi/lpfc/lpfc_init.c
51776 @@ -11299,8 +11299,10 @@ lpfc_init(void)
51777 "misc_register returned with status %d", error);
51778
51779 if (lpfc_enable_npiv) {
51780 - lpfc_transport_functions.vport_create = lpfc_vport_create;
51781 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
51782 + pax_open_kernel();
51783 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
51784 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
51785 + pax_close_kernel();
51786 }
51787 lpfc_transport_template =
51788 fc_attach_transport(&lpfc_transport_functions);
51789 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
51790 index 7862c55..5aa65df 100644
51791 --- a/drivers/scsi/lpfc/lpfc_scsi.c
51792 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
51793 @@ -382,7 +382,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
51794 uint32_t evt_posted;
51795
51796 spin_lock_irqsave(&phba->hbalock, flags);
51797 - atomic_inc(&phba->num_rsrc_err);
51798 + atomic_inc_unchecked(&phba->num_rsrc_err);
51799 phba->last_rsrc_error_time = jiffies;
51800
51801 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
51802 @@ -423,8 +423,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
51803 unsigned long num_rsrc_err, num_cmd_success;
51804 int i;
51805
51806 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
51807 - num_cmd_success = atomic_read(&phba->num_cmd_success);
51808 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
51809 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
51810
51811 /*
51812 * The error and success command counters are global per
51813 @@ -452,8 +452,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
51814 }
51815 }
51816 lpfc_destroy_vport_work_array(phba, vports);
51817 - atomic_set(&phba->num_rsrc_err, 0);
51818 - atomic_set(&phba->num_cmd_success, 0);
51819 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
51820 + atomic_set_unchecked(&phba->num_cmd_success, 0);
51821 }
51822
51823 /**
51824 diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
51825 index dd46101..ca80eb9 100644
51826 --- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
51827 +++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
51828 @@ -1559,7 +1559,7 @@ _scsih_get_resync(struct device *dev)
51829 {
51830 struct scsi_device *sdev = to_scsi_device(dev);
51831 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
51832 - static struct _raid_device *raid_device;
51833 + struct _raid_device *raid_device;
51834 unsigned long flags;
51835 Mpi2RaidVolPage0_t vol_pg0;
51836 Mpi2ConfigReply_t mpi_reply;
51837 @@ -1611,7 +1611,7 @@ _scsih_get_state(struct device *dev)
51838 {
51839 struct scsi_device *sdev = to_scsi_device(dev);
51840 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
51841 - static struct _raid_device *raid_device;
51842 + struct _raid_device *raid_device;
51843 unsigned long flags;
51844 Mpi2RaidVolPage0_t vol_pg0;
51845 Mpi2ConfigReply_t mpi_reply;
51846 @@ -6648,7 +6648,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
51847 Mpi2EventDataIrOperationStatus_t *event_data =
51848 (Mpi2EventDataIrOperationStatus_t *)
51849 fw_event->event_data;
51850 - static struct _raid_device *raid_device;
51851 + struct _raid_device *raid_device;
51852 unsigned long flags;
51853 u16 handle;
51854
51855 @@ -7119,7 +7119,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
51856 u64 sas_address;
51857 struct _sas_device *sas_device;
51858 struct _sas_node *expander_device;
51859 - static struct _raid_device *raid_device;
51860 + struct _raid_device *raid_device;
51861 u8 retry_count;
51862 unsigned long flags;
51863
51864 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
51865 index 6f3275d..fa5e6b6 100644
51866 --- a/drivers/scsi/pmcraid.c
51867 +++ b/drivers/scsi/pmcraid.c
51868 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
51869 res->scsi_dev = scsi_dev;
51870 scsi_dev->hostdata = res;
51871 res->change_detected = 0;
51872 - atomic_set(&res->read_failures, 0);
51873 - atomic_set(&res->write_failures, 0);
51874 + atomic_set_unchecked(&res->read_failures, 0);
51875 + atomic_set_unchecked(&res->write_failures, 0);
51876 rc = 0;
51877 }
51878 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
51879 @@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
51880
51881 /* If this was a SCSI read/write command keep count of errors */
51882 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
51883 - atomic_inc(&res->read_failures);
51884 + atomic_inc_unchecked(&res->read_failures);
51885 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
51886 - atomic_inc(&res->write_failures);
51887 + atomic_inc_unchecked(&res->write_failures);
51888
51889 if (!RES_IS_GSCSI(res->cfg_entry) &&
51890 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
51891 @@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
51892 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
51893 * hrrq_id assigned here in queuecommand
51894 */
51895 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
51896 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
51897 pinstance->num_hrrq;
51898 cmd->cmd_done = pmcraid_io_done;
51899
51900 @@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
51901 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
51902 * hrrq_id assigned here in queuecommand
51903 */
51904 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
51905 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
51906 pinstance->num_hrrq;
51907
51908 if (request_size) {
51909 @@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
51910
51911 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
51912 /* add resources only after host is added into system */
51913 - if (!atomic_read(&pinstance->expose_resources))
51914 + if (!atomic_read_unchecked(&pinstance->expose_resources))
51915 return;
51916
51917 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
51918 @@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
51919 init_waitqueue_head(&pinstance->reset_wait_q);
51920
51921 atomic_set(&pinstance->outstanding_cmds, 0);
51922 - atomic_set(&pinstance->last_message_id, 0);
51923 - atomic_set(&pinstance->expose_resources, 0);
51924 + atomic_set_unchecked(&pinstance->last_message_id, 0);
51925 + atomic_set_unchecked(&pinstance->expose_resources, 0);
51926
51927 INIT_LIST_HEAD(&pinstance->free_res_q);
51928 INIT_LIST_HEAD(&pinstance->used_res_q);
51929 @@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
51930 /* Schedule worker thread to handle CCN and take care of adding and
51931 * removing devices to OS
51932 */
51933 - atomic_set(&pinstance->expose_resources, 1);
51934 + atomic_set_unchecked(&pinstance->expose_resources, 1);
51935 schedule_work(&pinstance->worker_q);
51936 return rc;
51937
51938 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
51939 index e1d150f..6c6df44 100644
51940 --- a/drivers/scsi/pmcraid.h
51941 +++ b/drivers/scsi/pmcraid.h
51942 @@ -748,7 +748,7 @@ struct pmcraid_instance {
51943 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
51944
51945 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
51946 - atomic_t last_message_id;
51947 + atomic_unchecked_t last_message_id;
51948
51949 /* configuration table */
51950 struct pmcraid_config_table *cfg_table;
51951 @@ -777,7 +777,7 @@ struct pmcraid_instance {
51952 atomic_t outstanding_cmds;
51953
51954 /* should add/delete resources to mid-layer now ?*/
51955 - atomic_t expose_resources;
51956 + atomic_unchecked_t expose_resources;
51957
51958
51959
51960 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
51961 struct pmcraid_config_table_entry_ext cfg_entry_ext;
51962 };
51963 struct scsi_device *scsi_dev; /* Link scsi_device structure */
51964 - atomic_t read_failures; /* count of failed READ commands */
51965 - atomic_t write_failures; /* count of failed WRITE commands */
51966 + atomic_unchecked_t read_failures; /* count of failed READ commands */
51967 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
51968
51969 /* To indicate add/delete/modify during CCN */
51970 u8 change_detected;
51971 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
51972 index 16fe519..3b1ec82 100644
51973 --- a/drivers/scsi/qla2xxx/qla_attr.c
51974 +++ b/drivers/scsi/qla2xxx/qla_attr.c
51975 @@ -2188,7 +2188,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
51976 return 0;
51977 }
51978
51979 -struct fc_function_template qla2xxx_transport_functions = {
51980 +fc_function_template_no_const qla2xxx_transport_functions = {
51981
51982 .show_host_node_name = 1,
51983 .show_host_port_name = 1,
51984 @@ -2236,7 +2236,7 @@ struct fc_function_template qla2xxx_transport_functions = {
51985 .bsg_timeout = qla24xx_bsg_timeout,
51986 };
51987
51988 -struct fc_function_template qla2xxx_transport_vport_functions = {
51989 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
51990
51991 .show_host_node_name = 1,
51992 .show_host_port_name = 1,
51993 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
51994 index d646540..5b13554 100644
51995 --- a/drivers/scsi/qla2xxx/qla_gbl.h
51996 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
51997 @@ -569,8 +569,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
51998 struct device_attribute;
51999 extern struct device_attribute *qla2x00_host_attrs[];
52000 struct fc_function_template;
52001 -extern struct fc_function_template qla2xxx_transport_functions;
52002 -extern struct fc_function_template qla2xxx_transport_vport_functions;
52003 +extern fc_function_template_no_const qla2xxx_transport_functions;
52004 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
52005 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
52006 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
52007 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
52008 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
52009 index 8252c0e..613adad 100644
52010 --- a/drivers/scsi/qla2xxx/qla_os.c
52011 +++ b/drivers/scsi/qla2xxx/qla_os.c
52012 @@ -1493,8 +1493,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
52013 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
52014 /* Ok, a 64bit DMA mask is applicable. */
52015 ha->flags.enable_64bit_addressing = 1;
52016 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
52017 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
52018 + pax_open_kernel();
52019 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
52020 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
52021 + pax_close_kernel();
52022 return;
52023 }
52024 }
52025 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
52026 index 8f6d0fb..1b21097 100644
52027 --- a/drivers/scsi/qla4xxx/ql4_def.h
52028 +++ b/drivers/scsi/qla4xxx/ql4_def.h
52029 @@ -305,7 +305,7 @@ struct ddb_entry {
52030 * (4000 only) */
52031 atomic_t relogin_timer; /* Max Time to wait for
52032 * relogin to complete */
52033 - atomic_t relogin_retry_count; /* Num of times relogin has been
52034 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
52035 * retried */
52036 uint32_t default_time2wait; /* Default Min time between
52037 * relogins (+aens) */
52038 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
52039 index 199fcf7..3c3a918 100644
52040 --- a/drivers/scsi/qla4xxx/ql4_os.c
52041 +++ b/drivers/scsi/qla4xxx/ql4_os.c
52042 @@ -4496,12 +4496,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
52043 */
52044 if (!iscsi_is_session_online(cls_sess)) {
52045 /* Reset retry relogin timer */
52046 - atomic_inc(&ddb_entry->relogin_retry_count);
52047 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
52048 DEBUG2(ql4_printk(KERN_INFO, ha,
52049 "%s: index[%d] relogin timed out-retrying"
52050 " relogin (%d), retry (%d)\n", __func__,
52051 ddb_entry->fw_ddb_index,
52052 - atomic_read(&ddb_entry->relogin_retry_count),
52053 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
52054 ddb_entry->default_time2wait + 4));
52055 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
52056 atomic_set(&ddb_entry->retry_relogin_timer,
52057 @@ -6609,7 +6609,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
52058
52059 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
52060 atomic_set(&ddb_entry->relogin_timer, 0);
52061 - atomic_set(&ddb_entry->relogin_retry_count, 0);
52062 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
52063 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
52064 ddb_entry->default_relogin_timeout =
52065 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
52066 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
52067 index d81f3cc..0093e5b 100644
52068 --- a/drivers/scsi/scsi.c
52069 +++ b/drivers/scsi/scsi.c
52070 @@ -645,7 +645,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
52071 struct Scsi_Host *host = cmd->device->host;
52072 int rtn = 0;
52073
52074 - atomic_inc(&cmd->device->iorequest_cnt);
52075 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
52076
52077 /* check if the device is still usable */
52078 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
52079 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
52080 index 7cb8c73..14561b5 100644
52081 --- a/drivers/scsi/scsi_lib.c
52082 +++ b/drivers/scsi/scsi_lib.c
52083 @@ -1581,7 +1581,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
52084 shost = sdev->host;
52085 scsi_init_cmd_errh(cmd);
52086 cmd->result = DID_NO_CONNECT << 16;
52087 - atomic_inc(&cmd->device->iorequest_cnt);
52088 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
52089
52090 /*
52091 * SCSI request completion path will do scsi_device_unbusy(),
52092 @@ -1604,9 +1604,9 @@ static void scsi_softirq_done(struct request *rq)
52093
52094 INIT_LIST_HEAD(&cmd->eh_entry);
52095
52096 - atomic_inc(&cmd->device->iodone_cnt);
52097 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
52098 if (cmd->result)
52099 - atomic_inc(&cmd->device->ioerr_cnt);
52100 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
52101
52102 disposition = scsi_decide_disposition(cmd);
52103 if (disposition != SUCCESS &&
52104 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
52105 index 8b4105a..1f58363 100644
52106 --- a/drivers/scsi/scsi_sysfs.c
52107 +++ b/drivers/scsi/scsi_sysfs.c
52108 @@ -805,7 +805,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
52109 char *buf) \
52110 { \
52111 struct scsi_device *sdev = to_scsi_device(dev); \
52112 - unsigned long long count = atomic_read(&sdev->field); \
52113 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
52114 return snprintf(buf, 20, "0x%llx\n", count); \
52115 } \
52116 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
52117 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
52118 index 5d6f348..18778a6b 100644
52119 --- a/drivers/scsi/scsi_transport_fc.c
52120 +++ b/drivers/scsi/scsi_transport_fc.c
52121 @@ -501,7 +501,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
52122 * Netlink Infrastructure
52123 */
52124
52125 -static atomic_t fc_event_seq;
52126 +static atomic_unchecked_t fc_event_seq;
52127
52128 /**
52129 * fc_get_event_number - Obtain the next sequential FC event number
52130 @@ -514,7 +514,7 @@ static atomic_t fc_event_seq;
52131 u32
52132 fc_get_event_number(void)
52133 {
52134 - return atomic_add_return(1, &fc_event_seq);
52135 + return atomic_add_return_unchecked(1, &fc_event_seq);
52136 }
52137 EXPORT_SYMBOL(fc_get_event_number);
52138
52139 @@ -658,7 +658,7 @@ static __init int fc_transport_init(void)
52140 {
52141 int error;
52142
52143 - atomic_set(&fc_event_seq, 0);
52144 + atomic_set_unchecked(&fc_event_seq, 0);
52145
52146 error = transport_class_register(&fc_host_class);
52147 if (error)
52148 @@ -848,7 +848,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
52149 char *cp;
52150
52151 *val = simple_strtoul(buf, &cp, 0);
52152 - if ((*cp && (*cp != '\n')) || (*val < 0))
52153 + if (*cp && (*cp != '\n'))
52154 return -EINVAL;
52155 /*
52156 * Check for overflow; dev_loss_tmo is u32
52157 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
52158 index 67d43e3..8cee73c 100644
52159 --- a/drivers/scsi/scsi_transport_iscsi.c
52160 +++ b/drivers/scsi/scsi_transport_iscsi.c
52161 @@ -79,7 +79,7 @@ struct iscsi_internal {
52162 struct transport_container session_cont;
52163 };
52164
52165 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
52166 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
52167 static struct workqueue_struct *iscsi_eh_timer_workq;
52168
52169 static DEFINE_IDA(iscsi_sess_ida);
52170 @@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
52171 int err;
52172
52173 ihost = shost->shost_data;
52174 - session->sid = atomic_add_return(1, &iscsi_session_nr);
52175 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
52176
52177 if (target_id == ISCSI_MAX_TARGET) {
52178 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
52179 @@ -4515,7 +4515,7 @@ static __init int iscsi_transport_init(void)
52180 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
52181 ISCSI_TRANSPORT_VERSION);
52182
52183 - atomic_set(&iscsi_session_nr, 0);
52184 + atomic_set_unchecked(&iscsi_session_nr, 0);
52185
52186 err = class_register(&iscsi_transport_class);
52187 if (err)
52188 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
52189 index ae45bd9..c32a586 100644
52190 --- a/drivers/scsi/scsi_transport_srp.c
52191 +++ b/drivers/scsi/scsi_transport_srp.c
52192 @@ -35,7 +35,7 @@
52193 #include "scsi_priv.h"
52194
52195 struct srp_host_attrs {
52196 - atomic_t next_port_id;
52197 + atomic_unchecked_t next_port_id;
52198 };
52199 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
52200
52201 @@ -100,7 +100,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
52202 struct Scsi_Host *shost = dev_to_shost(dev);
52203 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
52204
52205 - atomic_set(&srp_host->next_port_id, 0);
52206 + atomic_set_unchecked(&srp_host->next_port_id, 0);
52207 return 0;
52208 }
52209
52210 @@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
52211 rport_fast_io_fail_timedout);
52212 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
52213
52214 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
52215 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
52216 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
52217
52218 transport_setup_device(&rport->dev);
52219 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
52220 index 2c2041c..9d94085 100644
52221 --- a/drivers/scsi/sd.c
52222 +++ b/drivers/scsi/sd.c
52223 @@ -3002,7 +3002,7 @@ static int sd_probe(struct device *dev)
52224 sdkp->disk = gd;
52225 sdkp->index = index;
52226 atomic_set(&sdkp->openers, 0);
52227 - atomic_set(&sdkp->device->ioerr_cnt, 0);
52228 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
52229
52230 if (!sdp->request_queue->rq_timeout) {
52231 if (sdp->type != TYPE_MOD)
52232 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
52233 index 01cf888..59e0475 100644
52234 --- a/drivers/scsi/sg.c
52235 +++ b/drivers/scsi/sg.c
52236 @@ -1138,7 +1138,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
52237 sdp->disk->disk_name,
52238 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
52239 NULL,
52240 - (char *)arg);
52241 + (char __user *)arg);
52242 case BLKTRACESTART:
52243 return blk_trace_startstop(sdp->device->request_queue, 1);
52244 case BLKTRACESTOP:
52245 diff --git a/drivers/soc/tegra/fuse/fuse-tegra.c b/drivers/soc/tegra/fuse/fuse-tegra.c
52246 index 11a5043..e36f04c 100644
52247 --- a/drivers/soc/tegra/fuse/fuse-tegra.c
52248 +++ b/drivers/soc/tegra/fuse/fuse-tegra.c
52249 @@ -70,7 +70,7 @@ static ssize_t fuse_read(struct file *fd, struct kobject *kobj,
52250 return i;
52251 }
52252
52253 -static struct bin_attribute fuse_bin_attr = {
52254 +static bin_attribute_no_const fuse_bin_attr = {
52255 .attr = { .name = "fuse", .mode = S_IRUGO, },
52256 .read = fuse_read,
52257 };
52258 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
52259 index ca935df..ae8a3dc 100644
52260 --- a/drivers/spi/spi.c
52261 +++ b/drivers/spi/spi.c
52262 @@ -2210,7 +2210,7 @@ int spi_bus_unlock(struct spi_master *master)
52263 EXPORT_SYMBOL_GPL(spi_bus_unlock);
52264
52265 /* portable code must never pass more than 32 bytes */
52266 -#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
52267 +#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
52268
52269 static u8 *buf;
52270
52271 diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
52272 index b41429f..2de5373 100644
52273 --- a/drivers/staging/android/timed_output.c
52274 +++ b/drivers/staging/android/timed_output.c
52275 @@ -25,7 +25,7 @@
52276 #include "timed_output.h"
52277
52278 static struct class *timed_output_class;
52279 -static atomic_t device_count;
52280 +static atomic_unchecked_t device_count;
52281
52282 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
52283 char *buf)
52284 @@ -65,7 +65,7 @@ static int create_timed_output_class(void)
52285 timed_output_class = class_create(THIS_MODULE, "timed_output");
52286 if (IS_ERR(timed_output_class))
52287 return PTR_ERR(timed_output_class);
52288 - atomic_set(&device_count, 0);
52289 + atomic_set_unchecked(&device_count, 0);
52290 timed_output_class->dev_groups = timed_output_groups;
52291 }
52292
52293 @@ -83,7 +83,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
52294 if (ret < 0)
52295 return ret;
52296
52297 - tdev->index = atomic_inc_return(&device_count);
52298 + tdev->index = atomic_inc_return_unchecked(&device_count);
52299 tdev->dev = device_create(timed_output_class, NULL,
52300 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
52301 if (IS_ERR(tdev->dev))
52302 diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
52303 index 001348c..cfaac8a 100644
52304 --- a/drivers/staging/gdm724x/gdm_tty.c
52305 +++ b/drivers/staging/gdm724x/gdm_tty.c
52306 @@ -44,7 +44,7 @@
52307 #define gdm_tty_send_control(n, r, v, d, l) (\
52308 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
52309
52310 -#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
52311 +#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
52312
52313 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
52314 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
52315 diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
52316 index 6b22106..6c6e641 100644
52317 --- a/drivers/staging/imx-drm/imx-drm-core.c
52318 +++ b/drivers/staging/imx-drm/imx-drm-core.c
52319 @@ -355,7 +355,7 @@ int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc,
52320 if (imxdrm->pipes >= MAX_CRTC)
52321 return -EINVAL;
52322
52323 - if (imxdrm->drm->open_count)
52324 + if (local_read(&imxdrm->drm->open_count))
52325 return -EBUSY;
52326
52327 imx_drm_crtc = kzalloc(sizeof(*imx_drm_crtc), GFP_KERNEL);
52328 diff --git a/drivers/staging/line6/driver.c b/drivers/staging/line6/driver.c
52329 index 503b2d7..c918745 100644
52330 --- a/drivers/staging/line6/driver.c
52331 +++ b/drivers/staging/line6/driver.c
52332 @@ -463,7 +463,7 @@ int line6_read_data(struct usb_line6 *line6, int address, void *data,
52333 {
52334 struct usb_device *usbdev = line6->usbdev;
52335 int ret;
52336 - unsigned char len;
52337 + unsigned char *plen;
52338
52339 /* query the serial number: */
52340 ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
52341 @@ -476,27 +476,34 @@ int line6_read_data(struct usb_line6 *line6, int address, void *data,
52342 return ret;
52343 }
52344
52345 + plen = kmalloc(1, GFP_KERNEL);
52346 + if (plen == NULL)
52347 + return -ENOMEM;
52348 +
52349 /* Wait for data length. We'll get 0xff until length arrives. */
52350 do {
52351 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
52352 USB_TYPE_VENDOR | USB_RECIP_DEVICE |
52353 USB_DIR_IN,
52354 - 0x0012, 0x0000, &len, 1,
52355 + 0x0012, 0x0000, plen, 1,
52356 LINE6_TIMEOUT * HZ);
52357 if (ret < 0) {
52358 dev_err(line6->ifcdev,
52359 "receive length failed (error %d)\n", ret);
52360 + kfree(plen);
52361 return ret;
52362 }
52363 - } while (len == 0xff);
52364 + } while (*plen == 0xff);
52365
52366 - if (len != datalen) {
52367 + if (*plen != datalen) {
52368 /* should be equal or something went wrong */
52369 dev_err(line6->ifcdev,
52370 "length mismatch (expected %d, got %d)\n",
52371 - (int)datalen, (int)len);
52372 + (int)datalen, (int)*plen);
52373 + kfree(plen);
52374 return -EINVAL;
52375 }
52376 + kfree(plen);
52377
52378 /* receive the result: */
52379 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
52380 diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
52381 index bcce919..f30fcf9 100644
52382 --- a/drivers/staging/lustre/lnet/selftest/brw_test.c
52383 +++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
52384 @@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
52385 return 0;
52386 }
52387
52388 -sfw_test_client_ops_t brw_test_client;
52389 -void brw_init_test_client(void)
52390 -{
52391 - brw_test_client.tso_init = brw_client_init;
52392 - brw_test_client.tso_fini = brw_client_fini;
52393 - brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
52394 - brw_test_client.tso_done_rpc = brw_client_done_rpc;
52395 +sfw_test_client_ops_t brw_test_client = {
52396 + .tso_init = brw_client_init,
52397 + .tso_fini = brw_client_fini,
52398 + .tso_prep_rpc = brw_client_prep_rpc,
52399 + .tso_done_rpc = brw_client_done_rpc,
52400 };
52401
52402 srpc_service_t brw_test_service;
52403 diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
52404 index 7e83dff..1f9a545 100644
52405 --- a/drivers/staging/lustre/lnet/selftest/framework.c
52406 +++ b/drivers/staging/lustre/lnet/selftest/framework.c
52407 @@ -1633,12 +1633,10 @@ static srpc_service_t sfw_services[] =
52408
52409 extern sfw_test_client_ops_t ping_test_client;
52410 extern srpc_service_t ping_test_service;
52411 -extern void ping_init_test_client(void);
52412 extern void ping_init_test_service(void);
52413
52414 extern sfw_test_client_ops_t brw_test_client;
52415 extern srpc_service_t brw_test_service;
52416 -extern void brw_init_test_client(void);
52417 extern void brw_init_test_service(void);
52418
52419
52420 @@ -1682,12 +1680,10 @@ sfw_startup (void)
52421 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
52422 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
52423
52424 - brw_init_test_client();
52425 brw_init_test_service();
52426 rc = sfw_register_test(&brw_test_service, &brw_test_client);
52427 LASSERT (rc == 0);
52428
52429 - ping_init_test_client();
52430 ping_init_test_service();
52431 rc = sfw_register_test(&ping_test_service, &ping_test_client);
52432 LASSERT (rc == 0);
52433 diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
52434 index 750cac4..e4d751f 100644
52435 --- a/drivers/staging/lustre/lnet/selftest/ping_test.c
52436 +++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
52437 @@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
52438 return 0;
52439 }
52440
52441 -sfw_test_client_ops_t ping_test_client;
52442 -void ping_init_test_client(void)
52443 -{
52444 - ping_test_client.tso_init = ping_client_init;
52445 - ping_test_client.tso_fini = ping_client_fini;
52446 - ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
52447 - ping_test_client.tso_done_rpc = ping_client_done_rpc;
52448 -}
52449 +sfw_test_client_ops_t ping_test_client = {
52450 + .tso_init = ping_client_init,
52451 + .tso_fini = ping_client_fini,
52452 + .tso_prep_rpc = ping_client_prep_rpc,
52453 + .tso_done_rpc = ping_client_done_rpc,
52454 +};
52455
52456 srpc_service_t ping_test_service;
52457 void ping_init_test_service(void)
52458 diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
52459 index 30b1812f..9e5bd0b 100644
52460 --- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
52461 +++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
52462 @@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
52463 ldlm_completion_callback lcs_completion;
52464 ldlm_blocking_callback lcs_blocking;
52465 ldlm_glimpse_callback lcs_glimpse;
52466 -};
52467 +} __no_const;
52468
52469 /* ldlm_lockd.c */
52470 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
52471 diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
52472 index 489bdd3..65058081 100644
52473 --- a/drivers/staging/lustre/lustre/include/obd.h
52474 +++ b/drivers/staging/lustre/lustre/include/obd.h
52475 @@ -1438,7 +1438,7 @@ struct md_ops {
52476 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
52477 * wrapper function in include/linux/obd_class.h.
52478 */
52479 -};
52480 +} __no_const;
52481
52482 struct lsm_operations {
52483 void (*lsm_free)(struct lov_stripe_md *);
52484 diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52485 index b798daa..b28ca8f 100644
52486 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52487 +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52488 @@ -258,7 +258,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
52489 int added = (mode == LCK_NL);
52490 int overlaps = 0;
52491 int splitted = 0;
52492 - const struct ldlm_callback_suite null_cbs = { NULL };
52493 + const struct ldlm_callback_suite null_cbs = { };
52494
52495 CDEBUG(D_DLMTRACE, "flags %#llx owner %llu pid %u mode %u start %llu end %llu\n",
52496 *flags, new->l_policy_data.l_flock.owner,
52497 diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52498 index 13a9266..3439390 100644
52499 --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52500 +++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52501 @@ -235,7 +235,7 @@ int proc_console_max_delay_cs(struct ctl_table *table, int write,
52502 void __user *buffer, size_t *lenp, loff_t *ppos)
52503 {
52504 int rc, max_delay_cs;
52505 - struct ctl_table dummy = *table;
52506 + ctl_table_no_const dummy = *table;
52507 long d;
52508
52509 dummy.data = &max_delay_cs;
52510 @@ -267,7 +267,7 @@ int proc_console_min_delay_cs(struct ctl_table *table, int write,
52511 void __user *buffer, size_t *lenp, loff_t *ppos)
52512 {
52513 int rc, min_delay_cs;
52514 - struct ctl_table dummy = *table;
52515 + ctl_table_no_const dummy = *table;
52516 long d;
52517
52518 dummy.data = &min_delay_cs;
52519 @@ -299,7 +299,7 @@ int proc_console_backoff(struct ctl_table *table, int write,
52520 void __user *buffer, size_t *lenp, loff_t *ppos)
52521 {
52522 int rc, backoff;
52523 - struct ctl_table dummy = *table;
52524 + ctl_table_no_const dummy = *table;
52525
52526 dummy.data = &backoff;
52527 dummy.proc_handler = &proc_dointvec;
52528 diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
52529 index 3396858..c0bd996 100644
52530 --- a/drivers/staging/lustre/lustre/libcfs/module.c
52531 +++ b/drivers/staging/lustre/lustre/libcfs/module.c
52532 @@ -314,11 +314,11 @@ out:
52533
52534
52535 struct cfs_psdev_ops libcfs_psdev_ops = {
52536 - libcfs_psdev_open,
52537 - libcfs_psdev_release,
52538 - NULL,
52539 - NULL,
52540 - libcfs_ioctl
52541 + .p_open = libcfs_psdev_open,
52542 + .p_close = libcfs_psdev_release,
52543 + .p_read = NULL,
52544 + .p_write = NULL,
52545 + .p_ioctl = libcfs_ioctl
52546 };
52547
52548 extern int insert_proc(void);
52549 diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
52550 index efa2faf..03a9836 100644
52551 --- a/drivers/staging/lustre/lustre/llite/dir.c
52552 +++ b/drivers/staging/lustre/lustre/llite/dir.c
52553 @@ -659,7 +659,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
52554 int mode;
52555 int err;
52556
52557 - mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
52558 + mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
52559 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
52560 strlen(filename), mode, LUSTRE_OPC_MKDIR,
52561 lump);
52562 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
52563 index a0f4868..139f1fb 100644
52564 --- a/drivers/staging/octeon/ethernet-rx.c
52565 +++ b/drivers/staging/octeon/ethernet-rx.c
52566 @@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
52567 /* Increment RX stats for virtual ports */
52568 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
52569 #ifdef CONFIG_64BIT
52570 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
52571 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
52572 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
52573 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
52574 #else
52575 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
52576 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
52577 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
52578 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
52579 #endif
52580 }
52581 netif_receive_skb(skb);
52582 @@ -432,9 +432,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
52583 dev->name);
52584 */
52585 #ifdef CONFIG_64BIT
52586 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
52587 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
52588 #else
52589 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
52590 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
52591 #endif
52592 dev_kfree_skb_irq(skb);
52593 }
52594 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
52595 index 2aa7235..ba3c205 100644
52596 --- a/drivers/staging/octeon/ethernet.c
52597 +++ b/drivers/staging/octeon/ethernet.c
52598 @@ -247,11 +247,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
52599 * since the RX tasklet also increments it.
52600 */
52601 #ifdef CONFIG_64BIT
52602 - atomic64_add(rx_status.dropped_packets,
52603 - (atomic64_t *)&priv->stats.rx_dropped);
52604 + atomic64_add_unchecked(rx_status.dropped_packets,
52605 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
52606 #else
52607 - atomic_add(rx_status.dropped_packets,
52608 - (atomic_t *)&priv->stats.rx_dropped);
52609 + atomic_add_unchecked(rx_status.dropped_packets,
52610 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
52611 #endif
52612 }
52613
52614 diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
52615 index 56d5c50..a14f4db 100644
52616 --- a/drivers/staging/rtl8188eu/include/hal_intf.h
52617 +++ b/drivers/staging/rtl8188eu/include/hal_intf.h
52618 @@ -234,7 +234,7 @@ struct hal_ops {
52619
52620 void (*hal_notch_filter)(struct adapter *adapter, bool enable);
52621 void (*hal_reset_security_engine)(struct adapter *adapter);
52622 -};
52623 +} __no_const;
52624
52625 enum rt_eeprom_type {
52626 EEPROM_93C46,
52627 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
52628 index dc23395..cf7e9b1 100644
52629 --- a/drivers/staging/rtl8712/rtl871x_io.h
52630 +++ b/drivers/staging/rtl8712/rtl871x_io.h
52631 @@ -108,7 +108,7 @@ struct _io_ops {
52632 u8 *pmem);
52633 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
52634 u8 *pmem);
52635 -};
52636 +} __no_const;
52637
52638 struct io_req {
52639 struct list_head list;
52640 diff --git a/drivers/staging/unisys/visorchipset/visorchipset.h b/drivers/staging/unisys/visorchipset/visorchipset.h
52641 index 2bf2e2f..84421c9 100644
52642 --- a/drivers/staging/unisys/visorchipset/visorchipset.h
52643 +++ b/drivers/staging/unisys/visorchipset/visorchipset.h
52644 @@ -228,7 +228,7 @@ typedef struct {
52645 void (*device_resume)(ulong busNo, ulong devNo);
52646 int (*get_channel_info)(uuid_le typeGuid, ulong *minSize,
52647 ulong *maxSize);
52648 -} VISORCHIPSET_BUSDEV_NOTIFIERS;
52649 +} __no_const VISORCHIPSET_BUSDEV_NOTIFIERS;
52650
52651 /* These functions live inside visorchipset, and will be called to indicate
52652 * responses to specific events (by code outside of visorchipset).
52653 @@ -243,7 +243,7 @@ typedef struct {
52654 void (*device_destroy)(ulong busNo, ulong devNo, int response);
52655 void (*device_pause)(ulong busNo, ulong devNo, int response);
52656 void (*device_resume)(ulong busNo, ulong devNo, int response);
52657 -} VISORCHIPSET_BUSDEV_RESPONDERS;
52658 +} __no_const VISORCHIPSET_BUSDEV_RESPONDERS;
52659
52660 /** Register functions (in the bus driver) to get called by visorchipset
52661 * whenever a bus or device appears for which this service partition is
52662 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
52663 index 164136b..7244df5 100644
52664 --- a/drivers/staging/vt6655/hostap.c
52665 +++ b/drivers/staging/vt6655/hostap.c
52666 @@ -68,14 +68,13 @@ static int msglevel = MSG_LEVEL_INFO;
52667 *
52668 */
52669
52670 +static net_device_ops_no_const apdev_netdev_ops;
52671 +
52672 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
52673 {
52674 PSDevice apdev_priv;
52675 struct net_device *dev = pDevice->dev;
52676 int ret;
52677 - const struct net_device_ops apdev_netdev_ops = {
52678 - .ndo_start_xmit = pDevice->tx_80211,
52679 - };
52680
52681 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
52682
52683 @@ -87,6 +86,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
52684 *apdev_priv = *pDevice;
52685 eth_hw_addr_inherit(pDevice->apdev, dev);
52686
52687 + /* only half broken now */
52688 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
52689 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
52690
52691 pDevice->apdev->type = ARPHRD_IEEE80211;
52692 diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
52693 index e7e9372..161f530 100644
52694 --- a/drivers/target/sbp/sbp_target.c
52695 +++ b/drivers/target/sbp/sbp_target.c
52696 @@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
52697
52698 #define SESSION_MAINTENANCE_INTERVAL HZ
52699
52700 -static atomic_t login_id = ATOMIC_INIT(0);
52701 +static atomic_unchecked_t login_id = ATOMIC_INIT(0);
52702
52703 static void session_maintenance_work(struct work_struct *);
52704 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
52705 @@ -444,7 +444,7 @@ static void sbp_management_request_login(
52706 login->lun = se_lun;
52707 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
52708 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
52709 - login->login_id = atomic_inc_return(&login_id);
52710 + login->login_id = atomic_inc_return_unchecked(&login_id);
52711
52712 login->tgt_agt = sbp_target_agent_register(login);
52713 if (IS_ERR(login->tgt_agt)) {
52714 diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
52715 index 15a1c13..6c9b96b 100644
52716 --- a/drivers/target/target_core_device.c
52717 +++ b/drivers/target/target_core_device.c
52718 @@ -1526,7 +1526,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
52719 spin_lock_init(&dev->se_tmr_lock);
52720 spin_lock_init(&dev->qf_cmd_lock);
52721 sema_init(&dev->caw_sem, 1);
52722 - atomic_set(&dev->dev_ordered_id, 0);
52723 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
52724 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
52725 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
52726 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
52727 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
52728 index ab61014..8f1116e 100644
52729 --- a/drivers/target/target_core_transport.c
52730 +++ b/drivers/target/target_core_transport.c
52731 @@ -1165,7 +1165,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
52732 * Used to determine when ORDERED commands should go from
52733 * Dormant to Active status.
52734 */
52735 - cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
52736 + cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
52737 smp_mb__after_atomic();
52738 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
52739 cmd->se_ordered_id, cmd->sam_task_attr,
52740 diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
52741 index 4b2b999..cad9fa5 100644
52742 --- a/drivers/thermal/of-thermal.c
52743 +++ b/drivers/thermal/of-thermal.c
52744 @@ -30,6 +30,7 @@
52745 #include <linux/err.h>
52746 #include <linux/export.h>
52747 #include <linux/string.h>
52748 +#include <linux/mm.h>
52749
52750 #include "thermal_core.h"
52751
52752 @@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
52753 tz->get_trend = get_trend;
52754 tz->sensor_data = data;
52755
52756 - tzd->ops->get_temp = of_thermal_get_temp;
52757 - tzd->ops->get_trend = of_thermal_get_trend;
52758 + pax_open_kernel();
52759 + *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
52760 + *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
52761 + pax_close_kernel();
52762 mutex_unlock(&tzd->lock);
52763
52764 return tzd;
52765 @@ -461,8 +464,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
52766 return;
52767
52768 mutex_lock(&tzd->lock);
52769 - tzd->ops->get_temp = NULL;
52770 - tzd->ops->get_trend = NULL;
52771 + pax_open_kernel();
52772 + *(void **)&tzd->ops->get_temp = NULL;
52773 + *(void **)&tzd->ops->get_trend = NULL;
52774 + pax_close_kernel();
52775
52776 tz->get_temp = NULL;
52777 tz->get_trend = NULL;
52778 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
52779 index fd66f57..48e6376 100644
52780 --- a/drivers/tty/cyclades.c
52781 +++ b/drivers/tty/cyclades.c
52782 @@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
52783 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
52784 info->port.count);
52785 #endif
52786 - info->port.count++;
52787 + atomic_inc(&info->port.count);
52788 #ifdef CY_DEBUG_COUNT
52789 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
52790 - current->pid, info->port.count);
52791 + current->pid, atomic_read(&info->port.count));
52792 #endif
52793
52794 /*
52795 @@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
52796 for (j = 0; j < cy_card[i].nports; j++) {
52797 info = &cy_card[i].ports[j];
52798
52799 - if (info->port.count) {
52800 + if (atomic_read(&info->port.count)) {
52801 /* XXX is the ldisc num worth this? */
52802 struct tty_struct *tty;
52803 struct tty_ldisc *ld;
52804 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
52805 index 4fcec1d..5a036f7 100644
52806 --- a/drivers/tty/hvc/hvc_console.c
52807 +++ b/drivers/tty/hvc/hvc_console.c
52808 @@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
52809
52810 spin_lock_irqsave(&hp->port.lock, flags);
52811 /* Check and then increment for fast path open. */
52812 - if (hp->port.count++ > 0) {
52813 + if (atomic_inc_return(&hp->port.count) > 1) {
52814 spin_unlock_irqrestore(&hp->port.lock, flags);
52815 hvc_kick();
52816 return 0;
52817 @@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
52818
52819 spin_lock_irqsave(&hp->port.lock, flags);
52820
52821 - if (--hp->port.count == 0) {
52822 + if (atomic_dec_return(&hp->port.count) == 0) {
52823 spin_unlock_irqrestore(&hp->port.lock, flags);
52824 /* We are done with the tty pointer now. */
52825 tty_port_tty_set(&hp->port, NULL);
52826 @@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
52827 */
52828 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
52829 } else {
52830 - if (hp->port.count < 0)
52831 + if (atomic_read(&hp->port.count) < 0)
52832 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
52833 - hp->vtermno, hp->port.count);
52834 + hp->vtermno, atomic_read(&hp->port.count));
52835 spin_unlock_irqrestore(&hp->port.lock, flags);
52836 }
52837 }
52838 @@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
52839 * open->hangup case this can be called after the final close so prevent
52840 * that from happening for now.
52841 */
52842 - if (hp->port.count <= 0) {
52843 + if (atomic_read(&hp->port.count) <= 0) {
52844 spin_unlock_irqrestore(&hp->port.lock, flags);
52845 return;
52846 }
52847
52848 - hp->port.count = 0;
52849 + atomic_set(&hp->port.count, 0);
52850 spin_unlock_irqrestore(&hp->port.lock, flags);
52851 tty_port_tty_set(&hp->port, NULL);
52852
52853 @@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
52854 return -EPIPE;
52855
52856 /* FIXME what's this (unprotected) check for? */
52857 - if (hp->port.count <= 0)
52858 + if (atomic_read(&hp->port.count) <= 0)
52859 return -EIO;
52860
52861 spin_lock_irqsave(&hp->lock, flags);
52862 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
52863 index 81e939e..95ead10 100644
52864 --- a/drivers/tty/hvc/hvcs.c
52865 +++ b/drivers/tty/hvc/hvcs.c
52866 @@ -83,6 +83,7 @@
52867 #include <asm/hvcserver.h>
52868 #include <asm/uaccess.h>
52869 #include <asm/vio.h>
52870 +#include <asm/local.h>
52871
52872 /*
52873 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
52874 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
52875
52876 spin_lock_irqsave(&hvcsd->lock, flags);
52877
52878 - if (hvcsd->port.count > 0) {
52879 + if (atomic_read(&hvcsd->port.count) > 0) {
52880 spin_unlock_irqrestore(&hvcsd->lock, flags);
52881 printk(KERN_INFO "HVCS: vterm state unchanged. "
52882 "The hvcs device node is still in use.\n");
52883 @@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
52884 }
52885 }
52886
52887 - hvcsd->port.count = 0;
52888 + atomic_set(&hvcsd->port.count, 0);
52889 hvcsd->port.tty = tty;
52890 tty->driver_data = hvcsd;
52891
52892 @@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
52893 unsigned long flags;
52894
52895 spin_lock_irqsave(&hvcsd->lock, flags);
52896 - hvcsd->port.count++;
52897 + atomic_inc(&hvcsd->port.count);
52898 hvcsd->todo_mask |= HVCS_SCHED_READ;
52899 spin_unlock_irqrestore(&hvcsd->lock, flags);
52900
52901 @@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
52902 hvcsd = tty->driver_data;
52903
52904 spin_lock_irqsave(&hvcsd->lock, flags);
52905 - if (--hvcsd->port.count == 0) {
52906 + if (atomic_dec_and_test(&hvcsd->port.count)) {
52907
52908 vio_disable_interrupts(hvcsd->vdev);
52909
52910 @@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
52911
52912 free_irq(irq, hvcsd);
52913 return;
52914 - } else if (hvcsd->port.count < 0) {
52915 + } else if (atomic_read(&hvcsd->port.count) < 0) {
52916 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
52917 " is missmanaged.\n",
52918 - hvcsd->vdev->unit_address, hvcsd->port.count);
52919 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
52920 }
52921
52922 spin_unlock_irqrestore(&hvcsd->lock, flags);
52923 @@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
52924
52925 spin_lock_irqsave(&hvcsd->lock, flags);
52926 /* Preserve this so that we know how many kref refs to put */
52927 - temp_open_count = hvcsd->port.count;
52928 + temp_open_count = atomic_read(&hvcsd->port.count);
52929
52930 /*
52931 * Don't kref put inside the spinlock because the destruction
52932 @@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
52933 tty->driver_data = NULL;
52934 hvcsd->port.tty = NULL;
52935
52936 - hvcsd->port.count = 0;
52937 + atomic_set(&hvcsd->port.count, 0);
52938
52939 /* This will drop any buffered data on the floor which is OK in a hangup
52940 * scenario. */
52941 @@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
52942 * the middle of a write operation? This is a crummy place to do this
52943 * but we want to keep it all in the spinlock.
52944 */
52945 - if (hvcsd->port.count <= 0) {
52946 + if (atomic_read(&hvcsd->port.count) <= 0) {
52947 spin_unlock_irqrestore(&hvcsd->lock, flags);
52948 return -ENODEV;
52949 }
52950 @@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
52951 {
52952 struct hvcs_struct *hvcsd = tty->driver_data;
52953
52954 - if (!hvcsd || hvcsd->port.count <= 0)
52955 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
52956 return 0;
52957
52958 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
52959 diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
52960 index 4190199..06d5bfa 100644
52961 --- a/drivers/tty/hvc/hvsi.c
52962 +++ b/drivers/tty/hvc/hvsi.c
52963 @@ -85,7 +85,7 @@ struct hvsi_struct {
52964 int n_outbuf;
52965 uint32_t vtermno;
52966 uint32_t virq;
52967 - atomic_t seqno; /* HVSI packet sequence number */
52968 + atomic_unchecked_t seqno; /* HVSI packet sequence number */
52969 uint16_t mctrl;
52970 uint8_t state; /* HVSI protocol state */
52971 uint8_t flags;
52972 @@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
52973
52974 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
52975 packet.hdr.len = sizeof(struct hvsi_query_response);
52976 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52977 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52978 packet.verb = VSV_SEND_VERSION_NUMBER;
52979 packet.u.version = HVSI_VERSION;
52980 packet.query_seqno = query_seqno+1;
52981 @@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
52982
52983 packet.hdr.type = VS_QUERY_PACKET_HEADER;
52984 packet.hdr.len = sizeof(struct hvsi_query);
52985 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52986 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52987 packet.verb = verb;
52988
52989 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
52990 @@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
52991 int wrote;
52992
52993 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
52994 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52995 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52996 packet.hdr.len = sizeof(struct hvsi_control);
52997 packet.verb = VSV_SET_MODEM_CTL;
52998 packet.mask = HVSI_TSDTR;
52999 @@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
53000 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
53001
53002 packet.hdr.type = VS_DATA_PACKET_HEADER;
53003 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53004 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53005 packet.hdr.len = count + sizeof(struct hvsi_header);
53006 memcpy(&packet.data, buf, count);
53007
53008 @@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
53009 struct hvsi_control packet __ALIGNED__;
53010
53011 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
53012 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53013 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53014 packet.hdr.len = 6;
53015 packet.verb = VSV_CLOSE_PROTOCOL;
53016
53017 @@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
53018
53019 tty_port_tty_set(&hp->port, tty);
53020 spin_lock_irqsave(&hp->lock, flags);
53021 - hp->port.count++;
53022 + atomic_inc(&hp->port.count);
53023 atomic_set(&hp->seqno, 0);
53024 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
53025 spin_unlock_irqrestore(&hp->lock, flags);
53026 @@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
53027
53028 spin_lock_irqsave(&hp->lock, flags);
53029
53030 - if (--hp->port.count == 0) {
53031 + if (atomic_dec_return(&hp->port.count) == 0) {
53032 tty_port_tty_set(&hp->port, NULL);
53033 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
53034
53035 @@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
53036
53037 spin_lock_irqsave(&hp->lock, flags);
53038 }
53039 - } else if (hp->port.count < 0)
53040 + } else if (atomic_read(&hp->port.count) < 0)
53041 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
53042 - hp - hvsi_ports, hp->port.count);
53043 + hp - hvsi_ports, atomic_read(&hp->port.count));
53044
53045 spin_unlock_irqrestore(&hp->lock, flags);
53046 }
53047 @@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
53048 tty_port_tty_set(&hp->port, NULL);
53049
53050 spin_lock_irqsave(&hp->lock, flags);
53051 - hp->port.count = 0;
53052 + atomic_set(&hp->port.count, 0);
53053 hp->n_outbuf = 0;
53054 spin_unlock_irqrestore(&hp->lock, flags);
53055 }
53056 diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
53057 index 7ae6c29..05c6dba 100644
53058 --- a/drivers/tty/hvc/hvsi_lib.c
53059 +++ b/drivers/tty/hvc/hvsi_lib.c
53060 @@ -8,7 +8,7 @@
53061
53062 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
53063 {
53064 - packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
53065 + packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
53066
53067 /* Assumes that always succeeds, works in practice */
53068 return pv->put_chars(pv->termno, (char *)packet, packet->len);
53069 @@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
53070
53071 /* Reset state */
53072 pv->established = 0;
53073 - atomic_set(&pv->seqno, 0);
53074 + atomic_set_unchecked(&pv->seqno, 0);
53075
53076 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
53077
53078 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
53079 index 345cebb..d5a1e9e 100644
53080 --- a/drivers/tty/ipwireless/tty.c
53081 +++ b/drivers/tty/ipwireless/tty.c
53082 @@ -28,6 +28,7 @@
53083 #include <linux/tty_driver.h>
53084 #include <linux/tty_flip.h>
53085 #include <linux/uaccess.h>
53086 +#include <asm/local.h>
53087
53088 #include "tty.h"
53089 #include "network.h"
53090 @@ -93,10 +94,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
53091 return -ENODEV;
53092
53093 mutex_lock(&tty->ipw_tty_mutex);
53094 - if (tty->port.count == 0)
53095 + if (atomic_read(&tty->port.count) == 0)
53096 tty->tx_bytes_queued = 0;
53097
53098 - tty->port.count++;
53099 + atomic_inc(&tty->port.count);
53100
53101 tty->port.tty = linux_tty;
53102 linux_tty->driver_data = tty;
53103 @@ -112,9 +113,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
53104
53105 static void do_ipw_close(struct ipw_tty *tty)
53106 {
53107 - tty->port.count--;
53108 -
53109 - if (tty->port.count == 0) {
53110 + if (atomic_dec_return(&tty->port.count) == 0) {
53111 struct tty_struct *linux_tty = tty->port.tty;
53112
53113 if (linux_tty != NULL) {
53114 @@ -135,7 +134,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
53115 return;
53116
53117 mutex_lock(&tty->ipw_tty_mutex);
53118 - if (tty->port.count == 0) {
53119 + if (atomic_read(&tty->port.count) == 0) {
53120 mutex_unlock(&tty->ipw_tty_mutex);
53121 return;
53122 }
53123 @@ -158,7 +157,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
53124
53125 mutex_lock(&tty->ipw_tty_mutex);
53126
53127 - if (!tty->port.count) {
53128 + if (!atomic_read(&tty->port.count)) {
53129 mutex_unlock(&tty->ipw_tty_mutex);
53130 return;
53131 }
53132 @@ -197,7 +196,7 @@ static int ipw_write(struct tty_struct *linux_tty,
53133 return -ENODEV;
53134
53135 mutex_lock(&tty->ipw_tty_mutex);
53136 - if (!tty->port.count) {
53137 + if (!atomic_read(&tty->port.count)) {
53138 mutex_unlock(&tty->ipw_tty_mutex);
53139 return -EINVAL;
53140 }
53141 @@ -237,7 +236,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
53142 if (!tty)
53143 return -ENODEV;
53144
53145 - if (!tty->port.count)
53146 + if (!atomic_read(&tty->port.count))
53147 return -EINVAL;
53148
53149 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
53150 @@ -279,7 +278,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
53151 if (!tty)
53152 return 0;
53153
53154 - if (!tty->port.count)
53155 + if (!atomic_read(&tty->port.count))
53156 return 0;
53157
53158 return tty->tx_bytes_queued;
53159 @@ -360,7 +359,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
53160 if (!tty)
53161 return -ENODEV;
53162
53163 - if (!tty->port.count)
53164 + if (!atomic_read(&tty->port.count))
53165 return -EINVAL;
53166
53167 return get_control_lines(tty);
53168 @@ -376,7 +375,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
53169 if (!tty)
53170 return -ENODEV;
53171
53172 - if (!tty->port.count)
53173 + if (!atomic_read(&tty->port.count))
53174 return -EINVAL;
53175
53176 return set_control_lines(tty, set, clear);
53177 @@ -390,7 +389,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
53178 if (!tty)
53179 return -ENODEV;
53180
53181 - if (!tty->port.count)
53182 + if (!atomic_read(&tty->port.count))
53183 return -EINVAL;
53184
53185 /* FIXME: Exactly how is the tty object locked here .. */
53186 @@ -546,7 +545,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
53187 * are gone */
53188 mutex_lock(&ttyj->ipw_tty_mutex);
53189 }
53190 - while (ttyj->port.count)
53191 + while (atomic_read(&ttyj->port.count))
53192 do_ipw_close(ttyj);
53193 ipwireless_disassociate_network_ttys(network,
53194 ttyj->channel_idx);
53195 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
53196 index 1deaca4..c8582d4 100644
53197 --- a/drivers/tty/moxa.c
53198 +++ b/drivers/tty/moxa.c
53199 @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
53200 }
53201
53202 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
53203 - ch->port.count++;
53204 + atomic_inc(&ch->port.count);
53205 tty->driver_data = ch;
53206 tty_port_tty_set(&ch->port, tty);
53207 mutex_lock(&ch->port.mutex);
53208 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
53209 index c434376..114ce13 100644
53210 --- a/drivers/tty/n_gsm.c
53211 +++ b/drivers/tty/n_gsm.c
53212 @@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
53213 spin_lock_init(&dlci->lock);
53214 mutex_init(&dlci->mutex);
53215 dlci->fifo = &dlci->_fifo;
53216 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
53217 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
53218 kfree(dlci);
53219 return NULL;
53220 }
53221 @@ -2958,7 +2958,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
53222 struct gsm_dlci *dlci = tty->driver_data;
53223 struct tty_port *port = &dlci->port;
53224
53225 - port->count++;
53226 + atomic_inc(&port->count);
53227 tty_port_tty_set(port, tty);
53228
53229 dlci->modem_rx = 0;
53230 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
53231 index f44f1ba..a8d5915 100644
53232 --- a/drivers/tty/n_tty.c
53233 +++ b/drivers/tty/n_tty.c
53234 @@ -115,7 +115,7 @@ struct n_tty_data {
53235 int minimum_to_wake;
53236
53237 /* consumer-published */
53238 - size_t read_tail;
53239 + size_t read_tail __intentional_overflow(-1);
53240 size_t line_start;
53241
53242 /* protected by output lock */
53243 @@ -2517,6 +2517,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
53244 {
53245 *ops = tty_ldisc_N_TTY;
53246 ops->owner = NULL;
53247 - ops->refcount = ops->flags = 0;
53248 + atomic_set(&ops->refcount, 0);
53249 + ops->flags = 0;
53250 }
53251 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
53252 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
53253 index 9bbdb1d..dc514ee 100644
53254 --- a/drivers/tty/pty.c
53255 +++ b/drivers/tty/pty.c
53256 @@ -789,8 +789,10 @@ static void __init unix98_pty_init(void)
53257 panic("Couldn't register Unix98 pts driver");
53258
53259 /* Now create the /dev/ptmx special device */
53260 + pax_open_kernel();
53261 tty_default_fops(&ptmx_fops);
53262 - ptmx_fops.open = ptmx_open;
53263 + *(void **)&ptmx_fops.open = ptmx_open;
53264 + pax_close_kernel();
53265
53266 cdev_init(&ptmx_cdev, &ptmx_fops);
53267 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
53268 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
53269 index 383c4c7..d408e21 100644
53270 --- a/drivers/tty/rocket.c
53271 +++ b/drivers/tty/rocket.c
53272 @@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
53273 tty->driver_data = info;
53274 tty_port_tty_set(port, tty);
53275
53276 - if (port->count++ == 0) {
53277 + if (atomic_inc_return(&port->count) == 1) {
53278 atomic_inc(&rp_num_ports_open);
53279
53280 #ifdef ROCKET_DEBUG_OPEN
53281 @@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
53282 #endif
53283 }
53284 #ifdef ROCKET_DEBUG_OPEN
53285 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
53286 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
53287 #endif
53288
53289 /*
53290 @@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
53291 spin_unlock_irqrestore(&info->port.lock, flags);
53292 return;
53293 }
53294 - if (info->port.count)
53295 + if (atomic_read(&info->port.count))
53296 atomic_dec(&rp_num_ports_open);
53297 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
53298 spin_unlock_irqrestore(&info->port.lock, flags);
53299 diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
53300 index aa28209..e08fb85 100644
53301 --- a/drivers/tty/serial/ioc4_serial.c
53302 +++ b/drivers/tty/serial/ioc4_serial.c
53303 @@ -437,7 +437,7 @@ struct ioc4_soft {
53304 } is_intr_info[MAX_IOC4_INTR_ENTS];
53305
53306 /* Number of entries active in the above array */
53307 - atomic_t is_num_intrs;
53308 + atomic_unchecked_t is_num_intrs;
53309 } is_intr_type[IOC4_NUM_INTR_TYPES];
53310
53311 /* is_ir_lock must be held while
53312 @@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
53313 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
53314 || (type == IOC4_OTHER_INTR_TYPE)));
53315
53316 - i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
53317 + i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
53318 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
53319
53320 /* Save off the lower level interrupt handler */
53321 @@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
53322
53323 soft = arg;
53324 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
53325 - num_intrs = (int)atomic_read(
53326 + num_intrs = (int)atomic_read_unchecked(
53327 &soft->is_intr_type[intr_type].is_num_intrs);
53328
53329 this_mir = this_ir = pending_intrs(soft, intr_type);
53330 diff --git a/drivers/tty/serial/kgdb_nmi.c b/drivers/tty/serial/kgdb_nmi.c
53331 index 6ec7501..265bcbf 100644
53332 --- a/drivers/tty/serial/kgdb_nmi.c
53333 +++ b/drivers/tty/serial/kgdb_nmi.c
53334 @@ -51,7 +51,9 @@ static int kgdb_nmi_console_setup(struct console *co, char *options)
53335 * I/O utilities that messages sent to the console will automatically
53336 * be displayed on the dbg_io.
53337 */
53338 - dbg_io_ops->is_console = true;
53339 + pax_open_kernel();
53340 + *(int *)&dbg_io_ops->is_console = true;
53341 + pax_close_kernel();
53342
53343 return 0;
53344 }
53345 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
53346 index a260cde..6b2b5ce 100644
53347 --- a/drivers/tty/serial/kgdboc.c
53348 +++ b/drivers/tty/serial/kgdboc.c
53349 @@ -24,8 +24,9 @@
53350 #define MAX_CONFIG_LEN 40
53351
53352 static struct kgdb_io kgdboc_io_ops;
53353 +static struct kgdb_io kgdboc_io_ops_console;
53354
53355 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
53356 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
53357 static int configured = -1;
53358
53359 static char config[MAX_CONFIG_LEN];
53360 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
53361 kgdboc_unregister_kbd();
53362 if (configured == 1)
53363 kgdb_unregister_io_module(&kgdboc_io_ops);
53364 + else if (configured == 2)
53365 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
53366 }
53367
53368 static int configure_kgdboc(void)
53369 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
53370 int err;
53371 char *cptr = config;
53372 struct console *cons;
53373 + int is_console = 0;
53374
53375 err = kgdboc_option_setup(config);
53376 if (err || !strlen(config) || isspace(config[0]))
53377 goto noconfig;
53378
53379 err = -ENODEV;
53380 - kgdboc_io_ops.is_console = 0;
53381 kgdb_tty_driver = NULL;
53382
53383 kgdboc_use_kms = 0;
53384 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
53385 int idx;
53386 if (cons->device && cons->device(cons, &idx) == p &&
53387 idx == tty_line) {
53388 - kgdboc_io_ops.is_console = 1;
53389 + is_console = 1;
53390 break;
53391 }
53392 cons = cons->next;
53393 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
53394 kgdb_tty_line = tty_line;
53395
53396 do_register:
53397 - err = kgdb_register_io_module(&kgdboc_io_ops);
53398 + if (is_console) {
53399 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
53400 + configured = 2;
53401 + } else {
53402 + err = kgdb_register_io_module(&kgdboc_io_ops);
53403 + configured = 1;
53404 + }
53405 if (err)
53406 goto noconfig;
53407
53408 @@ -205,8 +214,6 @@ do_register:
53409 if (err)
53410 goto nmi_con_failed;
53411
53412 - configured = 1;
53413 -
53414 return 0;
53415
53416 nmi_con_failed:
53417 @@ -223,7 +230,7 @@ noconfig:
53418 static int __init init_kgdboc(void)
53419 {
53420 /* Already configured? */
53421 - if (configured == 1)
53422 + if (configured >= 1)
53423 return 0;
53424
53425 return configure_kgdboc();
53426 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
53427 if (config[len - 1] == '\n')
53428 config[len - 1] = '\0';
53429
53430 - if (configured == 1)
53431 + if (configured >= 1)
53432 cleanup_kgdboc();
53433
53434 /* Go and configure with the new params. */
53435 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
53436 .post_exception = kgdboc_post_exp_handler,
53437 };
53438
53439 +static struct kgdb_io kgdboc_io_ops_console = {
53440 + .name = "kgdboc",
53441 + .read_char = kgdboc_get_char,
53442 + .write_char = kgdboc_put_char,
53443 + .pre_exception = kgdboc_pre_exp_handler,
53444 + .post_exception = kgdboc_post_exp_handler,
53445 + .is_console = 1
53446 +};
53447 +
53448 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
53449 /* This is only available if kgdboc is a built in for early debugging */
53450 static int __init kgdboc_early_init(char *opt)
53451 diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
53452 index 077570a..12550a9 100644
53453 --- a/drivers/tty/serial/msm_serial.c
53454 +++ b/drivers/tty/serial/msm_serial.c
53455 @@ -981,7 +981,7 @@ static struct uart_driver msm_uart_driver = {
53456 .cons = MSM_CONSOLE,
53457 };
53458
53459 -static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
53460 +static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
53461
53462 static const struct of_device_id msm_uartdm_table[] = {
53463 { .compatible = "qcom,msm-uartdm-v1.1", .data = (void *)UARTDM_1P1 },
53464 @@ -1000,7 +1000,7 @@ static int msm_serial_probe(struct platform_device *pdev)
53465 int irq;
53466
53467 if (pdev->id == -1)
53468 - pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
53469 + pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
53470
53471 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
53472 return -ENXIO;
53473 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
53474 index c78f43a..22b1dab 100644
53475 --- a/drivers/tty/serial/samsung.c
53476 +++ b/drivers/tty/serial/samsung.c
53477 @@ -478,11 +478,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
53478 }
53479 }
53480
53481 +static int s3c64xx_serial_startup(struct uart_port *port);
53482 static int s3c24xx_serial_startup(struct uart_port *port)
53483 {
53484 struct s3c24xx_uart_port *ourport = to_ourport(port);
53485 int ret;
53486
53487 + /* Startup sequence is different for s3c64xx and higher SoC's */
53488 + if (s3c24xx_serial_has_interrupt_mask(port))
53489 + return s3c64xx_serial_startup(port);
53490 +
53491 dbg("s3c24xx_serial_startup: port=%p (%08llx,%p)\n",
53492 port, (unsigned long long)port->mapbase, port->membase);
53493
53494 @@ -1155,10 +1160,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
53495 /* setup info for port */
53496 port->dev = &platdev->dev;
53497
53498 - /* Startup sequence is different for s3c64xx and higher SoC's */
53499 - if (s3c24xx_serial_has_interrupt_mask(port))
53500 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
53501 -
53502 port->uartclk = 1;
53503
53504 if (cfg->uart_flags & UPF_CONS_FLOW) {
53505 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
53506 index 0f03988..8a8038d 100644
53507 --- a/drivers/tty/serial/serial_core.c
53508 +++ b/drivers/tty/serial/serial_core.c
53509 @@ -1343,7 +1343,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
53510
53511 pr_debug("uart_close(%d) called\n", uport ? uport->line : -1);
53512
53513 - if (!port->count || tty_port_close_start(port, tty, filp) == 0)
53514 + if (!atomic_read(&port->count) || tty_port_close_start(port, tty, filp) == 0)
53515 return;
53516
53517 /*
53518 @@ -1470,7 +1470,7 @@ static void uart_hangup(struct tty_struct *tty)
53519 uart_flush_buffer(tty);
53520 uart_shutdown(tty, state);
53521 spin_lock_irqsave(&port->lock, flags);
53522 - port->count = 0;
53523 + atomic_set(&port->count, 0);
53524 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
53525 spin_unlock_irqrestore(&port->lock, flags);
53526 tty_port_tty_set(port, NULL);
53527 @@ -1568,7 +1568,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
53528 goto end;
53529 }
53530
53531 - port->count++;
53532 + atomic_inc(&port->count);
53533 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
53534 retval = -ENXIO;
53535 goto err_dec_count;
53536 @@ -1600,7 +1600,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
53537 end:
53538 return retval;
53539 err_dec_count:
53540 - port->count--;
53541 + atomic_inc(&port->count);
53542 mutex_unlock(&port->mutex);
53543 goto end;
53544 }
53545 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
53546 index b799170..87dafd5 100644
53547 --- a/drivers/tty/synclink.c
53548 +++ b/drivers/tty/synclink.c
53549 @@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
53550
53551 if (debug_level >= DEBUG_LEVEL_INFO)
53552 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
53553 - __FILE__,__LINE__, info->device_name, info->port.count);
53554 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
53555
53556 if (tty_port_close_start(&info->port, tty, filp) == 0)
53557 goto cleanup;
53558 @@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
53559 cleanup:
53560 if (debug_level >= DEBUG_LEVEL_INFO)
53561 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
53562 - tty->driver->name, info->port.count);
53563 + tty->driver->name, atomic_read(&info->port.count));
53564
53565 } /* end of mgsl_close() */
53566
53567 @@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
53568
53569 mgsl_flush_buffer(tty);
53570 shutdown(info);
53571 -
53572 - info->port.count = 0;
53573 +
53574 + atomic_set(&info->port.count, 0);
53575 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53576 info->port.tty = NULL;
53577
53578 @@ -3296,10 +3296,10 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53579
53580 if (debug_level >= DEBUG_LEVEL_INFO)
53581 printk("%s(%d):block_til_ready before block on %s count=%d\n",
53582 - __FILE__,__LINE__, tty->driver->name, port->count );
53583 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53584
53585 spin_lock_irqsave(&info->irq_spinlock, flags);
53586 - port->count--;
53587 + atomic_dec(&port->count);
53588 spin_unlock_irqrestore(&info->irq_spinlock, flags);
53589 port->blocked_open++;
53590
53591 @@ -3327,7 +3327,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53592
53593 if (debug_level >= DEBUG_LEVEL_INFO)
53594 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
53595 - __FILE__,__LINE__, tty->driver->name, port->count );
53596 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53597
53598 tty_unlock(tty);
53599 schedule();
53600 @@ -3339,12 +3339,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53601
53602 /* FIXME: Racy on hangup during close wait */
53603 if (!tty_hung_up_p(filp))
53604 - port->count++;
53605 + atomic_inc(&port->count);
53606 port->blocked_open--;
53607
53608 if (debug_level >= DEBUG_LEVEL_INFO)
53609 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
53610 - __FILE__,__LINE__, tty->driver->name, port->count );
53611 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53612
53613 if (!retval)
53614 port->flags |= ASYNC_NORMAL_ACTIVE;
53615 @@ -3396,7 +3396,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
53616
53617 if (debug_level >= DEBUG_LEVEL_INFO)
53618 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
53619 - __FILE__,__LINE__,tty->driver->name, info->port.count);
53620 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
53621
53622 /* If port is closing, signal caller to try again */
53623 if (info->port.flags & ASYNC_CLOSING){
53624 @@ -3415,10 +3415,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
53625 spin_unlock_irqrestore(&info->netlock, flags);
53626 goto cleanup;
53627 }
53628 - info->port.count++;
53629 + atomic_inc(&info->port.count);
53630 spin_unlock_irqrestore(&info->netlock, flags);
53631
53632 - if (info->port.count == 1) {
53633 + if (atomic_read(&info->port.count) == 1) {
53634 /* 1st open on this device, init hardware */
53635 retval = startup(info);
53636 if (retval < 0)
53637 @@ -3442,8 +3442,8 @@ cleanup:
53638 if (retval) {
53639 if (tty->count == 1)
53640 info->port.tty = NULL; /* tty layer will release tty struct */
53641 - if(info->port.count)
53642 - info->port.count--;
53643 + if (atomic_read(&info->port.count))
53644 + atomic_dec(&info->port.count);
53645 }
53646
53647 return retval;
53648 @@ -7661,7 +7661,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
53649 unsigned short new_crctype;
53650
53651 /* return error if TTY interface open */
53652 - if (info->port.count)
53653 + if (atomic_read(&info->port.count))
53654 return -EBUSY;
53655
53656 switch (encoding)
53657 @@ -7756,7 +7756,7 @@ static int hdlcdev_open(struct net_device *dev)
53658
53659 /* arbitrate between network and tty opens */
53660 spin_lock_irqsave(&info->netlock, flags);
53661 - if (info->port.count != 0 || info->netcount != 0) {
53662 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
53663 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
53664 spin_unlock_irqrestore(&info->netlock, flags);
53665 return -EBUSY;
53666 @@ -7842,7 +7842,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
53667 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
53668
53669 /* return error if TTY interface open */
53670 - if (info->port.count)
53671 + if (atomic_read(&info->port.count))
53672 return -EBUSY;
53673
53674 if (cmd != SIOCWANDEV)
53675 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
53676 index 0e8c39b..e0cb171 100644
53677 --- a/drivers/tty/synclink_gt.c
53678 +++ b/drivers/tty/synclink_gt.c
53679 @@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
53680 tty->driver_data = info;
53681 info->port.tty = tty;
53682
53683 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
53684 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
53685
53686 /* If port is closing, signal caller to try again */
53687 if (info->port.flags & ASYNC_CLOSING){
53688 @@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
53689 mutex_unlock(&info->port.mutex);
53690 goto cleanup;
53691 }
53692 - info->port.count++;
53693 + atomic_inc(&info->port.count);
53694 spin_unlock_irqrestore(&info->netlock, flags);
53695
53696 - if (info->port.count == 1) {
53697 + if (atomic_read(&info->port.count) == 1) {
53698 /* 1st open on this device, init hardware */
53699 retval = startup(info);
53700 if (retval < 0) {
53701 @@ -715,8 +715,8 @@ cleanup:
53702 if (retval) {
53703 if (tty->count == 1)
53704 info->port.tty = NULL; /* tty layer will release tty struct */
53705 - if(info->port.count)
53706 - info->port.count--;
53707 + if(atomic_read(&info->port.count))
53708 + atomic_dec(&info->port.count);
53709 }
53710
53711 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
53712 @@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53713
53714 if (sanity_check(info, tty->name, "close"))
53715 return;
53716 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
53717 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
53718
53719 if (tty_port_close_start(&info->port, tty, filp) == 0)
53720 goto cleanup;
53721 @@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53722 tty_port_close_end(&info->port, tty);
53723 info->port.tty = NULL;
53724 cleanup:
53725 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
53726 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
53727 }
53728
53729 static void hangup(struct tty_struct *tty)
53730 @@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
53731 shutdown(info);
53732
53733 spin_lock_irqsave(&info->port.lock, flags);
53734 - info->port.count = 0;
53735 + atomic_set(&info->port.count, 0);
53736 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53737 info->port.tty = NULL;
53738 spin_unlock_irqrestore(&info->port.lock, flags);
53739 @@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
53740 unsigned short new_crctype;
53741
53742 /* return error if TTY interface open */
53743 - if (info->port.count)
53744 + if (atomic_read(&info->port.count))
53745 return -EBUSY;
53746
53747 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
53748 @@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
53749
53750 /* arbitrate between network and tty opens */
53751 spin_lock_irqsave(&info->netlock, flags);
53752 - if (info->port.count != 0 || info->netcount != 0) {
53753 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
53754 DBGINFO(("%s hdlc_open busy\n", dev->name));
53755 spin_unlock_irqrestore(&info->netlock, flags);
53756 return -EBUSY;
53757 @@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
53758 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
53759
53760 /* return error if TTY interface open */
53761 - if (info->port.count)
53762 + if (atomic_read(&info->port.count))
53763 return -EBUSY;
53764
53765 if (cmd != SIOCWANDEV)
53766 @@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
53767 if (port == NULL)
53768 continue;
53769 spin_lock(&port->lock);
53770 - if ((port->port.count || port->netcount) &&
53771 + if ((atomic_read(&port->port.count) || port->netcount) &&
53772 port->pending_bh && !port->bh_running &&
53773 !port->bh_requested) {
53774 DBGISR(("%s bh queued\n", port->device_name));
53775 @@ -3299,7 +3299,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53776 add_wait_queue(&port->open_wait, &wait);
53777
53778 spin_lock_irqsave(&info->lock, flags);
53779 - port->count--;
53780 + atomic_dec(&port->count);
53781 spin_unlock_irqrestore(&info->lock, flags);
53782 port->blocked_open++;
53783
53784 @@ -3335,7 +3335,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53785 remove_wait_queue(&port->open_wait, &wait);
53786
53787 if (!tty_hung_up_p(filp))
53788 - port->count++;
53789 + atomic_inc(&port->count);
53790 port->blocked_open--;
53791
53792 if (!retval)
53793 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
53794 index c3f9091..abe4601 100644
53795 --- a/drivers/tty/synclinkmp.c
53796 +++ b/drivers/tty/synclinkmp.c
53797 @@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
53798
53799 if (debug_level >= DEBUG_LEVEL_INFO)
53800 printk("%s(%d):%s open(), old ref count = %d\n",
53801 - __FILE__,__LINE__,tty->driver->name, info->port.count);
53802 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
53803
53804 /* If port is closing, signal caller to try again */
53805 if (info->port.flags & ASYNC_CLOSING){
53806 @@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
53807 spin_unlock_irqrestore(&info->netlock, flags);
53808 goto cleanup;
53809 }
53810 - info->port.count++;
53811 + atomic_inc(&info->port.count);
53812 spin_unlock_irqrestore(&info->netlock, flags);
53813
53814 - if (info->port.count == 1) {
53815 + if (atomic_read(&info->port.count) == 1) {
53816 /* 1st open on this device, init hardware */
53817 retval = startup(info);
53818 if (retval < 0)
53819 @@ -796,8 +796,8 @@ cleanup:
53820 if (retval) {
53821 if (tty->count == 1)
53822 info->port.tty = NULL; /* tty layer will release tty struct */
53823 - if(info->port.count)
53824 - info->port.count--;
53825 + if(atomic_read(&info->port.count))
53826 + atomic_dec(&info->port.count);
53827 }
53828
53829 return retval;
53830 @@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53831
53832 if (debug_level >= DEBUG_LEVEL_INFO)
53833 printk("%s(%d):%s close() entry, count=%d\n",
53834 - __FILE__,__LINE__, info->device_name, info->port.count);
53835 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
53836
53837 if (tty_port_close_start(&info->port, tty, filp) == 0)
53838 goto cleanup;
53839 @@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53840 cleanup:
53841 if (debug_level >= DEBUG_LEVEL_INFO)
53842 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
53843 - tty->driver->name, info->port.count);
53844 + tty->driver->name, atomic_read(&info->port.count));
53845 }
53846
53847 /* Called by tty_hangup() when a hangup is signaled.
53848 @@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
53849 shutdown(info);
53850
53851 spin_lock_irqsave(&info->port.lock, flags);
53852 - info->port.count = 0;
53853 + atomic_set(&info->port.count, 0);
53854 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53855 info->port.tty = NULL;
53856 spin_unlock_irqrestore(&info->port.lock, flags);
53857 @@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
53858 unsigned short new_crctype;
53859
53860 /* return error if TTY interface open */
53861 - if (info->port.count)
53862 + if (atomic_read(&info->port.count))
53863 return -EBUSY;
53864
53865 switch (encoding)
53866 @@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
53867
53868 /* arbitrate between network and tty opens */
53869 spin_lock_irqsave(&info->netlock, flags);
53870 - if (info->port.count != 0 || info->netcount != 0) {
53871 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
53872 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
53873 spin_unlock_irqrestore(&info->netlock, flags);
53874 return -EBUSY;
53875 @@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
53876 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
53877
53878 /* return error if TTY interface open */
53879 - if (info->port.count)
53880 + if (atomic_read(&info->port.count))
53881 return -EBUSY;
53882
53883 if (cmd != SIOCWANDEV)
53884 @@ -2621,7 +2621,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
53885 * do not request bottom half processing if the
53886 * device is not open in a normal mode.
53887 */
53888 - if ( port && (port->port.count || port->netcount) &&
53889 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
53890 port->pending_bh && !port->bh_running &&
53891 !port->bh_requested ) {
53892 if ( debug_level >= DEBUG_LEVEL_ISR )
53893 @@ -3318,10 +3318,10 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53894
53895 if (debug_level >= DEBUG_LEVEL_INFO)
53896 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
53897 - __FILE__,__LINE__, tty->driver->name, port->count );
53898 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53899
53900 spin_lock_irqsave(&info->lock, flags);
53901 - port->count--;
53902 + atomic_dec(&port->count);
53903 spin_unlock_irqrestore(&info->lock, flags);
53904 port->blocked_open++;
53905
53906 @@ -3349,7 +3349,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53907
53908 if (debug_level >= DEBUG_LEVEL_INFO)
53909 printk("%s(%d):%s block_til_ready() count=%d\n",
53910 - __FILE__,__LINE__, tty->driver->name, port->count );
53911 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53912
53913 tty_unlock(tty);
53914 schedule();
53915 @@ -3359,12 +3359,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53916 set_current_state(TASK_RUNNING);
53917 remove_wait_queue(&port->open_wait, &wait);
53918 if (!tty_hung_up_p(filp))
53919 - port->count++;
53920 + atomic_inc(&port->count);
53921 port->blocked_open--;
53922
53923 if (debug_level >= DEBUG_LEVEL_INFO)
53924 printk("%s(%d):%s block_til_ready() after, count=%d\n",
53925 - __FILE__,__LINE__, tty->driver->name, port->count );
53926 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53927
53928 if (!retval)
53929 port->flags |= ASYNC_NORMAL_ACTIVE;
53930 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
53931 index 42bad18..447d7a2 100644
53932 --- a/drivers/tty/sysrq.c
53933 +++ b/drivers/tty/sysrq.c
53934 @@ -1084,7 +1084,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
53935 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
53936 size_t count, loff_t *ppos)
53937 {
53938 - if (count) {
53939 + if (count && capable(CAP_SYS_ADMIN)) {
53940 char c;
53941
53942 if (get_user(c, buf))
53943 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
53944 index 848c17a..e930437 100644
53945 --- a/drivers/tty/tty_io.c
53946 +++ b/drivers/tty/tty_io.c
53947 @@ -3469,7 +3469,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
53948
53949 void tty_default_fops(struct file_operations *fops)
53950 {
53951 - *fops = tty_fops;
53952 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
53953 }
53954
53955 /*
53956 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
53957 index 2d822aa..a566234 100644
53958 --- a/drivers/tty/tty_ldisc.c
53959 +++ b/drivers/tty/tty_ldisc.c
53960 @@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
53961 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
53962 tty_ldiscs[disc] = new_ldisc;
53963 new_ldisc->num = disc;
53964 - new_ldisc->refcount = 0;
53965 + atomic_set(&new_ldisc->refcount, 0);
53966 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
53967
53968 return ret;
53969 @@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
53970 return -EINVAL;
53971
53972 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
53973 - if (tty_ldiscs[disc]->refcount)
53974 + if (atomic_read(&tty_ldiscs[disc]->refcount))
53975 ret = -EBUSY;
53976 else
53977 tty_ldiscs[disc] = NULL;
53978 @@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
53979 if (ldops) {
53980 ret = ERR_PTR(-EAGAIN);
53981 if (try_module_get(ldops->owner)) {
53982 - ldops->refcount++;
53983 + atomic_inc(&ldops->refcount);
53984 ret = ldops;
53985 }
53986 }
53987 @@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
53988 unsigned long flags;
53989
53990 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
53991 - ldops->refcount--;
53992 + atomic_dec(&ldops->refcount);
53993 module_put(ldops->owner);
53994 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
53995 }
53996 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
53997 index 1b93357..ea9f82c 100644
53998 --- a/drivers/tty/tty_port.c
53999 +++ b/drivers/tty/tty_port.c
54000 @@ -237,7 +237,7 @@ void tty_port_hangup(struct tty_port *port)
54001 unsigned long flags;
54002
54003 spin_lock_irqsave(&port->lock, flags);
54004 - port->count = 0;
54005 + atomic_set(&port->count, 0);
54006 port->flags &= ~ASYNC_NORMAL_ACTIVE;
54007 tty = port->tty;
54008 if (tty)
54009 @@ -399,7 +399,7 @@ int tty_port_block_til_ready(struct tty_port *port,
54010
54011 /* The port lock protects the port counts */
54012 spin_lock_irqsave(&port->lock, flags);
54013 - port->count--;
54014 + atomic_dec(&port->count);
54015 port->blocked_open++;
54016 spin_unlock_irqrestore(&port->lock, flags);
54017
54018 @@ -441,7 +441,7 @@ int tty_port_block_til_ready(struct tty_port *port,
54019 we must not mess that up further */
54020 spin_lock_irqsave(&port->lock, flags);
54021 if (!tty_hung_up_p(filp))
54022 - port->count++;
54023 + atomic_inc(&port->count);
54024 port->blocked_open--;
54025 if (retval == 0)
54026 port->flags |= ASYNC_NORMAL_ACTIVE;
54027 @@ -479,19 +479,19 @@ int tty_port_close_start(struct tty_port *port,
54028 return 0;
54029 }
54030
54031 - if (tty->count == 1 && port->count != 1) {
54032 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
54033 printk(KERN_WARNING
54034 "tty_port_close_start: tty->count = 1 port count = %d.\n",
54035 - port->count);
54036 - port->count = 1;
54037 + atomic_read(&port->count));
54038 + atomic_set(&port->count, 1);
54039 }
54040 - if (--port->count < 0) {
54041 + if (atomic_dec_return(&port->count) < 0) {
54042 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
54043 - port->count);
54044 - port->count = 0;
54045 + atomic_read(&port->count));
54046 + atomic_set(&port->count, 0);
54047 }
54048
54049 - if (port->count) {
54050 + if (atomic_read(&port->count)) {
54051 spin_unlock_irqrestore(&port->lock, flags);
54052 return 0;
54053 }
54054 @@ -592,7 +592,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
54055 struct file *filp)
54056 {
54057 spin_lock_irq(&port->lock);
54058 - ++port->count;
54059 + atomic_inc(&port->count);
54060 spin_unlock_irq(&port->lock);
54061 tty_port_tty_set(port, tty);
54062
54063 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
54064 index d0e3a44..5f8b754 100644
54065 --- a/drivers/tty/vt/keyboard.c
54066 +++ b/drivers/tty/vt/keyboard.c
54067 @@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
54068 kbd->kbdmode == VC_OFF) &&
54069 value != KVAL(K_SAK))
54070 return; /* SAK is allowed even in raw mode */
54071 +
54072 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54073 + {
54074 + void *func = fn_handler[value];
54075 + if (func == fn_show_state || func == fn_show_ptregs ||
54076 + func == fn_show_mem)
54077 + return;
54078 + }
54079 +#endif
54080 +
54081 fn_handler[value](vc);
54082 }
54083
54084 @@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
54085 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
54086 return -EFAULT;
54087
54088 - if (!capable(CAP_SYS_TTY_CONFIG))
54089 - perm = 0;
54090 -
54091 switch (cmd) {
54092 case KDGKBENT:
54093 /* Ensure another thread doesn't free it under us */
54094 @@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
54095 spin_unlock_irqrestore(&kbd_event_lock, flags);
54096 return put_user(val, &user_kbe->kb_value);
54097 case KDSKBENT:
54098 + if (!capable(CAP_SYS_TTY_CONFIG))
54099 + perm = 0;
54100 +
54101 if (!perm)
54102 return -EPERM;
54103 if (!i && v == K_NOSUCHMAP) {
54104 @@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
54105 int i, j, k;
54106 int ret;
54107
54108 - if (!capable(CAP_SYS_TTY_CONFIG))
54109 - perm = 0;
54110 -
54111 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
54112 if (!kbs) {
54113 ret = -ENOMEM;
54114 @@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
54115 kfree(kbs);
54116 return ((p && *p) ? -EOVERFLOW : 0);
54117 case KDSKBSENT:
54118 + if (!capable(CAP_SYS_TTY_CONFIG))
54119 + perm = 0;
54120 +
54121 if (!perm) {
54122 ret = -EPERM;
54123 goto reterr;
54124 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
54125 index a673e5b..36e5d32 100644
54126 --- a/drivers/uio/uio.c
54127 +++ b/drivers/uio/uio.c
54128 @@ -25,6 +25,7 @@
54129 #include <linux/kobject.h>
54130 #include <linux/cdev.h>
54131 #include <linux/uio_driver.h>
54132 +#include <asm/local.h>
54133
54134 #define UIO_MAX_DEVICES (1U << MINORBITS)
54135
54136 @@ -32,7 +33,7 @@ struct uio_device {
54137 struct module *owner;
54138 struct device *dev;
54139 int minor;
54140 - atomic_t event;
54141 + atomic_unchecked_t event;
54142 struct fasync_struct *async_queue;
54143 wait_queue_head_t wait;
54144 struct uio_info *info;
54145 @@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
54146 struct device_attribute *attr, char *buf)
54147 {
54148 struct uio_device *idev = dev_get_drvdata(dev);
54149 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
54150 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
54151 }
54152 static DEVICE_ATTR_RO(event);
54153
54154 @@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
54155 {
54156 struct uio_device *idev = info->uio_dev;
54157
54158 - atomic_inc(&idev->event);
54159 + atomic_inc_unchecked(&idev->event);
54160 wake_up_interruptible(&idev->wait);
54161 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
54162 }
54163 @@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
54164 }
54165
54166 listener->dev = idev;
54167 - listener->event_count = atomic_read(&idev->event);
54168 + listener->event_count = atomic_read_unchecked(&idev->event);
54169 filep->private_data = listener;
54170
54171 if (idev->info->open) {
54172 @@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
54173 return -EIO;
54174
54175 poll_wait(filep, &idev->wait, wait);
54176 - if (listener->event_count != atomic_read(&idev->event))
54177 + if (listener->event_count != atomic_read_unchecked(&idev->event))
54178 return POLLIN | POLLRDNORM;
54179 return 0;
54180 }
54181 @@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
54182 do {
54183 set_current_state(TASK_INTERRUPTIBLE);
54184
54185 - event_count = atomic_read(&idev->event);
54186 + event_count = atomic_read_unchecked(&idev->event);
54187 if (event_count != listener->event_count) {
54188 if (copy_to_user(buf, &event_count, count))
54189 retval = -EFAULT;
54190 @@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
54191 static int uio_find_mem_index(struct vm_area_struct *vma)
54192 {
54193 struct uio_device *idev = vma->vm_private_data;
54194 + unsigned long size;
54195
54196 if (vma->vm_pgoff < MAX_UIO_MAPS) {
54197 - if (idev->info->mem[vma->vm_pgoff].size == 0)
54198 + size = idev->info->mem[vma->vm_pgoff].size;
54199 + if (size == 0)
54200 + return -1;
54201 + if (vma->vm_end - vma->vm_start > size)
54202 return -1;
54203 return (int)vma->vm_pgoff;
54204 }
54205 @@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
54206 idev->owner = owner;
54207 idev->info = info;
54208 init_waitqueue_head(&idev->wait);
54209 - atomic_set(&idev->event, 0);
54210 + atomic_set_unchecked(&idev->event, 0);
54211
54212 ret = uio_get_minor(idev);
54213 if (ret)
54214 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
54215 index 813d4d3..a71934f 100644
54216 --- a/drivers/usb/atm/cxacru.c
54217 +++ b/drivers/usb/atm/cxacru.c
54218 @@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
54219 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
54220 if (ret < 2)
54221 return -EINVAL;
54222 - if (index < 0 || index > 0x7f)
54223 + if (index > 0x7f)
54224 return -EINVAL;
54225 pos += tmp;
54226
54227 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
54228 index dada014..1d0d517 100644
54229 --- a/drivers/usb/atm/usbatm.c
54230 +++ b/drivers/usb/atm/usbatm.c
54231 @@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54232 if (printk_ratelimit())
54233 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
54234 __func__, vpi, vci);
54235 - atomic_inc(&vcc->stats->rx_err);
54236 + atomic_inc_unchecked(&vcc->stats->rx_err);
54237 return;
54238 }
54239
54240 @@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54241 if (length > ATM_MAX_AAL5_PDU) {
54242 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
54243 __func__, length, vcc);
54244 - atomic_inc(&vcc->stats->rx_err);
54245 + atomic_inc_unchecked(&vcc->stats->rx_err);
54246 goto out;
54247 }
54248
54249 @@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54250 if (sarb->len < pdu_length) {
54251 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
54252 __func__, pdu_length, sarb->len, vcc);
54253 - atomic_inc(&vcc->stats->rx_err);
54254 + atomic_inc_unchecked(&vcc->stats->rx_err);
54255 goto out;
54256 }
54257
54258 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
54259 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
54260 __func__, vcc);
54261 - atomic_inc(&vcc->stats->rx_err);
54262 + atomic_inc_unchecked(&vcc->stats->rx_err);
54263 goto out;
54264 }
54265
54266 @@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54267 if (printk_ratelimit())
54268 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
54269 __func__, length);
54270 - atomic_inc(&vcc->stats->rx_drop);
54271 + atomic_inc_unchecked(&vcc->stats->rx_drop);
54272 goto out;
54273 }
54274
54275 @@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54276
54277 vcc->push(vcc, skb);
54278
54279 - atomic_inc(&vcc->stats->rx);
54280 + atomic_inc_unchecked(&vcc->stats->rx);
54281 out:
54282 skb_trim(sarb, 0);
54283 }
54284 @@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
54285 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
54286
54287 usbatm_pop(vcc, skb);
54288 - atomic_inc(&vcc->stats->tx);
54289 + atomic_inc_unchecked(&vcc->stats->tx);
54290
54291 skb = skb_dequeue(&instance->sndqueue);
54292 }
54293 @@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
54294 if (!left--)
54295 return sprintf(page,
54296 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
54297 - atomic_read(&atm_dev->stats.aal5.tx),
54298 - atomic_read(&atm_dev->stats.aal5.tx_err),
54299 - atomic_read(&atm_dev->stats.aal5.rx),
54300 - atomic_read(&atm_dev->stats.aal5.rx_err),
54301 - atomic_read(&atm_dev->stats.aal5.rx_drop));
54302 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
54303 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
54304 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
54305 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
54306 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
54307
54308 if (!left--) {
54309 if (instance->disconnected)
54310 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
54311 index 2a3bbdf..91d72cf 100644
54312 --- a/drivers/usb/core/devices.c
54313 +++ b/drivers/usb/core/devices.c
54314 @@ -126,7 +126,7 @@ static const char format_endpt[] =
54315 * time it gets called.
54316 */
54317 static struct device_connect_event {
54318 - atomic_t count;
54319 + atomic_unchecked_t count;
54320 wait_queue_head_t wait;
54321 } device_event = {
54322 .count = ATOMIC_INIT(1),
54323 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
54324
54325 void usbfs_conn_disc_event(void)
54326 {
54327 - atomic_add(2, &device_event.count);
54328 + atomic_add_unchecked(2, &device_event.count);
54329 wake_up(&device_event.wait);
54330 }
54331
54332 @@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
54333
54334 poll_wait(file, &device_event.wait, wait);
54335
54336 - event_count = atomic_read(&device_event.count);
54337 + event_count = atomic_read_unchecked(&device_event.count);
54338 if (file->f_version != event_count) {
54339 file->f_version = event_count;
54340 return POLLIN | POLLRDNORM;
54341 diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
54342 index 0b59731..46ee7d1 100644
54343 --- a/drivers/usb/core/devio.c
54344 +++ b/drivers/usb/core/devio.c
54345 @@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
54346 struct usb_dev_state *ps = file->private_data;
54347 struct usb_device *dev = ps->dev;
54348 ssize_t ret = 0;
54349 - unsigned len;
54350 + size_t len;
54351 loff_t pos;
54352 int i;
54353
54354 @@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
54355 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
54356 struct usb_config_descriptor *config =
54357 (struct usb_config_descriptor *)dev->rawdescriptors[i];
54358 - unsigned int length = le16_to_cpu(config->wTotalLength);
54359 + size_t length = le16_to_cpu(config->wTotalLength);
54360
54361 if (*ppos < pos + length) {
54362
54363 /* The descriptor may claim to be longer than it
54364 * really is. Here is the actual allocated length. */
54365 - unsigned alloclen =
54366 + size_t alloclen =
54367 le16_to_cpu(dev->config[i].desc.wTotalLength);
54368
54369 - len = length - (*ppos - pos);
54370 + len = length + pos - *ppos;
54371 if (len > nbytes)
54372 len = nbytes;
54373
54374 /* Simply don't write (skip over) unallocated parts */
54375 if (alloclen > (*ppos - pos)) {
54376 - alloclen -= (*ppos - pos);
54377 + alloclen = alloclen + pos - *ppos;
54378 if (copy_to_user(buf,
54379 dev->rawdescriptors[i] + (*ppos - pos),
54380 min(len, alloclen))) {
54381 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
54382 index 258e6fe..9ea48d7 100644
54383 --- a/drivers/usb/core/hcd.c
54384 +++ b/drivers/usb/core/hcd.c
54385 @@ -1550,7 +1550,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
54386 */
54387 usb_get_urb(urb);
54388 atomic_inc(&urb->use_count);
54389 - atomic_inc(&urb->dev->urbnum);
54390 + atomic_inc_unchecked(&urb->dev->urbnum);
54391 usbmon_urb_submit(&hcd->self, urb);
54392
54393 /* NOTE requirements on root-hub callers (usbfs and the hub
54394 @@ -1577,7 +1577,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
54395 urb->hcpriv = NULL;
54396 INIT_LIST_HEAD(&urb->urb_list);
54397 atomic_dec(&urb->use_count);
54398 - atomic_dec(&urb->dev->urbnum);
54399 + atomic_dec_unchecked(&urb->dev->urbnum);
54400 if (atomic_read(&urb->reject))
54401 wake_up(&usb_kill_urb_queue);
54402 usb_put_urb(urb);
54403 diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
54404 index 674c262..71fdd90 100644
54405 --- a/drivers/usb/core/hub.c
54406 +++ b/drivers/usb/core/hub.c
54407 @@ -27,6 +27,7 @@
54408 #include <linux/freezer.h>
54409 #include <linux/random.h>
54410 #include <linux/pm_qos.h>
54411 +#include <linux/grsecurity.h>
54412
54413 #include <asm/uaccess.h>
54414 #include <asm/byteorder.h>
54415 @@ -4665,6 +4666,10 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus,
54416 goto done;
54417 return;
54418 }
54419 +
54420 + if (gr_handle_new_usb())
54421 + goto done;
54422 +
54423 if (hub_is_superspeed(hub->hdev))
54424 unit_load = 150;
54425 else
54426 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
54427 index 0c8a7fc..c45b40a 100644
54428 --- a/drivers/usb/core/message.c
54429 +++ b/drivers/usb/core/message.c
54430 @@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
54431 * Return: If successful, the number of bytes transferred. Otherwise, a negative
54432 * error number.
54433 */
54434 -int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
54435 +int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
54436 __u8 requesttype, __u16 value, __u16 index, void *data,
54437 __u16 size, int timeout)
54438 {
54439 @@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
54440 * If successful, 0. Otherwise a negative error number. The number of actual
54441 * bytes transferred will be stored in the @actual_length parameter.
54442 */
54443 -int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
54444 +int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
54445 void *data, int len, int *actual_length, int timeout)
54446 {
54447 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
54448 @@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
54449 * bytes transferred will be stored in the @actual_length parameter.
54450 *
54451 */
54452 -int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
54453 +int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
54454 void *data, int len, int *actual_length, int timeout)
54455 {
54456 struct urb *urb;
54457 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
54458 index 1236c60..d47a51c 100644
54459 --- a/drivers/usb/core/sysfs.c
54460 +++ b/drivers/usb/core/sysfs.c
54461 @@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
54462 struct usb_device *udev;
54463
54464 udev = to_usb_device(dev);
54465 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
54466 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
54467 }
54468 static DEVICE_ATTR_RO(urbnum);
54469
54470 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
54471 index 2dd2362..1135437 100644
54472 --- a/drivers/usb/core/usb.c
54473 +++ b/drivers/usb/core/usb.c
54474 @@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
54475 set_dev_node(&dev->dev, dev_to_node(bus->controller));
54476 dev->state = USB_STATE_ATTACHED;
54477 dev->lpm_disable_count = 1;
54478 - atomic_set(&dev->urbnum, 0);
54479 + atomic_set_unchecked(&dev->urbnum, 0);
54480
54481 INIT_LIST_HEAD(&dev->ep0.urb_list);
54482 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
54483 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
54484 index 8cfc319..4868255 100644
54485 --- a/drivers/usb/early/ehci-dbgp.c
54486 +++ b/drivers/usb/early/ehci-dbgp.c
54487 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
54488
54489 #ifdef CONFIG_KGDB
54490 static struct kgdb_io kgdbdbgp_io_ops;
54491 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
54492 +static struct kgdb_io kgdbdbgp_io_ops_console;
54493 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
54494 #else
54495 #define dbgp_kgdb_mode (0)
54496 #endif
54497 @@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
54498 .write_char = kgdbdbgp_write_char,
54499 };
54500
54501 +static struct kgdb_io kgdbdbgp_io_ops_console = {
54502 + .name = "kgdbdbgp",
54503 + .read_char = kgdbdbgp_read_char,
54504 + .write_char = kgdbdbgp_write_char,
54505 + .is_console = 1
54506 +};
54507 +
54508 static int kgdbdbgp_wait_time;
54509
54510 static int __init kgdbdbgp_parse_config(char *str)
54511 @@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
54512 ptr++;
54513 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
54514 }
54515 - kgdb_register_io_module(&kgdbdbgp_io_ops);
54516 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
54517 + if (early_dbgp_console.index != -1)
54518 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
54519 + else
54520 + kgdb_register_io_module(&kgdbdbgp_io_ops);
54521
54522 return 0;
54523 }
54524 diff --git a/drivers/usb/gadget/function/f_uac1.c b/drivers/usb/gadget/function/f_uac1.c
54525 index 2b4c82d..06a8ee6 100644
54526 --- a/drivers/usb/gadget/function/f_uac1.c
54527 +++ b/drivers/usb/gadget/function/f_uac1.c
54528 @@ -13,6 +13,7 @@
54529 #include <linux/kernel.h>
54530 #include <linux/device.h>
54531 #include <linux/atomic.h>
54532 +#include <linux/module.h>
54533
54534 #include "u_uac1.h"
54535
54536 diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
54537 index ad0aca8..8ff84865 100644
54538 --- a/drivers/usb/gadget/function/u_serial.c
54539 +++ b/drivers/usb/gadget/function/u_serial.c
54540 @@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
54541 spin_lock_irq(&port->port_lock);
54542
54543 /* already open? Great. */
54544 - if (port->port.count) {
54545 + if (atomic_read(&port->port.count)) {
54546 status = 0;
54547 - port->port.count++;
54548 + atomic_inc(&port->port.count);
54549
54550 /* currently opening/closing? wait ... */
54551 } else if (port->openclose) {
54552 @@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
54553 tty->driver_data = port;
54554 port->port.tty = tty;
54555
54556 - port->port.count = 1;
54557 + atomic_set(&port->port.count, 1);
54558 port->openclose = false;
54559
54560 /* if connected, start the I/O stream */
54561 @@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
54562
54563 spin_lock_irq(&port->port_lock);
54564
54565 - if (port->port.count != 1) {
54566 - if (port->port.count == 0)
54567 + if (atomic_read(&port->port.count) != 1) {
54568 + if (atomic_read(&port->port.count) == 0)
54569 WARN_ON(1);
54570 else
54571 - --port->port.count;
54572 + atomic_dec(&port->port.count);
54573 goto exit;
54574 }
54575
54576 @@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
54577 * and sleep if necessary
54578 */
54579 port->openclose = true;
54580 - port->port.count = 0;
54581 + atomic_set(&port->port.count, 0);
54582
54583 gser = port->port_usb;
54584 if (gser && gser->disconnect)
54585 @@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
54586 int cond;
54587
54588 spin_lock_irq(&port->port_lock);
54589 - cond = (port->port.count == 0) && !port->openclose;
54590 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
54591 spin_unlock_irq(&port->port_lock);
54592 return cond;
54593 }
54594 @@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
54595 /* if it's already open, start I/O ... and notify the serial
54596 * protocol about open/close status (connect/disconnect).
54597 */
54598 - if (port->port.count) {
54599 + if (atomic_read(&port->port.count)) {
54600 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
54601 gs_start_io(port);
54602 if (gser->connect)
54603 @@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
54604
54605 port->port_usb = NULL;
54606 gser->ioport = NULL;
54607 - if (port->port.count > 0 || port->openclose) {
54608 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
54609 wake_up_interruptible(&port->drain_wait);
54610 if (port->port.tty)
54611 tty_hangup(port->port.tty);
54612 @@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
54613
54614 /* finally, free any unused/unusable I/O buffers */
54615 spin_lock_irqsave(&port->port_lock, flags);
54616 - if (port->port.count == 0 && !port->openclose)
54617 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
54618 gs_buf_free(&port->port_write_buf);
54619 gs_free_requests(gser->out, &port->read_pool, NULL);
54620 gs_free_requests(gser->out, &port->read_queue, NULL);
54621 diff --git a/drivers/usb/gadget/function/u_uac1.c b/drivers/usb/gadget/function/u_uac1.c
54622 index 7a55fea..cc0ed4f 100644
54623 --- a/drivers/usb/gadget/function/u_uac1.c
54624 +++ b/drivers/usb/gadget/function/u_uac1.c
54625 @@ -16,6 +16,7 @@
54626 #include <linux/ctype.h>
54627 #include <linux/random.h>
54628 #include <linux/syscalls.h>
54629 +#include <linux/module.h>
54630
54631 #include "u_uac1.h"
54632
54633 diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
54634 index 6130b75..3b60008 100644
54635 --- a/drivers/usb/host/ehci-hub.c
54636 +++ b/drivers/usb/host/ehci-hub.c
54637 @@ -771,7 +771,7 @@ static struct urb *request_single_step_set_feature_urb(
54638 urb->transfer_flags = URB_DIR_IN;
54639 usb_get_urb(urb);
54640 atomic_inc(&urb->use_count);
54641 - atomic_inc(&urb->dev->urbnum);
54642 + atomic_inc_unchecked(&urb->dev->urbnum);
54643 urb->setup_dma = dma_map_single(
54644 hcd->self.controller,
54645 urb->setup_packet,
54646 @@ -838,7 +838,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
54647 urb->status = -EINPROGRESS;
54648 usb_get_urb(urb);
54649 atomic_inc(&urb->use_count);
54650 - atomic_inc(&urb->dev->urbnum);
54651 + atomic_inc_unchecked(&urb->dev->urbnum);
54652 retval = submit_single_step_set_feature(hcd, urb, 0);
54653 if (!retval && !wait_for_completion_timeout(&done,
54654 msecs_to_jiffies(2000))) {
54655 diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c
54656 index d0d8fad..668ef7b 100644
54657 --- a/drivers/usb/host/hwa-hc.c
54658 +++ b/drivers/usb/host/hwa-hc.c
54659 @@ -337,7 +337,10 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
54660 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
54661 struct wahc *wa = &hwahc->wa;
54662 struct device *dev = &wa->usb_iface->dev;
54663 - u8 mas_le[UWB_NUM_MAS/8];
54664 + u8 *mas_le = kmalloc(UWB_NUM_MAS/8, GFP_KERNEL);
54665 +
54666 + if (mas_le == NULL)
54667 + return -ENOMEM;
54668
54669 /* Set the stream index */
54670 result = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
54671 @@ -356,10 +359,12 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
54672 WUSB_REQ_SET_WUSB_MAS,
54673 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
54674 0, wa->usb_iface->cur_altsetting->desc.bInterfaceNumber,
54675 - mas_le, 32, USB_CTRL_SET_TIMEOUT);
54676 + mas_le, UWB_NUM_MAS/8, USB_CTRL_SET_TIMEOUT);
54677 if (result < 0)
54678 dev_err(dev, "Cannot set WUSB MAS allocation: %d\n", result);
54679 out:
54680 + kfree(mas_le);
54681 +
54682 return result;
54683 }
54684
54685 diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
54686 index b3d245e..99549ed 100644
54687 --- a/drivers/usb/misc/appledisplay.c
54688 +++ b/drivers/usb/misc/appledisplay.c
54689 @@ -84,7 +84,7 @@ struct appledisplay {
54690 struct mutex sysfslock; /* concurrent read and write */
54691 };
54692
54693 -static atomic_t count_displays = ATOMIC_INIT(0);
54694 +static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
54695 static struct workqueue_struct *wq;
54696
54697 static void appledisplay_complete(struct urb *urb)
54698 @@ -288,7 +288,7 @@ static int appledisplay_probe(struct usb_interface *iface,
54699
54700 /* Register backlight device */
54701 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
54702 - atomic_inc_return(&count_displays) - 1);
54703 + atomic_inc_return_unchecked(&count_displays) - 1);
54704 memset(&props, 0, sizeof(struct backlight_properties));
54705 props.type = BACKLIGHT_RAW;
54706 props.max_brightness = 0xff;
54707 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
54708 index 8d7fc48..01c4986 100644
54709 --- a/drivers/usb/serial/console.c
54710 +++ b/drivers/usb/serial/console.c
54711 @@ -123,7 +123,7 @@ static int usb_console_setup(struct console *co, char *options)
54712
54713 info->port = port;
54714
54715 - ++port->port.count;
54716 + atomic_inc(&port->port.count);
54717 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
54718 if (serial->type->set_termios) {
54719 /*
54720 @@ -167,7 +167,7 @@ static int usb_console_setup(struct console *co, char *options)
54721 }
54722 /* Now that any required fake tty operations are completed restore
54723 * the tty port count */
54724 - --port->port.count;
54725 + atomic_dec(&port->port.count);
54726 /* The console is special in terms of closing the device so
54727 * indicate this port is now acting as a system console. */
54728 port->port.console = 1;
54729 @@ -180,7 +180,7 @@ static int usb_console_setup(struct console *co, char *options)
54730 free_tty:
54731 kfree(tty);
54732 reset_open_count:
54733 - port->port.count = 0;
54734 + atomic_set(&port->port.count, 0);
54735 usb_autopm_put_interface(serial->interface);
54736 error_get_interface:
54737 usb_serial_put(serial);
54738 @@ -191,7 +191,7 @@ static int usb_console_setup(struct console *co, char *options)
54739 static void usb_console_write(struct console *co,
54740 const char *buf, unsigned count)
54741 {
54742 - static struct usbcons_info *info = &usbcons_info;
54743 + struct usbcons_info *info = &usbcons_info;
54744 struct usb_serial_port *port = info->port;
54745 struct usb_serial *serial;
54746 int retval = -ENODEV;
54747 diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
54748 index 307e339..6aa97cb 100644
54749 --- a/drivers/usb/storage/usb.h
54750 +++ b/drivers/usb/storage/usb.h
54751 @@ -63,7 +63,7 @@ struct us_unusual_dev {
54752 __u8 useProtocol;
54753 __u8 useTransport;
54754 int (*initFunction)(struct us_data *);
54755 -};
54756 +} __do_const;
54757
54758
54759 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
54760 diff --git a/drivers/usb/usbip/vhci.h b/drivers/usb/usbip/vhci.h
54761 index a863a98..d272795 100644
54762 --- a/drivers/usb/usbip/vhci.h
54763 +++ b/drivers/usb/usbip/vhci.h
54764 @@ -83,7 +83,7 @@ struct vhci_hcd {
54765 unsigned resuming:1;
54766 unsigned long re_timeout;
54767
54768 - atomic_t seqnum;
54769 + atomic_unchecked_t seqnum;
54770
54771 /*
54772 * NOTE:
54773 diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
54774 index c02374b..32d47a9 100644
54775 --- a/drivers/usb/usbip/vhci_hcd.c
54776 +++ b/drivers/usb/usbip/vhci_hcd.c
54777 @@ -439,7 +439,7 @@ static void vhci_tx_urb(struct urb *urb)
54778
54779 spin_lock(&vdev->priv_lock);
54780
54781 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
54782 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
54783 if (priv->seqnum == 0xffff)
54784 dev_info(&urb->dev->dev, "seqnum max\n");
54785
54786 @@ -686,7 +686,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
54787 return -ENOMEM;
54788 }
54789
54790 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
54791 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
54792 if (unlink->seqnum == 0xffff)
54793 pr_info("seqnum max\n");
54794
54795 @@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
54796 vdev->rhport = rhport;
54797 }
54798
54799 - atomic_set(&vhci->seqnum, 0);
54800 + atomic_set_unchecked(&vhci->seqnum, 0);
54801 spin_lock_init(&vhci->lock);
54802
54803 hcd->power_budget = 0; /* no limit */
54804 diff --git a/drivers/usb/usbip/vhci_rx.c b/drivers/usb/usbip/vhci_rx.c
54805 index 00e4a54..d676f85 100644
54806 --- a/drivers/usb/usbip/vhci_rx.c
54807 +++ b/drivers/usb/usbip/vhci_rx.c
54808 @@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
54809 if (!urb) {
54810 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
54811 pr_info("max seqnum %d\n",
54812 - atomic_read(&the_controller->seqnum));
54813 + atomic_read_unchecked(&the_controller->seqnum));
54814 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
54815 return;
54816 }
54817 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
54818 index f2a8d29..7bc3fe7 100644
54819 --- a/drivers/usb/wusbcore/wa-hc.h
54820 +++ b/drivers/usb/wusbcore/wa-hc.h
54821 @@ -240,7 +240,7 @@ struct wahc {
54822 spinlock_t xfer_list_lock;
54823 struct work_struct xfer_enqueue_work;
54824 struct work_struct xfer_error_work;
54825 - atomic_t xfer_id_count;
54826 + atomic_unchecked_t xfer_id_count;
54827
54828 kernel_ulong_t quirks;
54829 };
54830 @@ -305,7 +305,7 @@ static inline void wa_init(struct wahc *wa)
54831 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
54832 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
54833 wa->dto_in_use = 0;
54834 - atomic_set(&wa->xfer_id_count, 1);
54835 + atomic_set_unchecked(&wa->xfer_id_count, 1);
54836 /* init the buf in URBs */
54837 for (index = 0; index < WA_MAX_BUF_IN_URBS; ++index)
54838 usb_init_urb(&(wa->buf_in_urbs[index]));
54839 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
54840 index e279015..c2d0dae 100644
54841 --- a/drivers/usb/wusbcore/wa-xfer.c
54842 +++ b/drivers/usb/wusbcore/wa-xfer.c
54843 @@ -314,7 +314,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
54844 */
54845 static void wa_xfer_id_init(struct wa_xfer *xfer)
54846 {
54847 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
54848 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
54849 }
54850
54851 /* Return the xfer's ID. */
54852 diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
54853 index f018d8d..ccab63f 100644
54854 --- a/drivers/vfio/vfio.c
54855 +++ b/drivers/vfio/vfio.c
54856 @@ -481,7 +481,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
54857 return 0;
54858
54859 /* TODO Prevent device auto probing */
54860 - WARN("Device %s added to live group %d!\n", dev_name(dev),
54861 + WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
54862 iommu_group_id(group->iommu_group));
54863
54864 return 0;
54865 diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
54866 index 5174eba..451e6bc 100644
54867 --- a/drivers/vhost/vringh.c
54868 +++ b/drivers/vhost/vringh.c
54869 @@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
54870 /* Userspace access helpers: in this case, addresses are really userspace. */
54871 static inline int getu16_user(u16 *val, const u16 *p)
54872 {
54873 - return get_user(*val, (__force u16 __user *)p);
54874 + return get_user(*val, (u16 __force_user *)p);
54875 }
54876
54877 static inline int putu16_user(u16 *p, u16 val)
54878 {
54879 - return put_user(val, (__force u16 __user *)p);
54880 + return put_user(val, (u16 __force_user *)p);
54881 }
54882
54883 static inline int copydesc_user(void *dst, const void *src, size_t len)
54884 {
54885 - return copy_from_user(dst, (__force void __user *)src, len) ?
54886 + return copy_from_user(dst, (void __force_user *)src, len) ?
54887 -EFAULT : 0;
54888 }
54889
54890 @@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
54891 const struct vring_used_elem *src,
54892 unsigned int num)
54893 {
54894 - return copy_to_user((__force void __user *)dst, src,
54895 + return copy_to_user((void __force_user *)dst, src,
54896 sizeof(*dst) * num) ? -EFAULT : 0;
54897 }
54898
54899 static inline int xfer_from_user(void *src, void *dst, size_t len)
54900 {
54901 - return copy_from_user(dst, (__force void __user *)src, len) ?
54902 + return copy_from_user(dst, (void __force_user *)src, len) ?
54903 -EFAULT : 0;
54904 }
54905
54906 static inline int xfer_to_user(void *dst, void *src, size_t len)
54907 {
54908 - return copy_to_user((__force void __user *)dst, src, len) ?
54909 + return copy_to_user((void __force_user *)dst, src, len) ?
54910 -EFAULT : 0;
54911 }
54912
54913 @@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
54914 vrh->last_used_idx = 0;
54915 vrh->vring.num = num;
54916 /* vring expects kernel addresses, but only used via accessors. */
54917 - vrh->vring.desc = (__force struct vring_desc *)desc;
54918 - vrh->vring.avail = (__force struct vring_avail *)avail;
54919 - vrh->vring.used = (__force struct vring_used *)used;
54920 + vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
54921 + vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
54922 + vrh->vring.used = (__force_kernel struct vring_used *)used;
54923 return 0;
54924 }
54925 EXPORT_SYMBOL(vringh_init_user);
54926 @@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
54927
54928 static inline int putu16_kern(u16 *p, u16 val)
54929 {
54930 - ACCESS_ONCE(*p) = val;
54931 + ACCESS_ONCE_RW(*p) = val;
54932 return 0;
54933 }
54934
54935 diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
54936 index 84a110a..96312c3 100644
54937 --- a/drivers/video/backlight/kb3886_bl.c
54938 +++ b/drivers/video/backlight/kb3886_bl.c
54939 @@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
54940 static unsigned long kb3886bl_flags;
54941 #define KB3886BL_SUSPENDED 0x01
54942
54943 -static struct dmi_system_id kb3886bl_device_table[] __initdata = {
54944 +static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
54945 {
54946 .ident = "Sahara Touch-iT",
54947 .matches = {
54948 diff --git a/drivers/video/fbdev/arcfb.c b/drivers/video/fbdev/arcfb.c
54949 index 1b0b233..6f34c2c 100644
54950 --- a/drivers/video/fbdev/arcfb.c
54951 +++ b/drivers/video/fbdev/arcfb.c
54952 @@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
54953 return -ENOSPC;
54954
54955 err = 0;
54956 - if ((count + p) > fbmemlength) {
54957 + if (count > (fbmemlength - p)) {
54958 count = fbmemlength - p;
54959 err = -ENOSPC;
54960 }
54961 diff --git a/drivers/video/fbdev/aty/aty128fb.c b/drivers/video/fbdev/aty/aty128fb.c
54962 index ff60701..814b973 100644
54963 --- a/drivers/video/fbdev/aty/aty128fb.c
54964 +++ b/drivers/video/fbdev/aty/aty128fb.c
54965 @@ -149,7 +149,7 @@ enum {
54966 };
54967
54968 /* Must match above enum */
54969 -static char * const r128_family[] = {
54970 +static const char * const r128_family[] = {
54971 "AGP",
54972 "PCI",
54973 "PRO AGP",
54974 diff --git a/drivers/video/fbdev/aty/atyfb_base.c b/drivers/video/fbdev/aty/atyfb_base.c
54975 index 37ec09b..98f8862 100644
54976 --- a/drivers/video/fbdev/aty/atyfb_base.c
54977 +++ b/drivers/video/fbdev/aty/atyfb_base.c
54978 @@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
54979 par->accel_flags = var->accel_flags; /* hack */
54980
54981 if (var->accel_flags) {
54982 - info->fbops->fb_sync = atyfb_sync;
54983 + pax_open_kernel();
54984 + *(void **)&info->fbops->fb_sync = atyfb_sync;
54985 + pax_close_kernel();
54986 info->flags &= ~FBINFO_HWACCEL_DISABLED;
54987 } else {
54988 - info->fbops->fb_sync = NULL;
54989 + pax_open_kernel();
54990 + *(void **)&info->fbops->fb_sync = NULL;
54991 + pax_close_kernel();
54992 info->flags |= FBINFO_HWACCEL_DISABLED;
54993 }
54994
54995 diff --git a/drivers/video/fbdev/aty/mach64_cursor.c b/drivers/video/fbdev/aty/mach64_cursor.c
54996 index 2fa0317..4983f2a 100644
54997 --- a/drivers/video/fbdev/aty/mach64_cursor.c
54998 +++ b/drivers/video/fbdev/aty/mach64_cursor.c
54999 @@ -8,6 +8,7 @@
55000 #include "../core/fb_draw.h"
55001
55002 #include <asm/io.h>
55003 +#include <asm/pgtable.h>
55004
55005 #ifdef __sparc__
55006 #include <asm/fbio.h>
55007 @@ -218,7 +219,9 @@ int aty_init_cursor(struct fb_info *info)
55008 info->sprite.buf_align = 16; /* and 64 lines tall. */
55009 info->sprite.flags = FB_PIXMAP_IO;
55010
55011 - info->fbops->fb_cursor = atyfb_cursor;
55012 + pax_open_kernel();
55013 + *(void **)&info->fbops->fb_cursor = atyfb_cursor;
55014 + pax_close_kernel();
55015
55016 return 0;
55017 }
55018 diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
55019 index 900aa4e..6d49418 100644
55020 --- a/drivers/video/fbdev/core/fb_defio.c
55021 +++ b/drivers/video/fbdev/core/fb_defio.c
55022 @@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
55023
55024 BUG_ON(!fbdefio);
55025 mutex_init(&fbdefio->lock);
55026 - info->fbops->fb_mmap = fb_deferred_io_mmap;
55027 + pax_open_kernel();
55028 + *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
55029 + pax_close_kernel();
55030 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
55031 INIT_LIST_HEAD(&fbdefio->pagelist);
55032 if (fbdefio->delay == 0) /* set a default of 1 s */
55033 @@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
55034 page->mapping = NULL;
55035 }
55036
55037 - info->fbops->fb_mmap = NULL;
55038 + *(void **)&info->fbops->fb_mmap = NULL;
55039 mutex_destroy(&fbdefio->lock);
55040 }
55041 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
55042 diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
55043 index b5e85f6..290f8c7 100644
55044 --- a/drivers/video/fbdev/core/fbmem.c
55045 +++ b/drivers/video/fbdev/core/fbmem.c
55046 @@ -1301,7 +1301,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
55047 __u32 data;
55048 int err;
55049
55050 - err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
55051 + err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
55052
55053 data = (__u32) (unsigned long) fix->smem_start;
55054 err |= put_user(data, &fix32->smem_start);
55055 diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
55056 index 4254336..282567e 100644
55057 --- a/drivers/video/fbdev/hyperv_fb.c
55058 +++ b/drivers/video/fbdev/hyperv_fb.c
55059 @@ -240,7 +240,7 @@ static uint screen_fb_size;
55060 static inline int synthvid_send(struct hv_device *hdev,
55061 struct synthvid_msg *msg)
55062 {
55063 - static atomic64_t request_id = ATOMIC64_INIT(0);
55064 + static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
55065 int ret;
55066
55067 msg->pipe_hdr.type = PIPE_MSG_DATA;
55068 @@ -248,7 +248,7 @@ static inline int synthvid_send(struct hv_device *hdev,
55069
55070 ret = vmbus_sendpacket(hdev->channel, msg,
55071 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
55072 - atomic64_inc_return(&request_id),
55073 + atomic64_inc_return_unchecked(&request_id),
55074 VM_PKT_DATA_INBAND, 0);
55075
55076 if (ret)
55077 diff --git a/drivers/video/fbdev/i810/i810_accel.c b/drivers/video/fbdev/i810/i810_accel.c
55078 index 7672d2e..b56437f 100644
55079 --- a/drivers/video/fbdev/i810/i810_accel.c
55080 +++ b/drivers/video/fbdev/i810/i810_accel.c
55081 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
55082 }
55083 }
55084 printk("ringbuffer lockup!!!\n");
55085 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
55086 i810_report_error(mmio);
55087 par->dev_flags |= LOCKUP;
55088 info->pixmap.scan_align = 1;
55089 diff --git a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55090 index a01147f..5d896f8 100644
55091 --- a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55092 +++ b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55093 @@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
55094
55095 #ifdef CONFIG_FB_MATROX_MYSTIQUE
55096 struct matrox_switch matrox_mystique = {
55097 - MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
55098 + .preinit = MGA1064_preinit,
55099 + .reset = MGA1064_reset,
55100 + .init = MGA1064_init,
55101 + .restore = MGA1064_restore,
55102 };
55103 EXPORT_SYMBOL(matrox_mystique);
55104 #endif
55105
55106 #ifdef CONFIG_FB_MATROX_G
55107 struct matrox_switch matrox_G100 = {
55108 - MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
55109 + .preinit = MGAG100_preinit,
55110 + .reset = MGAG100_reset,
55111 + .init = MGAG100_init,
55112 + .restore = MGAG100_restore,
55113 };
55114 EXPORT_SYMBOL(matrox_G100);
55115 #endif
55116 diff --git a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55117 index 195ad7c..09743fc 100644
55118 --- a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55119 +++ b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55120 @@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
55121 }
55122
55123 struct matrox_switch matrox_millennium = {
55124 - Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
55125 + .preinit = Ti3026_preinit,
55126 + .reset = Ti3026_reset,
55127 + .init = Ti3026_init,
55128 + .restore = Ti3026_restore
55129 };
55130 EXPORT_SYMBOL(matrox_millennium);
55131 #endif
55132 diff --git a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55133 index fe92eed..106e085 100644
55134 --- a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55135 +++ b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55136 @@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
55137 struct mb862xxfb_par *par = info->par;
55138
55139 if (info->var.bits_per_pixel == 32) {
55140 - info->fbops->fb_fillrect = cfb_fillrect;
55141 - info->fbops->fb_copyarea = cfb_copyarea;
55142 - info->fbops->fb_imageblit = cfb_imageblit;
55143 + pax_open_kernel();
55144 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55145 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55146 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55147 + pax_close_kernel();
55148 } else {
55149 outreg(disp, GC_L0EM, 3);
55150 - info->fbops->fb_fillrect = mb86290fb_fillrect;
55151 - info->fbops->fb_copyarea = mb86290fb_copyarea;
55152 - info->fbops->fb_imageblit = mb86290fb_imageblit;
55153 + pax_open_kernel();
55154 + *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
55155 + *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
55156 + *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
55157 + pax_close_kernel();
55158 }
55159 outreg(draw, GDC_REG_DRAW_BASE, 0);
55160 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
55161 diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c
55162 index def0412..fed6529 100644
55163 --- a/drivers/video/fbdev/nvidia/nvidia.c
55164 +++ b/drivers/video/fbdev/nvidia/nvidia.c
55165 @@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
55166 info->fix.line_length = (info->var.xres_virtual *
55167 info->var.bits_per_pixel) >> 3;
55168 if (info->var.accel_flags) {
55169 - info->fbops->fb_imageblit = nvidiafb_imageblit;
55170 - info->fbops->fb_fillrect = nvidiafb_fillrect;
55171 - info->fbops->fb_copyarea = nvidiafb_copyarea;
55172 - info->fbops->fb_sync = nvidiafb_sync;
55173 + pax_open_kernel();
55174 + *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
55175 + *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
55176 + *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
55177 + *(void **)&info->fbops->fb_sync = nvidiafb_sync;
55178 + pax_close_kernel();
55179 info->pixmap.scan_align = 4;
55180 info->flags &= ~FBINFO_HWACCEL_DISABLED;
55181 info->flags |= FBINFO_READS_FAST;
55182 NVResetGraphics(info);
55183 } else {
55184 - info->fbops->fb_imageblit = cfb_imageblit;
55185 - info->fbops->fb_fillrect = cfb_fillrect;
55186 - info->fbops->fb_copyarea = cfb_copyarea;
55187 - info->fbops->fb_sync = NULL;
55188 + pax_open_kernel();
55189 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55190 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55191 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55192 + *(void **)&info->fbops->fb_sync = NULL;
55193 + pax_close_kernel();
55194 info->pixmap.scan_align = 1;
55195 info->flags |= FBINFO_HWACCEL_DISABLED;
55196 info->flags &= ~FBINFO_READS_FAST;
55197 @@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
55198 info->pixmap.size = 8 * 1024;
55199 info->pixmap.flags = FB_PIXMAP_SYSTEM;
55200
55201 - if (!hwcur)
55202 - info->fbops->fb_cursor = NULL;
55203 + if (!hwcur) {
55204 + pax_open_kernel();
55205 + *(void **)&info->fbops->fb_cursor = NULL;
55206 + pax_close_kernel();
55207 + }
55208
55209 info->var.accel_flags = (!noaccel);
55210
55211 diff --git a/drivers/video/fbdev/omap2/dss/display.c b/drivers/video/fbdev/omap2/dss/display.c
55212 index 2412a0d..294215b 100644
55213 --- a/drivers/video/fbdev/omap2/dss/display.c
55214 +++ b/drivers/video/fbdev/omap2/dss/display.c
55215 @@ -161,12 +161,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
55216 if (dssdev->name == NULL)
55217 dssdev->name = dssdev->alias;
55218
55219 + pax_open_kernel();
55220 if (drv && drv->get_resolution == NULL)
55221 - drv->get_resolution = omapdss_default_get_resolution;
55222 + *(void **)&drv->get_resolution = omapdss_default_get_resolution;
55223 if (drv && drv->get_recommended_bpp == NULL)
55224 - drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55225 + *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55226 if (drv && drv->get_timings == NULL)
55227 - drv->get_timings = omapdss_default_get_timings;
55228 + *(void **)&drv->get_timings = omapdss_default_get_timings;
55229 + pax_close_kernel();
55230
55231 mutex_lock(&panel_list_mutex);
55232 list_add_tail(&dssdev->panel_list, &panel_list);
55233 diff --git a/drivers/video/fbdev/s1d13xxxfb.c b/drivers/video/fbdev/s1d13xxxfb.c
55234 index 83433cb..71e9b98 100644
55235 --- a/drivers/video/fbdev/s1d13xxxfb.c
55236 +++ b/drivers/video/fbdev/s1d13xxxfb.c
55237 @@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
55238
55239 switch(prod_id) {
55240 case S1D13506_PROD_ID: /* activate acceleration */
55241 - s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55242 - s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55243 + pax_open_kernel();
55244 + *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55245 + *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55246 + pax_close_kernel();
55247 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
55248 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
55249 break;
55250 diff --git a/drivers/video/fbdev/sh_mobile_lcdcfb.c b/drivers/video/fbdev/sh_mobile_lcdcfb.c
55251 index 2bcc84a..29dd1ea 100644
55252 --- a/drivers/video/fbdev/sh_mobile_lcdcfb.c
55253 +++ b/drivers/video/fbdev/sh_mobile_lcdcfb.c
55254 @@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
55255 }
55256
55257 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
55258 - lcdc_sys_write_index,
55259 - lcdc_sys_write_data,
55260 - lcdc_sys_read_data,
55261 + .write_index = lcdc_sys_write_index,
55262 + .write_data = lcdc_sys_write_data,
55263 + .read_data = lcdc_sys_read_data,
55264 };
55265
55266 static int sh_mobile_lcdc_sginit(struct fb_info *info,
55267 diff --git a/drivers/video/fbdev/smscufx.c b/drivers/video/fbdev/smscufx.c
55268 index d513ed6..90b0de9 100644
55269 --- a/drivers/video/fbdev/smscufx.c
55270 +++ b/drivers/video/fbdev/smscufx.c
55271 @@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
55272 fb_deferred_io_cleanup(info);
55273 kfree(info->fbdefio);
55274 info->fbdefio = NULL;
55275 - info->fbops->fb_mmap = ufx_ops_mmap;
55276 + pax_open_kernel();
55277 + *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
55278 + pax_close_kernel();
55279 }
55280
55281 pr_debug("released /dev/fb%d user=%d count=%d",
55282 diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c
55283 index 77b890e..458e666 100644
55284 --- a/drivers/video/fbdev/udlfb.c
55285 +++ b/drivers/video/fbdev/udlfb.c
55286 @@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
55287 dlfb_urb_completion(urb);
55288
55289 error:
55290 - atomic_add(bytes_sent, &dev->bytes_sent);
55291 - atomic_add(bytes_identical, &dev->bytes_identical);
55292 - atomic_add(width*height*2, &dev->bytes_rendered);
55293 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55294 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55295 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
55296 end_cycles = get_cycles();
55297 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
55298 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55299 >> 10)), /* Kcycles */
55300 &dev->cpu_kcycles_used);
55301
55302 @@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
55303 dlfb_urb_completion(urb);
55304
55305 error:
55306 - atomic_add(bytes_sent, &dev->bytes_sent);
55307 - atomic_add(bytes_identical, &dev->bytes_identical);
55308 - atomic_add(bytes_rendered, &dev->bytes_rendered);
55309 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55310 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55311 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
55312 end_cycles = get_cycles();
55313 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
55314 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55315 >> 10)), /* Kcycles */
55316 &dev->cpu_kcycles_used);
55317 }
55318 @@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
55319 fb_deferred_io_cleanup(info);
55320 kfree(info->fbdefio);
55321 info->fbdefio = NULL;
55322 - info->fbops->fb_mmap = dlfb_ops_mmap;
55323 + pax_open_kernel();
55324 + *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
55325 + pax_close_kernel();
55326 }
55327
55328 pr_warn("released /dev/fb%d user=%d count=%d\n",
55329 @@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
55330 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55331 struct dlfb_data *dev = fb_info->par;
55332 return snprintf(buf, PAGE_SIZE, "%u\n",
55333 - atomic_read(&dev->bytes_rendered));
55334 + atomic_read_unchecked(&dev->bytes_rendered));
55335 }
55336
55337 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55338 @@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55339 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55340 struct dlfb_data *dev = fb_info->par;
55341 return snprintf(buf, PAGE_SIZE, "%u\n",
55342 - atomic_read(&dev->bytes_identical));
55343 + atomic_read_unchecked(&dev->bytes_identical));
55344 }
55345
55346 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55347 @@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55348 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55349 struct dlfb_data *dev = fb_info->par;
55350 return snprintf(buf, PAGE_SIZE, "%u\n",
55351 - atomic_read(&dev->bytes_sent));
55352 + atomic_read_unchecked(&dev->bytes_sent));
55353 }
55354
55355 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55356 @@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55357 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55358 struct dlfb_data *dev = fb_info->par;
55359 return snprintf(buf, PAGE_SIZE, "%u\n",
55360 - atomic_read(&dev->cpu_kcycles_used));
55361 + atomic_read_unchecked(&dev->cpu_kcycles_used));
55362 }
55363
55364 static ssize_t edid_show(
55365 @@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
55366 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55367 struct dlfb_data *dev = fb_info->par;
55368
55369 - atomic_set(&dev->bytes_rendered, 0);
55370 - atomic_set(&dev->bytes_identical, 0);
55371 - atomic_set(&dev->bytes_sent, 0);
55372 - atomic_set(&dev->cpu_kcycles_used, 0);
55373 + atomic_set_unchecked(&dev->bytes_rendered, 0);
55374 + atomic_set_unchecked(&dev->bytes_identical, 0);
55375 + atomic_set_unchecked(&dev->bytes_sent, 0);
55376 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
55377
55378 return count;
55379 }
55380 diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c
55381 index 509d452..7c9d2de 100644
55382 --- a/drivers/video/fbdev/uvesafb.c
55383 +++ b/drivers/video/fbdev/uvesafb.c
55384 @@ -19,6 +19,7 @@
55385 #include <linux/io.h>
55386 #include <linux/mutex.h>
55387 #include <linux/slab.h>
55388 +#include <linux/moduleloader.h>
55389 #include <video/edid.h>
55390 #include <video/uvesafb.h>
55391 #ifdef CONFIG_X86
55392 @@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
55393 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
55394 par->pmi_setpal = par->ypan = 0;
55395 } else {
55396 +
55397 +#ifdef CONFIG_PAX_KERNEXEC
55398 +#ifdef CONFIG_MODULES
55399 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
55400 +#endif
55401 + if (!par->pmi_code) {
55402 + par->pmi_setpal = par->ypan = 0;
55403 + return 0;
55404 + }
55405 +#endif
55406 +
55407 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
55408 + task->t.regs.edi);
55409 +
55410 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55411 + pax_open_kernel();
55412 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
55413 + pax_close_kernel();
55414 +
55415 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
55416 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
55417 +#else
55418 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
55419 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
55420 +#endif
55421 +
55422 printk(KERN_INFO "uvesafb: protected mode interface info at "
55423 "%04x:%04x\n",
55424 (u16)task->t.regs.es, (u16)task->t.regs.edi);
55425 @@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
55426 par->ypan = ypan;
55427
55428 if (par->pmi_setpal || par->ypan) {
55429 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
55430 if (__supported_pte_mask & _PAGE_NX) {
55431 par->pmi_setpal = par->ypan = 0;
55432 printk(KERN_WARNING "uvesafb: NX protection is active, "
55433 "better not use the PMI.\n");
55434 - } else {
55435 + } else
55436 +#endif
55437 uvesafb_vbe_getpmi(task, par);
55438 - }
55439 }
55440 #else
55441 /* The protected mode interface is not available on non-x86. */
55442 @@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55443 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
55444
55445 /* Disable blanking if the user requested so. */
55446 - if (!blank)
55447 - info->fbops->fb_blank = NULL;
55448 + if (!blank) {
55449 + pax_open_kernel();
55450 + *(void **)&info->fbops->fb_blank = NULL;
55451 + pax_close_kernel();
55452 + }
55453
55454 /*
55455 * Find out how much IO memory is required for the mode with
55456 @@ -1525,8 +1552,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55457 info->flags = FBINFO_FLAG_DEFAULT |
55458 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
55459
55460 - if (!par->ypan)
55461 - info->fbops->fb_pan_display = NULL;
55462 + if (!par->ypan) {
55463 + pax_open_kernel();
55464 + *(void **)&info->fbops->fb_pan_display = NULL;
55465 + pax_close_kernel();
55466 + }
55467 }
55468
55469 static void uvesafb_init_mtrr(struct fb_info *info)
55470 @@ -1787,6 +1817,11 @@ out_mode:
55471 out:
55472 kfree(par->vbe_modes);
55473
55474 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55475 + if (par->pmi_code)
55476 + module_free_exec(NULL, par->pmi_code);
55477 +#endif
55478 +
55479 framebuffer_release(info);
55480 return err;
55481 }
55482 @@ -1811,6 +1846,11 @@ static int uvesafb_remove(struct platform_device *dev)
55483 kfree(par->vbe_state_orig);
55484 kfree(par->vbe_state_saved);
55485
55486 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55487 + if (par->pmi_code)
55488 + module_free_exec(NULL, par->pmi_code);
55489 +#endif
55490 +
55491 framebuffer_release(info);
55492 }
55493 return 0;
55494 diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
55495 index 6170e7f..dd63031 100644
55496 --- a/drivers/video/fbdev/vesafb.c
55497 +++ b/drivers/video/fbdev/vesafb.c
55498 @@ -9,6 +9,7 @@
55499 */
55500
55501 #include <linux/module.h>
55502 +#include <linux/moduleloader.h>
55503 #include <linux/kernel.h>
55504 #include <linux/errno.h>
55505 #include <linux/string.h>
55506 @@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
55507 static int vram_total; /* Set total amount of memory */
55508 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
55509 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
55510 -static void (*pmi_start)(void) __read_mostly;
55511 -static void (*pmi_pal) (void) __read_mostly;
55512 +static void (*pmi_start)(void) __read_only;
55513 +static void (*pmi_pal) (void) __read_only;
55514 static int depth __read_mostly;
55515 static int vga_compat __read_mostly;
55516 /* --------------------------------------------------------------------- */
55517 @@ -233,6 +234,7 @@ static int vesafb_probe(struct platform_device *dev)
55518 unsigned int size_remap;
55519 unsigned int size_total;
55520 char *option = NULL;
55521 + void *pmi_code = NULL;
55522
55523 /* ignore error return of fb_get_options */
55524 fb_get_options("vesafb", &option);
55525 @@ -279,10 +281,6 @@ static int vesafb_probe(struct platform_device *dev)
55526 size_remap = size_total;
55527 vesafb_fix.smem_len = size_remap;
55528
55529 -#ifndef __i386__
55530 - screen_info.vesapm_seg = 0;
55531 -#endif
55532 -
55533 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
55534 printk(KERN_WARNING
55535 "vesafb: cannot reserve video memory at 0x%lx\n",
55536 @@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
55537 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
55538 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
55539
55540 +#ifdef __i386__
55541 +
55542 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55543 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
55544 + if (!pmi_code)
55545 +#elif !defined(CONFIG_PAX_KERNEXEC)
55546 + if (0)
55547 +#endif
55548 +
55549 +#endif
55550 + screen_info.vesapm_seg = 0;
55551 +
55552 if (screen_info.vesapm_seg) {
55553 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
55554 - screen_info.vesapm_seg,screen_info.vesapm_off);
55555 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
55556 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
55557 }
55558
55559 if (screen_info.vesapm_seg < 0xc000)
55560 @@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
55561
55562 if (ypan || pmi_setpal) {
55563 unsigned short *pmi_base;
55564 +
55565 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
55566 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
55567 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
55568 +
55569 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55570 + pax_open_kernel();
55571 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
55572 +#else
55573 + pmi_code = pmi_base;
55574 +#endif
55575 +
55576 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
55577 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
55578 +
55579 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55580 + pmi_start = ktva_ktla(pmi_start);
55581 + pmi_pal = ktva_ktla(pmi_pal);
55582 + pax_close_kernel();
55583 +#endif
55584 +
55585 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
55586 if (pmi_base[3]) {
55587 printk(KERN_INFO "vesafb: pmi: ports = ");
55588 @@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
55589 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
55590 (ypan ? FBINFO_HWACCEL_YPAN : 0);
55591
55592 - if (!ypan)
55593 - info->fbops->fb_pan_display = NULL;
55594 + if (!ypan) {
55595 + pax_open_kernel();
55596 + *(void **)&info->fbops->fb_pan_display = NULL;
55597 + pax_close_kernel();
55598 + }
55599
55600 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
55601 err = -ENOMEM;
55602 @@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
55603 fb_info(info, "%s frame buffer device\n", info->fix.id);
55604 return 0;
55605 err:
55606 +
55607 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55608 + module_free_exec(NULL, pmi_code);
55609 +#endif
55610 +
55611 if (info->screen_base)
55612 iounmap(info->screen_base);
55613 framebuffer_release(info);
55614 diff --git a/drivers/video/fbdev/via/via_clock.h b/drivers/video/fbdev/via/via_clock.h
55615 index 88714ae..16c2e11 100644
55616 --- a/drivers/video/fbdev/via/via_clock.h
55617 +++ b/drivers/video/fbdev/via/via_clock.h
55618 @@ -56,7 +56,7 @@ struct via_clock {
55619
55620 void (*set_engine_pll_state)(u8 state);
55621 void (*set_engine_pll)(struct via_pll_config config);
55622 -};
55623 +} __no_const;
55624
55625
55626 static inline u32 get_pll_internal_frequency(u32 ref_freq,
55627 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
55628 index 3c14e43..2630570 100644
55629 --- a/drivers/video/logo/logo_linux_clut224.ppm
55630 +++ b/drivers/video/logo/logo_linux_clut224.ppm
55631 @@ -2,1603 +2,1123 @@ P3
55632 # Standard 224-color Linux logo
55633 80 80
55634 255
55635 - 0 0 0 0 0 0 0 0 0 0 0 0
55636 - 0 0 0 0 0 0 0 0 0 0 0 0
55637 - 0 0 0 0 0 0 0 0 0 0 0 0
55638 - 0 0 0 0 0 0 0 0 0 0 0 0
55639 - 0 0 0 0 0 0 0 0 0 0 0 0
55640 - 0 0 0 0 0 0 0 0 0 0 0 0
55641 - 0 0 0 0 0 0 0 0 0 0 0 0
55642 - 0 0 0 0 0 0 0 0 0 0 0 0
55643 - 0 0 0 0 0 0 0 0 0 0 0 0
55644 - 6 6 6 6 6 6 10 10 10 10 10 10
55645 - 10 10 10 6 6 6 6 6 6 6 6 6
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 0 0 0
55657 - 0 0 0 0 0 0 0 0 0 0 0 0
55658 - 0 0 0 0 0 0 0 0 0 0 0 0
55659 - 0 0 0 0 0 0 0 0 0 0 0 0
55660 - 0 0 0 0 0 0 0 0 0 0 0 0
55661 - 0 0 0 0 0 0 0 0 0 0 0 0
55662 - 0 0 0 0 0 0 0 0 0 0 0 0
55663 - 0 0 0 6 6 6 10 10 10 14 14 14
55664 - 22 22 22 26 26 26 30 30 30 34 34 34
55665 - 30 30 30 30 30 30 26 26 26 18 18 18
55666 - 14 14 14 10 10 10 6 6 6 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 1 0 0 1 0 0 0
55677 - 0 0 0 0 0 0 0 0 0 0 0 0
55678 - 0 0 0 0 0 0 0 0 0 0 0 0
55679 - 0 0 0 0 0 0 0 0 0 0 0 0
55680 - 0 0 0 0 0 0 0 0 0 0 0 0
55681 - 0 0 0 0 0 0 0 0 0 0 0 0
55682 - 0 0 0 0 0 0 0 0 0 0 0 0
55683 - 6 6 6 14 14 14 26 26 26 42 42 42
55684 - 54 54 54 66 66 66 78 78 78 78 78 78
55685 - 78 78 78 74 74 74 66 66 66 54 54 54
55686 - 42 42 42 26 26 26 18 18 18 10 10 10
55687 - 6 6 6 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 1 0 0 0 0 0 0 0 0 0
55697 - 0 0 0 0 0 0 0 0 0 0 0 0
55698 - 0 0 0 0 0 0 0 0 0 0 0 0
55699 - 0 0 0 0 0 0 0 0 0 0 0 0
55700 - 0 0 0 0 0 0 0 0 0 0 0 0
55701 - 0 0 0 0 0 0 0 0 0 0 0 0
55702 - 0 0 0 0 0 0 0 0 0 10 10 10
55703 - 22 22 22 42 42 42 66 66 66 86 86 86
55704 - 66 66 66 38 38 38 38 38 38 22 22 22
55705 - 26 26 26 34 34 34 54 54 54 66 66 66
55706 - 86 86 86 70 70 70 46 46 46 26 26 26
55707 - 14 14 14 6 6 6 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 1 0 0 1 0 0 1 0 0 0
55717 - 0 0 0 0 0 0 0 0 0 0 0 0
55718 - 0 0 0 0 0 0 0 0 0 0 0 0
55719 - 0 0 0 0 0 0 0 0 0 0 0 0
55720 - 0 0 0 0 0 0 0 0 0 0 0 0
55721 - 0 0 0 0 0 0 0 0 0 0 0 0
55722 - 0 0 0 0 0 0 10 10 10 26 26 26
55723 - 50 50 50 82 82 82 58 58 58 6 6 6
55724 - 2 2 6 2 2 6 2 2 6 2 2 6
55725 - 2 2 6 2 2 6 2 2 6 2 2 6
55726 - 6 6 6 54 54 54 86 86 86 66 66 66
55727 - 38 38 38 18 18 18 6 6 6 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 0 0 0
55737 - 0 0 0 0 0 0 0 0 0 0 0 0
55738 - 0 0 0 0 0 0 0 0 0 0 0 0
55739 - 0 0 0 0 0 0 0 0 0 0 0 0
55740 - 0 0 0 0 0 0 0 0 0 0 0 0
55741 - 0 0 0 0 0 0 0 0 0 0 0 0
55742 - 0 0 0 6 6 6 22 22 22 50 50 50
55743 - 78 78 78 34 34 34 2 2 6 2 2 6
55744 - 2 2 6 2 2 6 2 2 6 2 2 6
55745 - 2 2 6 2 2 6 2 2 6 2 2 6
55746 - 2 2 6 2 2 6 6 6 6 70 70 70
55747 - 78 78 78 46 46 46 22 22 22 6 6 6
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 1 0 0 1 0 0 1 0 0 0
55757 - 0 0 0 0 0 0 0 0 0 0 0 0
55758 - 0 0 0 0 0 0 0 0 0 0 0 0
55759 - 0 0 0 0 0 0 0 0 0 0 0 0
55760 - 0 0 0 0 0 0 0 0 0 0 0 0
55761 - 0 0 0 0 0 0 0 0 0 0 0 0
55762 - 6 6 6 18 18 18 42 42 42 82 82 82
55763 - 26 26 26 2 2 6 2 2 6 2 2 6
55764 - 2 2 6 2 2 6 2 2 6 2 2 6
55765 - 2 2 6 2 2 6 2 2 6 14 14 14
55766 - 46 46 46 34 34 34 6 6 6 2 2 6
55767 - 42 42 42 78 78 78 42 42 42 18 18 18
55768 - 6 6 6 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 1 0 0 0 0 0 1 0 0 0
55777 - 0 0 0 0 0 0 0 0 0 0 0 0
55778 - 0 0 0 0 0 0 0 0 0 0 0 0
55779 - 0 0 0 0 0 0 0 0 0 0 0 0
55780 - 0 0 0 0 0 0 0 0 0 0 0 0
55781 - 0 0 0 0 0 0 0 0 0 0 0 0
55782 - 10 10 10 30 30 30 66 66 66 58 58 58
55783 - 2 2 6 2 2 6 2 2 6 2 2 6
55784 - 2 2 6 2 2 6 2 2 6 2 2 6
55785 - 2 2 6 2 2 6 2 2 6 26 26 26
55786 - 86 86 86 101 101 101 46 46 46 10 10 10
55787 - 2 2 6 58 58 58 70 70 70 34 34 34
55788 - 10 10 10 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 1 0 0 1 0 0 1 0 0 0
55797 - 0 0 0 0 0 0 0 0 0 0 0 0
55798 - 0 0 0 0 0 0 0 0 0 0 0 0
55799 - 0 0 0 0 0 0 0 0 0 0 0 0
55800 - 0 0 0 0 0 0 0 0 0 0 0 0
55801 - 0 0 0 0 0 0 0 0 0 0 0 0
55802 - 14 14 14 42 42 42 86 86 86 10 10 10
55803 - 2 2 6 2 2 6 2 2 6 2 2 6
55804 - 2 2 6 2 2 6 2 2 6 2 2 6
55805 - 2 2 6 2 2 6 2 2 6 30 30 30
55806 - 94 94 94 94 94 94 58 58 58 26 26 26
55807 - 2 2 6 6 6 6 78 78 78 54 54 54
55808 - 22 22 22 6 6 6 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 0 0 0 0 0 0
55817 - 0 0 0 0 0 0 0 0 0 0 0 0
55818 - 0 0 0 0 0 0 0 0 0 0 0 0
55819 - 0 0 0 0 0 0 0 0 0 0 0 0
55820 - 0 0 0 0 0 0 0 0 0 0 0 0
55821 - 0 0 0 0 0 0 0 0 0 6 6 6
55822 - 22 22 22 62 62 62 62 62 62 2 2 6
55823 - 2 2 6 2 2 6 2 2 6 2 2 6
55824 - 2 2 6 2 2 6 2 2 6 2 2 6
55825 - 2 2 6 2 2 6 2 2 6 26 26 26
55826 - 54 54 54 38 38 38 18 18 18 10 10 10
55827 - 2 2 6 2 2 6 34 34 34 82 82 82
55828 - 38 38 38 14 14 14 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 0 0 1 0 0 1 0 0 0
55837 - 0 0 0 0 0 0 0 0 0 0 0 0
55838 - 0 0 0 0 0 0 0 0 0 0 0 0
55839 - 0 0 0 0 0 0 0 0 0 0 0 0
55840 - 0 0 0 0 0 0 0 0 0 0 0 0
55841 - 0 0 0 0 0 0 0 0 0 6 6 6
55842 - 30 30 30 78 78 78 30 30 30 2 2 6
55843 - 2 2 6 2 2 6 2 2 6 2 2 6
55844 - 2 2 6 2 2 6 2 2 6 2 2 6
55845 - 2 2 6 2 2 6 2 2 6 10 10 10
55846 - 10 10 10 2 2 6 2 2 6 2 2 6
55847 - 2 2 6 2 2 6 2 2 6 78 78 78
55848 - 50 50 50 18 18 18 6 6 6 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 - 0 0 1 0 0 0 0 0 0 0 0 0
55857 - 0 0 0 0 0 0 0 0 0 0 0 0
55858 - 0 0 0 0 0 0 0 0 0 0 0 0
55859 - 0 0 0 0 0 0 0 0 0 0 0 0
55860 - 0 0 0 0 0 0 0 0 0 0 0 0
55861 - 0 0 0 0 0 0 0 0 0 10 10 10
55862 - 38 38 38 86 86 86 14 14 14 2 2 6
55863 - 2 2 6 2 2 6 2 2 6 2 2 6
55864 - 2 2 6 2 2 6 2 2 6 2 2 6
55865 - 2 2 6 2 2 6 2 2 6 2 2 6
55866 - 2 2 6 2 2 6 2 2 6 2 2 6
55867 - 2 2 6 2 2 6 2 2 6 54 54 54
55868 - 66 66 66 26 26 26 6 6 6 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 0 0 0
55876 - 0 0 0 0 0 1 0 0 1 0 0 0
55877 - 0 0 0 0 0 0 0 0 0 0 0 0
55878 - 0 0 0 0 0 0 0 0 0 0 0 0
55879 - 0 0 0 0 0 0 0 0 0 0 0 0
55880 - 0 0 0 0 0 0 0 0 0 0 0 0
55881 - 0 0 0 0 0 0 0 0 0 14 14 14
55882 - 42 42 42 82 82 82 2 2 6 2 2 6
55883 - 2 2 6 6 6 6 10 10 10 2 2 6
55884 - 2 2 6 2 2 6 2 2 6 2 2 6
55885 - 2 2 6 2 2 6 2 2 6 6 6 6
55886 - 14 14 14 10 10 10 2 2 6 2 2 6
55887 - 2 2 6 2 2 6 2 2 6 18 18 18
55888 - 82 82 82 34 34 34 10 10 10 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 0 0 0
55896 - 0 0 1 0 0 0 0 0 0 0 0 0
55897 - 0 0 0 0 0 0 0 0 0 0 0 0
55898 - 0 0 0 0 0 0 0 0 0 0 0 0
55899 - 0 0 0 0 0 0 0 0 0 0 0 0
55900 - 0 0 0 0 0 0 0 0 0 0 0 0
55901 - 0 0 0 0 0 0 0 0 0 14 14 14
55902 - 46 46 46 86 86 86 2 2 6 2 2 6
55903 - 6 6 6 6 6 6 22 22 22 34 34 34
55904 - 6 6 6 2 2 6 2 2 6 2 2 6
55905 - 2 2 6 2 2 6 18 18 18 34 34 34
55906 - 10 10 10 50 50 50 22 22 22 2 2 6
55907 - 2 2 6 2 2 6 2 2 6 10 10 10
55908 - 86 86 86 42 42 42 14 14 14 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 0 0 0 0 0 0
55916 - 0 0 1 0 0 1 0 0 1 0 0 0
55917 - 0 0 0 0 0 0 0 0 0 0 0 0
55918 - 0 0 0 0 0 0 0 0 0 0 0 0
55919 - 0 0 0 0 0 0 0 0 0 0 0 0
55920 - 0 0 0 0 0 0 0 0 0 0 0 0
55921 - 0 0 0 0 0 0 0 0 0 14 14 14
55922 - 46 46 46 86 86 86 2 2 6 2 2 6
55923 - 38 38 38 116 116 116 94 94 94 22 22 22
55924 - 22 22 22 2 2 6 2 2 6 2 2 6
55925 - 14 14 14 86 86 86 138 138 138 162 162 162
55926 -154 154 154 38 38 38 26 26 26 6 6 6
55927 - 2 2 6 2 2 6 2 2 6 2 2 6
55928 - 86 86 86 46 46 46 14 14 14 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 0 0 0 0 0 0 0 0 0
55936 - 0 0 0 0 0 0 0 0 0 0 0 0
55937 - 0 0 0 0 0 0 0 0 0 0 0 0
55938 - 0 0 0 0 0 0 0 0 0 0 0 0
55939 - 0 0 0 0 0 0 0 0 0 0 0 0
55940 - 0 0 0 0 0 0 0 0 0 0 0 0
55941 - 0 0 0 0 0 0 0 0 0 14 14 14
55942 - 46 46 46 86 86 86 2 2 6 14 14 14
55943 -134 134 134 198 198 198 195 195 195 116 116 116
55944 - 10 10 10 2 2 6 2 2 6 6 6 6
55945 -101 98 89 187 187 187 210 210 210 218 218 218
55946 -214 214 214 134 134 134 14 14 14 6 6 6
55947 - 2 2 6 2 2 6 2 2 6 2 2 6
55948 - 86 86 86 50 50 50 18 18 18 6 6 6
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 - 0 0 0 0 0 0 0 0 1 0 0 0
55956 - 0 0 1 0 0 1 0 0 1 0 0 0
55957 - 0 0 0 0 0 0 0 0 0 0 0 0
55958 - 0 0 0 0 0 0 0 0 0 0 0 0
55959 - 0 0 0 0 0 0 0 0 0 0 0 0
55960 - 0 0 0 0 0 0 0 0 0 0 0 0
55961 - 0 0 0 0 0 0 0 0 0 14 14 14
55962 - 46 46 46 86 86 86 2 2 6 54 54 54
55963 -218 218 218 195 195 195 226 226 226 246 246 246
55964 - 58 58 58 2 2 6 2 2 6 30 30 30
55965 -210 210 210 253 253 253 174 174 174 123 123 123
55966 -221 221 221 234 234 234 74 74 74 2 2 6
55967 - 2 2 6 2 2 6 2 2 6 2 2 6
55968 - 70 70 70 58 58 58 22 22 22 6 6 6
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 - 0 0 0 0 0 0 0 0 0 0 0 0
55976 - 0 0 0 0 0 0 0 0 0 0 0 0
55977 - 0 0 0 0 0 0 0 0 0 0 0 0
55978 - 0 0 0 0 0 0 0 0 0 0 0 0
55979 - 0 0 0 0 0 0 0 0 0 0 0 0
55980 - 0 0 0 0 0 0 0 0 0 0 0 0
55981 - 0 0 0 0 0 0 0 0 0 14 14 14
55982 - 46 46 46 82 82 82 2 2 6 106 106 106
55983 -170 170 170 26 26 26 86 86 86 226 226 226
55984 -123 123 123 10 10 10 14 14 14 46 46 46
55985 -231 231 231 190 190 190 6 6 6 70 70 70
55986 - 90 90 90 238 238 238 158 158 158 2 2 6
55987 - 2 2 6 2 2 6 2 2 6 2 2 6
55988 - 70 70 70 58 58 58 22 22 22 6 6 6
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 - 0 0 0 0 0 0 0 0 1 0 0 0
55996 - 0 0 1 0 0 1 0 0 1 0 0 0
55997 - 0 0 0 0 0 0 0 0 0 0 0 0
55998 - 0 0 0 0 0 0 0 0 0 0 0 0
55999 - 0 0 0 0 0 0 0 0 0 0 0 0
56000 - 0 0 0 0 0 0 0 0 0 0 0 0
56001 - 0 0 0 0 0 0 0 0 0 14 14 14
56002 - 42 42 42 86 86 86 6 6 6 116 116 116
56003 -106 106 106 6 6 6 70 70 70 149 149 149
56004 -128 128 128 18 18 18 38 38 38 54 54 54
56005 -221 221 221 106 106 106 2 2 6 14 14 14
56006 - 46 46 46 190 190 190 198 198 198 2 2 6
56007 - 2 2 6 2 2 6 2 2 6 2 2 6
56008 - 74 74 74 62 62 62 22 22 22 6 6 6
56009 - 0 0 0 0 0 0 0 0 0 0 0 0
56010 - 0 0 0 0 0 0 0 0 0 0 0 0
56011 - 0 0 0 0 0 0 0 0 0 0 0 0
56012 - 0 0 0 0 0 0 0 0 0 0 0 0
56013 - 0 0 0 0 0 0 0 0 0 0 0 0
56014 - 0 0 0 0 0 0 0 0 0 0 0 0
56015 - 0 0 0 0 0 0 0 0 1 0 0 0
56016 - 0 0 1 0 0 0 0 0 1 0 0 0
56017 - 0 0 0 0 0 0 0 0 0 0 0 0
56018 - 0 0 0 0 0 0 0 0 0 0 0 0
56019 - 0 0 0 0 0 0 0 0 0 0 0 0
56020 - 0 0 0 0 0 0 0 0 0 0 0 0
56021 - 0 0 0 0 0 0 0 0 0 14 14 14
56022 - 42 42 42 94 94 94 14 14 14 101 101 101
56023 -128 128 128 2 2 6 18 18 18 116 116 116
56024 -118 98 46 121 92 8 121 92 8 98 78 10
56025 -162 162 162 106 106 106 2 2 6 2 2 6
56026 - 2 2 6 195 195 195 195 195 195 6 6 6
56027 - 2 2 6 2 2 6 2 2 6 2 2 6
56028 - 74 74 74 62 62 62 22 22 22 6 6 6
56029 - 0 0 0 0 0 0 0 0 0 0 0 0
56030 - 0 0 0 0 0 0 0 0 0 0 0 0
56031 - 0 0 0 0 0 0 0 0 0 0 0 0
56032 - 0 0 0 0 0 0 0 0 0 0 0 0
56033 - 0 0 0 0 0 0 0 0 0 0 0 0
56034 - 0 0 0 0 0 0 0 0 0 0 0 0
56035 - 0 0 0 0 0 0 0 0 1 0 0 1
56036 - 0 0 1 0 0 0 0 0 1 0 0 0
56037 - 0 0 0 0 0 0 0 0 0 0 0 0
56038 - 0 0 0 0 0 0 0 0 0 0 0 0
56039 - 0 0 0 0 0 0 0 0 0 0 0 0
56040 - 0 0 0 0 0 0 0 0 0 0 0 0
56041 - 0 0 0 0 0 0 0 0 0 10 10 10
56042 - 38 38 38 90 90 90 14 14 14 58 58 58
56043 -210 210 210 26 26 26 54 38 6 154 114 10
56044 -226 170 11 236 186 11 225 175 15 184 144 12
56045 -215 174 15 175 146 61 37 26 9 2 2 6
56046 - 70 70 70 246 246 246 138 138 138 2 2 6
56047 - 2 2 6 2 2 6 2 2 6 2 2 6
56048 - 70 70 70 66 66 66 26 26 26 6 6 6
56049 - 0 0 0 0 0 0 0 0 0 0 0 0
56050 - 0 0 0 0 0 0 0 0 0 0 0 0
56051 - 0 0 0 0 0 0 0 0 0 0 0 0
56052 - 0 0 0 0 0 0 0 0 0 0 0 0
56053 - 0 0 0 0 0 0 0 0 0 0 0 0
56054 - 0 0 0 0 0 0 0 0 0 0 0 0
56055 - 0 0 0 0 0 0 0 0 0 0 0 0
56056 - 0 0 0 0 0 0 0 0 0 0 0 0
56057 - 0 0 0 0 0 0 0 0 0 0 0 0
56058 - 0 0 0 0 0 0 0 0 0 0 0 0
56059 - 0 0 0 0 0 0 0 0 0 0 0 0
56060 - 0 0 0 0 0 0 0 0 0 0 0 0
56061 - 0 0 0 0 0 0 0 0 0 10 10 10
56062 - 38 38 38 86 86 86 14 14 14 10 10 10
56063 -195 195 195 188 164 115 192 133 9 225 175 15
56064 -239 182 13 234 190 10 232 195 16 232 200 30
56065 -245 207 45 241 208 19 232 195 16 184 144 12
56066 -218 194 134 211 206 186 42 42 42 2 2 6
56067 - 2 2 6 2 2 6 2 2 6 2 2 6
56068 - 50 50 50 74 74 74 30 30 30 6 6 6
56069 - 0 0 0 0 0 0 0 0 0 0 0 0
56070 - 0 0 0 0 0 0 0 0 0 0 0 0
56071 - 0 0 0 0 0 0 0 0 0 0 0 0
56072 - 0 0 0 0 0 0 0 0 0 0 0 0
56073 - 0 0 0 0 0 0 0 0 0 0 0 0
56074 - 0 0 0 0 0 0 0 0 0 0 0 0
56075 - 0 0 0 0 0 0 0 0 0 0 0 0
56076 - 0 0 0 0 0 0 0 0 0 0 0 0
56077 - 0 0 0 0 0 0 0 0 0 0 0 0
56078 - 0 0 0 0 0 0 0 0 0 0 0 0
56079 - 0 0 0 0 0 0 0 0 0 0 0 0
56080 - 0 0 0 0 0 0 0 0 0 0 0 0
56081 - 0 0 0 0 0 0 0 0 0 10 10 10
56082 - 34 34 34 86 86 86 14 14 14 2 2 6
56083 -121 87 25 192 133 9 219 162 10 239 182 13
56084 -236 186 11 232 195 16 241 208 19 244 214 54
56085 -246 218 60 246 218 38 246 215 20 241 208 19
56086 -241 208 19 226 184 13 121 87 25 2 2 6
56087 - 2 2 6 2 2 6 2 2 6 2 2 6
56088 - 50 50 50 82 82 82 34 34 34 10 10 10
56089 - 0 0 0 0 0 0 0 0 0 0 0 0
56090 - 0 0 0 0 0 0 0 0 0 0 0 0
56091 - 0 0 0 0 0 0 0 0 0 0 0 0
56092 - 0 0 0 0 0 0 0 0 0 0 0 0
56093 - 0 0 0 0 0 0 0 0 0 0 0 0
56094 - 0 0 0 0 0 0 0 0 0 0 0 0
56095 - 0 0 0 0 0 0 0 0 0 0 0 0
56096 - 0 0 0 0 0 0 0 0 0 0 0 0
56097 - 0 0 0 0 0 0 0 0 0 0 0 0
56098 - 0 0 0 0 0 0 0 0 0 0 0 0
56099 - 0 0 0 0 0 0 0 0 0 0 0 0
56100 - 0 0 0 0 0 0 0 0 0 0 0 0
56101 - 0 0 0 0 0 0 0 0 0 10 10 10
56102 - 34 34 34 82 82 82 30 30 30 61 42 6
56103 -180 123 7 206 145 10 230 174 11 239 182 13
56104 -234 190 10 238 202 15 241 208 19 246 218 74
56105 -246 218 38 246 215 20 246 215 20 246 215 20
56106 -226 184 13 215 174 15 184 144 12 6 6 6
56107 - 2 2 6 2 2 6 2 2 6 2 2 6
56108 - 26 26 26 94 94 94 42 42 42 14 14 14
56109 - 0 0 0 0 0 0 0 0 0 0 0 0
56110 - 0 0 0 0 0 0 0 0 0 0 0 0
56111 - 0 0 0 0 0 0 0 0 0 0 0 0
56112 - 0 0 0 0 0 0 0 0 0 0 0 0
56113 - 0 0 0 0 0 0 0 0 0 0 0 0
56114 - 0 0 0 0 0 0 0 0 0 0 0 0
56115 - 0 0 0 0 0 0 0 0 0 0 0 0
56116 - 0 0 0 0 0 0 0 0 0 0 0 0
56117 - 0 0 0 0 0 0 0 0 0 0 0 0
56118 - 0 0 0 0 0 0 0 0 0 0 0 0
56119 - 0 0 0 0 0 0 0 0 0 0 0 0
56120 - 0 0 0 0 0 0 0 0 0 0 0 0
56121 - 0 0 0 0 0 0 0 0 0 10 10 10
56122 - 30 30 30 78 78 78 50 50 50 104 69 6
56123 -192 133 9 216 158 10 236 178 12 236 186 11
56124 -232 195 16 241 208 19 244 214 54 245 215 43
56125 -246 215 20 246 215 20 241 208 19 198 155 10
56126 -200 144 11 216 158 10 156 118 10 2 2 6
56127 - 2 2 6 2 2 6 2 2 6 2 2 6
56128 - 6 6 6 90 90 90 54 54 54 18 18 18
56129 - 6 6 6 0 0 0 0 0 0 0 0 0
56130 - 0 0 0 0 0 0 0 0 0 0 0 0
56131 - 0 0 0 0 0 0 0 0 0 0 0 0
56132 - 0 0 0 0 0 0 0 0 0 0 0 0
56133 - 0 0 0 0 0 0 0 0 0 0 0 0
56134 - 0 0 0 0 0 0 0 0 0 0 0 0
56135 - 0 0 0 0 0 0 0 0 0 0 0 0
56136 - 0 0 0 0 0 0 0 0 0 0 0 0
56137 - 0 0 0 0 0 0 0 0 0 0 0 0
56138 - 0 0 0 0 0 0 0 0 0 0 0 0
56139 - 0 0 0 0 0 0 0 0 0 0 0 0
56140 - 0 0 0 0 0 0 0 0 0 0 0 0
56141 - 0 0 0 0 0 0 0 0 0 10 10 10
56142 - 30 30 30 78 78 78 46 46 46 22 22 22
56143 -137 92 6 210 162 10 239 182 13 238 190 10
56144 -238 202 15 241 208 19 246 215 20 246 215 20
56145 -241 208 19 203 166 17 185 133 11 210 150 10
56146 -216 158 10 210 150 10 102 78 10 2 2 6
56147 - 6 6 6 54 54 54 14 14 14 2 2 6
56148 - 2 2 6 62 62 62 74 74 74 30 30 30
56149 - 10 10 10 0 0 0 0 0 0 0 0 0
56150 - 0 0 0 0 0 0 0 0 0 0 0 0
56151 - 0 0 0 0 0 0 0 0 0 0 0 0
56152 - 0 0 0 0 0 0 0 0 0 0 0 0
56153 - 0 0 0 0 0 0 0 0 0 0 0 0
56154 - 0 0 0 0 0 0 0 0 0 0 0 0
56155 - 0 0 0 0 0 0 0 0 0 0 0 0
56156 - 0 0 0 0 0 0 0 0 0 0 0 0
56157 - 0 0 0 0 0 0 0 0 0 0 0 0
56158 - 0 0 0 0 0 0 0 0 0 0 0 0
56159 - 0 0 0 0 0 0 0 0 0 0 0 0
56160 - 0 0 0 0 0 0 0 0 0 0 0 0
56161 - 0 0 0 0 0 0 0 0 0 10 10 10
56162 - 34 34 34 78 78 78 50 50 50 6 6 6
56163 - 94 70 30 139 102 15 190 146 13 226 184 13
56164 -232 200 30 232 195 16 215 174 15 190 146 13
56165 -168 122 10 192 133 9 210 150 10 213 154 11
56166 -202 150 34 182 157 106 101 98 89 2 2 6
56167 - 2 2 6 78 78 78 116 116 116 58 58 58
56168 - 2 2 6 22 22 22 90 90 90 46 46 46
56169 - 18 18 18 6 6 6 0 0 0 0 0 0
56170 - 0 0 0 0 0 0 0 0 0 0 0 0
56171 - 0 0 0 0 0 0 0 0 0 0 0 0
56172 - 0 0 0 0 0 0 0 0 0 0 0 0
56173 - 0 0 0 0 0 0 0 0 0 0 0 0
56174 - 0 0 0 0 0 0 0 0 0 0 0 0
56175 - 0 0 0 0 0 0 0 0 0 0 0 0
56176 - 0 0 0 0 0 0 0 0 0 0 0 0
56177 - 0 0 0 0 0 0 0 0 0 0 0 0
56178 - 0 0 0 0 0 0 0 0 0 0 0 0
56179 - 0 0 0 0 0 0 0 0 0 0 0 0
56180 - 0 0 0 0 0 0 0 0 0 0 0 0
56181 - 0 0 0 0 0 0 0 0 0 10 10 10
56182 - 38 38 38 86 86 86 50 50 50 6 6 6
56183 -128 128 128 174 154 114 156 107 11 168 122 10
56184 -198 155 10 184 144 12 197 138 11 200 144 11
56185 -206 145 10 206 145 10 197 138 11 188 164 115
56186 -195 195 195 198 198 198 174 174 174 14 14 14
56187 - 2 2 6 22 22 22 116 116 116 116 116 116
56188 - 22 22 22 2 2 6 74 74 74 70 70 70
56189 - 30 30 30 10 10 10 0 0 0 0 0 0
56190 - 0 0 0 0 0 0 0 0 0 0 0 0
56191 - 0 0 0 0 0 0 0 0 0 0 0 0
56192 - 0 0 0 0 0 0 0 0 0 0 0 0
56193 - 0 0 0 0 0 0 0 0 0 0 0 0
56194 - 0 0 0 0 0 0 0 0 0 0 0 0
56195 - 0 0 0 0 0 0 0 0 0 0 0 0
56196 - 0 0 0 0 0 0 0 0 0 0 0 0
56197 - 0 0 0 0 0 0 0 0 0 0 0 0
56198 - 0 0 0 0 0 0 0 0 0 0 0 0
56199 - 0 0 0 0 0 0 0 0 0 0 0 0
56200 - 0 0 0 0 0 0 0 0 0 0 0 0
56201 - 0 0 0 0 0 0 6 6 6 18 18 18
56202 - 50 50 50 101 101 101 26 26 26 10 10 10
56203 -138 138 138 190 190 190 174 154 114 156 107 11
56204 -197 138 11 200 144 11 197 138 11 192 133 9
56205 -180 123 7 190 142 34 190 178 144 187 187 187
56206 -202 202 202 221 221 221 214 214 214 66 66 66
56207 - 2 2 6 2 2 6 50 50 50 62 62 62
56208 - 6 6 6 2 2 6 10 10 10 90 90 90
56209 - 50 50 50 18 18 18 6 6 6 0 0 0
56210 - 0 0 0 0 0 0 0 0 0 0 0 0
56211 - 0 0 0 0 0 0 0 0 0 0 0 0
56212 - 0 0 0 0 0 0 0 0 0 0 0 0
56213 - 0 0 0 0 0 0 0 0 0 0 0 0
56214 - 0 0 0 0 0 0 0 0 0 0 0 0
56215 - 0 0 0 0 0 0 0 0 0 0 0 0
56216 - 0 0 0 0 0 0 0 0 0 0 0 0
56217 - 0 0 0 0 0 0 0 0 0 0 0 0
56218 - 0 0 0 0 0 0 0 0 0 0 0 0
56219 - 0 0 0 0 0 0 0 0 0 0 0 0
56220 - 0 0 0 0 0 0 0 0 0 0 0 0
56221 - 0 0 0 0 0 0 10 10 10 34 34 34
56222 - 74 74 74 74 74 74 2 2 6 6 6 6
56223 -144 144 144 198 198 198 190 190 190 178 166 146
56224 -154 121 60 156 107 11 156 107 11 168 124 44
56225 -174 154 114 187 187 187 190 190 190 210 210 210
56226 -246 246 246 253 253 253 253 253 253 182 182 182
56227 - 6 6 6 2 2 6 2 2 6 2 2 6
56228 - 2 2 6 2 2 6 2 2 6 62 62 62
56229 - 74 74 74 34 34 34 14 14 14 0 0 0
56230 - 0 0 0 0 0 0 0 0 0 0 0 0
56231 - 0 0 0 0 0 0 0 0 0 0 0 0
56232 - 0 0 0 0 0 0 0 0 0 0 0 0
56233 - 0 0 0 0 0 0 0 0 0 0 0 0
56234 - 0 0 0 0 0 0 0 0 0 0 0 0
56235 - 0 0 0 0 0 0 0 0 0 0 0 0
56236 - 0 0 0 0 0 0 0 0 0 0 0 0
56237 - 0 0 0 0 0 0 0 0 0 0 0 0
56238 - 0 0 0 0 0 0 0 0 0 0 0 0
56239 - 0 0 0 0 0 0 0 0 0 0 0 0
56240 - 0 0 0 0 0 0 0 0 0 0 0 0
56241 - 0 0 0 10 10 10 22 22 22 54 54 54
56242 - 94 94 94 18 18 18 2 2 6 46 46 46
56243 -234 234 234 221 221 221 190 190 190 190 190 190
56244 -190 190 190 187 187 187 187 187 187 190 190 190
56245 -190 190 190 195 195 195 214 214 214 242 242 242
56246 -253 253 253 253 253 253 253 253 253 253 253 253
56247 - 82 82 82 2 2 6 2 2 6 2 2 6
56248 - 2 2 6 2 2 6 2 2 6 14 14 14
56249 - 86 86 86 54 54 54 22 22 22 6 6 6
56250 - 0 0 0 0 0 0 0 0 0 0 0 0
56251 - 0 0 0 0 0 0 0 0 0 0 0 0
56252 - 0 0 0 0 0 0 0 0 0 0 0 0
56253 - 0 0 0 0 0 0 0 0 0 0 0 0
56254 - 0 0 0 0 0 0 0 0 0 0 0 0
56255 - 0 0 0 0 0 0 0 0 0 0 0 0
56256 - 0 0 0 0 0 0 0 0 0 0 0 0
56257 - 0 0 0 0 0 0 0 0 0 0 0 0
56258 - 0 0 0 0 0 0 0 0 0 0 0 0
56259 - 0 0 0 0 0 0 0 0 0 0 0 0
56260 - 0 0 0 0 0 0 0 0 0 0 0 0
56261 - 6 6 6 18 18 18 46 46 46 90 90 90
56262 - 46 46 46 18 18 18 6 6 6 182 182 182
56263 -253 253 253 246 246 246 206 206 206 190 190 190
56264 -190 190 190 190 190 190 190 190 190 190 190 190
56265 -206 206 206 231 231 231 250 250 250 253 253 253
56266 -253 253 253 253 253 253 253 253 253 253 253 253
56267 -202 202 202 14 14 14 2 2 6 2 2 6
56268 - 2 2 6 2 2 6 2 2 6 2 2 6
56269 - 42 42 42 86 86 86 42 42 42 18 18 18
56270 - 6 6 6 0 0 0 0 0 0 0 0 0
56271 - 0 0 0 0 0 0 0 0 0 0 0 0
56272 - 0 0 0 0 0 0 0 0 0 0 0 0
56273 - 0 0 0 0 0 0 0 0 0 0 0 0
56274 - 0 0 0 0 0 0 0 0 0 0 0 0
56275 - 0 0 0 0 0 0 0 0 0 0 0 0
56276 - 0 0 0 0 0 0 0 0 0 0 0 0
56277 - 0 0 0 0 0 0 0 0 0 0 0 0
56278 - 0 0 0 0 0 0 0 0 0 0 0 0
56279 - 0 0 0 0 0 0 0 0 0 0 0 0
56280 - 0 0 0 0 0 0 0 0 0 6 6 6
56281 - 14 14 14 38 38 38 74 74 74 66 66 66
56282 - 2 2 6 6 6 6 90 90 90 250 250 250
56283 -253 253 253 253 253 253 238 238 238 198 198 198
56284 -190 190 190 190 190 190 195 195 195 221 221 221
56285 -246 246 246 253 253 253 253 253 253 253 253 253
56286 -253 253 253 253 253 253 253 253 253 253 253 253
56287 -253 253 253 82 82 82 2 2 6 2 2 6
56288 - 2 2 6 2 2 6 2 2 6 2 2 6
56289 - 2 2 6 78 78 78 70 70 70 34 34 34
56290 - 14 14 14 6 6 6 0 0 0 0 0 0
56291 - 0 0 0 0 0 0 0 0 0 0 0 0
56292 - 0 0 0 0 0 0 0 0 0 0 0 0
56293 - 0 0 0 0 0 0 0 0 0 0 0 0
56294 - 0 0 0 0 0 0 0 0 0 0 0 0
56295 - 0 0 0 0 0 0 0 0 0 0 0 0
56296 - 0 0 0 0 0 0 0 0 0 0 0 0
56297 - 0 0 0 0 0 0 0 0 0 0 0 0
56298 - 0 0 0 0 0 0 0 0 0 0 0 0
56299 - 0 0 0 0 0 0 0 0 0 0 0 0
56300 - 0 0 0 0 0 0 0 0 0 14 14 14
56301 - 34 34 34 66 66 66 78 78 78 6 6 6
56302 - 2 2 6 18 18 18 218 218 218 253 253 253
56303 -253 253 253 253 253 253 253 253 253 246 246 246
56304 -226 226 226 231 231 231 246 246 246 253 253 253
56305 -253 253 253 253 253 253 253 253 253 253 253 253
56306 -253 253 253 253 253 253 253 253 253 253 253 253
56307 -253 253 253 178 178 178 2 2 6 2 2 6
56308 - 2 2 6 2 2 6 2 2 6 2 2 6
56309 - 2 2 6 18 18 18 90 90 90 62 62 62
56310 - 30 30 30 10 10 10 0 0 0 0 0 0
56311 - 0 0 0 0 0 0 0 0 0 0 0 0
56312 - 0 0 0 0 0 0 0 0 0 0 0 0
56313 - 0 0 0 0 0 0 0 0 0 0 0 0
56314 - 0 0 0 0 0 0 0 0 0 0 0 0
56315 - 0 0 0 0 0 0 0 0 0 0 0 0
56316 - 0 0 0 0 0 0 0 0 0 0 0 0
56317 - 0 0 0 0 0 0 0 0 0 0 0 0
56318 - 0 0 0 0 0 0 0 0 0 0 0 0
56319 - 0 0 0 0 0 0 0 0 0 0 0 0
56320 - 0 0 0 0 0 0 10 10 10 26 26 26
56321 - 58 58 58 90 90 90 18 18 18 2 2 6
56322 - 2 2 6 110 110 110 253 253 253 253 253 253
56323 -253 253 253 253 253 253 253 253 253 253 253 253
56324 -250 250 250 253 253 253 253 253 253 253 253 253
56325 -253 253 253 253 253 253 253 253 253 253 253 253
56326 -253 253 253 253 253 253 253 253 253 253 253 253
56327 -253 253 253 231 231 231 18 18 18 2 2 6
56328 - 2 2 6 2 2 6 2 2 6 2 2 6
56329 - 2 2 6 2 2 6 18 18 18 94 94 94
56330 - 54 54 54 26 26 26 10 10 10 0 0 0
56331 - 0 0 0 0 0 0 0 0 0 0 0 0
56332 - 0 0 0 0 0 0 0 0 0 0 0 0
56333 - 0 0 0 0 0 0 0 0 0 0 0 0
56334 - 0 0 0 0 0 0 0 0 0 0 0 0
56335 - 0 0 0 0 0 0 0 0 0 0 0 0
56336 - 0 0 0 0 0 0 0 0 0 0 0 0
56337 - 0 0 0 0 0 0 0 0 0 0 0 0
56338 - 0 0 0 0 0 0 0 0 0 0 0 0
56339 - 0 0 0 0 0 0 0 0 0 0 0 0
56340 - 0 0 0 6 6 6 22 22 22 50 50 50
56341 - 90 90 90 26 26 26 2 2 6 2 2 6
56342 - 14 14 14 195 195 195 250 250 250 253 253 253
56343 -253 253 253 253 253 253 253 253 253 253 253 253
56344 -253 253 253 253 253 253 253 253 253 253 253 253
56345 -253 253 253 253 253 253 253 253 253 253 253 253
56346 -253 253 253 253 253 253 253 253 253 253 253 253
56347 -250 250 250 242 242 242 54 54 54 2 2 6
56348 - 2 2 6 2 2 6 2 2 6 2 2 6
56349 - 2 2 6 2 2 6 2 2 6 38 38 38
56350 - 86 86 86 50 50 50 22 22 22 6 6 6
56351 - 0 0 0 0 0 0 0 0 0 0 0 0
56352 - 0 0 0 0 0 0 0 0 0 0 0 0
56353 - 0 0 0 0 0 0 0 0 0 0 0 0
56354 - 0 0 0 0 0 0 0 0 0 0 0 0
56355 - 0 0 0 0 0 0 0 0 0 0 0 0
56356 - 0 0 0 0 0 0 0 0 0 0 0 0
56357 - 0 0 0 0 0 0 0 0 0 0 0 0
56358 - 0 0 0 0 0 0 0 0 0 0 0 0
56359 - 0 0 0 0 0 0 0 0 0 0 0 0
56360 - 6 6 6 14 14 14 38 38 38 82 82 82
56361 - 34 34 34 2 2 6 2 2 6 2 2 6
56362 - 42 42 42 195 195 195 246 246 246 253 253 253
56363 -253 253 253 253 253 253 253 253 253 250 250 250
56364 -242 242 242 242 242 242 250 250 250 253 253 253
56365 -253 253 253 253 253 253 253 253 253 253 253 253
56366 -253 253 253 250 250 250 246 246 246 238 238 238
56367 -226 226 226 231 231 231 101 101 101 6 6 6
56368 - 2 2 6 2 2 6 2 2 6 2 2 6
56369 - 2 2 6 2 2 6 2 2 6 2 2 6
56370 - 38 38 38 82 82 82 42 42 42 14 14 14
56371 - 6 6 6 0 0 0 0 0 0 0 0 0
56372 - 0 0 0 0 0 0 0 0 0 0 0 0
56373 - 0 0 0 0 0 0 0 0 0 0 0 0
56374 - 0 0 0 0 0 0 0 0 0 0 0 0
56375 - 0 0 0 0 0 0 0 0 0 0 0 0
56376 - 0 0 0 0 0 0 0 0 0 0 0 0
56377 - 0 0 0 0 0 0 0 0 0 0 0 0
56378 - 0 0 0 0 0 0 0 0 0 0 0 0
56379 - 0 0 0 0 0 0 0 0 0 0 0 0
56380 - 10 10 10 26 26 26 62 62 62 66 66 66
56381 - 2 2 6 2 2 6 2 2 6 6 6 6
56382 - 70 70 70 170 170 170 206 206 206 234 234 234
56383 -246 246 246 250 250 250 250 250 250 238 238 238
56384 -226 226 226 231 231 231 238 238 238 250 250 250
56385 -250 250 250 250 250 250 246 246 246 231 231 231
56386 -214 214 214 206 206 206 202 202 202 202 202 202
56387 -198 198 198 202 202 202 182 182 182 18 18 18
56388 - 2 2 6 2 2 6 2 2 6 2 2 6
56389 - 2 2 6 2 2 6 2 2 6 2 2 6
56390 - 2 2 6 62 62 62 66 66 66 30 30 30
56391 - 10 10 10 0 0 0 0 0 0 0 0 0
56392 - 0 0 0 0 0 0 0 0 0 0 0 0
56393 - 0 0 0 0 0 0 0 0 0 0 0 0
56394 - 0 0 0 0 0 0 0 0 0 0 0 0
56395 - 0 0 0 0 0 0 0 0 0 0 0 0
56396 - 0 0 0 0 0 0 0 0 0 0 0 0
56397 - 0 0 0 0 0 0 0 0 0 0 0 0
56398 - 0 0 0 0 0 0 0 0 0 0 0 0
56399 - 0 0 0 0 0 0 0 0 0 0 0 0
56400 - 14 14 14 42 42 42 82 82 82 18 18 18
56401 - 2 2 6 2 2 6 2 2 6 10 10 10
56402 - 94 94 94 182 182 182 218 218 218 242 242 242
56403 -250 250 250 253 253 253 253 253 253 250 250 250
56404 -234 234 234 253 253 253 253 253 253 253 253 253
56405 -253 253 253 253 253 253 253 253 253 246 246 246
56406 -238 238 238 226 226 226 210 210 210 202 202 202
56407 -195 195 195 195 195 195 210 210 210 158 158 158
56408 - 6 6 6 14 14 14 50 50 50 14 14 14
56409 - 2 2 6 2 2 6 2 2 6 2 2 6
56410 - 2 2 6 6 6 6 86 86 86 46 46 46
56411 - 18 18 18 6 6 6 0 0 0 0 0 0
56412 - 0 0 0 0 0 0 0 0 0 0 0 0
56413 - 0 0 0 0 0 0 0 0 0 0 0 0
56414 - 0 0 0 0 0 0 0 0 0 0 0 0
56415 - 0 0 0 0 0 0 0 0 0 0 0 0
56416 - 0 0 0 0 0 0 0 0 0 0 0 0
56417 - 0 0 0 0 0 0 0 0 0 0 0 0
56418 - 0 0 0 0 0 0 0 0 0 0 0 0
56419 - 0 0 0 0 0 0 0 0 0 6 6 6
56420 - 22 22 22 54 54 54 70 70 70 2 2 6
56421 - 2 2 6 10 10 10 2 2 6 22 22 22
56422 -166 166 166 231 231 231 250 250 250 253 253 253
56423 -253 253 253 253 253 253 253 253 253 250 250 250
56424 -242 242 242 253 253 253 253 253 253 253 253 253
56425 -253 253 253 253 253 253 253 253 253 253 253 253
56426 -253 253 253 253 253 253 253 253 253 246 246 246
56427 -231 231 231 206 206 206 198 198 198 226 226 226
56428 - 94 94 94 2 2 6 6 6 6 38 38 38
56429 - 30 30 30 2 2 6 2 2 6 2 2 6
56430 - 2 2 6 2 2 6 62 62 62 66 66 66
56431 - 26 26 26 10 10 10 0 0 0 0 0 0
56432 - 0 0 0 0 0 0 0 0 0 0 0 0
56433 - 0 0 0 0 0 0 0 0 0 0 0 0
56434 - 0 0 0 0 0 0 0 0 0 0 0 0
56435 - 0 0 0 0 0 0 0 0 0 0 0 0
56436 - 0 0 0 0 0 0 0 0 0 0 0 0
56437 - 0 0 0 0 0 0 0 0 0 0 0 0
56438 - 0 0 0 0 0 0 0 0 0 0 0 0
56439 - 0 0 0 0 0 0 0 0 0 10 10 10
56440 - 30 30 30 74 74 74 50 50 50 2 2 6
56441 - 26 26 26 26 26 26 2 2 6 106 106 106
56442 -238 238 238 253 253 253 253 253 253 253 253 253
56443 -253 253 253 253 253 253 253 253 253 253 253 253
56444 -253 253 253 253 253 253 253 253 253 253 253 253
56445 -253 253 253 253 253 253 253 253 253 253 253 253
56446 -253 253 253 253 253 253 253 253 253 253 253 253
56447 -253 253 253 246 246 246 218 218 218 202 202 202
56448 -210 210 210 14 14 14 2 2 6 2 2 6
56449 - 30 30 30 22 22 22 2 2 6 2 2 6
56450 - 2 2 6 2 2 6 18 18 18 86 86 86
56451 - 42 42 42 14 14 14 0 0 0 0 0 0
56452 - 0 0 0 0 0 0 0 0 0 0 0 0
56453 - 0 0 0 0 0 0 0 0 0 0 0 0
56454 - 0 0 0 0 0 0 0 0 0 0 0 0
56455 - 0 0 0 0 0 0 0 0 0 0 0 0
56456 - 0 0 0 0 0 0 0 0 0 0 0 0
56457 - 0 0 0 0 0 0 0 0 0 0 0 0
56458 - 0 0 0 0 0 0 0 0 0 0 0 0
56459 - 0 0 0 0 0 0 0 0 0 14 14 14
56460 - 42 42 42 90 90 90 22 22 22 2 2 6
56461 - 42 42 42 2 2 6 18 18 18 218 218 218
56462 -253 253 253 253 253 253 253 253 253 253 253 253
56463 -253 253 253 253 253 253 253 253 253 253 253 253
56464 -253 253 253 253 253 253 253 253 253 253 253 253
56465 -253 253 253 253 253 253 253 253 253 253 253 253
56466 -253 253 253 253 253 253 253 253 253 253 253 253
56467 -253 253 253 253 253 253 250 250 250 221 221 221
56468 -218 218 218 101 101 101 2 2 6 14 14 14
56469 - 18 18 18 38 38 38 10 10 10 2 2 6
56470 - 2 2 6 2 2 6 2 2 6 78 78 78
56471 - 58 58 58 22 22 22 6 6 6 0 0 0
56472 - 0 0 0 0 0 0 0 0 0 0 0 0
56473 - 0 0 0 0 0 0 0 0 0 0 0 0
56474 - 0 0 0 0 0 0 0 0 0 0 0 0
56475 - 0 0 0 0 0 0 0 0 0 0 0 0
56476 - 0 0 0 0 0 0 0 0 0 0 0 0
56477 - 0 0 0 0 0 0 0 0 0 0 0 0
56478 - 0 0 0 0 0 0 0 0 0 0 0 0
56479 - 0 0 0 0 0 0 6 6 6 18 18 18
56480 - 54 54 54 82 82 82 2 2 6 26 26 26
56481 - 22 22 22 2 2 6 123 123 123 253 253 253
56482 -253 253 253 253 253 253 253 253 253 253 253 253
56483 -253 253 253 253 253 253 253 253 253 253 253 253
56484 -253 253 253 253 253 253 253 253 253 253 253 253
56485 -253 253 253 253 253 253 253 253 253 253 253 253
56486 -253 253 253 253 253 253 253 253 253 253 253 253
56487 -253 253 253 253 253 253 253 253 253 250 250 250
56488 -238 238 238 198 198 198 6 6 6 38 38 38
56489 - 58 58 58 26 26 26 38 38 38 2 2 6
56490 - 2 2 6 2 2 6 2 2 6 46 46 46
56491 - 78 78 78 30 30 30 10 10 10 0 0 0
56492 - 0 0 0 0 0 0 0 0 0 0 0 0
56493 - 0 0 0 0 0 0 0 0 0 0 0 0
56494 - 0 0 0 0 0 0 0 0 0 0 0 0
56495 - 0 0 0 0 0 0 0 0 0 0 0 0
56496 - 0 0 0 0 0 0 0 0 0 0 0 0
56497 - 0 0 0 0 0 0 0 0 0 0 0 0
56498 - 0 0 0 0 0 0 0 0 0 0 0 0
56499 - 0 0 0 0 0 0 10 10 10 30 30 30
56500 - 74 74 74 58 58 58 2 2 6 42 42 42
56501 - 2 2 6 22 22 22 231 231 231 253 253 253
56502 -253 253 253 253 253 253 253 253 253 253 253 253
56503 -253 253 253 253 253 253 253 253 253 250 250 250
56504 -253 253 253 253 253 253 253 253 253 253 253 253
56505 -253 253 253 253 253 253 253 253 253 253 253 253
56506 -253 253 253 253 253 253 253 253 253 253 253 253
56507 -253 253 253 253 253 253 253 253 253 253 253 253
56508 -253 253 253 246 246 246 46 46 46 38 38 38
56509 - 42 42 42 14 14 14 38 38 38 14 14 14
56510 - 2 2 6 2 2 6 2 2 6 6 6 6
56511 - 86 86 86 46 46 46 14 14 14 0 0 0
56512 - 0 0 0 0 0 0 0 0 0 0 0 0
56513 - 0 0 0 0 0 0 0 0 0 0 0 0
56514 - 0 0 0 0 0 0 0 0 0 0 0 0
56515 - 0 0 0 0 0 0 0 0 0 0 0 0
56516 - 0 0 0 0 0 0 0 0 0 0 0 0
56517 - 0 0 0 0 0 0 0 0 0 0 0 0
56518 - 0 0 0 0 0 0 0 0 0 0 0 0
56519 - 0 0 0 6 6 6 14 14 14 42 42 42
56520 - 90 90 90 18 18 18 18 18 18 26 26 26
56521 - 2 2 6 116 116 116 253 253 253 253 253 253
56522 -253 253 253 253 253 253 253 253 253 253 253 253
56523 -253 253 253 253 253 253 250 250 250 238 238 238
56524 -253 253 253 253 253 253 253 253 253 253 253 253
56525 -253 253 253 253 253 253 253 253 253 253 253 253
56526 -253 253 253 253 253 253 253 253 253 253 253 253
56527 -253 253 253 253 253 253 253 253 253 253 253 253
56528 -253 253 253 253 253 253 94 94 94 6 6 6
56529 - 2 2 6 2 2 6 10 10 10 34 34 34
56530 - 2 2 6 2 2 6 2 2 6 2 2 6
56531 - 74 74 74 58 58 58 22 22 22 6 6 6
56532 - 0 0 0 0 0 0 0 0 0 0 0 0
56533 - 0 0 0 0 0 0 0 0 0 0 0 0
56534 - 0 0 0 0 0 0 0 0 0 0 0 0
56535 - 0 0 0 0 0 0 0 0 0 0 0 0
56536 - 0 0 0 0 0 0 0 0 0 0 0 0
56537 - 0 0 0 0 0 0 0 0 0 0 0 0
56538 - 0 0 0 0 0 0 0 0 0 0 0 0
56539 - 0 0 0 10 10 10 26 26 26 66 66 66
56540 - 82 82 82 2 2 6 38 38 38 6 6 6
56541 - 14 14 14 210 210 210 253 253 253 253 253 253
56542 -253 253 253 253 253 253 253 253 253 253 253 253
56543 -253 253 253 253 253 253 246 246 246 242 242 242
56544 -253 253 253 253 253 253 253 253 253 253 253 253
56545 -253 253 253 253 253 253 253 253 253 253 253 253
56546 -253 253 253 253 253 253 253 253 253 253 253 253
56547 -253 253 253 253 253 253 253 253 253 253 253 253
56548 -253 253 253 253 253 253 144 144 144 2 2 6
56549 - 2 2 6 2 2 6 2 2 6 46 46 46
56550 - 2 2 6 2 2 6 2 2 6 2 2 6
56551 - 42 42 42 74 74 74 30 30 30 10 10 10
56552 - 0 0 0 0 0 0 0 0 0 0 0 0
56553 - 0 0 0 0 0 0 0 0 0 0 0 0
56554 - 0 0 0 0 0 0 0 0 0 0 0 0
56555 - 0 0 0 0 0 0 0 0 0 0 0 0
56556 - 0 0 0 0 0 0 0 0 0 0 0 0
56557 - 0 0 0 0 0 0 0 0 0 0 0 0
56558 - 0 0 0 0 0 0 0 0 0 0 0 0
56559 - 6 6 6 14 14 14 42 42 42 90 90 90
56560 - 26 26 26 6 6 6 42 42 42 2 2 6
56561 - 74 74 74 250 250 250 253 253 253 253 253 253
56562 -253 253 253 253 253 253 253 253 253 253 253 253
56563 -253 253 253 253 253 253 242 242 242 242 242 242
56564 -253 253 253 253 253 253 253 253 253 253 253 253
56565 -253 253 253 253 253 253 253 253 253 253 253 253
56566 -253 253 253 253 253 253 253 253 253 253 253 253
56567 -253 253 253 253 253 253 253 253 253 253 253 253
56568 -253 253 253 253 253 253 182 182 182 2 2 6
56569 - 2 2 6 2 2 6 2 2 6 46 46 46
56570 - 2 2 6 2 2 6 2 2 6 2 2 6
56571 - 10 10 10 86 86 86 38 38 38 10 10 10
56572 - 0 0 0 0 0 0 0 0 0 0 0 0
56573 - 0 0 0 0 0 0 0 0 0 0 0 0
56574 - 0 0 0 0 0 0 0 0 0 0 0 0
56575 - 0 0 0 0 0 0 0 0 0 0 0 0
56576 - 0 0 0 0 0 0 0 0 0 0 0 0
56577 - 0 0 0 0 0 0 0 0 0 0 0 0
56578 - 0 0 0 0 0 0 0 0 0 0 0 0
56579 - 10 10 10 26 26 26 66 66 66 82 82 82
56580 - 2 2 6 22 22 22 18 18 18 2 2 6
56581 -149 149 149 253 253 253 253 253 253 253 253 253
56582 -253 253 253 253 253 253 253 253 253 253 253 253
56583 -253 253 253 253 253 253 234 234 234 242 242 242
56584 -253 253 253 253 253 253 253 253 253 253 253 253
56585 -253 253 253 253 253 253 253 253 253 253 253 253
56586 -253 253 253 253 253 253 253 253 253 253 253 253
56587 -253 253 253 253 253 253 253 253 253 253 253 253
56588 -253 253 253 253 253 253 206 206 206 2 2 6
56589 - 2 2 6 2 2 6 2 2 6 38 38 38
56590 - 2 2 6 2 2 6 2 2 6 2 2 6
56591 - 6 6 6 86 86 86 46 46 46 14 14 14
56592 - 0 0 0 0 0 0 0 0 0 0 0 0
56593 - 0 0 0 0 0 0 0 0 0 0 0 0
56594 - 0 0 0 0 0 0 0 0 0 0 0 0
56595 - 0 0 0 0 0 0 0 0 0 0 0 0
56596 - 0 0 0 0 0 0 0 0 0 0 0 0
56597 - 0 0 0 0 0 0 0 0 0 0 0 0
56598 - 0 0 0 0 0 0 0 0 0 6 6 6
56599 - 18 18 18 46 46 46 86 86 86 18 18 18
56600 - 2 2 6 34 34 34 10 10 10 6 6 6
56601 -210 210 210 253 253 253 253 253 253 253 253 253
56602 -253 253 253 253 253 253 253 253 253 253 253 253
56603 -253 253 253 253 253 253 234 234 234 242 242 242
56604 -253 253 253 253 253 253 253 253 253 253 253 253
56605 -253 253 253 253 253 253 253 253 253 253 253 253
56606 -253 253 253 253 253 253 253 253 253 253 253 253
56607 -253 253 253 253 253 253 253 253 253 253 253 253
56608 -253 253 253 253 253 253 221 221 221 6 6 6
56609 - 2 2 6 2 2 6 6 6 6 30 30 30
56610 - 2 2 6 2 2 6 2 2 6 2 2 6
56611 - 2 2 6 82 82 82 54 54 54 18 18 18
56612 - 6 6 6 0 0 0 0 0 0 0 0 0
56613 - 0 0 0 0 0 0 0 0 0 0 0 0
56614 - 0 0 0 0 0 0 0 0 0 0 0 0
56615 - 0 0 0 0 0 0 0 0 0 0 0 0
56616 - 0 0 0 0 0 0 0 0 0 0 0 0
56617 - 0 0 0 0 0 0 0 0 0 0 0 0
56618 - 0 0 0 0 0 0 0 0 0 10 10 10
56619 - 26 26 26 66 66 66 62 62 62 2 2 6
56620 - 2 2 6 38 38 38 10 10 10 26 26 26
56621 -238 238 238 253 253 253 253 253 253 253 253 253
56622 -253 253 253 253 253 253 253 253 253 253 253 253
56623 -253 253 253 253 253 253 231 231 231 238 238 238
56624 -253 253 253 253 253 253 253 253 253 253 253 253
56625 -253 253 253 253 253 253 253 253 253 253 253 253
56626 -253 253 253 253 253 253 253 253 253 253 253 253
56627 -253 253 253 253 253 253 253 253 253 253 253 253
56628 -253 253 253 253 253 253 231 231 231 6 6 6
56629 - 2 2 6 2 2 6 10 10 10 30 30 30
56630 - 2 2 6 2 2 6 2 2 6 2 2 6
56631 - 2 2 6 66 66 66 58 58 58 22 22 22
56632 - 6 6 6 0 0 0 0 0 0 0 0 0
56633 - 0 0 0 0 0 0 0 0 0 0 0 0
56634 - 0 0 0 0 0 0 0 0 0 0 0 0
56635 - 0 0 0 0 0 0 0 0 0 0 0 0
56636 - 0 0 0 0 0 0 0 0 0 0 0 0
56637 - 0 0 0 0 0 0 0 0 0 0 0 0
56638 - 0 0 0 0 0 0 0 0 0 10 10 10
56639 - 38 38 38 78 78 78 6 6 6 2 2 6
56640 - 2 2 6 46 46 46 14 14 14 42 42 42
56641 -246 246 246 253 253 253 253 253 253 253 253 253
56642 -253 253 253 253 253 253 253 253 253 253 253 253
56643 -253 253 253 253 253 253 231 231 231 242 242 242
56644 -253 253 253 253 253 253 253 253 253 253 253 253
56645 -253 253 253 253 253 253 253 253 253 253 253 253
56646 -253 253 253 253 253 253 253 253 253 253 253 253
56647 -253 253 253 253 253 253 253 253 253 253 253 253
56648 -253 253 253 253 253 253 234 234 234 10 10 10
56649 - 2 2 6 2 2 6 22 22 22 14 14 14
56650 - 2 2 6 2 2 6 2 2 6 2 2 6
56651 - 2 2 6 66 66 66 62 62 62 22 22 22
56652 - 6 6 6 0 0 0 0 0 0 0 0 0
56653 - 0 0 0 0 0 0 0 0 0 0 0 0
56654 - 0 0 0 0 0 0 0 0 0 0 0 0
56655 - 0 0 0 0 0 0 0 0 0 0 0 0
56656 - 0 0 0 0 0 0 0 0 0 0 0 0
56657 - 0 0 0 0 0 0 0 0 0 0 0 0
56658 - 0 0 0 0 0 0 6 6 6 18 18 18
56659 - 50 50 50 74 74 74 2 2 6 2 2 6
56660 - 14 14 14 70 70 70 34 34 34 62 62 62
56661 -250 250 250 253 253 253 253 253 253 253 253 253
56662 -253 253 253 253 253 253 253 253 253 253 253 253
56663 -253 253 253 253 253 253 231 231 231 246 246 246
56664 -253 253 253 253 253 253 253 253 253 253 253 253
56665 -253 253 253 253 253 253 253 253 253 253 253 253
56666 -253 253 253 253 253 253 253 253 253 253 253 253
56667 -253 253 253 253 253 253 253 253 253 253 253 253
56668 -253 253 253 253 253 253 234 234 234 14 14 14
56669 - 2 2 6 2 2 6 30 30 30 2 2 6
56670 - 2 2 6 2 2 6 2 2 6 2 2 6
56671 - 2 2 6 66 66 66 62 62 62 22 22 22
56672 - 6 6 6 0 0 0 0 0 0 0 0 0
56673 - 0 0 0 0 0 0 0 0 0 0 0 0
56674 - 0 0 0 0 0 0 0 0 0 0 0 0
56675 - 0 0 0 0 0 0 0 0 0 0 0 0
56676 - 0 0 0 0 0 0 0 0 0 0 0 0
56677 - 0 0 0 0 0 0 0 0 0 0 0 0
56678 - 0 0 0 0 0 0 6 6 6 18 18 18
56679 - 54 54 54 62 62 62 2 2 6 2 2 6
56680 - 2 2 6 30 30 30 46 46 46 70 70 70
56681 -250 250 250 253 253 253 253 253 253 253 253 253
56682 -253 253 253 253 253 253 253 253 253 253 253 253
56683 -253 253 253 253 253 253 231 231 231 246 246 246
56684 -253 253 253 253 253 253 253 253 253 253 253 253
56685 -253 253 253 253 253 253 253 253 253 253 253 253
56686 -253 253 253 253 253 253 253 253 253 253 253 253
56687 -253 253 253 253 253 253 253 253 253 253 253 253
56688 -253 253 253 253 253 253 226 226 226 10 10 10
56689 - 2 2 6 6 6 6 30 30 30 2 2 6
56690 - 2 2 6 2 2 6 2 2 6 2 2 6
56691 - 2 2 6 66 66 66 58 58 58 22 22 22
56692 - 6 6 6 0 0 0 0 0 0 0 0 0
56693 - 0 0 0 0 0 0 0 0 0 0 0 0
56694 - 0 0 0 0 0 0 0 0 0 0 0 0
56695 - 0 0 0 0 0 0 0 0 0 0 0 0
56696 - 0 0 0 0 0 0 0 0 0 0 0 0
56697 - 0 0 0 0 0 0 0 0 0 0 0 0
56698 - 0 0 0 0 0 0 6 6 6 22 22 22
56699 - 58 58 58 62 62 62 2 2 6 2 2 6
56700 - 2 2 6 2 2 6 30 30 30 78 78 78
56701 -250 250 250 253 253 253 253 253 253 253 253 253
56702 -253 253 253 253 253 253 253 253 253 253 253 253
56703 -253 253 253 253 253 253 231 231 231 246 246 246
56704 -253 253 253 253 253 253 253 253 253 253 253 253
56705 -253 253 253 253 253 253 253 253 253 253 253 253
56706 -253 253 253 253 253 253 253 253 253 253 253 253
56707 -253 253 253 253 253 253 253 253 253 253 253 253
56708 -253 253 253 253 253 253 206 206 206 2 2 6
56709 - 22 22 22 34 34 34 18 14 6 22 22 22
56710 - 26 26 26 18 18 18 6 6 6 2 2 6
56711 - 2 2 6 82 82 82 54 54 54 18 18 18
56712 - 6 6 6 0 0 0 0 0 0 0 0 0
56713 - 0 0 0 0 0 0 0 0 0 0 0 0
56714 - 0 0 0 0 0 0 0 0 0 0 0 0
56715 - 0 0 0 0 0 0 0 0 0 0 0 0
56716 - 0 0 0 0 0 0 0 0 0 0 0 0
56717 - 0 0 0 0 0 0 0 0 0 0 0 0
56718 - 0 0 0 0 0 0 6 6 6 26 26 26
56719 - 62 62 62 106 106 106 74 54 14 185 133 11
56720 -210 162 10 121 92 8 6 6 6 62 62 62
56721 -238 238 238 253 253 253 253 253 253 253 253 253
56722 -253 253 253 253 253 253 253 253 253 253 253 253
56723 -253 253 253 253 253 253 231 231 231 246 246 246
56724 -253 253 253 253 253 253 253 253 253 253 253 253
56725 -253 253 253 253 253 253 253 253 253 253 253 253
56726 -253 253 253 253 253 253 253 253 253 253 253 253
56727 -253 253 253 253 253 253 253 253 253 253 253 253
56728 -253 253 253 253 253 253 158 158 158 18 18 18
56729 - 14 14 14 2 2 6 2 2 6 2 2 6
56730 - 6 6 6 18 18 18 66 66 66 38 38 38
56731 - 6 6 6 94 94 94 50 50 50 18 18 18
56732 - 6 6 6 0 0 0 0 0 0 0 0 0
56733 - 0 0 0 0 0 0 0 0 0 0 0 0
56734 - 0 0 0 0 0 0 0 0 0 0 0 0
56735 - 0 0 0 0 0 0 0 0 0 0 0 0
56736 - 0 0 0 0 0 0 0 0 0 0 0 0
56737 - 0 0 0 0 0 0 0 0 0 6 6 6
56738 - 10 10 10 10 10 10 18 18 18 38 38 38
56739 - 78 78 78 142 134 106 216 158 10 242 186 14
56740 -246 190 14 246 190 14 156 118 10 10 10 10
56741 - 90 90 90 238 238 238 253 253 253 253 253 253
56742 -253 253 253 253 253 253 253 253 253 253 253 253
56743 -253 253 253 253 253 253 231 231 231 250 250 250
56744 -253 253 253 253 253 253 253 253 253 253 253 253
56745 -253 253 253 253 253 253 253 253 253 253 253 253
56746 -253 253 253 253 253 253 253 253 253 253 253 253
56747 -253 253 253 253 253 253 253 253 253 246 230 190
56748 -238 204 91 238 204 91 181 142 44 37 26 9
56749 - 2 2 6 2 2 6 2 2 6 2 2 6
56750 - 2 2 6 2 2 6 38 38 38 46 46 46
56751 - 26 26 26 106 106 106 54 54 54 18 18 18
56752 - 6 6 6 0 0 0 0 0 0 0 0 0
56753 - 0 0 0 0 0 0 0 0 0 0 0 0
56754 - 0 0 0 0 0 0 0 0 0 0 0 0
56755 - 0 0 0 0 0 0 0 0 0 0 0 0
56756 - 0 0 0 0 0 0 0 0 0 0 0 0
56757 - 0 0 0 6 6 6 14 14 14 22 22 22
56758 - 30 30 30 38 38 38 50 50 50 70 70 70
56759 -106 106 106 190 142 34 226 170 11 242 186 14
56760 -246 190 14 246 190 14 246 190 14 154 114 10
56761 - 6 6 6 74 74 74 226 226 226 253 253 253
56762 -253 253 253 253 253 253 253 253 253 253 253 253
56763 -253 253 253 253 253 253 231 231 231 250 250 250
56764 -253 253 253 253 253 253 253 253 253 253 253 253
56765 -253 253 253 253 253 253 253 253 253 253 253 253
56766 -253 253 253 253 253 253 253 253 253 253 253 253
56767 -253 253 253 253 253 253 253 253 253 228 184 62
56768 -241 196 14 241 208 19 232 195 16 38 30 10
56769 - 2 2 6 2 2 6 2 2 6 2 2 6
56770 - 2 2 6 6 6 6 30 30 30 26 26 26
56771 -203 166 17 154 142 90 66 66 66 26 26 26
56772 - 6 6 6 0 0 0 0 0 0 0 0 0
56773 - 0 0 0 0 0 0 0 0 0 0 0 0
56774 - 0 0 0 0 0 0 0 0 0 0 0 0
56775 - 0 0 0 0 0 0 0 0 0 0 0 0
56776 - 0 0 0 0 0 0 0 0 0 0 0 0
56777 - 6 6 6 18 18 18 38 38 38 58 58 58
56778 - 78 78 78 86 86 86 101 101 101 123 123 123
56779 -175 146 61 210 150 10 234 174 13 246 186 14
56780 -246 190 14 246 190 14 246 190 14 238 190 10
56781 -102 78 10 2 2 6 46 46 46 198 198 198
56782 -253 253 253 253 253 253 253 253 253 253 253 253
56783 -253 253 253 253 253 253 234 234 234 242 242 242
56784 -253 253 253 253 253 253 253 253 253 253 253 253
56785 -253 253 253 253 253 253 253 253 253 253 253 253
56786 -253 253 253 253 253 253 253 253 253 253 253 253
56787 -253 253 253 253 253 253 253 253 253 224 178 62
56788 -242 186 14 241 196 14 210 166 10 22 18 6
56789 - 2 2 6 2 2 6 2 2 6 2 2 6
56790 - 2 2 6 2 2 6 6 6 6 121 92 8
56791 -238 202 15 232 195 16 82 82 82 34 34 34
56792 - 10 10 10 0 0 0 0 0 0 0 0 0
56793 - 0 0 0 0 0 0 0 0 0 0 0 0
56794 - 0 0 0 0 0 0 0 0 0 0 0 0
56795 - 0 0 0 0 0 0 0 0 0 0 0 0
56796 - 0 0 0 0 0 0 0 0 0 0 0 0
56797 - 14 14 14 38 38 38 70 70 70 154 122 46
56798 -190 142 34 200 144 11 197 138 11 197 138 11
56799 -213 154 11 226 170 11 242 186 14 246 190 14
56800 -246 190 14 246 190 14 246 190 14 246 190 14
56801 -225 175 15 46 32 6 2 2 6 22 22 22
56802 -158 158 158 250 250 250 253 253 253 253 253 253
56803 -253 253 253 253 253 253 253 253 253 253 253 253
56804 -253 253 253 253 253 253 253 253 253 253 253 253
56805 -253 253 253 253 253 253 253 253 253 253 253 253
56806 -253 253 253 253 253 253 253 253 253 253 253 253
56807 -253 253 253 250 250 250 242 242 242 224 178 62
56808 -239 182 13 236 186 11 213 154 11 46 32 6
56809 - 2 2 6 2 2 6 2 2 6 2 2 6
56810 - 2 2 6 2 2 6 61 42 6 225 175 15
56811 -238 190 10 236 186 11 112 100 78 42 42 42
56812 - 14 14 14 0 0 0 0 0 0 0 0 0
56813 - 0 0 0 0 0 0 0 0 0 0 0 0
56814 - 0 0 0 0 0 0 0 0 0 0 0 0
56815 - 0 0 0 0 0 0 0 0 0 0 0 0
56816 - 0 0 0 0 0 0 0 0 0 6 6 6
56817 - 22 22 22 54 54 54 154 122 46 213 154 11
56818 -226 170 11 230 174 11 226 170 11 226 170 11
56819 -236 178 12 242 186 14 246 190 14 246 190 14
56820 -246 190 14 246 190 14 246 190 14 246 190 14
56821 -241 196 14 184 144 12 10 10 10 2 2 6
56822 - 6 6 6 116 116 116 242 242 242 253 253 253
56823 -253 253 253 253 253 253 253 253 253 253 253 253
56824 -253 253 253 253 253 253 253 253 253 253 253 253
56825 -253 253 253 253 253 253 253 253 253 253 253 253
56826 -253 253 253 253 253 253 253 253 253 253 253 253
56827 -253 253 253 231 231 231 198 198 198 214 170 54
56828 -236 178 12 236 178 12 210 150 10 137 92 6
56829 - 18 14 6 2 2 6 2 2 6 2 2 6
56830 - 6 6 6 70 47 6 200 144 11 236 178 12
56831 -239 182 13 239 182 13 124 112 88 58 58 58
56832 - 22 22 22 6 6 6 0 0 0 0 0 0
56833 - 0 0 0 0 0 0 0 0 0 0 0 0
56834 - 0 0 0 0 0 0 0 0 0 0 0 0
56835 - 0 0 0 0 0 0 0 0 0 0 0 0
56836 - 0 0 0 0 0 0 0 0 0 10 10 10
56837 - 30 30 30 70 70 70 180 133 36 226 170 11
56838 -239 182 13 242 186 14 242 186 14 246 186 14
56839 -246 190 14 246 190 14 246 190 14 246 190 14
56840 -246 190 14 246 190 14 246 190 14 246 190 14
56841 -246 190 14 232 195 16 98 70 6 2 2 6
56842 - 2 2 6 2 2 6 66 66 66 221 221 221
56843 -253 253 253 253 253 253 253 253 253 253 253 253
56844 -253 253 253 253 253 253 253 253 253 253 253 253
56845 -253 253 253 253 253 253 253 253 253 253 253 253
56846 -253 253 253 253 253 253 253 253 253 253 253 253
56847 -253 253 253 206 206 206 198 198 198 214 166 58
56848 -230 174 11 230 174 11 216 158 10 192 133 9
56849 -163 110 8 116 81 8 102 78 10 116 81 8
56850 -167 114 7 197 138 11 226 170 11 239 182 13
56851 -242 186 14 242 186 14 162 146 94 78 78 78
56852 - 34 34 34 14 14 14 6 6 6 0 0 0
56853 - 0 0 0 0 0 0 0 0 0 0 0 0
56854 - 0 0 0 0 0 0 0 0 0 0 0 0
56855 - 0 0 0 0 0 0 0 0 0 0 0 0
56856 - 0 0 0 0 0 0 0 0 0 6 6 6
56857 - 30 30 30 78 78 78 190 142 34 226 170 11
56858 -239 182 13 246 190 14 246 190 14 246 190 14
56859 -246 190 14 246 190 14 246 190 14 246 190 14
56860 -246 190 14 246 190 14 246 190 14 246 190 14
56861 -246 190 14 241 196 14 203 166 17 22 18 6
56862 - 2 2 6 2 2 6 2 2 6 38 38 38
56863 -218 218 218 253 253 253 253 253 253 253 253 253
56864 -253 253 253 253 253 253 253 253 253 253 253 253
56865 -253 253 253 253 253 253 253 253 253 253 253 253
56866 -253 253 253 253 253 253 253 253 253 253 253 253
56867 -250 250 250 206 206 206 198 198 198 202 162 69
56868 -226 170 11 236 178 12 224 166 10 210 150 10
56869 -200 144 11 197 138 11 192 133 9 197 138 11
56870 -210 150 10 226 170 11 242 186 14 246 190 14
56871 -246 190 14 246 186 14 225 175 15 124 112 88
56872 - 62 62 62 30 30 30 14 14 14 6 6 6
56873 - 0 0 0 0 0 0 0 0 0 0 0 0
56874 - 0 0 0 0 0 0 0 0 0 0 0 0
56875 - 0 0 0 0 0 0 0 0 0 0 0 0
56876 - 0 0 0 0 0 0 0 0 0 10 10 10
56877 - 30 30 30 78 78 78 174 135 50 224 166 10
56878 -239 182 13 246 190 14 246 190 14 246 190 14
56879 -246 190 14 246 190 14 246 190 14 246 190 14
56880 -246 190 14 246 190 14 246 190 14 246 190 14
56881 -246 190 14 246 190 14 241 196 14 139 102 15
56882 - 2 2 6 2 2 6 2 2 6 2 2 6
56883 - 78 78 78 250 250 250 253 253 253 253 253 253
56884 -253 253 253 253 253 253 253 253 253 253 253 253
56885 -253 253 253 253 253 253 253 253 253 253 253 253
56886 -253 253 253 253 253 253 253 253 253 253 253 253
56887 -250 250 250 214 214 214 198 198 198 190 150 46
56888 -219 162 10 236 178 12 234 174 13 224 166 10
56889 -216 158 10 213 154 11 213 154 11 216 158 10
56890 -226 170 11 239 182 13 246 190 14 246 190 14
56891 -246 190 14 246 190 14 242 186 14 206 162 42
56892 -101 101 101 58 58 58 30 30 30 14 14 14
56893 - 6 6 6 0 0 0 0 0 0 0 0 0
56894 - 0 0 0 0 0 0 0 0 0 0 0 0
56895 - 0 0 0 0 0 0 0 0 0 0 0 0
56896 - 0 0 0 0 0 0 0 0 0 10 10 10
56897 - 30 30 30 74 74 74 174 135 50 216 158 10
56898 -236 178 12 246 190 14 246 190 14 246 190 14
56899 -246 190 14 246 190 14 246 190 14 246 190 14
56900 -246 190 14 246 190 14 246 190 14 246 190 14
56901 -246 190 14 246 190 14 241 196 14 226 184 13
56902 - 61 42 6 2 2 6 2 2 6 2 2 6
56903 - 22 22 22 238 238 238 253 253 253 253 253 253
56904 -253 253 253 253 253 253 253 253 253 253 253 253
56905 -253 253 253 253 253 253 253 253 253 253 253 253
56906 -253 253 253 253 253 253 253 253 253 253 253 253
56907 -253 253 253 226 226 226 187 187 187 180 133 36
56908 -216 158 10 236 178 12 239 182 13 236 178 12
56909 -230 174 11 226 170 11 226 170 11 230 174 11
56910 -236 178 12 242 186 14 246 190 14 246 190 14
56911 -246 190 14 246 190 14 246 186 14 239 182 13
56912 -206 162 42 106 106 106 66 66 66 34 34 34
56913 - 14 14 14 6 6 6 0 0 0 0 0 0
56914 - 0 0 0 0 0 0 0 0 0 0 0 0
56915 - 0 0 0 0 0 0 0 0 0 0 0 0
56916 - 0 0 0 0 0 0 0 0 0 6 6 6
56917 - 26 26 26 70 70 70 163 133 67 213 154 11
56918 -236 178 12 246 190 14 246 190 14 246 190 14
56919 -246 190 14 246 190 14 246 190 14 246 190 14
56920 -246 190 14 246 190 14 246 190 14 246 190 14
56921 -246 190 14 246 190 14 246 190 14 241 196 14
56922 -190 146 13 18 14 6 2 2 6 2 2 6
56923 - 46 46 46 246 246 246 253 253 253 253 253 253
56924 -253 253 253 253 253 253 253 253 253 253 253 253
56925 -253 253 253 253 253 253 253 253 253 253 253 253
56926 -253 253 253 253 253 253 253 253 253 253 253 253
56927 -253 253 253 221 221 221 86 86 86 156 107 11
56928 -216 158 10 236 178 12 242 186 14 246 186 14
56929 -242 186 14 239 182 13 239 182 13 242 186 14
56930 -242 186 14 246 186 14 246 190 14 246 190 14
56931 -246 190 14 246 190 14 246 190 14 246 190 14
56932 -242 186 14 225 175 15 142 122 72 66 66 66
56933 - 30 30 30 10 10 10 0 0 0 0 0 0
56934 - 0 0 0 0 0 0 0 0 0 0 0 0
56935 - 0 0 0 0 0 0 0 0 0 0 0 0
56936 - 0 0 0 0 0 0 0 0 0 6 6 6
56937 - 26 26 26 70 70 70 163 133 67 210 150 10
56938 -236 178 12 246 190 14 246 190 14 246 190 14
56939 -246 190 14 246 190 14 246 190 14 246 190 14
56940 -246 190 14 246 190 14 246 190 14 246 190 14
56941 -246 190 14 246 190 14 246 190 14 246 190 14
56942 -232 195 16 121 92 8 34 34 34 106 106 106
56943 -221 221 221 253 253 253 253 253 253 253 253 253
56944 -253 253 253 253 253 253 253 253 253 253 253 253
56945 -253 253 253 253 253 253 253 253 253 253 253 253
56946 -253 253 253 253 253 253 253 253 253 253 253 253
56947 -242 242 242 82 82 82 18 14 6 163 110 8
56948 -216 158 10 236 178 12 242 186 14 246 190 14
56949 -246 190 14 246 190 14 246 190 14 246 190 14
56950 -246 190 14 246 190 14 246 190 14 246 190 14
56951 -246 190 14 246 190 14 246 190 14 246 190 14
56952 -246 190 14 246 190 14 242 186 14 163 133 67
56953 - 46 46 46 18 18 18 6 6 6 0 0 0
56954 - 0 0 0 0 0 0 0 0 0 0 0 0
56955 - 0 0 0 0 0 0 0 0 0 0 0 0
56956 - 0 0 0 0 0 0 0 0 0 10 10 10
56957 - 30 30 30 78 78 78 163 133 67 210 150 10
56958 -236 178 12 246 186 14 246 190 14 246 190 14
56959 -246 190 14 246 190 14 246 190 14 246 190 14
56960 -246 190 14 246 190 14 246 190 14 246 190 14
56961 -246 190 14 246 190 14 246 190 14 246 190 14
56962 -241 196 14 215 174 15 190 178 144 253 253 253
56963 -253 253 253 253 253 253 253 253 253 253 253 253
56964 -253 253 253 253 253 253 253 253 253 253 253 253
56965 -253 253 253 253 253 253 253 253 253 253 253 253
56966 -253 253 253 253 253 253 253 253 253 218 218 218
56967 - 58 58 58 2 2 6 22 18 6 167 114 7
56968 -216 158 10 236 178 12 246 186 14 246 190 14
56969 -246 190 14 246 190 14 246 190 14 246 190 14
56970 -246 190 14 246 190 14 246 190 14 246 190 14
56971 -246 190 14 246 190 14 246 190 14 246 190 14
56972 -246 190 14 246 186 14 242 186 14 190 150 46
56973 - 54 54 54 22 22 22 6 6 6 0 0 0
56974 - 0 0 0 0 0 0 0 0 0 0 0 0
56975 - 0 0 0 0 0 0 0 0 0 0 0 0
56976 - 0 0 0 0 0 0 0 0 0 14 14 14
56977 - 38 38 38 86 86 86 180 133 36 213 154 11
56978 -236 178 12 246 186 14 246 190 14 246 190 14
56979 -246 190 14 246 190 14 246 190 14 246 190 14
56980 -246 190 14 246 190 14 246 190 14 246 190 14
56981 -246 190 14 246 190 14 246 190 14 246 190 14
56982 -246 190 14 232 195 16 190 146 13 214 214 214
56983 -253 253 253 253 253 253 253 253 253 253 253 253
56984 -253 253 253 253 253 253 253 253 253 253 253 253
56985 -253 253 253 253 253 253 253 253 253 253 253 253
56986 -253 253 253 250 250 250 170 170 170 26 26 26
56987 - 2 2 6 2 2 6 37 26 9 163 110 8
56988 -219 162 10 239 182 13 246 186 14 246 190 14
56989 -246 190 14 246 190 14 246 190 14 246 190 14
56990 -246 190 14 246 190 14 246 190 14 246 190 14
56991 -246 190 14 246 190 14 246 190 14 246 190 14
56992 -246 186 14 236 178 12 224 166 10 142 122 72
56993 - 46 46 46 18 18 18 6 6 6 0 0 0
56994 - 0 0 0 0 0 0 0 0 0 0 0 0
56995 - 0 0 0 0 0 0 0 0 0 0 0 0
56996 - 0 0 0 0 0 0 6 6 6 18 18 18
56997 - 50 50 50 109 106 95 192 133 9 224 166 10
56998 -242 186 14 246 190 14 246 190 14 246 190 14
56999 -246 190 14 246 190 14 246 190 14 246 190 14
57000 -246 190 14 246 190 14 246 190 14 246 190 14
57001 -246 190 14 246 190 14 246 190 14 246 190 14
57002 -242 186 14 226 184 13 210 162 10 142 110 46
57003 -226 226 226 253 253 253 253 253 253 253 253 253
57004 -253 253 253 253 253 253 253 253 253 253 253 253
57005 -253 253 253 253 253 253 253 253 253 253 253 253
57006 -198 198 198 66 66 66 2 2 6 2 2 6
57007 - 2 2 6 2 2 6 50 34 6 156 107 11
57008 -219 162 10 239 182 13 246 186 14 246 190 14
57009 -246 190 14 246 190 14 246 190 14 246 190 14
57010 -246 190 14 246 190 14 246 190 14 246 190 14
57011 -246 190 14 246 190 14 246 190 14 242 186 14
57012 -234 174 13 213 154 11 154 122 46 66 66 66
57013 - 30 30 30 10 10 10 0 0 0 0 0 0
57014 - 0 0 0 0 0 0 0 0 0 0 0 0
57015 - 0 0 0 0 0 0 0 0 0 0 0 0
57016 - 0 0 0 0 0 0 6 6 6 22 22 22
57017 - 58 58 58 154 121 60 206 145 10 234 174 13
57018 -242 186 14 246 186 14 246 190 14 246 190 14
57019 -246 190 14 246 190 14 246 190 14 246 190 14
57020 -246 190 14 246 190 14 246 190 14 246 190 14
57021 -246 190 14 246 190 14 246 190 14 246 190 14
57022 -246 186 14 236 178 12 210 162 10 163 110 8
57023 - 61 42 6 138 138 138 218 218 218 250 250 250
57024 -253 253 253 253 253 253 253 253 253 250 250 250
57025 -242 242 242 210 210 210 144 144 144 66 66 66
57026 - 6 6 6 2 2 6 2 2 6 2 2 6
57027 - 2 2 6 2 2 6 61 42 6 163 110 8
57028 -216 158 10 236 178 12 246 190 14 246 190 14
57029 -246 190 14 246 190 14 246 190 14 246 190 14
57030 -246 190 14 246 190 14 246 190 14 246 190 14
57031 -246 190 14 239 182 13 230 174 11 216 158 10
57032 -190 142 34 124 112 88 70 70 70 38 38 38
57033 - 18 18 18 6 6 6 0 0 0 0 0 0
57034 - 0 0 0 0 0 0 0 0 0 0 0 0
57035 - 0 0 0 0 0 0 0 0 0 0 0 0
57036 - 0 0 0 0 0 0 6 6 6 22 22 22
57037 - 62 62 62 168 124 44 206 145 10 224 166 10
57038 -236 178 12 239 182 13 242 186 14 242 186 14
57039 -246 186 14 246 190 14 246 190 14 246 190 14
57040 -246 190 14 246 190 14 246 190 14 246 190 14
57041 -246 190 14 246 190 14 246 190 14 246 190 14
57042 -246 190 14 236 178 12 216 158 10 175 118 6
57043 - 80 54 7 2 2 6 6 6 6 30 30 30
57044 - 54 54 54 62 62 62 50 50 50 38 38 38
57045 - 14 14 14 2 2 6 2 2 6 2 2 6
57046 - 2 2 6 2 2 6 2 2 6 2 2 6
57047 - 2 2 6 6 6 6 80 54 7 167 114 7
57048 -213 154 11 236 178 12 246 190 14 246 190 14
57049 -246 190 14 246 190 14 246 190 14 246 190 14
57050 -246 190 14 242 186 14 239 182 13 239 182 13
57051 -230 174 11 210 150 10 174 135 50 124 112 88
57052 - 82 82 82 54 54 54 34 34 34 18 18 18
57053 - 6 6 6 0 0 0 0 0 0 0 0 0
57054 - 0 0 0 0 0 0 0 0 0 0 0 0
57055 - 0 0 0 0 0 0 0 0 0 0 0 0
57056 - 0 0 0 0 0 0 6 6 6 18 18 18
57057 - 50 50 50 158 118 36 192 133 9 200 144 11
57058 -216 158 10 219 162 10 224 166 10 226 170 11
57059 -230 174 11 236 178 12 239 182 13 239 182 13
57060 -242 186 14 246 186 14 246 190 14 246 190 14
57061 -246 190 14 246 190 14 246 190 14 246 190 14
57062 -246 186 14 230 174 11 210 150 10 163 110 8
57063 -104 69 6 10 10 10 2 2 6 2 2 6
57064 - 2 2 6 2 2 6 2 2 6 2 2 6
57065 - 2 2 6 2 2 6 2 2 6 2 2 6
57066 - 2 2 6 2 2 6 2 2 6 2 2 6
57067 - 2 2 6 6 6 6 91 60 6 167 114 7
57068 -206 145 10 230 174 11 242 186 14 246 190 14
57069 -246 190 14 246 190 14 246 186 14 242 186 14
57070 -239 182 13 230 174 11 224 166 10 213 154 11
57071 -180 133 36 124 112 88 86 86 86 58 58 58
57072 - 38 38 38 22 22 22 10 10 10 6 6 6
57073 - 0 0 0 0 0 0 0 0 0 0 0 0
57074 - 0 0 0 0 0 0 0 0 0 0 0 0
57075 - 0 0 0 0 0 0 0 0 0 0 0 0
57076 - 0 0 0 0 0 0 0 0 0 14 14 14
57077 - 34 34 34 70 70 70 138 110 50 158 118 36
57078 -167 114 7 180 123 7 192 133 9 197 138 11
57079 -200 144 11 206 145 10 213 154 11 219 162 10
57080 -224 166 10 230 174 11 239 182 13 242 186 14
57081 -246 186 14 246 186 14 246 186 14 246 186 14
57082 -239 182 13 216 158 10 185 133 11 152 99 6
57083 -104 69 6 18 14 6 2 2 6 2 2 6
57084 - 2 2 6 2 2 6 2 2 6 2 2 6
57085 - 2 2 6 2 2 6 2 2 6 2 2 6
57086 - 2 2 6 2 2 6 2 2 6 2 2 6
57087 - 2 2 6 6 6 6 80 54 7 152 99 6
57088 -192 133 9 219 162 10 236 178 12 239 182 13
57089 -246 186 14 242 186 14 239 182 13 236 178 12
57090 -224 166 10 206 145 10 192 133 9 154 121 60
57091 - 94 94 94 62 62 62 42 42 42 22 22 22
57092 - 14 14 14 6 6 6 0 0 0 0 0 0
57093 - 0 0 0 0 0 0 0 0 0 0 0 0
57094 - 0 0 0 0 0 0 0 0 0 0 0 0
57095 - 0 0 0 0 0 0 0 0 0 0 0 0
57096 - 0 0 0 0 0 0 0 0 0 6 6 6
57097 - 18 18 18 34 34 34 58 58 58 78 78 78
57098 -101 98 89 124 112 88 142 110 46 156 107 11
57099 -163 110 8 167 114 7 175 118 6 180 123 7
57100 -185 133 11 197 138 11 210 150 10 219 162 10
57101 -226 170 11 236 178 12 236 178 12 234 174 13
57102 -219 162 10 197 138 11 163 110 8 130 83 6
57103 - 91 60 6 10 10 10 2 2 6 2 2 6
57104 - 18 18 18 38 38 38 38 38 38 38 38 38
57105 - 38 38 38 38 38 38 38 38 38 38 38 38
57106 - 38 38 38 38 38 38 26 26 26 2 2 6
57107 - 2 2 6 6 6 6 70 47 6 137 92 6
57108 -175 118 6 200 144 11 219 162 10 230 174 11
57109 -234 174 13 230 174 11 219 162 10 210 150 10
57110 -192 133 9 163 110 8 124 112 88 82 82 82
57111 - 50 50 50 30 30 30 14 14 14 6 6 6
57112 - 0 0 0 0 0 0 0 0 0 0 0 0
57113 - 0 0 0 0 0 0 0 0 0 0 0 0
57114 - 0 0 0 0 0 0 0 0 0 0 0 0
57115 - 0 0 0 0 0 0 0 0 0 0 0 0
57116 - 0 0 0 0 0 0 0 0 0 0 0 0
57117 - 6 6 6 14 14 14 22 22 22 34 34 34
57118 - 42 42 42 58 58 58 74 74 74 86 86 86
57119 -101 98 89 122 102 70 130 98 46 121 87 25
57120 -137 92 6 152 99 6 163 110 8 180 123 7
57121 -185 133 11 197 138 11 206 145 10 200 144 11
57122 -180 123 7 156 107 11 130 83 6 104 69 6
57123 - 50 34 6 54 54 54 110 110 110 101 98 89
57124 - 86 86 86 82 82 82 78 78 78 78 78 78
57125 - 78 78 78 78 78 78 78 78 78 78 78 78
57126 - 78 78 78 82 82 82 86 86 86 94 94 94
57127 -106 106 106 101 101 101 86 66 34 124 80 6
57128 -156 107 11 180 123 7 192 133 9 200 144 11
57129 -206 145 10 200 144 11 192 133 9 175 118 6
57130 -139 102 15 109 106 95 70 70 70 42 42 42
57131 - 22 22 22 10 10 10 0 0 0 0 0 0
57132 - 0 0 0 0 0 0 0 0 0 0 0 0
57133 - 0 0 0 0 0 0 0 0 0 0 0 0
57134 - 0 0 0 0 0 0 0 0 0 0 0 0
57135 - 0 0 0 0 0 0 0 0 0 0 0 0
57136 - 0 0 0 0 0 0 0 0 0 0 0 0
57137 - 0 0 0 0 0 0 6 6 6 10 10 10
57138 - 14 14 14 22 22 22 30 30 30 38 38 38
57139 - 50 50 50 62 62 62 74 74 74 90 90 90
57140 -101 98 89 112 100 78 121 87 25 124 80 6
57141 -137 92 6 152 99 6 152 99 6 152 99 6
57142 -138 86 6 124 80 6 98 70 6 86 66 30
57143 -101 98 89 82 82 82 58 58 58 46 46 46
57144 - 38 38 38 34 34 34 34 34 34 34 34 34
57145 - 34 34 34 34 34 34 34 34 34 34 34 34
57146 - 34 34 34 34 34 34 38 38 38 42 42 42
57147 - 54 54 54 82 82 82 94 86 76 91 60 6
57148 -134 86 6 156 107 11 167 114 7 175 118 6
57149 -175 118 6 167 114 7 152 99 6 121 87 25
57150 -101 98 89 62 62 62 34 34 34 18 18 18
57151 - 6 6 6 0 0 0 0 0 0 0 0 0
57152 - 0 0 0 0 0 0 0 0 0 0 0 0
57153 - 0 0 0 0 0 0 0 0 0 0 0 0
57154 - 0 0 0 0 0 0 0 0 0 0 0 0
57155 - 0 0 0 0 0 0 0 0 0 0 0 0
57156 - 0 0 0 0 0 0 0 0 0 0 0 0
57157 - 0 0 0 0 0 0 0 0 0 0 0 0
57158 - 0 0 0 6 6 6 6 6 6 10 10 10
57159 - 18 18 18 22 22 22 30 30 30 42 42 42
57160 - 50 50 50 66 66 66 86 86 86 101 98 89
57161 -106 86 58 98 70 6 104 69 6 104 69 6
57162 -104 69 6 91 60 6 82 62 34 90 90 90
57163 - 62 62 62 38 38 38 22 22 22 14 14 14
57164 - 10 10 10 10 10 10 10 10 10 10 10 10
57165 - 10 10 10 10 10 10 6 6 6 10 10 10
57166 - 10 10 10 10 10 10 10 10 10 14 14 14
57167 - 22 22 22 42 42 42 70 70 70 89 81 66
57168 - 80 54 7 104 69 6 124 80 6 137 92 6
57169 -134 86 6 116 81 8 100 82 52 86 86 86
57170 - 58 58 58 30 30 30 14 14 14 6 6 6
57171 - 0 0 0 0 0 0 0 0 0 0 0 0
57172 - 0 0 0 0 0 0 0 0 0 0 0 0
57173 - 0 0 0 0 0 0 0 0 0 0 0 0
57174 - 0 0 0 0 0 0 0 0 0 0 0 0
57175 - 0 0 0 0 0 0 0 0 0 0 0 0
57176 - 0 0 0 0 0 0 0 0 0 0 0 0
57177 - 0 0 0 0 0 0 0 0 0 0 0 0
57178 - 0 0 0 0 0 0 0 0 0 0 0 0
57179 - 0 0 0 6 6 6 10 10 10 14 14 14
57180 - 18 18 18 26 26 26 38 38 38 54 54 54
57181 - 70 70 70 86 86 86 94 86 76 89 81 66
57182 - 89 81 66 86 86 86 74 74 74 50 50 50
57183 - 30 30 30 14 14 14 6 6 6 0 0 0
57184 - 0 0 0 0 0 0 0 0 0 0 0 0
57185 - 0 0 0 0 0 0 0 0 0 0 0 0
57186 - 0 0 0 0 0 0 0 0 0 0 0 0
57187 - 6 6 6 18 18 18 34 34 34 58 58 58
57188 - 82 82 82 89 81 66 89 81 66 89 81 66
57189 - 94 86 66 94 86 76 74 74 74 50 50 50
57190 - 26 26 26 14 14 14 6 6 6 0 0 0
57191 - 0 0 0 0 0 0 0 0 0 0 0 0
57192 - 0 0 0 0 0 0 0 0 0 0 0 0
57193 - 0 0 0 0 0 0 0 0 0 0 0 0
57194 - 0 0 0 0 0 0 0 0 0 0 0 0
57195 - 0 0 0 0 0 0 0 0 0 0 0 0
57196 - 0 0 0 0 0 0 0 0 0 0 0 0
57197 - 0 0 0 0 0 0 0 0 0 0 0 0
57198 - 0 0 0 0 0 0 0 0 0 0 0 0
57199 - 0 0 0 0 0 0 0 0 0 0 0 0
57200 - 6 6 6 6 6 6 14 14 14 18 18 18
57201 - 30 30 30 38 38 38 46 46 46 54 54 54
57202 - 50 50 50 42 42 42 30 30 30 18 18 18
57203 - 10 10 10 0 0 0 0 0 0 0 0 0
57204 - 0 0 0 0 0 0 0 0 0 0 0 0
57205 - 0 0 0 0 0 0 0 0 0 0 0 0
57206 - 0 0 0 0 0 0 0 0 0 0 0 0
57207 - 0 0 0 6 6 6 14 14 14 26 26 26
57208 - 38 38 38 50 50 50 58 58 58 58 58 58
57209 - 54 54 54 42 42 42 30 30 30 18 18 18
57210 - 10 10 10 0 0 0 0 0 0 0 0 0
57211 - 0 0 0 0 0 0 0 0 0 0 0 0
57212 - 0 0 0 0 0 0 0 0 0 0 0 0
57213 - 0 0 0 0 0 0 0 0 0 0 0 0
57214 - 0 0 0 0 0 0 0 0 0 0 0 0
57215 - 0 0 0 0 0 0 0 0 0 0 0 0
57216 - 0 0 0 0 0 0 0 0 0 0 0 0
57217 - 0 0 0 0 0 0 0 0 0 0 0 0
57218 - 0 0 0 0 0 0 0 0 0 0 0 0
57219 - 0 0 0 0 0 0 0 0 0 0 0 0
57220 - 0 0 0 0 0 0 0 0 0 6 6 6
57221 - 6 6 6 10 10 10 14 14 14 18 18 18
57222 - 18 18 18 14 14 14 10 10 10 6 6 6
57223 - 0 0 0 0 0 0 0 0 0 0 0 0
57224 - 0 0 0 0 0 0 0 0 0 0 0 0
57225 - 0 0 0 0 0 0 0 0 0 0 0 0
57226 - 0 0 0 0 0 0 0 0 0 0 0 0
57227 - 0 0 0 0 0 0 0 0 0 6 6 6
57228 - 14 14 14 18 18 18 22 22 22 22 22 22
57229 - 18 18 18 14 14 14 10 10 10 6 6 6
57230 - 0 0 0 0 0 0 0 0 0 0 0 0
57231 - 0 0 0 0 0 0 0 0 0 0 0 0
57232 - 0 0 0 0 0 0 0 0 0 0 0 0
57233 - 0 0 0 0 0 0 0 0 0 0 0 0
57234 - 0 0 0 0 0 0 0 0 0 0 0 0
57235 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57236 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57237 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57238 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57239 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57240 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57242 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57243 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57244 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57245 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57246 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57247 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57248 +4 4 4 4 4 4
57249 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57250 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57251 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57252 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57253 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57254 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57256 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57257 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57258 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57259 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57260 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57261 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57262 +4 4 4 4 4 4
57263 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57264 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57265 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57266 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57267 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57268 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57269 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57270 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57271 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57272 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57273 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57274 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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
57277 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57278 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57279 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57280 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57281 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57282 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57283 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57284 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57285 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57286 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57287 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57288 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57289 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57290 +4 4 4 4 4 4
57291 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57292 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57293 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57294 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57295 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57296 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57297 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57298 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57299 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57300 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57301 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57302 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57303 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57304 +4 4 4 4 4 4
57305 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57306 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57307 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57308 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57309 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57310 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57311 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57312 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57313 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57314 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57315 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57316 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57317 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57318 +4 4 4 4 4 4
57319 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57320 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57321 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57322 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57323 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
57324 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
57325 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57326 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57327 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57328 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
57329 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
57330 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
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
57333 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57334 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57335 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57336 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57337 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
57338 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
57339 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57340 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57341 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57342 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
57343 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
57344 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
57345 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57346 +4 4 4 4 4 4
57347 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57348 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57349 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57350 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57351 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
57352 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
57353 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
57354 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57355 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57356 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
57357 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
57358 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
57359 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
57360 +4 4 4 4 4 4
57361 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57362 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57363 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57364 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
57365 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
57366 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
57367 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
57368 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57369 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
57370 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
57371 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
57372 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
57373 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
57374 +4 4 4 4 4 4
57375 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57376 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57377 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57378 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
57379 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
57380 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
57381 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
57382 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
57383 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
57384 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
57385 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
57386 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
57387 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
57388 +4 4 4 4 4 4
57389 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57390 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57391 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
57392 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
57393 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
57394 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
57395 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
57396 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
57397 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
57398 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
57399 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
57400 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
57401 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
57402 +4 4 4 4 4 4
57403 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57404 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57405 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
57406 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
57407 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
57408 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
57409 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
57410 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
57411 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
57412 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
57413 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
57414 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
57415 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
57416 +4 4 4 4 4 4
57417 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57418 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57419 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
57420 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
57421 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
57422 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
57423 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
57424 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
57425 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
57426 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
57427 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
57428 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
57429 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
57430 +4 4 4 4 4 4
57431 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57432 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57433 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
57434 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
57435 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
57436 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
57437 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
57438 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
57439 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
57440 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
57441 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
57442 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
57443 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
57444 +4 4 4 4 4 4
57445 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57446 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57447 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
57448 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
57449 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
57450 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
57451 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
57452 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
57453 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
57454 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
57455 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
57456 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
57457 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
57458 +4 4 4 4 4 4
57459 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57460 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
57461 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
57462 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
57463 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
57464 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
57465 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
57466 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
57467 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
57468 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
57469 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
57470 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
57471 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
57472 +4 4 4 4 4 4
57473 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57474 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
57475 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
57476 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
57477 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
57478 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
57479 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
57480 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
57481 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
57482 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
57483 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
57484 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
57485 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
57486 +0 0 0 4 4 4
57487 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
57488 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
57489 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
57490 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
57491 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
57492 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
57493 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
57494 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
57495 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
57496 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
57497 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
57498 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
57499 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
57500 +2 0 0 0 0 0
57501 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
57502 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
57503 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
57504 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
57505 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
57506 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
57507 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
57508 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
57509 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
57510 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
57511 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
57512 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
57513 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
57514 +37 38 37 0 0 0
57515 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
57516 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
57517 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
57518 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
57519 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
57520 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
57521 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
57522 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
57523 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
57524 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
57525 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
57526 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
57527 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
57528 +85 115 134 4 0 0
57529 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
57530 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
57531 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
57532 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
57533 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
57534 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
57535 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
57536 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
57537 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
57538 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
57539 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
57540 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
57541 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
57542 +60 73 81 4 0 0
57543 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
57544 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
57545 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
57546 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
57547 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
57548 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
57549 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
57550 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
57551 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
57552 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
57553 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
57554 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
57555 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
57556 +16 19 21 4 0 0
57557 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
57558 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
57559 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
57560 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
57561 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
57562 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
57563 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
57564 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
57565 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
57566 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
57567 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
57568 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
57569 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
57570 +4 0 0 4 3 3
57571 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
57572 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
57573 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
57574 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
57575 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
57576 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
57577 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
57578 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
57579 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
57580 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
57581 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
57582 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
57583 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
57584 +3 2 2 4 4 4
57585 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
57586 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
57587 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
57588 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
57589 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
57590 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
57591 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
57592 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
57593 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
57594 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
57595 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
57596 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
57597 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
57598 +4 4 4 4 4 4
57599 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
57600 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
57601 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
57602 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
57603 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
57604 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
57605 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
57606 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
57607 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
57608 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
57609 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
57610 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
57611 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
57612 +4 4 4 4 4 4
57613 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
57614 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
57615 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
57616 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
57617 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
57618 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
57619 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
57620 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
57621 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
57622 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
57623 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
57624 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
57625 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
57626 +5 5 5 5 5 5
57627 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
57628 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
57629 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
57630 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
57631 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
57632 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57633 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
57634 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
57635 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
57636 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
57637 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
57638 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
57639 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
57640 +5 5 5 4 4 4
57641 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
57642 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
57643 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
57644 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
57645 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57646 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
57647 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
57648 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
57649 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
57650 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
57651 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
57652 +4 0 0 4 0 0 5 5 5 5 5 5 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
57655 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
57656 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
57657 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
57658 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
57659 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
57660 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57661 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57662 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
57663 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
57664 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
57665 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
57666 +3 3 3 5 5 5 6 6 6 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
57669 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
57670 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
57671 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
57672 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
57673 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57674 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
57675 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
57676 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
57677 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
57678 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
57679 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 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
57683 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
57684 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
57685 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
57686 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
57687 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
57688 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57689 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57690 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
57691 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
57692 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
57693 +6 6 6 4 0 0 4 0 0 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
57697 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
57698 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
57699 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
57700 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
57701 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
57702 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
57703 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
57704 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
57705 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
57706 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
57707 +4 0 0 4 3 3 5 5 5 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
57711 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
57712 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
57713 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
57714 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
57715 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
57716 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
57717 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
57718 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
57719 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
57720 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
57721 +6 6 6 4 0 0 6 6 6 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
57725 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
57726 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
57727 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
57728 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
57729 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57730 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
57731 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
57732 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
57733 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
57734 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
57735 +4 0 0 3 2 2 5 5 5 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
57739 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
57740 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
57741 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
57742 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
57743 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
57744 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
57745 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
57746 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
57747 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
57748 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
57749 +4 0 0 4 3 3 5 5 5 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
57753 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
57754 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
57755 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
57756 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
57757 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57758 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
57759 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
57760 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
57761 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
57762 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
57763 +4 0 0 4 3 3 5 5 5 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
57767 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
57768 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
57769 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
57770 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
57771 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57772 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
57773 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
57774 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
57775 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
57776 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
57777 +4 0 0 3 3 3 5 5 5 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
57781 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
57782 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
57783 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
57784 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
57785 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57786 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
57787 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
57788 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
57789 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
57790 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57791 +0 0 0 3 3 3 5 5 5 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
57795 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
57796 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
57797 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
57798 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
57799 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
57800 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
57801 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
57802 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
57803 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57804 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57805 +0 0 0 3 3 3 5 5 5 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
57809 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
57810 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
57811 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
57812 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
57813 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57814 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
57815 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
57816 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
57817 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
57818 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57819 +0 0 0 3 3 3 5 5 5 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
57823 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
57824 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
57825 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
57826 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
57827 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
57828 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
57829 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
57830 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
57831 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57832 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57833 +0 0 0 3 3 3 5 5 5 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
57837 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
57838 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
57839 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
57840 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
57841 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
57842 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
57843 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
57844 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
57845 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
57846 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57847 +0 0 0 3 3 3 5 5 5 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
57851 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
57852 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
57853 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
57854 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
57855 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
57856 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
57857 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
57858 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
57859 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57860 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57861 +0 0 0 3 3 3 5 5 5 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
57865 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
57866 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
57867 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
57868 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
57869 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
57870 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
57871 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
57872 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
57873 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
57874 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57875 +0 0 0 3 3 3 5 5 5 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
57879 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
57880 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
57881 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
57882 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
57883 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
57884 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
57885 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
57886 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
57887 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57888 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57889 +0 0 0 3 3 3 5 5 5 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
57893 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57894 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
57895 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
57896 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
57897 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
57898 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
57899 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
57900 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
57901 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
57902 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57903 +0 0 0 3 3 3 5 5 5 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
57907 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
57908 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
57909 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
57910 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
57911 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
57912 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
57913 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57914 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
57915 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57916 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57917 +0 0 0 3 3 3 5 5 5 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
57921 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57922 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
57923 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
57924 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
57925 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
57926 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
57927 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57928 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
57929 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
57930 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57931 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57932 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57933 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57934 +4 4 4 4 4 4
57935 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
57936 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
57937 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
57938 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
57939 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
57940 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
57941 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
57942 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
57943 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
57944 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57945 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57946 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57947 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57948 +4 4 4 4 4 4
57949 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57950 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
57951 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
57952 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
57953 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
57954 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
57955 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
57956 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
57957 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
57958 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57959 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57960 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57961 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57962 +4 4 4 4 4 4
57963 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
57964 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
57965 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
57966 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
57967 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
57968 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
57969 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
57970 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
57971 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
57972 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57973 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57974 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57975 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57976 +4 4 4 4 4 4
57977 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57978 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
57979 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
57980 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
57981 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
57982 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
57983 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
57984 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
57985 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
57986 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57987 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57988 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57989 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57990 +4 4 4 4 4 4
57991 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
57992 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
57993 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
57994 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
57995 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
57996 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
57997 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
57998 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
57999 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
58000 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
58001 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58002 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58003 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58004 +4 4 4 4 4 4
58005 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
58006 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
58007 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
58008 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
58009 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
58010 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
58011 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
58012 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
58013 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
58014 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
58015 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58016 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58017 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58018 +4 4 4 4 4 4
58019 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
58020 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
58021 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
58022 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
58023 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
58024 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
58025 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58026 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
58027 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
58028 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
58029 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58030 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58031 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58032 +4 4 4 4 4 4
58033 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
58034 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
58035 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
58036 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
58037 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
58038 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
58039 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
58040 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
58041 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
58042 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
58043 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58044 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58045 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58046 +4 4 4 4 4 4
58047 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
58048 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
58049 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
58050 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
58051 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
58052 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
58053 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
58054 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
58055 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
58056 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
58057 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58058 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58059 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58060 +4 4 4 4 4 4
58061 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58062 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
58063 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
58064 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
58065 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
58066 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
58067 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
58068 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
58069 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
58070 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
58071 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58072 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58073 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58074 +4 4 4 4 4 4
58075 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
58076 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
58077 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
58078 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
58079 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
58080 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
58081 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
58082 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
58083 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
58084 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
58085 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58086 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58087 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58088 +4 4 4 4 4 4
58089 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
58090 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
58091 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
58092 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
58093 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
58094 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
58095 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
58096 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
58097 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
58098 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58099 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58100 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58101 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58102 +4 4 4 4 4 4
58103 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
58104 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58105 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
58106 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
58107 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
58108 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
58109 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
58110 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
58111 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
58112 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58113 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58114 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58115 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58116 +4 4 4 4 4 4
58117 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
58118 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
58119 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
58120 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
58121 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
58122 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
58123 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
58124 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
58125 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
58126 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58127 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58128 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58129 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58130 +4 4 4 4 4 4
58131 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
58132 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
58133 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
58134 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
58135 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
58136 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
58137 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
58138 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
58139 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58140 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58141 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58142 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58143 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58144 +4 4 4 4 4 4
58145 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
58146 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
58147 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
58148 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
58149 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
58150 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
58151 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
58152 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
58153 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58154 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58155 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58156 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58157 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58158 +4 4 4 4 4 4
58159 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
58160 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
58161 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
58162 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
58163 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
58164 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
58165 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
58166 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
58167 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58168 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58169 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58170 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58171 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58172 +4 4 4 4 4 4
58173 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
58174 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
58175 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
58176 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
58177 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
58178 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
58179 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
58180 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
58181 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58182 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58183 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58184 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58185 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58186 +4 4 4 4 4 4
58187 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58188 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
58189 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
58190 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
58191 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
58192 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
58193 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
58194 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
58195 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58196 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58197 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58198 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58199 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58200 +4 4 4 4 4 4
58201 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58202 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
58203 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
58204 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
58205 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
58206 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
58207 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
58208 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58209 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58210 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58211 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58212 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58213 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58214 +4 4 4 4 4 4
58215 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58216 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58217 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
58218 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
58219 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
58220 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
58221 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
58222 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58223 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58224 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58225 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58226 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58228 +4 4 4 4 4 4
58229 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58230 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58231 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
58232 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
58233 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
58234 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
58235 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
58236 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58237 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58238 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58239 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58240 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58242 +4 4 4 4 4 4
58243 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58244 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58245 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58246 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
58247 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
58248 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
58249 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
58250 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58251 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58252 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58253 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58254 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58256 +4 4 4 4 4 4
58257 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58258 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58259 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58260 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
58261 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58262 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
58263 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
58264 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58265 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58266 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58267 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58268 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58269 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58270 +4 4 4 4 4 4
58271 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58272 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58273 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58274 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
58275 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
58276 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
58277 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
58278 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58279 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58280 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58281 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58282 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58283 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58284 +4 4 4 4 4 4
58285 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58286 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58287 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58288 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
58289 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
58290 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
58291 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58292 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58293 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58294 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58295 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58296 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58297 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58298 +4 4 4 4 4 4
58299 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58300 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58301 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58302 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58303 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
58304 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
58305 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
58306 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58307 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58308 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58309 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58310 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58311 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58312 +4 4 4 4 4 4
58313 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58314 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58315 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58316 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58317 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
58318 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
58319 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58320 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58321 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58322 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58323 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58324 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58325 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58326 +4 4 4 4 4 4
58327 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58328 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58329 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58330 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58331 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
58332 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
58333 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58334 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58335 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58336 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58337 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58338 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58339 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58340 +4 4 4 4 4 4
58341 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58342 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58343 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58344 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58345 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
58346 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
58347 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58348 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58349 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58350 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58351 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58352 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58353 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58354 +4 4 4 4 4 4
58355 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
58356 index fef20db..d28b1ab 100644
58357 --- a/drivers/xen/xenfs/xenstored.c
58358 +++ b/drivers/xen/xenfs/xenstored.c
58359 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
58360 static int xsd_kva_open(struct inode *inode, struct file *file)
58361 {
58362 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
58363 +#ifdef CONFIG_GRKERNSEC_HIDESYM
58364 + NULL);
58365 +#else
58366 xen_store_interface);
58367 +#endif
58368 +
58369 if (!file->private_data)
58370 return -ENOMEM;
58371 return 0;
58372 diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
58373 index cc1cfae..41158ad 100644
58374 --- a/fs/9p/vfs_addr.c
58375 +++ b/fs/9p/vfs_addr.c
58376 @@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
58377
58378 retval = v9fs_file_write_internal(inode,
58379 v9inode->writeback_fid,
58380 - (__force const char __user *)buffer,
58381 + (const char __force_user *)buffer,
58382 len, &offset, 0);
58383 if (retval > 0)
58384 retval = 0;
58385 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
58386 index 7fa4f7a..a7ebf8c 100644
58387 --- a/fs/9p/vfs_inode.c
58388 +++ b/fs/9p/vfs_inode.c
58389 @@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
58390 void
58391 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
58392 {
58393 - char *s = nd_get_link(nd);
58394 + const char *s = nd_get_link(nd);
58395
58396 p9_debug(P9_DEBUG_VFS, " %s %s\n",
58397 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
58398 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
58399 index 370b24c..ff0be7b 100644
58400 --- a/fs/Kconfig.binfmt
58401 +++ b/fs/Kconfig.binfmt
58402 @@ -103,7 +103,7 @@ config HAVE_AOUT
58403
58404 config BINFMT_AOUT
58405 tristate "Kernel support for a.out and ECOFF binaries"
58406 - depends on HAVE_AOUT
58407 + depends on HAVE_AOUT && BROKEN
58408 ---help---
58409 A.out (Assembler.OUTput) is a set of formats for libraries and
58410 executables used in the earliest versions of UNIX. Linux used
58411 diff --git a/fs/afs/inode.c b/fs/afs/inode.c
58412 index 2946712..f737435 100644
58413 --- a/fs/afs/inode.c
58414 +++ b/fs/afs/inode.c
58415 @@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
58416 struct afs_vnode *vnode;
58417 struct super_block *sb;
58418 struct inode *inode;
58419 - static atomic_t afs_autocell_ino;
58420 + static atomic_unchecked_t afs_autocell_ino;
58421
58422 _enter("{%x:%u},%*.*s,",
58423 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
58424 @@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
58425 data.fid.unique = 0;
58426 data.fid.vnode = 0;
58427
58428 - inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
58429 + inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
58430 afs_iget5_autocell_test, afs_iget5_set,
58431 &data);
58432 if (!inode) {
58433 diff --git a/fs/aio.c b/fs/aio.c
58434 index 7337500..2058af6 100644
58435 --- a/fs/aio.c
58436 +++ b/fs/aio.c
58437 @@ -380,7 +380,7 @@ static int aio_setup_ring(struct kioctx *ctx)
58438 size += sizeof(struct io_event) * nr_events;
58439
58440 nr_pages = PFN_UP(size);
58441 - if (nr_pages < 0)
58442 + if (nr_pages <= 0)
58443 return -EINVAL;
58444
58445 file = aio_private_file(ctx, nr_pages);
58446 diff --git a/fs/attr.c b/fs/attr.c
58447 index 6530ced..4a827e2 100644
58448 --- a/fs/attr.c
58449 +++ b/fs/attr.c
58450 @@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
58451 unsigned long limit;
58452
58453 limit = rlimit(RLIMIT_FSIZE);
58454 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
58455 if (limit != RLIM_INFINITY && offset > limit)
58456 goto out_sig;
58457 if (offset > inode->i_sb->s_maxbytes)
58458 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
58459 index 116fd38..c04182da 100644
58460 --- a/fs/autofs4/waitq.c
58461 +++ b/fs/autofs4/waitq.c
58462 @@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
58463 {
58464 unsigned long sigpipe, flags;
58465 mm_segment_t fs;
58466 - const char *data = (const char *)addr;
58467 + const char __user *data = (const char __force_user *)addr;
58468 ssize_t wr = 0;
58469
58470 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
58471 @@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
58472 return 1;
58473 }
58474
58475 +#ifdef CONFIG_GRKERNSEC_HIDESYM
58476 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
58477 +#endif
58478 +
58479 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
58480 enum autofs_notify notify)
58481 {
58482 @@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
58483
58484 /* If this is a direct mount request create a dummy name */
58485 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
58486 +#ifdef CONFIG_GRKERNSEC_HIDESYM
58487 + /* this name does get written to userland via autofs4_write() */
58488 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
58489 +#else
58490 qstr.len = sprintf(name, "%p", dentry);
58491 +#endif
58492 else {
58493 qstr.len = autofs4_getpath(sbi, dentry, &name);
58494 if (!qstr.len) {
58495 diff --git a/fs/befs/endian.h b/fs/befs/endian.h
58496 index 2722387..56059b5 100644
58497 --- a/fs/befs/endian.h
58498 +++ b/fs/befs/endian.h
58499 @@ -11,7 +11,7 @@
58500
58501 #include <asm/byteorder.h>
58502
58503 -static inline u64
58504 +static inline u64 __intentional_overflow(-1)
58505 fs64_to_cpu(const struct super_block *sb, fs64 n)
58506 {
58507 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58508 @@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
58509 return (__force fs64)cpu_to_be64(n);
58510 }
58511
58512 -static inline u32
58513 +static inline u32 __intentional_overflow(-1)
58514 fs32_to_cpu(const struct super_block *sb, fs32 n)
58515 {
58516 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58517 @@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
58518 return (__force fs32)cpu_to_be32(n);
58519 }
58520
58521 -static inline u16
58522 +static inline u16 __intentional_overflow(-1)
58523 fs16_to_cpu(const struct super_block *sb, fs16 n)
58524 {
58525 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58526 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
58527 index ca0ba15..0fa3257 100644
58528 --- a/fs/binfmt_aout.c
58529 +++ b/fs/binfmt_aout.c
58530 @@ -16,6 +16,7 @@
58531 #include <linux/string.h>
58532 #include <linux/fs.h>
58533 #include <linux/file.h>
58534 +#include <linux/security.h>
58535 #include <linux/stat.h>
58536 #include <linux/fcntl.h>
58537 #include <linux/ptrace.h>
58538 @@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
58539 #endif
58540 # define START_STACK(u) ((void __user *)u.start_stack)
58541
58542 + memset(&dump, 0, sizeof(dump));
58543 +
58544 fs = get_fs();
58545 set_fs(KERNEL_DS);
58546 has_dumped = 1;
58547 @@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
58548
58549 /* If the size of the dump file exceeds the rlimit, then see what would happen
58550 if we wrote the stack, but not the data area. */
58551 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
58552 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
58553 dump.u_dsize = 0;
58554
58555 /* Make sure we have enough room to write the stack and data areas. */
58556 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
58557 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
58558 dump.u_ssize = 0;
58559
58560 @@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
58561 rlim = rlimit(RLIMIT_DATA);
58562 if (rlim >= RLIM_INFINITY)
58563 rlim = ~0;
58564 +
58565 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
58566 if (ex.a_data + ex.a_bss > rlim)
58567 return -ENOMEM;
58568
58569 @@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
58570
58571 install_exec_creds(bprm);
58572
58573 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58574 + current->mm->pax_flags = 0UL;
58575 +#endif
58576 +
58577 +#ifdef CONFIG_PAX_PAGEEXEC
58578 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
58579 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
58580 +
58581 +#ifdef CONFIG_PAX_EMUTRAMP
58582 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
58583 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
58584 +#endif
58585 +
58586 +#ifdef CONFIG_PAX_MPROTECT
58587 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
58588 + current->mm->pax_flags |= MF_PAX_MPROTECT;
58589 +#endif
58590 +
58591 + }
58592 +#endif
58593 +
58594 if (N_MAGIC(ex) == OMAGIC) {
58595 unsigned long text_addr, map_size;
58596 loff_t pos;
58597 @@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
58598 }
58599
58600 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
58601 - PROT_READ | PROT_WRITE | PROT_EXEC,
58602 + PROT_READ | PROT_WRITE,
58603 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
58604 fd_offset + ex.a_text);
58605 if (error != N_DATADDR(ex)) {
58606 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
58607 index 3892c1a..4e27c04 100644
58608 --- a/fs/binfmt_elf.c
58609 +++ b/fs/binfmt_elf.c
58610 @@ -34,6 +34,7 @@
58611 #include <linux/utsname.h>
58612 #include <linux/coredump.h>
58613 #include <linux/sched.h>
58614 +#include <linux/xattr.h>
58615 #include <asm/uaccess.h>
58616 #include <asm/param.h>
58617 #include <asm/page.h>
58618 @@ -47,7 +48,7 @@
58619
58620 static int load_elf_binary(struct linux_binprm *bprm);
58621 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
58622 - int, int, unsigned long);
58623 + int, int, unsigned long) __intentional_overflow(-1);
58624
58625 #ifdef CONFIG_USELIB
58626 static int load_elf_library(struct file *);
58627 @@ -65,6 +66,14 @@ static int elf_core_dump(struct coredump_params *cprm);
58628 #define elf_core_dump NULL
58629 #endif
58630
58631 +#ifdef CONFIG_PAX_MPROTECT
58632 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
58633 +#endif
58634 +
58635 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58636 +static void elf_handle_mmap(struct file *file);
58637 +#endif
58638 +
58639 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
58640 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
58641 #else
58642 @@ -84,6 +93,15 @@ static struct linux_binfmt elf_format = {
58643 .load_binary = load_elf_binary,
58644 .load_shlib = load_elf_library,
58645 .core_dump = elf_core_dump,
58646 +
58647 +#ifdef CONFIG_PAX_MPROTECT
58648 + .handle_mprotect= elf_handle_mprotect,
58649 +#endif
58650 +
58651 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58652 + .handle_mmap = elf_handle_mmap,
58653 +#endif
58654 +
58655 .min_coredump = ELF_EXEC_PAGESIZE,
58656 };
58657
58658 @@ -91,6 +109,8 @@ static struct linux_binfmt elf_format = {
58659
58660 static int set_brk(unsigned long start, unsigned long end)
58661 {
58662 + unsigned long e = end;
58663 +
58664 start = ELF_PAGEALIGN(start);
58665 end = ELF_PAGEALIGN(end);
58666 if (end > start) {
58667 @@ -99,7 +119,7 @@ static int set_brk(unsigned long start, unsigned long end)
58668 if (BAD_ADDR(addr))
58669 return addr;
58670 }
58671 - current->mm->start_brk = current->mm->brk = end;
58672 + current->mm->start_brk = current->mm->brk = e;
58673 return 0;
58674 }
58675
58676 @@ -160,12 +180,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
58677 elf_addr_t __user *u_rand_bytes;
58678 const char *k_platform = ELF_PLATFORM;
58679 const char *k_base_platform = ELF_BASE_PLATFORM;
58680 - unsigned char k_rand_bytes[16];
58681 + u32 k_rand_bytes[4];
58682 int items;
58683 elf_addr_t *elf_info;
58684 int ei_index = 0;
58685 const struct cred *cred = current_cred();
58686 struct vm_area_struct *vma;
58687 + unsigned long saved_auxv[AT_VECTOR_SIZE];
58688
58689 /*
58690 * In some cases (e.g. Hyper-Threading), we want to avoid L1
58691 @@ -207,8 +228,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
58692 * Generate 16 random bytes for userspace PRNG seeding.
58693 */
58694 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
58695 - u_rand_bytes = (elf_addr_t __user *)
58696 - STACK_ALLOC(p, sizeof(k_rand_bytes));
58697 + prandom_seed(k_rand_bytes[0] ^ prandom_u32());
58698 + prandom_seed(k_rand_bytes[1] ^ prandom_u32());
58699 + prandom_seed(k_rand_bytes[2] ^ prandom_u32());
58700 + prandom_seed(k_rand_bytes[3] ^ prandom_u32());
58701 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
58702 + u_rand_bytes = (elf_addr_t __user *) p;
58703 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
58704 return -EFAULT;
58705
58706 @@ -323,9 +348,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
58707 return -EFAULT;
58708 current->mm->env_end = p;
58709
58710 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
58711 +
58712 /* Put the elf_info on the stack in the right place. */
58713 sp = (elf_addr_t __user *)envp + 1;
58714 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
58715 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
58716 return -EFAULT;
58717 return 0;
58718 }
58719 @@ -393,15 +420,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
58720 an ELF header */
58721
58722 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58723 - struct file *interpreter, unsigned long *interp_map_addr,
58724 - unsigned long no_base)
58725 + struct file *interpreter, unsigned long no_base)
58726 {
58727 struct elf_phdr *elf_phdata;
58728 struct elf_phdr *eppnt;
58729 - unsigned long load_addr = 0;
58730 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
58731 int load_addr_set = 0;
58732 unsigned long last_bss = 0, elf_bss = 0;
58733 - unsigned long error = ~0UL;
58734 + unsigned long error = -EINVAL;
58735 unsigned long total_size;
58736 int retval, i, size;
58737
58738 @@ -447,6 +473,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58739 goto out_close;
58740 }
58741
58742 +#ifdef CONFIG_PAX_SEGMEXEC
58743 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
58744 + pax_task_size = SEGMEXEC_TASK_SIZE;
58745 +#endif
58746 +
58747 eppnt = elf_phdata;
58748 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
58749 if (eppnt->p_type == PT_LOAD) {
58750 @@ -470,8 +501,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58751 map_addr = elf_map(interpreter, load_addr + vaddr,
58752 eppnt, elf_prot, elf_type, total_size);
58753 total_size = 0;
58754 - if (!*interp_map_addr)
58755 - *interp_map_addr = map_addr;
58756 error = map_addr;
58757 if (BAD_ADDR(map_addr))
58758 goto out_close;
58759 @@ -490,8 +519,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58760 k = load_addr + eppnt->p_vaddr;
58761 if (BAD_ADDR(k) ||
58762 eppnt->p_filesz > eppnt->p_memsz ||
58763 - eppnt->p_memsz > TASK_SIZE ||
58764 - TASK_SIZE - eppnt->p_memsz < k) {
58765 + eppnt->p_memsz > pax_task_size ||
58766 + pax_task_size - eppnt->p_memsz < k) {
58767 error = -ENOMEM;
58768 goto out_close;
58769 }
58770 @@ -530,9 +559,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58771 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
58772
58773 /* Map the last of the bss segment */
58774 - error = vm_brk(elf_bss, last_bss - elf_bss);
58775 - if (BAD_ADDR(error))
58776 - goto out_close;
58777 + if (last_bss > elf_bss) {
58778 + error = vm_brk(elf_bss, last_bss - elf_bss);
58779 + if (BAD_ADDR(error))
58780 + goto out_close;
58781 + }
58782 }
58783
58784 error = load_addr;
58785 @@ -543,6 +574,336 @@ out:
58786 return error;
58787 }
58788
58789 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
58790 +#ifdef CONFIG_PAX_SOFTMODE
58791 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
58792 +{
58793 + unsigned long pax_flags = 0UL;
58794 +
58795 +#ifdef CONFIG_PAX_PAGEEXEC
58796 + if (elf_phdata->p_flags & PF_PAGEEXEC)
58797 + pax_flags |= MF_PAX_PAGEEXEC;
58798 +#endif
58799 +
58800 +#ifdef CONFIG_PAX_SEGMEXEC
58801 + if (elf_phdata->p_flags & PF_SEGMEXEC)
58802 + pax_flags |= MF_PAX_SEGMEXEC;
58803 +#endif
58804 +
58805 +#ifdef CONFIG_PAX_EMUTRAMP
58806 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
58807 + pax_flags |= MF_PAX_EMUTRAMP;
58808 +#endif
58809 +
58810 +#ifdef CONFIG_PAX_MPROTECT
58811 + if (elf_phdata->p_flags & PF_MPROTECT)
58812 + pax_flags |= MF_PAX_MPROTECT;
58813 +#endif
58814 +
58815 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58816 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
58817 + pax_flags |= MF_PAX_RANDMMAP;
58818 +#endif
58819 +
58820 + return pax_flags;
58821 +}
58822 +#endif
58823 +
58824 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
58825 +{
58826 + unsigned long pax_flags = 0UL;
58827 +
58828 +#ifdef CONFIG_PAX_PAGEEXEC
58829 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
58830 + pax_flags |= MF_PAX_PAGEEXEC;
58831 +#endif
58832 +
58833 +#ifdef CONFIG_PAX_SEGMEXEC
58834 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
58835 + pax_flags |= MF_PAX_SEGMEXEC;
58836 +#endif
58837 +
58838 +#ifdef CONFIG_PAX_EMUTRAMP
58839 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
58840 + pax_flags |= MF_PAX_EMUTRAMP;
58841 +#endif
58842 +
58843 +#ifdef CONFIG_PAX_MPROTECT
58844 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
58845 + pax_flags |= MF_PAX_MPROTECT;
58846 +#endif
58847 +
58848 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58849 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
58850 + pax_flags |= MF_PAX_RANDMMAP;
58851 +#endif
58852 +
58853 + return pax_flags;
58854 +}
58855 +#endif
58856 +
58857 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
58858 +#ifdef CONFIG_PAX_SOFTMODE
58859 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
58860 +{
58861 + unsigned long pax_flags = 0UL;
58862 +
58863 +#ifdef CONFIG_PAX_PAGEEXEC
58864 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
58865 + pax_flags |= MF_PAX_PAGEEXEC;
58866 +#endif
58867 +
58868 +#ifdef CONFIG_PAX_SEGMEXEC
58869 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
58870 + pax_flags |= MF_PAX_SEGMEXEC;
58871 +#endif
58872 +
58873 +#ifdef CONFIG_PAX_EMUTRAMP
58874 + if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
58875 + pax_flags |= MF_PAX_EMUTRAMP;
58876 +#endif
58877 +
58878 +#ifdef CONFIG_PAX_MPROTECT
58879 + if (pax_flags_softmode & MF_PAX_MPROTECT)
58880 + pax_flags |= MF_PAX_MPROTECT;
58881 +#endif
58882 +
58883 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58884 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
58885 + pax_flags |= MF_PAX_RANDMMAP;
58886 +#endif
58887 +
58888 + return pax_flags;
58889 +}
58890 +#endif
58891 +
58892 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
58893 +{
58894 + unsigned long pax_flags = 0UL;
58895 +
58896 +#ifdef CONFIG_PAX_PAGEEXEC
58897 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
58898 + pax_flags |= MF_PAX_PAGEEXEC;
58899 +#endif
58900 +
58901 +#ifdef CONFIG_PAX_SEGMEXEC
58902 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
58903 + pax_flags |= MF_PAX_SEGMEXEC;
58904 +#endif
58905 +
58906 +#ifdef CONFIG_PAX_EMUTRAMP
58907 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
58908 + pax_flags |= MF_PAX_EMUTRAMP;
58909 +#endif
58910 +
58911 +#ifdef CONFIG_PAX_MPROTECT
58912 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
58913 + pax_flags |= MF_PAX_MPROTECT;
58914 +#endif
58915 +
58916 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58917 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
58918 + pax_flags |= MF_PAX_RANDMMAP;
58919 +#endif
58920 +
58921 + return pax_flags;
58922 +}
58923 +#endif
58924 +
58925 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58926 +static unsigned long pax_parse_defaults(void)
58927 +{
58928 + unsigned long pax_flags = 0UL;
58929 +
58930 +#ifdef CONFIG_PAX_SOFTMODE
58931 + if (pax_softmode)
58932 + return pax_flags;
58933 +#endif
58934 +
58935 +#ifdef CONFIG_PAX_PAGEEXEC
58936 + pax_flags |= MF_PAX_PAGEEXEC;
58937 +#endif
58938 +
58939 +#ifdef CONFIG_PAX_SEGMEXEC
58940 + pax_flags |= MF_PAX_SEGMEXEC;
58941 +#endif
58942 +
58943 +#ifdef CONFIG_PAX_MPROTECT
58944 + pax_flags |= MF_PAX_MPROTECT;
58945 +#endif
58946 +
58947 +#ifdef CONFIG_PAX_RANDMMAP
58948 + if (randomize_va_space)
58949 + pax_flags |= MF_PAX_RANDMMAP;
58950 +#endif
58951 +
58952 + return pax_flags;
58953 +}
58954 +
58955 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
58956 +{
58957 + unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
58958 +
58959 +#ifdef CONFIG_PAX_EI_PAX
58960 +
58961 +#ifdef CONFIG_PAX_SOFTMODE
58962 + if (pax_softmode)
58963 + return pax_flags;
58964 +#endif
58965 +
58966 + pax_flags = 0UL;
58967 +
58968 +#ifdef CONFIG_PAX_PAGEEXEC
58969 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
58970 + pax_flags |= MF_PAX_PAGEEXEC;
58971 +#endif
58972 +
58973 +#ifdef CONFIG_PAX_SEGMEXEC
58974 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
58975 + pax_flags |= MF_PAX_SEGMEXEC;
58976 +#endif
58977 +
58978 +#ifdef CONFIG_PAX_EMUTRAMP
58979 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
58980 + pax_flags |= MF_PAX_EMUTRAMP;
58981 +#endif
58982 +
58983 +#ifdef CONFIG_PAX_MPROTECT
58984 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
58985 + pax_flags |= MF_PAX_MPROTECT;
58986 +#endif
58987 +
58988 +#ifdef CONFIG_PAX_ASLR
58989 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
58990 + pax_flags |= MF_PAX_RANDMMAP;
58991 +#endif
58992 +
58993 +#endif
58994 +
58995 + return pax_flags;
58996 +
58997 +}
58998 +
58999 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
59000 +{
59001 +
59002 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
59003 + unsigned long i;
59004 +
59005 + for (i = 0UL; i < elf_ex->e_phnum; i++)
59006 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
59007 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
59008 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
59009 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
59010 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
59011 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
59012 + return PAX_PARSE_FLAGS_FALLBACK;
59013 +
59014 +#ifdef CONFIG_PAX_SOFTMODE
59015 + if (pax_softmode)
59016 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
59017 + else
59018 +#endif
59019 +
59020 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
59021 + break;
59022 + }
59023 +#endif
59024 +
59025 + return PAX_PARSE_FLAGS_FALLBACK;
59026 +}
59027 +
59028 +static unsigned long pax_parse_xattr_pax(struct file * const file)
59029 +{
59030 +
59031 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
59032 + ssize_t xattr_size, i;
59033 + unsigned char xattr_value[sizeof("pemrs") - 1];
59034 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
59035 +
59036 + xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
59037 + if (xattr_size < 0 || xattr_size > sizeof xattr_value)
59038 + return PAX_PARSE_FLAGS_FALLBACK;
59039 +
59040 + for (i = 0; i < xattr_size; i++)
59041 + switch (xattr_value[i]) {
59042 + default:
59043 + return PAX_PARSE_FLAGS_FALLBACK;
59044 +
59045 +#define parse_flag(option1, option2, flag) \
59046 + case option1: \
59047 + if (pax_flags_hardmode & MF_PAX_##flag) \
59048 + return PAX_PARSE_FLAGS_FALLBACK;\
59049 + pax_flags_hardmode |= MF_PAX_##flag; \
59050 + break; \
59051 + case option2: \
59052 + if (pax_flags_softmode & MF_PAX_##flag) \
59053 + return PAX_PARSE_FLAGS_FALLBACK;\
59054 + pax_flags_softmode |= MF_PAX_##flag; \
59055 + break;
59056 +
59057 + parse_flag('p', 'P', PAGEEXEC);
59058 + parse_flag('e', 'E', EMUTRAMP);
59059 + parse_flag('m', 'M', MPROTECT);
59060 + parse_flag('r', 'R', RANDMMAP);
59061 + parse_flag('s', 'S', SEGMEXEC);
59062 +
59063 +#undef parse_flag
59064 + }
59065 +
59066 + if (pax_flags_hardmode & pax_flags_softmode)
59067 + return PAX_PARSE_FLAGS_FALLBACK;
59068 +
59069 +#ifdef CONFIG_PAX_SOFTMODE
59070 + if (pax_softmode)
59071 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
59072 + else
59073 +#endif
59074 +
59075 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
59076 +#else
59077 + return PAX_PARSE_FLAGS_FALLBACK;
59078 +#endif
59079 +
59080 +}
59081 +
59082 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
59083 +{
59084 + unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
59085 +
59086 + pax_flags = pax_parse_defaults();
59087 + ei_pax_flags = pax_parse_ei_pax(elf_ex);
59088 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
59089 + xattr_pax_flags = pax_parse_xattr_pax(file);
59090 +
59091 + if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
59092 + xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
59093 + pt_pax_flags != xattr_pax_flags)
59094 + return -EINVAL;
59095 + if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
59096 + pax_flags = xattr_pax_flags;
59097 + else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
59098 + pax_flags = pt_pax_flags;
59099 + else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
59100 + pax_flags = ei_pax_flags;
59101 +
59102 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
59103 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59104 + if ((__supported_pte_mask & _PAGE_NX))
59105 + pax_flags &= ~MF_PAX_SEGMEXEC;
59106 + else
59107 + pax_flags &= ~MF_PAX_PAGEEXEC;
59108 + }
59109 +#endif
59110 +
59111 + if (0 > pax_check_flags(&pax_flags))
59112 + return -EINVAL;
59113 +
59114 + current->mm->pax_flags = pax_flags;
59115 + return 0;
59116 +}
59117 +#endif
59118 +
59119 /*
59120 * These are the functions used to load ELF style executables and shared
59121 * libraries. There is no binary dependent code anywhere else.
59122 @@ -556,6 +917,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
59123 {
59124 unsigned int random_variable = 0;
59125
59126 +#ifdef CONFIG_PAX_RANDUSTACK
59127 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
59128 + return stack_top - current->mm->delta_stack;
59129 +#endif
59130 +
59131 if ((current->flags & PF_RANDOMIZE) &&
59132 !(current->personality & ADDR_NO_RANDOMIZE)) {
59133 random_variable = get_random_int() & STACK_RND_MASK;
59134 @@ -574,7 +940,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
59135 unsigned long load_addr = 0, load_bias = 0;
59136 int load_addr_set = 0;
59137 char * elf_interpreter = NULL;
59138 - unsigned long error;
59139 + unsigned long error = 0;
59140 struct elf_phdr *elf_ppnt, *elf_phdata;
59141 unsigned long elf_bss, elf_brk;
59142 int retval, i;
59143 @@ -589,6 +955,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
59144 struct elfhdr elf_ex;
59145 struct elfhdr interp_elf_ex;
59146 } *loc;
59147 + unsigned long pax_task_size;
59148
59149 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
59150 if (!loc) {
59151 @@ -726,6 +1093,77 @@ static int load_elf_binary(struct linux_binprm *bprm)
59152 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
59153 may depend on the personality. */
59154 SET_PERSONALITY(loc->elf_ex);
59155 +
59156 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59157 + current->mm->pax_flags = 0UL;
59158 +#endif
59159 +
59160 +#ifdef CONFIG_PAX_DLRESOLVE
59161 + current->mm->call_dl_resolve = 0UL;
59162 +#endif
59163 +
59164 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
59165 + current->mm->call_syscall = 0UL;
59166 +#endif
59167 +
59168 +#ifdef CONFIG_PAX_ASLR
59169 + current->mm->delta_mmap = 0UL;
59170 + current->mm->delta_stack = 0UL;
59171 +#endif
59172 +
59173 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59174 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
59175 + send_sig(SIGKILL, current, 0);
59176 + goto out_free_dentry;
59177 + }
59178 +#endif
59179 +
59180 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
59181 + pax_set_initial_flags(bprm);
59182 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
59183 + if (pax_set_initial_flags_func)
59184 + (pax_set_initial_flags_func)(bprm);
59185 +#endif
59186 +
59187 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
59188 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
59189 + current->mm->context.user_cs_limit = PAGE_SIZE;
59190 + current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
59191 + }
59192 +#endif
59193 +
59194 +#ifdef CONFIG_PAX_SEGMEXEC
59195 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
59196 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
59197 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
59198 + pax_task_size = SEGMEXEC_TASK_SIZE;
59199 + current->mm->def_flags |= VM_NOHUGEPAGE;
59200 + } else
59201 +#endif
59202 +
59203 + pax_task_size = TASK_SIZE;
59204 +
59205 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
59206 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59207 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
59208 + put_cpu();
59209 + }
59210 +#endif
59211 +
59212 +#ifdef CONFIG_PAX_ASLR
59213 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
59214 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
59215 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
59216 + }
59217 +#endif
59218 +
59219 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
59220 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59221 + executable_stack = EXSTACK_DISABLE_X;
59222 + current->personality &= ~READ_IMPLIES_EXEC;
59223 + } else
59224 +#endif
59225 +
59226 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
59227 current->personality |= READ_IMPLIES_EXEC;
59228
59229 @@ -815,6 +1253,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
59230 #else
59231 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
59232 #endif
59233 +
59234 +#ifdef CONFIG_PAX_RANDMMAP
59235 + /* PaX: randomize base address at the default exe base if requested */
59236 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
59237 +#ifdef CONFIG_SPARC64
59238 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
59239 +#else
59240 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
59241 +#endif
59242 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
59243 + elf_flags |= MAP_FIXED;
59244 + }
59245 +#endif
59246 +
59247 }
59248
59249 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
59250 @@ -847,9 +1299,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
59251 * allowed task size. Note that p_filesz must always be
59252 * <= p_memsz so it is only necessary to check p_memsz.
59253 */
59254 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
59255 - elf_ppnt->p_memsz > TASK_SIZE ||
59256 - TASK_SIZE - elf_ppnt->p_memsz < k) {
59257 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
59258 + elf_ppnt->p_memsz > pax_task_size ||
59259 + pax_task_size - elf_ppnt->p_memsz < k) {
59260 /* set_brk can never work. Avoid overflows. */
59261 send_sig(SIGKILL, current, 0);
59262 retval = -EINVAL;
59263 @@ -888,17 +1340,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
59264 goto out_free_dentry;
59265 }
59266 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
59267 - send_sig(SIGSEGV, current, 0);
59268 - retval = -EFAULT; /* Nobody gets to see this, but.. */
59269 - goto out_free_dentry;
59270 + /*
59271 + * This bss-zeroing can fail if the ELF
59272 + * file specifies odd protections. So
59273 + * we don't check the return value
59274 + */
59275 }
59276
59277 +#ifdef CONFIG_PAX_RANDMMAP
59278 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
59279 + unsigned long start, size, flags;
59280 + vm_flags_t vm_flags;
59281 +
59282 + start = ELF_PAGEALIGN(elf_brk);
59283 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
59284 + flags = MAP_FIXED | MAP_PRIVATE;
59285 + vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
59286 +
59287 + down_write(&current->mm->mmap_sem);
59288 + start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
59289 + retval = -ENOMEM;
59290 + if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
59291 +// if (current->personality & ADDR_NO_RANDOMIZE)
59292 +// vm_flags |= VM_READ | VM_MAYREAD;
59293 + start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
59294 + retval = IS_ERR_VALUE(start) ? start : 0;
59295 + }
59296 + up_write(&current->mm->mmap_sem);
59297 + if (retval == 0)
59298 + retval = set_brk(start + size, start + size + PAGE_SIZE);
59299 + if (retval < 0) {
59300 + send_sig(SIGKILL, current, 0);
59301 + goto out_free_dentry;
59302 + }
59303 + }
59304 +#endif
59305 +
59306 if (elf_interpreter) {
59307 - unsigned long interp_map_addr = 0;
59308 -
59309 elf_entry = load_elf_interp(&loc->interp_elf_ex,
59310 interpreter,
59311 - &interp_map_addr,
59312 load_bias);
59313 if (!IS_ERR((void *)elf_entry)) {
59314 /*
59315 @@ -1130,7 +1610,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
59316 * Decide what to dump of a segment, part, all or none.
59317 */
59318 static unsigned long vma_dump_size(struct vm_area_struct *vma,
59319 - unsigned long mm_flags)
59320 + unsigned long mm_flags, long signr)
59321 {
59322 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
59323
59324 @@ -1168,7 +1648,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
59325 if (vma->vm_file == NULL)
59326 return 0;
59327
59328 - if (FILTER(MAPPED_PRIVATE))
59329 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
59330 goto whole;
59331
59332 /*
59333 @@ -1375,9 +1855,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
59334 {
59335 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
59336 int i = 0;
59337 - do
59338 + do {
59339 i += 2;
59340 - while (auxv[i - 2] != AT_NULL);
59341 + } while (auxv[i - 2] != AT_NULL);
59342 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
59343 }
59344
59345 @@ -1386,7 +1866,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
59346 {
59347 mm_segment_t old_fs = get_fs();
59348 set_fs(KERNEL_DS);
59349 - copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
59350 + copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
59351 set_fs(old_fs);
59352 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
59353 }
59354 @@ -2010,14 +2490,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
59355 }
59356
59357 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
59358 - unsigned long mm_flags)
59359 + struct coredump_params *cprm)
59360 {
59361 struct vm_area_struct *vma;
59362 size_t size = 0;
59363
59364 for (vma = first_vma(current, gate_vma); vma != NULL;
59365 vma = next_vma(vma, gate_vma))
59366 - size += vma_dump_size(vma, mm_flags);
59367 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59368 return size;
59369 }
59370
59371 @@ -2108,7 +2588,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59372
59373 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
59374
59375 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
59376 + offset += elf_core_vma_data_size(gate_vma, cprm);
59377 offset += elf_core_extra_data_size();
59378 e_shoff = offset;
59379
59380 @@ -2136,7 +2616,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59381 phdr.p_offset = offset;
59382 phdr.p_vaddr = vma->vm_start;
59383 phdr.p_paddr = 0;
59384 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
59385 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59386 phdr.p_memsz = vma->vm_end - vma->vm_start;
59387 offset += phdr.p_filesz;
59388 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
59389 @@ -2169,7 +2649,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59390 unsigned long addr;
59391 unsigned long end;
59392
59393 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
59394 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59395
59396 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
59397 struct page *page;
59398 @@ -2210,6 +2690,167 @@ out:
59399
59400 #endif /* CONFIG_ELF_CORE */
59401
59402 +#ifdef CONFIG_PAX_MPROTECT
59403 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
59404 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
59405 + * we'll remove VM_MAYWRITE for good on RELRO segments.
59406 + *
59407 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
59408 + * basis because we want to allow the common case and not the special ones.
59409 + */
59410 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
59411 +{
59412 + struct elfhdr elf_h;
59413 + struct elf_phdr elf_p;
59414 + unsigned long i;
59415 + unsigned long oldflags;
59416 + bool is_textrel_rw, is_textrel_rx, is_relro;
59417 +
59418 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
59419 + return;
59420 +
59421 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
59422 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
59423 +
59424 +#ifdef CONFIG_PAX_ELFRELOCS
59425 + /* possible TEXTREL */
59426 + is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
59427 + is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
59428 +#else
59429 + is_textrel_rw = false;
59430 + is_textrel_rx = false;
59431 +#endif
59432 +
59433 + /* possible RELRO */
59434 + is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
59435 +
59436 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
59437 + return;
59438 +
59439 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
59440 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
59441 +
59442 +#ifdef CONFIG_PAX_ETEXECRELOCS
59443 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
59444 +#else
59445 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
59446 +#endif
59447 +
59448 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
59449 + !elf_check_arch(&elf_h) ||
59450 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
59451 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
59452 + return;
59453 +
59454 + for (i = 0UL; i < elf_h.e_phnum; i++) {
59455 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
59456 + return;
59457 + switch (elf_p.p_type) {
59458 + case PT_DYNAMIC:
59459 + if (!is_textrel_rw && !is_textrel_rx)
59460 + continue;
59461 + i = 0UL;
59462 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
59463 + elf_dyn dyn;
59464 +
59465 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
59466 + break;
59467 + if (dyn.d_tag == DT_NULL)
59468 + break;
59469 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
59470 + gr_log_textrel(vma);
59471 + if (is_textrel_rw)
59472 + vma->vm_flags |= VM_MAYWRITE;
59473 + else
59474 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
59475 + vma->vm_flags &= ~VM_MAYWRITE;
59476 + break;
59477 + }
59478 + i++;
59479 + }
59480 + is_textrel_rw = false;
59481 + is_textrel_rx = false;
59482 + continue;
59483 +
59484 + case PT_GNU_RELRO:
59485 + if (!is_relro)
59486 + continue;
59487 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
59488 + vma->vm_flags &= ~VM_MAYWRITE;
59489 + is_relro = false;
59490 + continue;
59491 +
59492 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
59493 + case PT_PAX_FLAGS: {
59494 + const char *msg_mprotect = "", *msg_emutramp = "";
59495 + char *buffer_lib, *buffer_exe;
59496 +
59497 + if (elf_p.p_flags & PF_NOMPROTECT)
59498 + msg_mprotect = "MPROTECT disabled";
59499 +
59500 +#ifdef CONFIG_PAX_EMUTRAMP
59501 + if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
59502 + msg_emutramp = "EMUTRAMP enabled";
59503 +#endif
59504 +
59505 + if (!msg_mprotect[0] && !msg_emutramp[0])
59506 + continue;
59507 +
59508 + if (!printk_ratelimit())
59509 + continue;
59510 +
59511 + buffer_lib = (char *)__get_free_page(GFP_KERNEL);
59512 + buffer_exe = (char *)__get_free_page(GFP_KERNEL);
59513 + if (buffer_lib && buffer_exe) {
59514 + char *path_lib, *path_exe;
59515 +
59516 + path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
59517 + path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
59518 +
59519 + pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
59520 + (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
59521 +
59522 + }
59523 + free_page((unsigned long)buffer_exe);
59524 + free_page((unsigned long)buffer_lib);
59525 + continue;
59526 + }
59527 +#endif
59528 +
59529 + }
59530 + }
59531 +}
59532 +#endif
59533 +
59534 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59535 +
59536 +extern int grsec_enable_log_rwxmaps;
59537 +
59538 +static void elf_handle_mmap(struct file *file)
59539 +{
59540 + struct elfhdr elf_h;
59541 + struct elf_phdr elf_p;
59542 + unsigned long i;
59543 +
59544 + if (!grsec_enable_log_rwxmaps)
59545 + return;
59546 +
59547 + if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
59548 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
59549 + (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
59550 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
59551 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
59552 + return;
59553 +
59554 + for (i = 0UL; i < elf_h.e_phnum; i++) {
59555 + if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
59556 + return;
59557 + if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
59558 + gr_log_ptgnustack(file);
59559 + }
59560 +}
59561 +#endif
59562 +
59563 static int __init init_elf_binfmt(void)
59564 {
59565 register_binfmt(&elf_format);
59566 diff --git a/fs/block_dev.c b/fs/block_dev.c
59567 index 6d72746..536d1db 100644
59568 --- a/fs/block_dev.c
59569 +++ b/fs/block_dev.c
59570 @@ -701,7 +701,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
59571 else if (bdev->bd_contains == bdev)
59572 return true; /* is a whole device which isn't held */
59573
59574 - else if (whole->bd_holder == bd_may_claim)
59575 + else if (whole->bd_holder == (void *)bd_may_claim)
59576 return true; /* is a partition of a device that is being partitioned */
59577 else if (whole->bd_holder != NULL)
59578 return false; /* is a partition of a held device */
59579 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
59580 index 44ee5d2..8b23e53 100644
59581 --- a/fs/btrfs/ctree.c
59582 +++ b/fs/btrfs/ctree.c
59583 @@ -1184,9 +1184,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
59584 free_extent_buffer(buf);
59585 add_root_to_dirty_list(root);
59586 } else {
59587 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
59588 - parent_start = parent->start;
59589 - else
59590 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
59591 + if (parent)
59592 + parent_start = parent->start;
59593 + else
59594 + parent_start = 0;
59595 + } else
59596 parent_start = 0;
59597
59598 WARN_ON(trans->transid != btrfs_header_generation(parent));
59599 diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
59600 index a2e90f8..5135e5f 100644
59601 --- a/fs/btrfs/delayed-inode.c
59602 +++ b/fs/btrfs/delayed-inode.c
59603 @@ -462,7 +462,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
59604
59605 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
59606 {
59607 - int seq = atomic_inc_return(&delayed_root->items_seq);
59608 + int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
59609 if ((atomic_dec_return(&delayed_root->items) <
59610 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
59611 waitqueue_active(&delayed_root->wait))
59612 @@ -1412,7 +1412,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
59613
59614 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
59615 {
59616 - int val = atomic_read(&delayed_root->items_seq);
59617 + int val = atomic_read_unchecked(&delayed_root->items_seq);
59618
59619 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
59620 return 1;
59621 @@ -1436,7 +1436,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
59622 int seq;
59623 int ret;
59624
59625 - seq = atomic_read(&delayed_root->items_seq);
59626 + seq = atomic_read_unchecked(&delayed_root->items_seq);
59627
59628 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
59629 if (ret)
59630 diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
59631 index f70119f..ab5894d 100644
59632 --- a/fs/btrfs/delayed-inode.h
59633 +++ b/fs/btrfs/delayed-inode.h
59634 @@ -43,7 +43,7 @@ struct btrfs_delayed_root {
59635 */
59636 struct list_head prepare_list;
59637 atomic_t items; /* for delayed items */
59638 - atomic_t items_seq; /* for delayed items */
59639 + atomic_unchecked_t items_seq; /* for delayed items */
59640 int nodes; /* for delayed nodes */
59641 wait_queue_head_t wait;
59642 };
59643 @@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
59644 struct btrfs_delayed_root *delayed_root)
59645 {
59646 atomic_set(&delayed_root->items, 0);
59647 - atomic_set(&delayed_root->items_seq, 0);
59648 + atomic_set_unchecked(&delayed_root->items_seq, 0);
59649 delayed_root->nodes = 0;
59650 spin_lock_init(&delayed_root->lock);
59651 init_waitqueue_head(&delayed_root->wait);
59652 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
59653 index b765d41..5a8b0c3 100644
59654 --- a/fs/btrfs/ioctl.c
59655 +++ b/fs/btrfs/ioctl.c
59656 @@ -3975,9 +3975,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
59657 for (i = 0; i < num_types; i++) {
59658 struct btrfs_space_info *tmp;
59659
59660 + /* Don't copy in more than we allocated */
59661 if (!slot_count)
59662 break;
59663
59664 + slot_count--;
59665 +
59666 info = NULL;
59667 rcu_read_lock();
59668 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
59669 @@ -3999,10 +4002,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
59670 memcpy(dest, &space, sizeof(space));
59671 dest++;
59672 space_args.total_spaces++;
59673 - slot_count--;
59674 }
59675 - if (!slot_count)
59676 - break;
59677 }
59678 up_read(&info->groups_sem);
59679 }
59680 diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
59681 index c4124de..d7613eb6 100644
59682 --- a/fs/btrfs/super.c
59683 +++ b/fs/btrfs/super.c
59684 @@ -270,7 +270,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
59685 function, line, errstr);
59686 return;
59687 }
59688 - ACCESS_ONCE(trans->transaction->aborted) = errno;
59689 + ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
59690 /* Wake up anybody who may be waiting on this transaction */
59691 wake_up(&root->fs_info->transaction_wait);
59692 wake_up(&root->fs_info->transaction_blocked_wait);
59693 diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
59694 index 12e5355..cdf30c6 100644
59695 --- a/fs/btrfs/sysfs.c
59696 +++ b/fs/btrfs/sysfs.c
59697 @@ -475,7 +475,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
59698 for (set = 0; set < FEAT_MAX; set++) {
59699 int i;
59700 struct attribute *attrs[2];
59701 - struct attribute_group agroup = {
59702 + attribute_group_no_const agroup = {
59703 .name = "features",
59704 .attrs = attrs,
59705 };
59706 diff --git a/fs/btrfs/tree-log.h b/fs/btrfs/tree-log.h
59707 index e2e798a..f454c18 100644
59708 --- a/fs/btrfs/tree-log.h
59709 +++ b/fs/btrfs/tree-log.h
59710 @@ -41,7 +41,7 @@ static inline void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx)
59711 static inline void btrfs_set_log_full_commit(struct btrfs_fs_info *fs_info,
59712 struct btrfs_trans_handle *trans)
59713 {
59714 - ACCESS_ONCE(fs_info->last_trans_log_full_commit) = trans->transid;
59715 + ACCESS_ONCE_RW(fs_info->last_trans_log_full_commit) = trans->transid;
59716 }
59717
59718 static inline int btrfs_need_log_full_commit(struct btrfs_fs_info *fs_info,
59719 diff --git a/fs/buffer.c b/fs/buffer.c
59720 index 72daaa5..60ffeb9 100644
59721 --- a/fs/buffer.c
59722 +++ b/fs/buffer.c
59723 @@ -3432,7 +3432,7 @@ void __init buffer_init(void)
59724 bh_cachep = kmem_cache_create("buffer_head",
59725 sizeof(struct buffer_head), 0,
59726 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
59727 - SLAB_MEM_SPREAD),
59728 + SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
59729 NULL);
59730
59731 /*
59732 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
59733 index fbb08e9..0fda764 100644
59734 --- a/fs/cachefiles/bind.c
59735 +++ b/fs/cachefiles/bind.c
59736 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
59737 args);
59738
59739 /* start by checking things over */
59740 - ASSERT(cache->fstop_percent >= 0 &&
59741 - cache->fstop_percent < cache->fcull_percent &&
59742 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
59743 cache->fcull_percent < cache->frun_percent &&
59744 cache->frun_percent < 100);
59745
59746 - ASSERT(cache->bstop_percent >= 0 &&
59747 - cache->bstop_percent < cache->bcull_percent &&
59748 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
59749 cache->bcull_percent < cache->brun_percent &&
59750 cache->brun_percent < 100);
59751
59752 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
59753 index ce1b115..4a6852c 100644
59754 --- a/fs/cachefiles/daemon.c
59755 +++ b/fs/cachefiles/daemon.c
59756 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
59757 if (n > buflen)
59758 return -EMSGSIZE;
59759
59760 - if (copy_to_user(_buffer, buffer, n) != 0)
59761 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
59762 return -EFAULT;
59763
59764 return n;
59765 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
59766 if (test_bit(CACHEFILES_DEAD, &cache->flags))
59767 return -EIO;
59768
59769 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
59770 + if (datalen > PAGE_SIZE - 1)
59771 return -EOPNOTSUPP;
59772
59773 /* drag the command string into the kernel so we can parse it */
59774 @@ -385,7 +385,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
59775 if (args[0] != '%' || args[1] != '\0')
59776 return -EINVAL;
59777
59778 - if (fstop < 0 || fstop >= cache->fcull_percent)
59779 + if (fstop >= cache->fcull_percent)
59780 return cachefiles_daemon_range_error(cache, args);
59781
59782 cache->fstop_percent = fstop;
59783 @@ -457,7 +457,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
59784 if (args[0] != '%' || args[1] != '\0')
59785 return -EINVAL;
59786
59787 - if (bstop < 0 || bstop >= cache->bcull_percent)
59788 + if (bstop >= cache->bcull_percent)
59789 return cachefiles_daemon_range_error(cache, args);
59790
59791 cache->bstop_percent = bstop;
59792 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
59793 index 8c52472..c4e3a69 100644
59794 --- a/fs/cachefiles/internal.h
59795 +++ b/fs/cachefiles/internal.h
59796 @@ -66,7 +66,7 @@ struct cachefiles_cache {
59797 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
59798 struct rb_root active_nodes; /* active nodes (can't be culled) */
59799 rwlock_t active_lock; /* lock for active_nodes */
59800 - atomic_t gravecounter; /* graveyard uniquifier */
59801 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
59802 unsigned frun_percent; /* when to stop culling (% files) */
59803 unsigned fcull_percent; /* when to start culling (% files) */
59804 unsigned fstop_percent; /* when to stop allocating (% files) */
59805 @@ -178,19 +178,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
59806 * proc.c
59807 */
59808 #ifdef CONFIG_CACHEFILES_HISTOGRAM
59809 -extern atomic_t cachefiles_lookup_histogram[HZ];
59810 -extern atomic_t cachefiles_mkdir_histogram[HZ];
59811 -extern atomic_t cachefiles_create_histogram[HZ];
59812 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
59813 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
59814 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
59815
59816 extern int __init cachefiles_proc_init(void);
59817 extern void cachefiles_proc_cleanup(void);
59818 static inline
59819 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
59820 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
59821 {
59822 unsigned long jif = jiffies - start_jif;
59823 if (jif >= HZ)
59824 jif = HZ - 1;
59825 - atomic_inc(&histogram[jif]);
59826 + atomic_inc_unchecked(&histogram[jif]);
59827 }
59828
59829 #else
59830 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
59831 index dad7d95..07475af 100644
59832 --- a/fs/cachefiles/namei.c
59833 +++ b/fs/cachefiles/namei.c
59834 @@ -312,7 +312,7 @@ try_again:
59835 /* first step is to make up a grave dentry in the graveyard */
59836 sprintf(nbuffer, "%08x%08x",
59837 (uint32_t) get_seconds(),
59838 - (uint32_t) atomic_inc_return(&cache->gravecounter));
59839 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
59840
59841 /* do the multiway lock magic */
59842 trap = lock_rename(cache->graveyard, dir);
59843 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
59844 index eccd339..4c1d995 100644
59845 --- a/fs/cachefiles/proc.c
59846 +++ b/fs/cachefiles/proc.c
59847 @@ -14,9 +14,9 @@
59848 #include <linux/seq_file.h>
59849 #include "internal.h"
59850
59851 -atomic_t cachefiles_lookup_histogram[HZ];
59852 -atomic_t cachefiles_mkdir_histogram[HZ];
59853 -atomic_t cachefiles_create_histogram[HZ];
59854 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
59855 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
59856 +atomic_unchecked_t cachefiles_create_histogram[HZ];
59857
59858 /*
59859 * display the latency histogram
59860 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
59861 return 0;
59862 default:
59863 index = (unsigned long) v - 3;
59864 - x = atomic_read(&cachefiles_lookup_histogram[index]);
59865 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
59866 - z = atomic_read(&cachefiles_create_histogram[index]);
59867 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
59868 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
59869 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
59870 if (x == 0 && y == 0 && z == 0)
59871 return 0;
59872
59873 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
59874 index 25e745b..220e604 100644
59875 --- a/fs/cachefiles/rdwr.c
59876 +++ b/fs/cachefiles/rdwr.c
59877 @@ -937,7 +937,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
59878 old_fs = get_fs();
59879 set_fs(KERNEL_DS);
59880 ret = file->f_op->write(
59881 - file, (const void __user *) data, len, &pos);
59882 + file, (const void __force_user *) data, len, &pos);
59883 set_fs(old_fs);
59884 kunmap(page);
59885 file_end_write(file);
59886 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
59887 index c29d6ae..719b9bb 100644
59888 --- a/fs/ceph/dir.c
59889 +++ b/fs/ceph/dir.c
59890 @@ -129,6 +129,8 @@ static int __dcache_readdir(struct file *file, struct dir_context *ctx,
59891 struct dentry *dentry, *last;
59892 struct ceph_dentry_info *di;
59893 int err = 0;
59894 + char d_name[DNAME_INLINE_LEN];
59895 + const unsigned char *name;
59896
59897 /* claim ref on last dentry we returned */
59898 last = fi->dentry;
59899 @@ -192,7 +194,12 @@ more:
59900
59901 dout(" %llu (%llu) dentry %p %.*s %p\n", di->offset, ctx->pos,
59902 dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
59903 - if (!dir_emit(ctx, dentry->d_name.name,
59904 + name = dentry->d_name.name;
59905 + if (name == dentry->d_iname) {
59906 + memcpy(d_name, name, dentry->d_name.len);
59907 + name = d_name;
59908 + }
59909 + if (!dir_emit(ctx, name,
59910 dentry->d_name.len,
59911 ceph_translate_ino(dentry->d_sb, dentry->d_inode->i_ino),
59912 dentry->d_inode->i_mode >> 12)) {
59913 @@ -250,7 +257,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
59914 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
59915 struct ceph_mds_client *mdsc = fsc->mdsc;
59916 unsigned frag = fpos_frag(ctx->pos);
59917 - int off = fpos_off(ctx->pos);
59918 + unsigned int off = fpos_off(ctx->pos);
59919 int err;
59920 u32 ftype;
59921 struct ceph_mds_reply_info_parsed *rinfo;
59922 diff --git a/fs/ceph/ioctl.c b/fs/ceph/ioctl.c
59923 index a822a6e..4644256 100644
59924 --- a/fs/ceph/ioctl.c
59925 +++ b/fs/ceph/ioctl.c
59926 @@ -41,7 +41,7 @@ static long __validate_layout(struct ceph_mds_client *mdsc,
59927 /* validate striping parameters */
59928 if ((l->object_size & ~PAGE_MASK) ||
59929 (l->stripe_unit & ~PAGE_MASK) ||
59930 - (l->stripe_unit != 0 &&
59931 + ((unsigned)l->stripe_unit != 0 &&
59932 ((unsigned)l->object_size % (unsigned)l->stripe_unit)))
59933 return -EINVAL;
59934
59935 diff --git a/fs/ceph/super.c b/fs/ceph/super.c
59936 index f6e1237..796ffd1 100644
59937 --- a/fs/ceph/super.c
59938 +++ b/fs/ceph/super.c
59939 @@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
59940 /*
59941 * construct our own bdi so we can control readahead, etc.
59942 */
59943 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
59944 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
59945
59946 static int ceph_register_bdi(struct super_block *sb,
59947 struct ceph_fs_client *fsc)
59948 @@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
59949 default_backing_dev_info.ra_pages;
59950
59951 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
59952 - atomic_long_inc_return(&bdi_seq));
59953 + atomic_long_inc_return_unchecked(&bdi_seq));
59954 if (!err)
59955 sb->s_bdi = &fsc->backing_dev_info;
59956 return err;
59957 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
59958 index 44ec726..bcb06a3 100644
59959 --- a/fs/cifs/cifs_debug.c
59960 +++ b/fs/cifs/cifs_debug.c
59961 @@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
59962
59963 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
59964 #ifdef CONFIG_CIFS_STATS2
59965 - atomic_set(&totBufAllocCount, 0);
59966 - atomic_set(&totSmBufAllocCount, 0);
59967 + atomic_set_unchecked(&totBufAllocCount, 0);
59968 + atomic_set_unchecked(&totSmBufAllocCount, 0);
59969 #endif /* CONFIG_CIFS_STATS2 */
59970 spin_lock(&cifs_tcp_ses_lock);
59971 list_for_each(tmp1, &cifs_tcp_ses_list) {
59972 @@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
59973 tcon = list_entry(tmp3,
59974 struct cifs_tcon,
59975 tcon_list);
59976 - atomic_set(&tcon->num_smbs_sent, 0);
59977 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
59978 if (server->ops->clear_stats)
59979 server->ops->clear_stats(tcon);
59980 }
59981 @@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
59982 smBufAllocCount.counter, cifs_min_small);
59983 #ifdef CONFIG_CIFS_STATS2
59984 seq_printf(m, "Total Large %d Small %d Allocations\n",
59985 - atomic_read(&totBufAllocCount),
59986 - atomic_read(&totSmBufAllocCount));
59987 + atomic_read_unchecked(&totBufAllocCount),
59988 + atomic_read_unchecked(&totSmBufAllocCount));
59989 #endif /* CONFIG_CIFS_STATS2 */
59990
59991 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
59992 @@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
59993 if (tcon->need_reconnect)
59994 seq_puts(m, "\tDISCONNECTED ");
59995 seq_printf(m, "\nSMBs: %d",
59996 - atomic_read(&tcon->num_smbs_sent));
59997 + atomic_read_unchecked(&tcon->num_smbs_sent));
59998 if (server->ops->print_stats)
59999 server->ops->print_stats(m, tcon);
60000 }
60001 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
60002 index 889b984..fcb8431 100644
60003 --- a/fs/cifs/cifsfs.c
60004 +++ b/fs/cifs/cifsfs.c
60005 @@ -1092,7 +1092,7 @@ cifs_init_request_bufs(void)
60006 */
60007 cifs_req_cachep = kmem_cache_create("cifs_request",
60008 CIFSMaxBufSize + max_hdr_size, 0,
60009 - SLAB_HWCACHE_ALIGN, NULL);
60010 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
60011 if (cifs_req_cachep == NULL)
60012 return -ENOMEM;
60013
60014 @@ -1119,7 +1119,7 @@ cifs_init_request_bufs(void)
60015 efficient to alloc 1 per page off the slab compared to 17K (5page)
60016 alloc of large cifs buffers even when page debugging is on */
60017 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
60018 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
60019 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
60020 NULL);
60021 if (cifs_sm_req_cachep == NULL) {
60022 mempool_destroy(cifs_req_poolp);
60023 @@ -1204,8 +1204,8 @@ init_cifs(void)
60024 atomic_set(&bufAllocCount, 0);
60025 atomic_set(&smBufAllocCount, 0);
60026 #ifdef CONFIG_CIFS_STATS2
60027 - atomic_set(&totBufAllocCount, 0);
60028 - atomic_set(&totSmBufAllocCount, 0);
60029 + atomic_set_unchecked(&totBufAllocCount, 0);
60030 + atomic_set_unchecked(&totSmBufAllocCount, 0);
60031 #endif /* CONFIG_CIFS_STATS2 */
60032
60033 atomic_set(&midCount, 0);
60034 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
60035 index 25b8392..01e46dc 100644
60036 --- a/fs/cifs/cifsglob.h
60037 +++ b/fs/cifs/cifsglob.h
60038 @@ -821,35 +821,35 @@ struct cifs_tcon {
60039 __u16 Flags; /* optional support bits */
60040 enum statusEnum tidStatus;
60041 #ifdef CONFIG_CIFS_STATS
60042 - atomic_t num_smbs_sent;
60043 + atomic_unchecked_t num_smbs_sent;
60044 union {
60045 struct {
60046 - atomic_t num_writes;
60047 - atomic_t num_reads;
60048 - atomic_t num_flushes;
60049 - atomic_t num_oplock_brks;
60050 - atomic_t num_opens;
60051 - atomic_t num_closes;
60052 - atomic_t num_deletes;
60053 - atomic_t num_mkdirs;
60054 - atomic_t num_posixopens;
60055 - atomic_t num_posixmkdirs;
60056 - atomic_t num_rmdirs;
60057 - atomic_t num_renames;
60058 - atomic_t num_t2renames;
60059 - atomic_t num_ffirst;
60060 - atomic_t num_fnext;
60061 - atomic_t num_fclose;
60062 - atomic_t num_hardlinks;
60063 - atomic_t num_symlinks;
60064 - atomic_t num_locks;
60065 - atomic_t num_acl_get;
60066 - atomic_t num_acl_set;
60067 + atomic_unchecked_t num_writes;
60068 + atomic_unchecked_t num_reads;
60069 + atomic_unchecked_t num_flushes;
60070 + atomic_unchecked_t num_oplock_brks;
60071 + atomic_unchecked_t num_opens;
60072 + atomic_unchecked_t num_closes;
60073 + atomic_unchecked_t num_deletes;
60074 + atomic_unchecked_t num_mkdirs;
60075 + atomic_unchecked_t num_posixopens;
60076 + atomic_unchecked_t num_posixmkdirs;
60077 + atomic_unchecked_t num_rmdirs;
60078 + atomic_unchecked_t num_renames;
60079 + atomic_unchecked_t num_t2renames;
60080 + atomic_unchecked_t num_ffirst;
60081 + atomic_unchecked_t num_fnext;
60082 + atomic_unchecked_t num_fclose;
60083 + atomic_unchecked_t num_hardlinks;
60084 + atomic_unchecked_t num_symlinks;
60085 + atomic_unchecked_t num_locks;
60086 + atomic_unchecked_t num_acl_get;
60087 + atomic_unchecked_t num_acl_set;
60088 } cifs_stats;
60089 #ifdef CONFIG_CIFS_SMB2
60090 struct {
60091 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
60092 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
60093 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
60094 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
60095 } smb2_stats;
60096 #endif /* CONFIG_CIFS_SMB2 */
60097 } stats;
60098 @@ -1190,7 +1190,7 @@ convert_delimiter(char *path, char delim)
60099 }
60100
60101 #ifdef CONFIG_CIFS_STATS
60102 -#define cifs_stats_inc atomic_inc
60103 +#define cifs_stats_inc atomic_inc_unchecked
60104
60105 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
60106 unsigned int bytes)
60107 @@ -1557,8 +1557,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
60108 /* Various Debug counters */
60109 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
60110 #ifdef CONFIG_CIFS_STATS2
60111 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
60112 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
60113 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
60114 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
60115 #endif
60116 GLOBAL_EXTERN atomic_t smBufAllocCount;
60117 GLOBAL_EXTERN atomic_t midCount;
60118 diff --git a/fs/cifs/file.c b/fs/cifs/file.c
60119 index 5f29354..359bc0d 100644
60120 --- a/fs/cifs/file.c
60121 +++ b/fs/cifs/file.c
60122 @@ -2056,10 +2056,14 @@ static int cifs_writepages(struct address_space *mapping,
60123 index = mapping->writeback_index; /* Start from prev offset */
60124 end = -1;
60125 } else {
60126 - index = wbc->range_start >> PAGE_CACHE_SHIFT;
60127 - end = wbc->range_end >> PAGE_CACHE_SHIFT;
60128 - if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
60129 + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
60130 range_whole = true;
60131 + index = 0;
60132 + end = ULONG_MAX;
60133 + } else {
60134 + index = wbc->range_start >> PAGE_CACHE_SHIFT;
60135 + end = wbc->range_end >> PAGE_CACHE_SHIFT;
60136 + }
60137 scanned = true;
60138 }
60139 server = cifs_sb_master_tcon(cifs_sb)->ses->server;
60140 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
60141 index b7415d5..3984ec0 100644
60142 --- a/fs/cifs/misc.c
60143 +++ b/fs/cifs/misc.c
60144 @@ -170,7 +170,7 @@ cifs_buf_get(void)
60145 memset(ret_buf, 0, buf_size + 3);
60146 atomic_inc(&bufAllocCount);
60147 #ifdef CONFIG_CIFS_STATS2
60148 - atomic_inc(&totBufAllocCount);
60149 + atomic_inc_unchecked(&totBufAllocCount);
60150 #endif /* CONFIG_CIFS_STATS2 */
60151 }
60152
60153 @@ -205,7 +205,7 @@ cifs_small_buf_get(void)
60154 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
60155 atomic_inc(&smBufAllocCount);
60156 #ifdef CONFIG_CIFS_STATS2
60157 - atomic_inc(&totSmBufAllocCount);
60158 + atomic_inc_unchecked(&totSmBufAllocCount);
60159 #endif /* CONFIG_CIFS_STATS2 */
60160
60161 }
60162 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
60163 index 52131d8..fd79e97 100644
60164 --- a/fs/cifs/smb1ops.c
60165 +++ b/fs/cifs/smb1ops.c
60166 @@ -626,27 +626,27 @@ static void
60167 cifs_clear_stats(struct cifs_tcon *tcon)
60168 {
60169 #ifdef CONFIG_CIFS_STATS
60170 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
60171 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
60172 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
60173 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
60174 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
60175 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
60176 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
60177 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
60178 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
60179 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
60180 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
60181 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
60182 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
60183 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
60184 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
60185 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
60186 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
60187 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
60188 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
60189 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
60190 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
60191 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
60192 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
60193 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
60194 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
60195 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
60196 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
60197 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
60198 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
60199 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
60200 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
60201 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
60202 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
60203 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
60204 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
60205 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
60206 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
60207 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
60208 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
60209 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
60210 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
60211 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
60212 #endif
60213 }
60214
60215 @@ -655,36 +655,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
60216 {
60217 #ifdef CONFIG_CIFS_STATS
60218 seq_printf(m, " Oplocks breaks: %d",
60219 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
60220 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
60221 seq_printf(m, "\nReads: %d Bytes: %llu",
60222 - atomic_read(&tcon->stats.cifs_stats.num_reads),
60223 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
60224 (long long)(tcon->bytes_read));
60225 seq_printf(m, "\nWrites: %d Bytes: %llu",
60226 - atomic_read(&tcon->stats.cifs_stats.num_writes),
60227 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
60228 (long long)(tcon->bytes_written));
60229 seq_printf(m, "\nFlushes: %d",
60230 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
60231 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
60232 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
60233 - atomic_read(&tcon->stats.cifs_stats.num_locks),
60234 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
60235 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
60236 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
60237 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
60238 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
60239 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
60240 - atomic_read(&tcon->stats.cifs_stats.num_opens),
60241 - atomic_read(&tcon->stats.cifs_stats.num_closes),
60242 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
60243 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
60244 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
60245 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
60246 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
60247 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
60248 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
60249 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
60250 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
60251 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
60252 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
60253 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
60254 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
60255 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
60256 seq_printf(m, "\nRenames: %d T2 Renames %d",
60257 - atomic_read(&tcon->stats.cifs_stats.num_renames),
60258 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
60259 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
60260 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
60261 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
60262 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
60263 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
60264 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
60265 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
60266 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
60267 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
60268 #endif
60269 }
60270
60271 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
60272 index f522193..586121b 100644
60273 --- a/fs/cifs/smb2ops.c
60274 +++ b/fs/cifs/smb2ops.c
60275 @@ -414,8 +414,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
60276 #ifdef CONFIG_CIFS_STATS
60277 int i;
60278 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
60279 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
60280 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
60281 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
60282 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
60283 }
60284 #endif
60285 }
60286 @@ -455,65 +455,65 @@ static void
60287 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
60288 {
60289 #ifdef CONFIG_CIFS_STATS
60290 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
60291 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
60292 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
60293 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
60294 seq_printf(m, "\nNegotiates: %d sent %d failed",
60295 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
60296 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
60297 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
60298 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
60299 seq_printf(m, "\nSessionSetups: %d sent %d failed",
60300 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
60301 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
60302 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
60303 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
60304 seq_printf(m, "\nLogoffs: %d sent %d failed",
60305 - atomic_read(&sent[SMB2_LOGOFF_HE]),
60306 - atomic_read(&failed[SMB2_LOGOFF_HE]));
60307 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
60308 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
60309 seq_printf(m, "\nTreeConnects: %d sent %d failed",
60310 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
60311 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
60312 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
60313 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
60314 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
60315 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
60316 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
60317 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
60318 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
60319 seq_printf(m, "\nCreates: %d sent %d failed",
60320 - atomic_read(&sent[SMB2_CREATE_HE]),
60321 - atomic_read(&failed[SMB2_CREATE_HE]));
60322 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
60323 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
60324 seq_printf(m, "\nCloses: %d sent %d failed",
60325 - atomic_read(&sent[SMB2_CLOSE_HE]),
60326 - atomic_read(&failed[SMB2_CLOSE_HE]));
60327 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
60328 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
60329 seq_printf(m, "\nFlushes: %d sent %d failed",
60330 - atomic_read(&sent[SMB2_FLUSH_HE]),
60331 - atomic_read(&failed[SMB2_FLUSH_HE]));
60332 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
60333 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
60334 seq_printf(m, "\nReads: %d sent %d failed",
60335 - atomic_read(&sent[SMB2_READ_HE]),
60336 - atomic_read(&failed[SMB2_READ_HE]));
60337 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
60338 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
60339 seq_printf(m, "\nWrites: %d sent %d failed",
60340 - atomic_read(&sent[SMB2_WRITE_HE]),
60341 - atomic_read(&failed[SMB2_WRITE_HE]));
60342 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
60343 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
60344 seq_printf(m, "\nLocks: %d sent %d failed",
60345 - atomic_read(&sent[SMB2_LOCK_HE]),
60346 - atomic_read(&failed[SMB2_LOCK_HE]));
60347 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
60348 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
60349 seq_printf(m, "\nIOCTLs: %d sent %d failed",
60350 - atomic_read(&sent[SMB2_IOCTL_HE]),
60351 - atomic_read(&failed[SMB2_IOCTL_HE]));
60352 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
60353 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
60354 seq_printf(m, "\nCancels: %d sent %d failed",
60355 - atomic_read(&sent[SMB2_CANCEL_HE]),
60356 - atomic_read(&failed[SMB2_CANCEL_HE]));
60357 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
60358 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
60359 seq_printf(m, "\nEchos: %d sent %d failed",
60360 - atomic_read(&sent[SMB2_ECHO_HE]),
60361 - atomic_read(&failed[SMB2_ECHO_HE]));
60362 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
60363 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
60364 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
60365 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
60366 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
60367 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
60368 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
60369 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
60370 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
60371 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
60372 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
60373 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
60374 seq_printf(m, "\nQueryInfos: %d sent %d failed",
60375 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
60376 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
60377 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
60378 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
60379 seq_printf(m, "\nSetInfos: %d sent %d failed",
60380 - atomic_read(&sent[SMB2_SET_INFO_HE]),
60381 - atomic_read(&failed[SMB2_SET_INFO_HE]));
60382 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
60383 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
60384 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
60385 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
60386 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
60387 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
60388 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
60389 #endif
60390 }
60391
60392 diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
60393 index 74b3a66..0c709f3 100644
60394 --- a/fs/cifs/smb2pdu.c
60395 +++ b/fs/cifs/smb2pdu.c
60396 @@ -2143,8 +2143,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
60397 default:
60398 cifs_dbg(VFS, "info level %u isn't supported\n",
60399 srch_inf->info_level);
60400 - rc = -EINVAL;
60401 - goto qdir_exit;
60402 + return -EINVAL;
60403 }
60404
60405 req->FileIndex = cpu_to_le32(index);
60406 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
60407 index 278f8fd..e69c52d 100644
60408 --- a/fs/coda/cache.c
60409 +++ b/fs/coda/cache.c
60410 @@ -24,7 +24,7 @@
60411 #include "coda_linux.h"
60412 #include "coda_cache.h"
60413
60414 -static atomic_t permission_epoch = ATOMIC_INIT(0);
60415 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
60416
60417 /* replace or extend an acl cache hit */
60418 void coda_cache_enter(struct inode *inode, int mask)
60419 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
60420 struct coda_inode_info *cii = ITOC(inode);
60421
60422 spin_lock(&cii->c_lock);
60423 - cii->c_cached_epoch = atomic_read(&permission_epoch);
60424 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
60425 if (!uid_eq(cii->c_uid, current_fsuid())) {
60426 cii->c_uid = current_fsuid();
60427 cii->c_cached_perm = mask;
60428 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
60429 {
60430 struct coda_inode_info *cii = ITOC(inode);
60431 spin_lock(&cii->c_lock);
60432 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
60433 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
60434 spin_unlock(&cii->c_lock);
60435 }
60436
60437 /* remove all acl caches */
60438 void coda_cache_clear_all(struct super_block *sb)
60439 {
60440 - atomic_inc(&permission_epoch);
60441 + atomic_inc_unchecked(&permission_epoch);
60442 }
60443
60444
60445 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
60446 spin_lock(&cii->c_lock);
60447 hit = (mask & cii->c_cached_perm) == mask &&
60448 uid_eq(cii->c_uid, current_fsuid()) &&
60449 - cii->c_cached_epoch == atomic_read(&permission_epoch);
60450 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
60451 spin_unlock(&cii->c_lock);
60452
60453 return hit;
60454 diff --git a/fs/compat.c b/fs/compat.c
60455 index 66d3d3c..9c10175 100644
60456 --- a/fs/compat.c
60457 +++ b/fs/compat.c
60458 @@ -54,7 +54,7 @@
60459 #include <asm/ioctls.h>
60460 #include "internal.h"
60461
60462 -int compat_log = 1;
60463 +int compat_log = 0;
60464
60465 int compat_printk(const char *fmt, ...)
60466 {
60467 @@ -512,7 +512,7 @@ COMPAT_SYSCALL_DEFINE2(io_setup, unsigned, nr_reqs, u32 __user *, ctx32p)
60468
60469 set_fs(KERNEL_DS);
60470 /* The __user pointer cast is valid because of the set_fs() */
60471 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
60472 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
60473 set_fs(oldfs);
60474 /* truncating is ok because it's a user address */
60475 if (!ret)
60476 @@ -562,7 +562,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
60477 goto out;
60478
60479 ret = -EINVAL;
60480 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
60481 + if (nr_segs > UIO_MAXIOV)
60482 goto out;
60483 if (nr_segs > fast_segs) {
60484 ret = -ENOMEM;
60485 @@ -850,6 +850,7 @@ struct compat_old_linux_dirent {
60486 struct compat_readdir_callback {
60487 struct dir_context ctx;
60488 struct compat_old_linux_dirent __user *dirent;
60489 + struct file * file;
60490 int result;
60491 };
60492
60493 @@ -867,6 +868,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
60494 buf->result = -EOVERFLOW;
60495 return -EOVERFLOW;
60496 }
60497 +
60498 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60499 + return 0;
60500 +
60501 buf->result++;
60502 dirent = buf->dirent;
60503 if (!access_ok(VERIFY_WRITE, dirent,
60504 @@ -898,6 +903,7 @@ COMPAT_SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
60505 if (!f.file)
60506 return -EBADF;
60507
60508 + buf.file = f.file;
60509 error = iterate_dir(f.file, &buf.ctx);
60510 if (buf.result)
60511 error = buf.result;
60512 @@ -917,6 +923,7 @@ struct compat_getdents_callback {
60513 struct dir_context ctx;
60514 struct compat_linux_dirent __user *current_dir;
60515 struct compat_linux_dirent __user *previous;
60516 + struct file * file;
60517 int count;
60518 int error;
60519 };
60520 @@ -938,6 +945,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
60521 buf->error = -EOVERFLOW;
60522 return -EOVERFLOW;
60523 }
60524 +
60525 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60526 + return 0;
60527 +
60528 dirent = buf->previous;
60529 if (dirent) {
60530 if (__put_user(offset, &dirent->d_off))
60531 @@ -983,6 +994,7 @@ COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd,
60532 if (!f.file)
60533 return -EBADF;
60534
60535 + buf.file = f.file;
60536 error = iterate_dir(f.file, &buf.ctx);
60537 if (error >= 0)
60538 error = buf.error;
60539 @@ -1003,6 +1015,7 @@ struct compat_getdents_callback64 {
60540 struct dir_context ctx;
60541 struct linux_dirent64 __user *current_dir;
60542 struct linux_dirent64 __user *previous;
60543 + struct file * file;
60544 int count;
60545 int error;
60546 };
60547 @@ -1019,6 +1032,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
60548 buf->error = -EINVAL; /* only used if we fail.. */
60549 if (reclen > buf->count)
60550 return -EINVAL;
60551 +
60552 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60553 + return 0;
60554 +
60555 dirent = buf->previous;
60556
60557 if (dirent) {
60558 @@ -1068,6 +1085,7 @@ COMPAT_SYSCALL_DEFINE3(getdents64, unsigned int, fd,
60559 if (!f.file)
60560 return -EBADF;
60561
60562 + buf.file = f.file;
60563 error = iterate_dir(f.file, &buf.ctx);
60564 if (error >= 0)
60565 error = buf.error;
60566 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
60567 index 4d24d17..4f8c09e 100644
60568 --- a/fs/compat_binfmt_elf.c
60569 +++ b/fs/compat_binfmt_elf.c
60570 @@ -30,11 +30,13 @@
60571 #undef elf_phdr
60572 #undef elf_shdr
60573 #undef elf_note
60574 +#undef elf_dyn
60575 #undef elf_addr_t
60576 #define elfhdr elf32_hdr
60577 #define elf_phdr elf32_phdr
60578 #define elf_shdr elf32_shdr
60579 #define elf_note elf32_note
60580 +#define elf_dyn Elf32_Dyn
60581 #define elf_addr_t Elf32_Addr
60582
60583 /*
60584 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
60585 index afec645..9c65620 100644
60586 --- a/fs/compat_ioctl.c
60587 +++ b/fs/compat_ioctl.c
60588 @@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
60589 return -EFAULT;
60590 if (__get_user(udata, &ss32->iomem_base))
60591 return -EFAULT;
60592 - ss.iomem_base = compat_ptr(udata);
60593 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
60594 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
60595 __get_user(ss.port_high, &ss32->port_high))
60596 return -EFAULT;
60597 @@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
60598 for (i = 0; i < nmsgs; i++) {
60599 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
60600 return -EFAULT;
60601 - if (get_user(datap, &umsgs[i].buf) ||
60602 - put_user(compat_ptr(datap), &tmsgs[i].buf))
60603 + if (get_user(datap, (compat_caddr_t __user *)&umsgs[i].buf) ||
60604 + put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
60605 return -EFAULT;
60606 }
60607 return sys_ioctl(fd, cmd, (unsigned long)tdata);
60608 @@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
60609 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
60610 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
60611 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
60612 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
60613 + copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
60614 return -EFAULT;
60615
60616 return ioctl_preallocate(file, p);
60617 @@ -1618,8 +1618,8 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
60618 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
60619 {
60620 unsigned int a, b;
60621 - a = *(unsigned int *)p;
60622 - b = *(unsigned int *)q;
60623 + a = *(const unsigned int *)p;
60624 + b = *(const unsigned int *)q;
60625 if (a > b)
60626 return 1;
60627 if (a < b)
60628 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
60629 index 668dcab..daebcd6 100644
60630 --- a/fs/configfs/dir.c
60631 +++ b/fs/configfs/dir.c
60632 @@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
60633 }
60634 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
60635 struct configfs_dirent *next;
60636 - const char *name;
60637 + const unsigned char * name;
60638 + char d_name[sizeof(next->s_dentry->d_iname)];
60639 int len;
60640 struct inode *inode = NULL;
60641
60642 @@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
60643 continue;
60644
60645 name = configfs_get_name(next);
60646 - len = strlen(name);
60647 + if (next->s_dentry && name == next->s_dentry->d_iname) {
60648 + len = next->s_dentry->d_name.len;
60649 + memcpy(d_name, name, len);
60650 + name = d_name;
60651 + } else
60652 + len = strlen(name);
60653
60654 /*
60655 * We'll have a dentry and an inode for
60656 diff --git a/fs/coredump.c b/fs/coredump.c
60657 index a93f7e6..d58bcbe 100644
60658 --- a/fs/coredump.c
60659 +++ b/fs/coredump.c
60660 @@ -442,8 +442,8 @@ static void wait_for_dump_helpers(struct file *file)
60661 struct pipe_inode_info *pipe = file->private_data;
60662
60663 pipe_lock(pipe);
60664 - pipe->readers++;
60665 - pipe->writers--;
60666 + atomic_inc(&pipe->readers);
60667 + atomic_dec(&pipe->writers);
60668 wake_up_interruptible_sync(&pipe->wait);
60669 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
60670 pipe_unlock(pipe);
60671 @@ -452,11 +452,11 @@ static void wait_for_dump_helpers(struct file *file)
60672 * We actually want wait_event_freezable() but then we need
60673 * to clear TIF_SIGPENDING and improve dump_interrupted().
60674 */
60675 - wait_event_interruptible(pipe->wait, pipe->readers == 1);
60676 + wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
60677
60678 pipe_lock(pipe);
60679 - pipe->readers--;
60680 - pipe->writers++;
60681 + atomic_dec(&pipe->readers);
60682 + atomic_inc(&pipe->writers);
60683 pipe_unlock(pipe);
60684 }
60685
60686 @@ -503,7 +503,9 @@ void do_coredump(const siginfo_t *siginfo)
60687 struct files_struct *displaced;
60688 bool need_nonrelative = false;
60689 bool core_dumped = false;
60690 - static atomic_t core_dump_count = ATOMIC_INIT(0);
60691 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
60692 + long signr = siginfo->si_signo;
60693 + int dumpable;
60694 struct coredump_params cprm = {
60695 .siginfo = siginfo,
60696 .regs = signal_pt_regs(),
60697 @@ -516,12 +518,17 @@ void do_coredump(const siginfo_t *siginfo)
60698 .mm_flags = mm->flags,
60699 };
60700
60701 - audit_core_dumps(siginfo->si_signo);
60702 + audit_core_dumps(signr);
60703 +
60704 + dumpable = __get_dumpable(cprm.mm_flags);
60705 +
60706 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
60707 + gr_handle_brute_attach(dumpable);
60708
60709 binfmt = mm->binfmt;
60710 if (!binfmt || !binfmt->core_dump)
60711 goto fail;
60712 - if (!__get_dumpable(cprm.mm_flags))
60713 + if (!dumpable)
60714 goto fail;
60715
60716 cred = prepare_creds();
60717 @@ -540,7 +547,7 @@ void do_coredump(const siginfo_t *siginfo)
60718 need_nonrelative = true;
60719 }
60720
60721 - retval = coredump_wait(siginfo->si_signo, &core_state);
60722 + retval = coredump_wait(signr, &core_state);
60723 if (retval < 0)
60724 goto fail_creds;
60725
60726 @@ -583,7 +590,7 @@ void do_coredump(const siginfo_t *siginfo)
60727 }
60728 cprm.limit = RLIM_INFINITY;
60729
60730 - dump_count = atomic_inc_return(&core_dump_count);
60731 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
60732 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
60733 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
60734 task_tgid_vnr(current), current->comm);
60735 @@ -615,6 +622,8 @@ void do_coredump(const siginfo_t *siginfo)
60736 } else {
60737 struct inode *inode;
60738
60739 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
60740 +
60741 if (cprm.limit < binfmt->min_coredump)
60742 goto fail_unlock;
60743
60744 @@ -673,7 +682,7 @@ close_fail:
60745 filp_close(cprm.file, NULL);
60746 fail_dropcount:
60747 if (ispipe)
60748 - atomic_dec(&core_dump_count);
60749 + atomic_dec_unchecked(&core_dump_count);
60750 fail_unlock:
60751 kfree(cn.corename);
60752 coredump_finish(mm, core_dumped);
60753 @@ -694,6 +703,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
60754 struct file *file = cprm->file;
60755 loff_t pos = file->f_pos;
60756 ssize_t n;
60757 +
60758 + gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
60759 if (cprm->written + nr > cprm->limit)
60760 return 0;
60761 while (nr) {
60762 diff --git a/fs/dcache.c b/fs/dcache.c
60763 index 34b40be8..2003532 100644
60764 --- a/fs/dcache.c
60765 +++ b/fs/dcache.c
60766 @@ -478,7 +478,7 @@ static void __dentry_kill(struct dentry *dentry)
60767 * dentry_iput drops the locks, at which point nobody (except
60768 * transient RCU lookups) can reach this dentry.
60769 */
60770 - BUG_ON((int)dentry->d_lockref.count > 0);
60771 + BUG_ON((int)__lockref_read(&dentry->d_lockref) > 0);
60772 this_cpu_dec(nr_dentry);
60773 if (dentry->d_op && dentry->d_op->d_release)
60774 dentry->d_op->d_release(dentry);
60775 @@ -531,7 +531,7 @@ static inline struct dentry *lock_parent(struct dentry *dentry)
60776 struct dentry *parent = dentry->d_parent;
60777 if (IS_ROOT(dentry))
60778 return NULL;
60779 - if (unlikely((int)dentry->d_lockref.count < 0))
60780 + if (unlikely((int)__lockref_read(&dentry->d_lockref) < 0))
60781 return NULL;
60782 if (likely(spin_trylock(&parent->d_lock)))
60783 return parent;
60784 @@ -608,7 +608,7 @@ repeat:
60785 dentry->d_flags |= DCACHE_REFERENCED;
60786 dentry_lru_add(dentry);
60787
60788 - dentry->d_lockref.count--;
60789 + __lockref_dec(&dentry->d_lockref);
60790 spin_unlock(&dentry->d_lock);
60791 return;
60792
60793 @@ -663,7 +663,7 @@ int d_invalidate(struct dentry * dentry)
60794 * We also need to leave mountpoints alone,
60795 * directory or not.
60796 */
60797 - if (dentry->d_lockref.count > 1 && dentry->d_inode) {
60798 + if (__lockref_read(&dentry->d_lockref) > 1 && dentry->d_inode) {
60799 if (S_ISDIR(dentry->d_inode->i_mode) || d_mountpoint(dentry)) {
60800 spin_unlock(&dentry->d_lock);
60801 return -EBUSY;
60802 @@ -679,7 +679,7 @@ EXPORT_SYMBOL(d_invalidate);
60803 /* This must be called with d_lock held */
60804 static inline void __dget_dlock(struct dentry *dentry)
60805 {
60806 - dentry->d_lockref.count++;
60807 + __lockref_inc(&dentry->d_lockref);
60808 }
60809
60810 static inline void __dget(struct dentry *dentry)
60811 @@ -720,8 +720,8 @@ repeat:
60812 goto repeat;
60813 }
60814 rcu_read_unlock();
60815 - BUG_ON(!ret->d_lockref.count);
60816 - ret->d_lockref.count++;
60817 + BUG_ON(!__lockref_read(&ret->d_lockref));
60818 + __lockref_inc(&ret->d_lockref);
60819 spin_unlock(&ret->d_lock);
60820 return ret;
60821 }
60822 @@ -798,7 +798,7 @@ restart:
60823 spin_lock(&inode->i_lock);
60824 hlist_for_each_entry(dentry, &inode->i_dentry, d_alias) {
60825 spin_lock(&dentry->d_lock);
60826 - if (!dentry->d_lockref.count) {
60827 + if (!__lockref_read(&dentry->d_lockref)) {
60828 /*
60829 * inform the fs via d_prune that this dentry
60830 * is about to be unhashed and destroyed.
60831 @@ -841,7 +841,7 @@ static void shrink_dentry_list(struct list_head *list)
60832 * We found an inuse dentry which was not removed from
60833 * the LRU because of laziness during lookup. Do not free it.
60834 */
60835 - if ((int)dentry->d_lockref.count > 0) {
60836 + if ((int)__lockref_read(&dentry->d_lockref) > 0) {
60837 spin_unlock(&dentry->d_lock);
60838 if (parent)
60839 spin_unlock(&parent->d_lock);
60840 @@ -879,8 +879,8 @@ static void shrink_dentry_list(struct list_head *list)
60841 dentry = parent;
60842 while (dentry && !lockref_put_or_lock(&dentry->d_lockref)) {
60843 parent = lock_parent(dentry);
60844 - if (dentry->d_lockref.count != 1) {
60845 - dentry->d_lockref.count--;
60846 + if (__lockref_read(&dentry->d_lockref) != 1) {
60847 + __lockref_inc(&dentry->d_lockref);
60848 spin_unlock(&dentry->d_lock);
60849 if (parent)
60850 spin_unlock(&parent->d_lock);
60851 @@ -920,7 +920,7 @@ dentry_lru_isolate(struct list_head *item, spinlock_t *lru_lock, void *arg)
60852 * counts, just remove them from the LRU. Otherwise give them
60853 * another pass through the LRU.
60854 */
60855 - if (dentry->d_lockref.count) {
60856 + if (__lockref_read(&dentry->d_lockref) > 0) {
60857 d_lru_isolate(dentry);
60858 spin_unlock(&dentry->d_lock);
60859 return LRU_REMOVED;
60860 @@ -1149,6 +1149,7 @@ out_unlock:
60861 return;
60862
60863 rename_retry:
60864 + done_seqretry(&rename_lock, seq);
60865 if (!retry)
60866 return;
60867 seq = 1;
60868 @@ -1255,7 +1256,7 @@ static enum d_walk_ret select_collect(void *_data, struct dentry *dentry)
60869 } else {
60870 if (dentry->d_flags & DCACHE_LRU_LIST)
60871 d_lru_del(dentry);
60872 - if (!dentry->d_lockref.count) {
60873 + if (!__lockref_read(&dentry->d_lockref)) {
60874 d_shrink_add(dentry, &data->dispose);
60875 data->found++;
60876 }
60877 @@ -1303,7 +1304,7 @@ static enum d_walk_ret umount_check(void *_data, struct dentry *dentry)
60878 return D_WALK_CONTINUE;
60879
60880 /* root with refcount 1 is fine */
60881 - if (dentry == _data && dentry->d_lockref.count == 1)
60882 + if (dentry == _data && __lockref_read(&dentry->d_lockref) == 1)
60883 return D_WALK_CONTINUE;
60884
60885 printk(KERN_ERR "BUG: Dentry %p{i=%lx,n=%pd} "
60886 @@ -1312,7 +1313,7 @@ static enum d_walk_ret umount_check(void *_data, struct dentry *dentry)
60887 dentry->d_inode ?
60888 dentry->d_inode->i_ino : 0UL,
60889 dentry,
60890 - dentry->d_lockref.count,
60891 + __lockref_read(&dentry->d_lockref),
60892 dentry->d_sb->s_type->name,
60893 dentry->d_sb->s_id);
60894 WARN_ON(1);
60895 @@ -1438,7 +1439,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
60896 */
60897 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
60898 if (name->len > DNAME_INLINE_LEN-1) {
60899 - dname = kmalloc(name->len + 1, GFP_KERNEL);
60900 + dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
60901 if (!dname) {
60902 kmem_cache_free(dentry_cache, dentry);
60903 return NULL;
60904 @@ -1456,7 +1457,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
60905 smp_wmb();
60906 dentry->d_name.name = dname;
60907
60908 - dentry->d_lockref.count = 1;
60909 + __lockref_set(&dentry->d_lockref, 1);
60910 dentry->d_flags = 0;
60911 spin_lock_init(&dentry->d_lock);
60912 seqcount_init(&dentry->d_seq);
60913 @@ -2196,7 +2197,7 @@ struct dentry *__d_lookup(const struct dentry *parent, const struct qstr *name)
60914 goto next;
60915 }
60916
60917 - dentry->d_lockref.count++;
60918 + __lockref_inc(&dentry->d_lockref);
60919 found = dentry;
60920 spin_unlock(&dentry->d_lock);
60921 break;
60922 @@ -2295,7 +2296,7 @@ again:
60923 spin_lock(&dentry->d_lock);
60924 inode = dentry->d_inode;
60925 isdir = S_ISDIR(inode->i_mode);
60926 - if (dentry->d_lockref.count == 1) {
60927 + if (__lockref_read(&dentry->d_lockref) == 1) {
60928 if (!spin_trylock(&inode->i_lock)) {
60929 spin_unlock(&dentry->d_lock);
60930 cpu_relax();
60931 @@ -3307,7 +3308,7 @@ static enum d_walk_ret d_genocide_kill(void *data, struct dentry *dentry)
60932
60933 if (!(dentry->d_flags & DCACHE_GENOCIDE)) {
60934 dentry->d_flags |= DCACHE_GENOCIDE;
60935 - dentry->d_lockref.count--;
60936 + __lockref_dec(&dentry->d_lockref);
60937 }
60938 }
60939 return D_WALK_CONTINUE;
60940 @@ -3423,7 +3424,8 @@ void __init vfs_caches_init(unsigned long mempages)
60941 mempages -= reserve;
60942
60943 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
60944 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
60945 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
60946 + SLAB_NO_SANITIZE, NULL);
60947
60948 dcache_init();
60949 inode_init();
60950 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
60951 index 1e3b99d..6512101 100644
60952 --- a/fs/debugfs/inode.c
60953 +++ b/fs/debugfs/inode.c
60954 @@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
60955 */
60956 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
60957 {
60958 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
60959 + return __create_file(name, S_IFDIR | S_IRWXU,
60960 +#else
60961 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
60962 +#endif
60963 parent, NULL, NULL);
60964 }
60965 EXPORT_SYMBOL_GPL(debugfs_create_dir);
60966 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
60967 index 57ee4c5..ecb13b0 100644
60968 --- a/fs/ecryptfs/inode.c
60969 +++ b/fs/ecryptfs/inode.c
60970 @@ -673,7 +673,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
60971 old_fs = get_fs();
60972 set_fs(get_ds());
60973 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
60974 - (char __user *)lower_buf,
60975 + (char __force_user *)lower_buf,
60976 PATH_MAX);
60977 set_fs(old_fs);
60978 if (rc < 0)
60979 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
60980 index e4141f2..d8263e8 100644
60981 --- a/fs/ecryptfs/miscdev.c
60982 +++ b/fs/ecryptfs/miscdev.c
60983 @@ -304,7 +304,7 @@ check_list:
60984 goto out_unlock_msg_ctx;
60985 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
60986 if (msg_ctx->msg) {
60987 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
60988 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
60989 goto out_unlock_msg_ctx;
60990 i += packet_length_size;
60991 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
60992 diff --git a/fs/exec.c b/fs/exec.c
60993 index a2b42a9..1e924b3 100644
60994 --- a/fs/exec.c
60995 +++ b/fs/exec.c
60996 @@ -56,8 +56,20 @@
60997 #include <linux/pipe_fs_i.h>
60998 #include <linux/oom.h>
60999 #include <linux/compat.h>
61000 +#include <linux/random.h>
61001 +#include <linux/seq_file.h>
61002 +#include <linux/coredump.h>
61003 +#include <linux/mman.h>
61004 +
61005 +#ifdef CONFIG_PAX_REFCOUNT
61006 +#include <linux/kallsyms.h>
61007 +#include <linux/kdebug.h>
61008 +#endif
61009 +
61010 +#include <trace/events/fs.h>
61011
61012 #include <asm/uaccess.h>
61013 +#include <asm/sections.h>
61014 #include <asm/mmu_context.h>
61015 #include <asm/tlb.h>
61016
61017 @@ -66,19 +78,34 @@
61018
61019 #include <trace/events/sched.h>
61020
61021 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
61022 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
61023 +{
61024 + 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");
61025 +}
61026 +#endif
61027 +
61028 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
61029 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
61030 +EXPORT_SYMBOL(pax_set_initial_flags_func);
61031 +#endif
61032 +
61033 int suid_dumpable = 0;
61034
61035 static LIST_HEAD(formats);
61036 static DEFINE_RWLOCK(binfmt_lock);
61037
61038 +extern int gr_process_kernel_exec_ban(void);
61039 +extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
61040 +
61041 void __register_binfmt(struct linux_binfmt * fmt, int insert)
61042 {
61043 BUG_ON(!fmt);
61044 if (WARN_ON(!fmt->load_binary))
61045 return;
61046 write_lock(&binfmt_lock);
61047 - insert ? list_add(&fmt->lh, &formats) :
61048 - list_add_tail(&fmt->lh, &formats);
61049 + insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
61050 + pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
61051 write_unlock(&binfmt_lock);
61052 }
61053
61054 @@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
61055 void unregister_binfmt(struct linux_binfmt * fmt)
61056 {
61057 write_lock(&binfmt_lock);
61058 - list_del(&fmt->lh);
61059 + pax_list_del((struct list_head *)&fmt->lh);
61060 write_unlock(&binfmt_lock);
61061 }
61062
61063 @@ -183,18 +210,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
61064 int write)
61065 {
61066 struct page *page;
61067 - int ret;
61068
61069 -#ifdef CONFIG_STACK_GROWSUP
61070 - if (write) {
61071 - ret = expand_downwards(bprm->vma, pos);
61072 - if (ret < 0)
61073 - return NULL;
61074 - }
61075 -#endif
61076 - ret = get_user_pages(current, bprm->mm, pos,
61077 - 1, write, 1, &page, NULL);
61078 - if (ret <= 0)
61079 + if (0 > expand_downwards(bprm->vma, pos))
61080 + return NULL;
61081 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
61082 return NULL;
61083
61084 if (write) {
61085 @@ -210,6 +229,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
61086 if (size <= ARG_MAX)
61087 return page;
61088
61089 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61090 + // only allow 512KB for argv+env on suid/sgid binaries
61091 + // to prevent easy ASLR exhaustion
61092 + if (((!uid_eq(bprm->cred->euid, current_euid())) ||
61093 + (!gid_eq(bprm->cred->egid, current_egid()))) &&
61094 + (size > (512 * 1024))) {
61095 + put_page(page);
61096 + return NULL;
61097 + }
61098 +#endif
61099 +
61100 /*
61101 * Limit to 1/4-th the stack size for the argv+env strings.
61102 * This ensures that:
61103 @@ -269,6 +299,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
61104 vma->vm_end = STACK_TOP_MAX;
61105 vma->vm_start = vma->vm_end - PAGE_SIZE;
61106 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
61107 +
61108 +#ifdef CONFIG_PAX_SEGMEXEC
61109 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
61110 +#endif
61111 +
61112 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
61113 INIT_LIST_HEAD(&vma->anon_vma_chain);
61114
61115 @@ -279,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
61116 mm->stack_vm = mm->total_vm = 1;
61117 up_write(&mm->mmap_sem);
61118 bprm->p = vma->vm_end - sizeof(void *);
61119 +
61120 +#ifdef CONFIG_PAX_RANDUSTACK
61121 + if (randomize_va_space)
61122 + bprm->p ^= prandom_u32() & ~PAGE_MASK;
61123 +#endif
61124 +
61125 return 0;
61126 err:
61127 up_write(&mm->mmap_sem);
61128 @@ -395,7 +436,7 @@ struct user_arg_ptr {
61129 } ptr;
61130 };
61131
61132 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61133 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61134 {
61135 const char __user *native;
61136
61137 @@ -404,14 +445,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61138 compat_uptr_t compat;
61139
61140 if (get_user(compat, argv.ptr.compat + nr))
61141 - return ERR_PTR(-EFAULT);
61142 + return (const char __force_user *)ERR_PTR(-EFAULT);
61143
61144 return compat_ptr(compat);
61145 }
61146 #endif
61147
61148 if (get_user(native, argv.ptr.native + nr))
61149 - return ERR_PTR(-EFAULT);
61150 + return (const char __force_user *)ERR_PTR(-EFAULT);
61151
61152 return native;
61153 }
61154 @@ -430,7 +471,7 @@ static int count(struct user_arg_ptr argv, int max)
61155 if (!p)
61156 break;
61157
61158 - if (IS_ERR(p))
61159 + if (IS_ERR((const char __force_kernel *)p))
61160 return -EFAULT;
61161
61162 if (i >= max)
61163 @@ -465,7 +506,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
61164
61165 ret = -EFAULT;
61166 str = get_user_arg_ptr(argv, argc);
61167 - if (IS_ERR(str))
61168 + if (IS_ERR((const char __force_kernel *)str))
61169 goto out;
61170
61171 len = strnlen_user(str, MAX_ARG_STRLEN);
61172 @@ -547,7 +588,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
61173 int r;
61174 mm_segment_t oldfs = get_fs();
61175 struct user_arg_ptr argv = {
61176 - .ptr.native = (const char __user *const __user *)__argv,
61177 + .ptr.native = (const char __user * const __force_user *)__argv,
61178 };
61179
61180 set_fs(KERNEL_DS);
61181 @@ -582,7 +623,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
61182 unsigned long new_end = old_end - shift;
61183 struct mmu_gather tlb;
61184
61185 - BUG_ON(new_start > new_end);
61186 + if (new_start >= new_end || new_start < mmap_min_addr)
61187 + return -ENOMEM;
61188
61189 /*
61190 * ensure there are no vmas between where we want to go
61191 @@ -591,6 +633,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
61192 if (vma != find_vma(mm, new_start))
61193 return -EFAULT;
61194
61195 +#ifdef CONFIG_PAX_SEGMEXEC
61196 + BUG_ON(pax_find_mirror_vma(vma));
61197 +#endif
61198 +
61199 /*
61200 * cover the whole range: [new_start, old_end)
61201 */
61202 @@ -671,10 +717,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
61203 stack_top = arch_align_stack(stack_top);
61204 stack_top = PAGE_ALIGN(stack_top);
61205
61206 - if (unlikely(stack_top < mmap_min_addr) ||
61207 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
61208 - return -ENOMEM;
61209 -
61210 stack_shift = vma->vm_end - stack_top;
61211
61212 bprm->p -= stack_shift;
61213 @@ -686,8 +728,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
61214 bprm->exec -= stack_shift;
61215
61216 down_write(&mm->mmap_sem);
61217 +
61218 + /* Move stack pages down in memory. */
61219 + if (stack_shift) {
61220 + ret = shift_arg_pages(vma, stack_shift);
61221 + if (ret)
61222 + goto out_unlock;
61223 + }
61224 +
61225 vm_flags = VM_STACK_FLAGS;
61226
61227 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
61228 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
61229 + vm_flags &= ~VM_EXEC;
61230 +
61231 +#ifdef CONFIG_PAX_MPROTECT
61232 + if (mm->pax_flags & MF_PAX_MPROTECT)
61233 + vm_flags &= ~VM_MAYEXEC;
61234 +#endif
61235 +
61236 + }
61237 +#endif
61238 +
61239 /*
61240 * Adjust stack execute permissions; explicitly enable for
61241 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
61242 @@ -706,13 +768,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
61243 goto out_unlock;
61244 BUG_ON(prev != vma);
61245
61246 - /* Move stack pages down in memory. */
61247 - if (stack_shift) {
61248 - ret = shift_arg_pages(vma, stack_shift);
61249 - if (ret)
61250 - goto out_unlock;
61251 - }
61252 -
61253 /* mprotect_fixup is overkill to remove the temporary stack flags */
61254 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
61255
61256 @@ -736,6 +791,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
61257 #endif
61258 current->mm->start_stack = bprm->p;
61259 ret = expand_stack(vma, stack_base);
61260 +
61261 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
61262 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
61263 + unsigned long size;
61264 + vm_flags_t vm_flags;
61265 +
61266 + size = STACK_TOP - vma->vm_end;
61267 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
61268 +
61269 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
61270 +
61271 +#ifdef CONFIG_X86
61272 + if (!ret) {
61273 + size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
61274 + ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
61275 + }
61276 +#endif
61277 +
61278 + }
61279 +#endif
61280 +
61281 if (ret)
61282 ret = -EFAULT;
61283
61284 @@ -771,6 +847,8 @@ static struct file *do_open_exec(struct filename *name)
61285
61286 fsnotify_open(file);
61287
61288 + trace_open_exec(name->name);
61289 +
61290 err = deny_write_access(file);
61291 if (err)
61292 goto exit;
61293 @@ -800,7 +878,7 @@ int kernel_read(struct file *file, loff_t offset,
61294 old_fs = get_fs();
61295 set_fs(get_ds());
61296 /* The cast to a user pointer is valid due to the set_fs() */
61297 - result = vfs_read(file, (void __user *)addr, count, &pos);
61298 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
61299 set_fs(old_fs);
61300 return result;
61301 }
61302 @@ -845,6 +923,7 @@ static int exec_mmap(struct mm_struct *mm)
61303 tsk->mm = mm;
61304 tsk->active_mm = mm;
61305 activate_mm(active_mm, mm);
61306 + populate_stack();
61307 tsk->mm->vmacache_seqnum = 0;
61308 vmacache_flush(tsk);
61309 task_unlock(tsk);
61310 @@ -1243,7 +1322,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
61311 }
61312 rcu_read_unlock();
61313
61314 - if (p->fs->users > n_fs)
61315 + if (atomic_read(&p->fs->users) > n_fs)
61316 bprm->unsafe |= LSM_UNSAFE_SHARE;
61317 else
61318 p->fs->in_exec = 1;
61319 @@ -1419,6 +1498,31 @@ static int exec_binprm(struct linux_binprm *bprm)
61320 return ret;
61321 }
61322
61323 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61324 +static DEFINE_PER_CPU(u64, exec_counter);
61325 +static int __init init_exec_counters(void)
61326 +{
61327 + unsigned int cpu;
61328 +
61329 + for_each_possible_cpu(cpu) {
61330 + per_cpu(exec_counter, cpu) = (u64)cpu;
61331 + }
61332 +
61333 + return 0;
61334 +}
61335 +early_initcall(init_exec_counters);
61336 +static inline void increment_exec_counter(void)
61337 +{
61338 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
61339 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
61340 +}
61341 +#else
61342 +static inline void increment_exec_counter(void) {}
61343 +#endif
61344 +
61345 +extern void gr_handle_exec_args(struct linux_binprm *bprm,
61346 + struct user_arg_ptr argv);
61347 +
61348 /*
61349 * sys_execve() executes a new program.
61350 */
61351 @@ -1426,6 +1530,11 @@ static int do_execve_common(struct filename *filename,
61352 struct user_arg_ptr argv,
61353 struct user_arg_ptr envp)
61354 {
61355 +#ifdef CONFIG_GRKERNSEC
61356 + struct file *old_exec_file;
61357 + struct acl_subject_label *old_acl;
61358 + struct rlimit old_rlim[RLIM_NLIMITS];
61359 +#endif
61360 struct linux_binprm *bprm;
61361 struct file *file;
61362 struct files_struct *displaced;
61363 @@ -1434,6 +1543,8 @@ static int do_execve_common(struct filename *filename,
61364 if (IS_ERR(filename))
61365 return PTR_ERR(filename);
61366
61367 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
61368 +
61369 /*
61370 * We move the actual failure in case of RLIMIT_NPROC excess from
61371 * set*uid() to execve() because too many poorly written programs
61372 @@ -1471,11 +1582,21 @@ static int do_execve_common(struct filename *filename,
61373 if (IS_ERR(file))
61374 goto out_unmark;
61375
61376 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
61377 + retval = -EPERM;
61378 + goto out_unmark;
61379 + }
61380 +
61381 sched_exec();
61382
61383 bprm->file = file;
61384 bprm->filename = bprm->interp = filename->name;
61385
61386 + if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
61387 + retval = -EACCES;
61388 + goto out_unmark;
61389 + }
61390 +
61391 retval = bprm_mm_init(bprm);
61392 if (retval)
61393 goto out_unmark;
61394 @@ -1492,24 +1613,70 @@ static int do_execve_common(struct filename *filename,
61395 if (retval < 0)
61396 goto out;
61397
61398 +#ifdef CONFIG_GRKERNSEC
61399 + old_acl = current->acl;
61400 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
61401 + old_exec_file = current->exec_file;
61402 + get_file(file);
61403 + current->exec_file = file;
61404 +#endif
61405 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61406 + /* limit suid stack to 8MB
61407 + * we saved the old limits above and will restore them if this exec fails
61408 + */
61409 + if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
61410 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
61411 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
61412 +#endif
61413 +
61414 + if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
61415 + retval = -EPERM;
61416 + goto out_fail;
61417 + }
61418 +
61419 + if (!gr_tpe_allow(file)) {
61420 + retval = -EACCES;
61421 + goto out_fail;
61422 + }
61423 +
61424 + if (gr_check_crash_exec(file)) {
61425 + retval = -EACCES;
61426 + goto out_fail;
61427 + }
61428 +
61429 + retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
61430 + bprm->unsafe);
61431 + if (retval < 0)
61432 + goto out_fail;
61433 +
61434 retval = copy_strings_kernel(1, &bprm->filename, bprm);
61435 if (retval < 0)
61436 - goto out;
61437 + goto out_fail;
61438
61439 bprm->exec = bprm->p;
61440 retval = copy_strings(bprm->envc, envp, bprm);
61441 if (retval < 0)
61442 - goto out;
61443 + goto out_fail;
61444
61445 retval = copy_strings(bprm->argc, argv, bprm);
61446 if (retval < 0)
61447 - goto out;
61448 + goto out_fail;
61449 +
61450 + gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
61451 +
61452 + gr_handle_exec_args(bprm, argv);
61453
61454 retval = exec_binprm(bprm);
61455 if (retval < 0)
61456 - goto out;
61457 + goto out_fail;
61458 +#ifdef CONFIG_GRKERNSEC
61459 + if (old_exec_file)
61460 + fput(old_exec_file);
61461 +#endif
61462
61463 /* execve succeeded */
61464 +
61465 + increment_exec_counter();
61466 current->fs->in_exec = 0;
61467 current->in_execve = 0;
61468 acct_update_integrals(current);
61469 @@ -1520,6 +1687,14 @@ static int do_execve_common(struct filename *filename,
61470 put_files_struct(displaced);
61471 return retval;
61472
61473 +out_fail:
61474 +#ifdef CONFIG_GRKERNSEC
61475 + current->acl = old_acl;
61476 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
61477 + fput(current->exec_file);
61478 + current->exec_file = old_exec_file;
61479 +#endif
61480 +
61481 out:
61482 if (bprm->mm) {
61483 acct_arg_size(bprm, 0);
61484 @@ -1611,3 +1786,312 @@ COMPAT_SYSCALL_DEFINE3(execve, const char __user *, filename,
61485 return compat_do_execve(getname(filename), argv, envp);
61486 }
61487 #endif
61488 +
61489 +int pax_check_flags(unsigned long *flags)
61490 +{
61491 + int retval = 0;
61492 +
61493 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
61494 + if (*flags & MF_PAX_SEGMEXEC)
61495 + {
61496 + *flags &= ~MF_PAX_SEGMEXEC;
61497 + retval = -EINVAL;
61498 + }
61499 +#endif
61500 +
61501 + if ((*flags & MF_PAX_PAGEEXEC)
61502 +
61503 +#ifdef CONFIG_PAX_PAGEEXEC
61504 + && (*flags & MF_PAX_SEGMEXEC)
61505 +#endif
61506 +
61507 + )
61508 + {
61509 + *flags &= ~MF_PAX_PAGEEXEC;
61510 + retval = -EINVAL;
61511 + }
61512 +
61513 + if ((*flags & MF_PAX_MPROTECT)
61514 +
61515 +#ifdef CONFIG_PAX_MPROTECT
61516 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
61517 +#endif
61518 +
61519 + )
61520 + {
61521 + *flags &= ~MF_PAX_MPROTECT;
61522 + retval = -EINVAL;
61523 + }
61524 +
61525 + if ((*flags & MF_PAX_EMUTRAMP)
61526 +
61527 +#ifdef CONFIG_PAX_EMUTRAMP
61528 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
61529 +#endif
61530 +
61531 + )
61532 + {
61533 + *flags &= ~MF_PAX_EMUTRAMP;
61534 + retval = -EINVAL;
61535 + }
61536 +
61537 + return retval;
61538 +}
61539 +
61540 +EXPORT_SYMBOL(pax_check_flags);
61541 +
61542 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
61543 +char *pax_get_path(const struct path *path, char *buf, int buflen)
61544 +{
61545 + char *pathname = d_path(path, buf, buflen);
61546 +
61547 + if (IS_ERR(pathname))
61548 + goto toolong;
61549 +
61550 + pathname = mangle_path(buf, pathname, "\t\n\\");
61551 + if (!pathname)
61552 + goto toolong;
61553 +
61554 + *pathname = 0;
61555 + return buf;
61556 +
61557 +toolong:
61558 + return "<path too long>";
61559 +}
61560 +EXPORT_SYMBOL(pax_get_path);
61561 +
61562 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
61563 +{
61564 + struct task_struct *tsk = current;
61565 + struct mm_struct *mm = current->mm;
61566 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
61567 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
61568 + char *path_exec = NULL;
61569 + char *path_fault = NULL;
61570 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
61571 + siginfo_t info = { };
61572 +
61573 + if (buffer_exec && buffer_fault) {
61574 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
61575 +
61576 + down_read(&mm->mmap_sem);
61577 + vma = mm->mmap;
61578 + while (vma && (!vma_exec || !vma_fault)) {
61579 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
61580 + vma_exec = vma;
61581 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
61582 + vma_fault = vma;
61583 + vma = vma->vm_next;
61584 + }
61585 + if (vma_exec)
61586 + path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
61587 + if (vma_fault) {
61588 + start = vma_fault->vm_start;
61589 + end = vma_fault->vm_end;
61590 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
61591 + if (vma_fault->vm_file)
61592 + path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
61593 + else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
61594 + path_fault = "<heap>";
61595 + else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
61596 + path_fault = "<stack>";
61597 + else
61598 + path_fault = "<anonymous mapping>";
61599 + }
61600 + up_read(&mm->mmap_sem);
61601 + }
61602 + if (tsk->signal->curr_ip)
61603 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
61604 + else
61605 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
61606 + 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),
61607 + from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
61608 + free_page((unsigned long)buffer_exec);
61609 + free_page((unsigned long)buffer_fault);
61610 + pax_report_insns(regs, pc, sp);
61611 + info.si_signo = SIGKILL;
61612 + info.si_errno = 0;
61613 + info.si_code = SI_KERNEL;
61614 + info.si_pid = 0;
61615 + info.si_uid = 0;
61616 + do_coredump(&info);
61617 +}
61618 +#endif
61619 +
61620 +#ifdef CONFIG_PAX_REFCOUNT
61621 +void pax_report_refcount_overflow(struct pt_regs *regs)
61622 +{
61623 + if (current->signal->curr_ip)
61624 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
61625 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
61626 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
61627 + else
61628 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
61629 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
61630 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
61631 + preempt_disable();
61632 + show_regs(regs);
61633 + preempt_enable();
61634 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
61635 +}
61636 +#endif
61637 +
61638 +#ifdef CONFIG_PAX_USERCOPY
61639 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
61640 +static noinline int check_stack_object(const void *obj, unsigned long len)
61641 +{
61642 + const void * const stack = task_stack_page(current);
61643 + const void * const stackend = stack + THREAD_SIZE;
61644 +
61645 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
61646 + const void *frame = NULL;
61647 + const void *oldframe;
61648 +#endif
61649 +
61650 + if (obj + len < obj)
61651 + return -1;
61652 +
61653 + if (obj + len <= stack || stackend <= obj)
61654 + return 0;
61655 +
61656 + if (obj < stack || stackend < obj + len)
61657 + return -1;
61658 +
61659 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
61660 + oldframe = __builtin_frame_address(1);
61661 + if (oldframe)
61662 + frame = __builtin_frame_address(2);
61663 + /*
61664 + low ----------------------------------------------> high
61665 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
61666 + ^----------------^
61667 + allow copies only within here
61668 + */
61669 + while (stack <= frame && frame < stackend) {
61670 + /* if obj + len extends past the last frame, this
61671 + check won't pass and the next frame will be 0,
61672 + causing us to bail out and correctly report
61673 + the copy as invalid
61674 + */
61675 + if (obj + len <= frame)
61676 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
61677 + oldframe = frame;
61678 + frame = *(const void * const *)frame;
61679 + }
61680 + return -1;
61681 +#else
61682 + return 1;
61683 +#endif
61684 +}
61685 +
61686 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
61687 +{
61688 + if (current->signal->curr_ip)
61689 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
61690 + &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
61691 + else
61692 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
61693 + to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
61694 + dump_stack();
61695 + gr_handle_kernel_exploit();
61696 + do_group_exit(SIGKILL);
61697 +}
61698 +#endif
61699 +
61700 +#ifdef CONFIG_PAX_USERCOPY
61701 +
61702 +static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
61703 +{
61704 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
61705 + unsigned long textlow = ktla_ktva((unsigned long)_stext);
61706 +#ifdef CONFIG_MODULES
61707 + unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
61708 +#else
61709 + unsigned long texthigh = ktla_ktva((unsigned long)_etext);
61710 +#endif
61711 +
61712 +#else
61713 + unsigned long textlow = (unsigned long)_stext;
61714 + unsigned long texthigh = (unsigned long)_etext;
61715 +
61716 +#ifdef CONFIG_X86_64
61717 + /* check against linear mapping as well */
61718 + if (high > (unsigned long)__va(__pa(textlow)) &&
61719 + low < (unsigned long)__va(__pa(texthigh)))
61720 + return true;
61721 +#endif
61722 +
61723 +#endif
61724 +
61725 + if (high <= textlow || low >= texthigh)
61726 + return false;
61727 + else
61728 + return true;
61729 +}
61730 +#endif
61731 +
61732 +void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size)
61733 +{
61734 +#ifdef CONFIG_PAX_USERCOPY
61735 + const char *type;
61736 +#endif
61737 +
61738 +#ifndef CONFIG_STACK_GROWSUP
61739 + unsigned long stackstart = (unsigned long)task_stack_page(current);
61740 + unsigned long currentsp = (unsigned long)&stackstart;
61741 + if (unlikely((currentsp < stackstart + 512 ||
61742 + currentsp >= stackstart + THREAD_SIZE) && !in_interrupt()))
61743 + BUG();
61744 +#endif
61745 +
61746 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
61747 + if (const_size)
61748 + return;
61749 +#endif
61750 +
61751 +#ifdef CONFIG_PAX_USERCOPY
61752 + if (!n)
61753 + return;
61754 +
61755 + type = check_heap_object(ptr, n);
61756 + if (!type) {
61757 + int ret = check_stack_object(ptr, n);
61758 + if (ret == 1 || ret == 2)
61759 + return;
61760 + if (ret == 0) {
61761 + if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
61762 + type = "<kernel text>";
61763 + else
61764 + return;
61765 + } else
61766 + type = "<process stack>";
61767 + }
61768 +
61769 + pax_report_usercopy(ptr, n, to_user, type);
61770 +#endif
61771 +
61772 +}
61773 +EXPORT_SYMBOL(__check_object_size);
61774 +
61775 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
61776 +void pax_track_stack(void)
61777 +{
61778 + unsigned long sp = (unsigned long)&sp;
61779 + if (sp < current_thread_info()->lowest_stack &&
61780 + sp > (unsigned long)task_stack_page(current))
61781 + current_thread_info()->lowest_stack = sp;
61782 + if (unlikely((sp & ~(THREAD_SIZE - 1)) < (THREAD_SIZE/16)))
61783 + BUG();
61784 +}
61785 +EXPORT_SYMBOL(pax_track_stack);
61786 +#endif
61787 +
61788 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
61789 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
61790 +{
61791 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
61792 + dump_stack();
61793 + do_group_exit(SIGKILL);
61794 +}
61795 +EXPORT_SYMBOL(report_size_overflow);
61796 +#endif
61797 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
61798 index 9f9992b..8b59411 100644
61799 --- a/fs/ext2/balloc.c
61800 +++ b/fs/ext2/balloc.c
61801 @@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
61802
61803 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
61804 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
61805 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
61806 + if (free_blocks < root_blocks + 1 &&
61807 !uid_eq(sbi->s_resuid, current_fsuid()) &&
61808 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
61809 - !in_group_p (sbi->s_resgid))) {
61810 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
61811 return 0;
61812 }
61813 return 1;
61814 diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
61815 index 9142614..97484fa 100644
61816 --- a/fs/ext2/xattr.c
61817 +++ b/fs/ext2/xattr.c
61818 @@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
61819 struct buffer_head *bh = NULL;
61820 struct ext2_xattr_entry *entry;
61821 char *end;
61822 - size_t rest = buffer_size;
61823 + size_t rest = buffer_size, total_size = 0;
61824 int error;
61825
61826 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
61827 @@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
61828 buffer += size;
61829 }
61830 rest -= size;
61831 + total_size += size;
61832 }
61833 }
61834 - error = buffer_size - rest; /* total size */
61835 + error = total_size;
61836
61837 cleanup:
61838 brelse(bh);
61839 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
61840 index 158b5d4..2432610 100644
61841 --- a/fs/ext3/balloc.c
61842 +++ b/fs/ext3/balloc.c
61843 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
61844
61845 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
61846 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
61847 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
61848 + if (free_blocks < root_blocks + 1 &&
61849 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
61850 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
61851 - !in_group_p (sbi->s_resgid))) {
61852 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
61853 return 0;
61854 }
61855 return 1;
61856 diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
61857 index c6874be..f8a6ae8 100644
61858 --- a/fs/ext3/xattr.c
61859 +++ b/fs/ext3/xattr.c
61860 @@ -330,7 +330,7 @@ static int
61861 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
61862 char *buffer, size_t buffer_size)
61863 {
61864 - size_t rest = buffer_size;
61865 + size_t rest = buffer_size, total_size = 0;
61866
61867 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
61868 const struct xattr_handler *handler =
61869 @@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
61870 buffer += size;
61871 }
61872 rest -= size;
61873 + total_size += size;
61874 }
61875 }
61876 - return buffer_size - rest;
61877 + return total_size;
61878 }
61879
61880 static int
61881 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
61882 index e069155..b825b08 100644
61883 --- a/fs/ext4/balloc.c
61884 +++ b/fs/ext4/balloc.c
61885 @@ -557,8 +557,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
61886 /* Hm, nope. Are (enough) root reserved clusters available? */
61887 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
61888 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
61889 - capable(CAP_SYS_RESOURCE) ||
61890 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
61891 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
61892 + capable_nolog(CAP_SYS_RESOURCE)) {
61893
61894 if (free_clusters >= (nclusters + dirty_clusters +
61895 resv_clusters))
61896 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
61897 index 96ac9d3..1c30e7e6 100644
61898 --- a/fs/ext4/ext4.h
61899 +++ b/fs/ext4/ext4.h
61900 @@ -1275,19 +1275,19 @@ struct ext4_sb_info {
61901 unsigned long s_mb_last_start;
61902
61903 /* stats for buddy allocator */
61904 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
61905 - atomic_t s_bal_success; /* we found long enough chunks */
61906 - atomic_t s_bal_allocated; /* in blocks */
61907 - atomic_t s_bal_ex_scanned; /* total extents scanned */
61908 - atomic_t s_bal_goals; /* goal hits */
61909 - atomic_t s_bal_breaks; /* too long searches */
61910 - atomic_t s_bal_2orders; /* 2^order hits */
61911 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
61912 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
61913 + atomic_unchecked_t s_bal_allocated; /* in blocks */
61914 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
61915 + atomic_unchecked_t s_bal_goals; /* goal hits */
61916 + atomic_unchecked_t s_bal_breaks; /* too long searches */
61917 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
61918 spinlock_t s_bal_lock;
61919 unsigned long s_mb_buddies_generated;
61920 unsigned long long s_mb_generation_time;
61921 - atomic_t s_mb_lost_chunks;
61922 - atomic_t s_mb_preallocated;
61923 - atomic_t s_mb_discarded;
61924 + atomic_unchecked_t s_mb_lost_chunks;
61925 + atomic_unchecked_t s_mb_preallocated;
61926 + atomic_unchecked_t s_mb_discarded;
61927 atomic_t s_lock_busy;
61928
61929 /* locality groups */
61930 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
61931 index 8b0f9ef..cb9f620 100644
61932 --- a/fs/ext4/mballoc.c
61933 +++ b/fs/ext4/mballoc.c
61934 @@ -1901,7 +1901,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
61935 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
61936
61937 if (EXT4_SB(sb)->s_mb_stats)
61938 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
61939 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
61940
61941 break;
61942 }
61943 @@ -2211,7 +2211,7 @@ repeat:
61944 ac->ac_status = AC_STATUS_CONTINUE;
61945 ac->ac_flags |= EXT4_MB_HINT_FIRST;
61946 cr = 3;
61947 - atomic_inc(&sbi->s_mb_lost_chunks);
61948 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
61949 goto repeat;
61950 }
61951 }
61952 @@ -2717,25 +2717,25 @@ int ext4_mb_release(struct super_block *sb)
61953 if (sbi->s_mb_stats) {
61954 ext4_msg(sb, KERN_INFO,
61955 "mballoc: %u blocks %u reqs (%u success)",
61956 - atomic_read(&sbi->s_bal_allocated),
61957 - atomic_read(&sbi->s_bal_reqs),
61958 - atomic_read(&sbi->s_bal_success));
61959 + atomic_read_unchecked(&sbi->s_bal_allocated),
61960 + atomic_read_unchecked(&sbi->s_bal_reqs),
61961 + atomic_read_unchecked(&sbi->s_bal_success));
61962 ext4_msg(sb, KERN_INFO,
61963 "mballoc: %u extents scanned, %u goal hits, "
61964 "%u 2^N hits, %u breaks, %u lost",
61965 - atomic_read(&sbi->s_bal_ex_scanned),
61966 - atomic_read(&sbi->s_bal_goals),
61967 - atomic_read(&sbi->s_bal_2orders),
61968 - atomic_read(&sbi->s_bal_breaks),
61969 - atomic_read(&sbi->s_mb_lost_chunks));
61970 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
61971 + atomic_read_unchecked(&sbi->s_bal_goals),
61972 + atomic_read_unchecked(&sbi->s_bal_2orders),
61973 + atomic_read_unchecked(&sbi->s_bal_breaks),
61974 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
61975 ext4_msg(sb, KERN_INFO,
61976 "mballoc: %lu generated and it took %Lu",
61977 sbi->s_mb_buddies_generated,
61978 sbi->s_mb_generation_time);
61979 ext4_msg(sb, KERN_INFO,
61980 "mballoc: %u preallocated, %u discarded",
61981 - atomic_read(&sbi->s_mb_preallocated),
61982 - atomic_read(&sbi->s_mb_discarded));
61983 + atomic_read_unchecked(&sbi->s_mb_preallocated),
61984 + atomic_read_unchecked(&sbi->s_mb_discarded));
61985 }
61986
61987 free_percpu(sbi->s_locality_groups);
61988 @@ -3192,16 +3192,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
61989 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
61990
61991 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
61992 - atomic_inc(&sbi->s_bal_reqs);
61993 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
61994 + atomic_inc_unchecked(&sbi->s_bal_reqs);
61995 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
61996 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
61997 - atomic_inc(&sbi->s_bal_success);
61998 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
61999 + atomic_inc_unchecked(&sbi->s_bal_success);
62000 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
62001 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
62002 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
62003 - atomic_inc(&sbi->s_bal_goals);
62004 + atomic_inc_unchecked(&sbi->s_bal_goals);
62005 if (ac->ac_found > sbi->s_mb_max_to_scan)
62006 - atomic_inc(&sbi->s_bal_breaks);
62007 + atomic_inc_unchecked(&sbi->s_bal_breaks);
62008 }
62009
62010 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
62011 @@ -3628,7 +3628,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
62012 trace_ext4_mb_new_inode_pa(ac, pa);
62013
62014 ext4_mb_use_inode_pa(ac, pa);
62015 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
62016 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
62017
62018 ei = EXT4_I(ac->ac_inode);
62019 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
62020 @@ -3688,7 +3688,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
62021 trace_ext4_mb_new_group_pa(ac, pa);
62022
62023 ext4_mb_use_group_pa(ac, pa);
62024 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
62025 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
62026
62027 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
62028 lg = ac->ac_lg;
62029 @@ -3777,7 +3777,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
62030 * from the bitmap and continue.
62031 */
62032 }
62033 - atomic_add(free, &sbi->s_mb_discarded);
62034 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
62035
62036 return err;
62037 }
62038 @@ -3795,7 +3795,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
62039 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
62040 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
62041 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
62042 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
62043 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
62044 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
62045
62046 return 0;
62047 diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
62048 index 8313ca3..8a37d08 100644
62049 --- a/fs/ext4/mmp.c
62050 +++ b/fs/ext4/mmp.c
62051 @@ -111,7 +111,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
62052 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
62053 const char *function, unsigned int line, const char *msg)
62054 {
62055 - __ext4_warning(sb, function, line, msg);
62056 + __ext4_warning(sb, function, line, "%s", msg);
62057 __ext4_warning(sb, function, line,
62058 "MMP failure info: last update time: %llu, last update "
62059 "node: %s, last update device: %s\n",
62060 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
62061 index b1f0ac7..77e9a05 100644
62062 --- a/fs/ext4/super.c
62063 +++ b/fs/ext4/super.c
62064 @@ -1274,7 +1274,7 @@ static ext4_fsblk_t get_sb_block(void **data)
62065 }
62066
62067 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
62068 -static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
62069 +static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
62070 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
62071
62072 #ifdef CONFIG_QUOTA
62073 @@ -2454,7 +2454,7 @@ struct ext4_attr {
62074 int offset;
62075 int deprecated_val;
62076 } u;
62077 -};
62078 +} __do_const;
62079
62080 static int parse_strtoull(const char *buf,
62081 unsigned long long max, unsigned long long *value)
62082 diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
62083 index 2d1e5803..1b082d415 100644
62084 --- a/fs/ext4/xattr.c
62085 +++ b/fs/ext4/xattr.c
62086 @@ -399,7 +399,7 @@ static int
62087 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
62088 char *buffer, size_t buffer_size)
62089 {
62090 - size_t rest = buffer_size;
62091 + size_t rest = buffer_size, total_size = 0;
62092
62093 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
62094 const struct xattr_handler *handler =
62095 @@ -416,9 +416,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
62096 buffer += size;
62097 }
62098 rest -= size;
62099 + total_size += size;
62100 }
62101 }
62102 - return buffer_size - rest;
62103 + return total_size;
62104 }
62105
62106 static int
62107 diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c
62108 index 6df8d3d..b8b92c2 100644
62109 --- a/fs/fat/namei_vfat.c
62110 +++ b/fs/fat/namei_vfat.c
62111 @@ -736,7 +736,12 @@ static struct dentry *vfat_lookup(struct inode *dir, struct dentry *dentry,
62112 }
62113
62114 alias = d_find_alias(inode);
62115 - if (alias && !vfat_d_anon_disconn(alias)) {
62116 + /*
62117 + * Checking "alias->d_parent == dentry->d_parent" to make sure
62118 + * FS is not corrupted (especially double linked dir).
62119 + */
62120 + if (alias && alias->d_parent == dentry->d_parent &&
62121 + !vfat_d_anon_disconn(alias)) {
62122 /*
62123 * This inode has non anonymous-DCACHE_DISCONNECTED
62124 * dentry. This means, the user did ->lookup() by an
62125 @@ -755,12 +760,9 @@ static struct dentry *vfat_lookup(struct inode *dir, struct dentry *dentry,
62126
62127 out:
62128 mutex_unlock(&MSDOS_SB(sb)->s_lock);
62129 - dentry->d_time = dentry->d_parent->d_inode->i_version;
62130 - dentry = d_splice_alias(inode, dentry);
62131 - if (dentry)
62132 - dentry->d_time = dentry->d_parent->d_inode->i_version;
62133 - return dentry;
62134 -
62135 + if (!inode)
62136 + dentry->d_time = dir->i_version;
62137 + return d_splice_alias(inode, dentry);
62138 error:
62139 mutex_unlock(&MSDOS_SB(sb)->s_lock);
62140 return ERR_PTR(err);
62141 @@ -793,7 +795,6 @@ static int vfat_create(struct inode *dir, struct dentry *dentry, umode_t mode,
62142 inode->i_mtime = inode->i_atime = inode->i_ctime = ts;
62143 /* timestamp is already written, so mark_inode_dirty() is unneeded. */
62144
62145 - dentry->d_time = dentry->d_parent->d_inode->i_version;
62146 d_instantiate(dentry, inode);
62147 out:
62148 mutex_unlock(&MSDOS_SB(sb)->s_lock);
62149 @@ -824,6 +825,7 @@ static int vfat_rmdir(struct inode *dir, struct dentry *dentry)
62150 clear_nlink(inode);
62151 inode->i_mtime = inode->i_atime = CURRENT_TIME_SEC;
62152 fat_detach(inode);
62153 + dentry->d_time = dir->i_version;
62154 out:
62155 mutex_unlock(&MSDOS_SB(sb)->s_lock);
62156
62157 @@ -849,6 +851,7 @@ static int vfat_unlink(struct inode *dir, struct dentry *dentry)
62158 clear_nlink(inode);
62159 inode->i_mtime = inode->i_atime = CURRENT_TIME_SEC;
62160 fat_detach(inode);
62161 + dentry->d_time = dir->i_version;
62162 out:
62163 mutex_unlock(&MSDOS_SB(sb)->s_lock);
62164
62165 @@ -889,7 +892,6 @@ static int vfat_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
62166 inode->i_mtime = inode->i_atime = inode->i_ctime = ts;
62167 /* timestamp is already written, so mark_inode_dirty() is unneeded. */
62168
62169 - dentry->d_time = dentry->d_parent->d_inode->i_version;
62170 d_instantiate(dentry, inode);
62171
62172 mutex_unlock(&MSDOS_SB(sb)->s_lock);
62173 diff --git a/fs/fcntl.c b/fs/fcntl.c
62174 index 22d1c3d..600cf7e 100644
62175 --- a/fs/fcntl.c
62176 +++ b/fs/fcntl.c
62177 @@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
62178 if (err)
62179 return err;
62180
62181 + if (gr_handle_chroot_fowner(pid, type))
62182 + return -ENOENT;
62183 + if (gr_check_protected_task_fowner(pid, type))
62184 + return -EACCES;
62185 +
62186 f_modown(filp, pid, type, force);
62187 return 0;
62188 }
62189 diff --git a/fs/fhandle.c b/fs/fhandle.c
62190 index 999ff5c..ac037c9 100644
62191 --- a/fs/fhandle.c
62192 +++ b/fs/fhandle.c
62193 @@ -8,6 +8,7 @@
62194 #include <linux/fs_struct.h>
62195 #include <linux/fsnotify.h>
62196 #include <linux/personality.h>
62197 +#include <linux/grsecurity.h>
62198 #include <asm/uaccess.h>
62199 #include "internal.h"
62200 #include "mount.h"
62201 @@ -67,8 +68,7 @@ static long do_sys_name_to_handle(struct path *path,
62202 } else
62203 retval = 0;
62204 /* copy the mount id */
62205 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
62206 - sizeof(*mnt_id)) ||
62207 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
62208 copy_to_user(ufh, handle,
62209 sizeof(struct file_handle) + handle_bytes))
62210 retval = -EFAULT;
62211 @@ -175,7 +175,7 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
62212 * the directory. Ideally we would like CAP_DAC_SEARCH.
62213 * But we don't have that
62214 */
62215 - if (!capable(CAP_DAC_READ_SEARCH)) {
62216 + if (!capable(CAP_DAC_READ_SEARCH) || !gr_chroot_fhandle()) {
62217 retval = -EPERM;
62218 goto out_err;
62219 }
62220 diff --git a/fs/file.c b/fs/file.c
62221 index 66923fe..2849783 100644
62222 --- a/fs/file.c
62223 +++ b/fs/file.c
62224 @@ -16,6 +16,7 @@
62225 #include <linux/slab.h>
62226 #include <linux/vmalloc.h>
62227 #include <linux/file.h>
62228 +#include <linux/security.h>
62229 #include <linux/fdtable.h>
62230 #include <linux/bitops.h>
62231 #include <linux/interrupt.h>
62232 @@ -139,7 +140,7 @@ out:
62233 * Return <0 error code on error; 1 on successful completion.
62234 * The files->file_lock should be held on entry, and will be held on exit.
62235 */
62236 -static int expand_fdtable(struct files_struct *files, int nr)
62237 +static int expand_fdtable(struct files_struct *files, unsigned int nr)
62238 __releases(files->file_lock)
62239 __acquires(files->file_lock)
62240 {
62241 @@ -184,7 +185,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
62242 * expanded and execution may have blocked.
62243 * The files->file_lock should be held on entry, and will be held on exit.
62244 */
62245 -static int expand_files(struct files_struct *files, int nr)
62246 +static int expand_files(struct files_struct *files, unsigned int nr)
62247 {
62248 struct fdtable *fdt;
62249
62250 @@ -799,6 +800,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
62251 if (!file)
62252 return __close_fd(files, fd);
62253
62254 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
62255 if (fd >= rlimit(RLIMIT_NOFILE))
62256 return -EBADF;
62257
62258 @@ -825,6 +827,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
62259 if (unlikely(oldfd == newfd))
62260 return -EINVAL;
62261
62262 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
62263 if (newfd >= rlimit(RLIMIT_NOFILE))
62264 return -EBADF;
62265
62266 @@ -880,6 +883,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
62267 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
62268 {
62269 int err;
62270 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
62271 if (from >= rlimit(RLIMIT_NOFILE))
62272 return -EINVAL;
62273 err = alloc_fd(from, flags);
62274 diff --git a/fs/filesystems.c b/fs/filesystems.c
62275 index 5797d45..7d7d79a 100644
62276 --- a/fs/filesystems.c
62277 +++ b/fs/filesystems.c
62278 @@ -275,7 +275,11 @@ struct file_system_type *get_fs_type(const char *name)
62279 int len = dot ? dot - name : strlen(name);
62280
62281 fs = __get_fs_type(name, len);
62282 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
62283 + if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
62284 +#else
62285 if (!fs && (request_module("fs-%.*s", len, name) == 0))
62286 +#endif
62287 fs = __get_fs_type(name, len);
62288
62289 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
62290 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
62291 index 7dca743..543d620 100644
62292 --- a/fs/fs_struct.c
62293 +++ b/fs/fs_struct.c
62294 @@ -4,6 +4,7 @@
62295 #include <linux/path.h>
62296 #include <linux/slab.h>
62297 #include <linux/fs_struct.h>
62298 +#include <linux/grsecurity.h>
62299 #include "internal.h"
62300
62301 /*
62302 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
62303 write_seqcount_begin(&fs->seq);
62304 old_root = fs->root;
62305 fs->root = *path;
62306 + gr_set_chroot_entries(current, path);
62307 write_seqcount_end(&fs->seq);
62308 spin_unlock(&fs->lock);
62309 if (old_root.dentry)
62310 @@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
62311 int hits = 0;
62312 spin_lock(&fs->lock);
62313 write_seqcount_begin(&fs->seq);
62314 + /* this root replacement is only done by pivot_root,
62315 + leave grsec's chroot tagging alone for this task
62316 + so that a pivoted root isn't treated as a chroot
62317 + */
62318 hits += replace_path(&fs->root, old_root, new_root);
62319 hits += replace_path(&fs->pwd, old_root, new_root);
62320 write_seqcount_end(&fs->seq);
62321 @@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
62322 task_lock(tsk);
62323 spin_lock(&fs->lock);
62324 tsk->fs = NULL;
62325 - kill = !--fs->users;
62326 + gr_clear_chroot_entries(tsk);
62327 + kill = !atomic_dec_return(&fs->users);
62328 spin_unlock(&fs->lock);
62329 task_unlock(tsk);
62330 if (kill)
62331 @@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
62332 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
62333 /* We don't need to lock fs - think why ;-) */
62334 if (fs) {
62335 - fs->users = 1;
62336 + atomic_set(&fs->users, 1);
62337 fs->in_exec = 0;
62338 spin_lock_init(&fs->lock);
62339 seqcount_init(&fs->seq);
62340 @@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
62341 spin_lock(&old->lock);
62342 fs->root = old->root;
62343 path_get(&fs->root);
62344 + /* instead of calling gr_set_chroot_entries here,
62345 + we call it from every caller of this function
62346 + */
62347 fs->pwd = old->pwd;
62348 path_get(&fs->pwd);
62349 spin_unlock(&old->lock);
62350 @@ -139,8 +149,9 @@ int unshare_fs_struct(void)
62351
62352 task_lock(current);
62353 spin_lock(&fs->lock);
62354 - kill = !--fs->users;
62355 + kill = !atomic_dec_return(&fs->users);
62356 current->fs = new_fs;
62357 + gr_set_chroot_entries(current, &new_fs->root);
62358 spin_unlock(&fs->lock);
62359 task_unlock(current);
62360
62361 @@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
62362
62363 int current_umask(void)
62364 {
62365 - return current->fs->umask;
62366 + return current->fs->umask | gr_acl_umask();
62367 }
62368 EXPORT_SYMBOL(current_umask);
62369
62370 /* to be mentioned only in INIT_TASK */
62371 struct fs_struct init_fs = {
62372 - .users = 1,
62373 + .users = ATOMIC_INIT(1),
62374 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
62375 .seq = SEQCNT_ZERO(init_fs.seq),
62376 .umask = 0022,
62377 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
62378 index 89acec7..a575262 100644
62379 --- a/fs/fscache/cookie.c
62380 +++ b/fs/fscache/cookie.c
62381 @@ -19,7 +19,7 @@
62382
62383 struct kmem_cache *fscache_cookie_jar;
62384
62385 -static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
62386 +static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
62387
62388 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
62389 static int fscache_alloc_object(struct fscache_cache *cache,
62390 @@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
62391 parent ? (char *) parent->def->name : "<no-parent>",
62392 def->name, netfs_data, enable);
62393
62394 - fscache_stat(&fscache_n_acquires);
62395 + fscache_stat_unchecked(&fscache_n_acquires);
62396
62397 /* if there's no parent cookie, then we don't create one here either */
62398 if (!parent) {
62399 - fscache_stat(&fscache_n_acquires_null);
62400 + fscache_stat_unchecked(&fscache_n_acquires_null);
62401 _leave(" [no parent]");
62402 return NULL;
62403 }
62404 @@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62405 /* allocate and initialise a cookie */
62406 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
62407 if (!cookie) {
62408 - fscache_stat(&fscache_n_acquires_oom);
62409 + fscache_stat_unchecked(&fscache_n_acquires_oom);
62410 _leave(" [ENOMEM]");
62411 return NULL;
62412 }
62413 @@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
62414
62415 switch (cookie->def->type) {
62416 case FSCACHE_COOKIE_TYPE_INDEX:
62417 - fscache_stat(&fscache_n_cookie_index);
62418 + fscache_stat_unchecked(&fscache_n_cookie_index);
62419 break;
62420 case FSCACHE_COOKIE_TYPE_DATAFILE:
62421 - fscache_stat(&fscache_n_cookie_data);
62422 + fscache_stat_unchecked(&fscache_n_cookie_data);
62423 break;
62424 default:
62425 - fscache_stat(&fscache_n_cookie_special);
62426 + fscache_stat_unchecked(&fscache_n_cookie_special);
62427 break;
62428 }
62429
62430 @@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62431 } else {
62432 atomic_dec(&parent->n_children);
62433 __fscache_cookie_put(cookie);
62434 - fscache_stat(&fscache_n_acquires_nobufs);
62435 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
62436 _leave(" = NULL");
62437 return NULL;
62438 }
62439 @@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62440 }
62441 }
62442
62443 - fscache_stat(&fscache_n_acquires_ok);
62444 + fscache_stat_unchecked(&fscache_n_acquires_ok);
62445 _leave(" = %p", cookie);
62446 return cookie;
62447 }
62448 @@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
62449 cache = fscache_select_cache_for_object(cookie->parent);
62450 if (!cache) {
62451 up_read(&fscache_addremove_sem);
62452 - fscache_stat(&fscache_n_acquires_no_cache);
62453 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
62454 _leave(" = -ENOMEDIUM [no cache]");
62455 return -ENOMEDIUM;
62456 }
62457 @@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
62458 object = cache->ops->alloc_object(cache, cookie);
62459 fscache_stat_d(&fscache_n_cop_alloc_object);
62460 if (IS_ERR(object)) {
62461 - fscache_stat(&fscache_n_object_no_alloc);
62462 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
62463 ret = PTR_ERR(object);
62464 goto error;
62465 }
62466
62467 - fscache_stat(&fscache_n_object_alloc);
62468 + fscache_stat_unchecked(&fscache_n_object_alloc);
62469
62470 - object->debug_id = atomic_inc_return(&fscache_object_debug_id);
62471 + object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
62472
62473 _debug("ALLOC OBJ%x: %s {%lx}",
62474 object->debug_id, cookie->def->name, object->events);
62475 @@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
62476
62477 _enter("{%s}", cookie->def->name);
62478
62479 - fscache_stat(&fscache_n_invalidates);
62480 + fscache_stat_unchecked(&fscache_n_invalidates);
62481
62482 /* Only permit invalidation of data files. Invalidating an index will
62483 * require the caller to release all its attachments to the tree rooted
62484 @@ -476,10 +476,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
62485 {
62486 struct fscache_object *object;
62487
62488 - fscache_stat(&fscache_n_updates);
62489 + fscache_stat_unchecked(&fscache_n_updates);
62490
62491 if (!cookie) {
62492 - fscache_stat(&fscache_n_updates_null);
62493 + fscache_stat_unchecked(&fscache_n_updates_null);
62494 _leave(" [no cookie]");
62495 return;
62496 }
62497 @@ -580,12 +580,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
62498 */
62499 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
62500 {
62501 - fscache_stat(&fscache_n_relinquishes);
62502 + fscache_stat_unchecked(&fscache_n_relinquishes);
62503 if (retire)
62504 - fscache_stat(&fscache_n_relinquishes_retire);
62505 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
62506
62507 if (!cookie) {
62508 - fscache_stat(&fscache_n_relinquishes_null);
62509 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
62510 _leave(" [no cookie]");
62511 return;
62512 }
62513 @@ -686,7 +686,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
62514 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
62515 goto inconsistent;
62516
62517 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
62518 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
62519
62520 __fscache_use_cookie(cookie);
62521 if (fscache_submit_op(object, op) < 0)
62522 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
62523 index 7872a62..d91b19f 100644
62524 --- a/fs/fscache/internal.h
62525 +++ b/fs/fscache/internal.h
62526 @@ -137,8 +137,8 @@ extern void fscache_operation_gc(struct work_struct *);
62527 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
62528 extern int fscache_wait_for_operation_activation(struct fscache_object *,
62529 struct fscache_operation *,
62530 - atomic_t *,
62531 - atomic_t *,
62532 + atomic_unchecked_t *,
62533 + atomic_unchecked_t *,
62534 void (*)(struct fscache_operation *));
62535 extern void fscache_invalidate_writes(struct fscache_cookie *);
62536
62537 @@ -157,101 +157,101 @@ extern void fscache_proc_cleanup(void);
62538 * stats.c
62539 */
62540 #ifdef CONFIG_FSCACHE_STATS
62541 -extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
62542 -extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
62543 +extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
62544 +extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
62545
62546 -extern atomic_t fscache_n_op_pend;
62547 -extern atomic_t fscache_n_op_run;
62548 -extern atomic_t fscache_n_op_enqueue;
62549 -extern atomic_t fscache_n_op_deferred_release;
62550 -extern atomic_t fscache_n_op_release;
62551 -extern atomic_t fscache_n_op_gc;
62552 -extern atomic_t fscache_n_op_cancelled;
62553 -extern atomic_t fscache_n_op_rejected;
62554 +extern atomic_unchecked_t fscache_n_op_pend;
62555 +extern atomic_unchecked_t fscache_n_op_run;
62556 +extern atomic_unchecked_t fscache_n_op_enqueue;
62557 +extern atomic_unchecked_t fscache_n_op_deferred_release;
62558 +extern atomic_unchecked_t fscache_n_op_release;
62559 +extern atomic_unchecked_t fscache_n_op_gc;
62560 +extern atomic_unchecked_t fscache_n_op_cancelled;
62561 +extern atomic_unchecked_t fscache_n_op_rejected;
62562
62563 -extern atomic_t fscache_n_attr_changed;
62564 -extern atomic_t fscache_n_attr_changed_ok;
62565 -extern atomic_t fscache_n_attr_changed_nobufs;
62566 -extern atomic_t fscache_n_attr_changed_nomem;
62567 -extern atomic_t fscache_n_attr_changed_calls;
62568 +extern atomic_unchecked_t fscache_n_attr_changed;
62569 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
62570 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
62571 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
62572 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
62573
62574 -extern atomic_t fscache_n_allocs;
62575 -extern atomic_t fscache_n_allocs_ok;
62576 -extern atomic_t fscache_n_allocs_wait;
62577 -extern atomic_t fscache_n_allocs_nobufs;
62578 -extern atomic_t fscache_n_allocs_intr;
62579 -extern atomic_t fscache_n_allocs_object_dead;
62580 -extern atomic_t fscache_n_alloc_ops;
62581 -extern atomic_t fscache_n_alloc_op_waits;
62582 +extern atomic_unchecked_t fscache_n_allocs;
62583 +extern atomic_unchecked_t fscache_n_allocs_ok;
62584 +extern atomic_unchecked_t fscache_n_allocs_wait;
62585 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
62586 +extern atomic_unchecked_t fscache_n_allocs_intr;
62587 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
62588 +extern atomic_unchecked_t fscache_n_alloc_ops;
62589 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
62590
62591 -extern atomic_t fscache_n_retrievals;
62592 -extern atomic_t fscache_n_retrievals_ok;
62593 -extern atomic_t fscache_n_retrievals_wait;
62594 -extern atomic_t fscache_n_retrievals_nodata;
62595 -extern atomic_t fscache_n_retrievals_nobufs;
62596 -extern atomic_t fscache_n_retrievals_intr;
62597 -extern atomic_t fscache_n_retrievals_nomem;
62598 -extern atomic_t fscache_n_retrievals_object_dead;
62599 -extern atomic_t fscache_n_retrieval_ops;
62600 -extern atomic_t fscache_n_retrieval_op_waits;
62601 +extern atomic_unchecked_t fscache_n_retrievals;
62602 +extern atomic_unchecked_t fscache_n_retrievals_ok;
62603 +extern atomic_unchecked_t fscache_n_retrievals_wait;
62604 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
62605 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
62606 +extern atomic_unchecked_t fscache_n_retrievals_intr;
62607 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
62608 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
62609 +extern atomic_unchecked_t fscache_n_retrieval_ops;
62610 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
62611
62612 -extern atomic_t fscache_n_stores;
62613 -extern atomic_t fscache_n_stores_ok;
62614 -extern atomic_t fscache_n_stores_again;
62615 -extern atomic_t fscache_n_stores_nobufs;
62616 -extern atomic_t fscache_n_stores_oom;
62617 -extern atomic_t fscache_n_store_ops;
62618 -extern atomic_t fscache_n_store_calls;
62619 -extern atomic_t fscache_n_store_pages;
62620 -extern atomic_t fscache_n_store_radix_deletes;
62621 -extern atomic_t fscache_n_store_pages_over_limit;
62622 +extern atomic_unchecked_t fscache_n_stores;
62623 +extern atomic_unchecked_t fscache_n_stores_ok;
62624 +extern atomic_unchecked_t fscache_n_stores_again;
62625 +extern atomic_unchecked_t fscache_n_stores_nobufs;
62626 +extern atomic_unchecked_t fscache_n_stores_oom;
62627 +extern atomic_unchecked_t fscache_n_store_ops;
62628 +extern atomic_unchecked_t fscache_n_store_calls;
62629 +extern atomic_unchecked_t fscache_n_store_pages;
62630 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
62631 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
62632
62633 -extern atomic_t fscache_n_store_vmscan_not_storing;
62634 -extern atomic_t fscache_n_store_vmscan_gone;
62635 -extern atomic_t fscache_n_store_vmscan_busy;
62636 -extern atomic_t fscache_n_store_vmscan_cancelled;
62637 -extern atomic_t fscache_n_store_vmscan_wait;
62638 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
62639 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
62640 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
62641 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
62642 +extern atomic_unchecked_t fscache_n_store_vmscan_wait;
62643
62644 -extern atomic_t fscache_n_marks;
62645 -extern atomic_t fscache_n_uncaches;
62646 +extern atomic_unchecked_t fscache_n_marks;
62647 +extern atomic_unchecked_t fscache_n_uncaches;
62648
62649 -extern atomic_t fscache_n_acquires;
62650 -extern atomic_t fscache_n_acquires_null;
62651 -extern atomic_t fscache_n_acquires_no_cache;
62652 -extern atomic_t fscache_n_acquires_ok;
62653 -extern atomic_t fscache_n_acquires_nobufs;
62654 -extern atomic_t fscache_n_acquires_oom;
62655 +extern atomic_unchecked_t fscache_n_acquires;
62656 +extern atomic_unchecked_t fscache_n_acquires_null;
62657 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
62658 +extern atomic_unchecked_t fscache_n_acquires_ok;
62659 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
62660 +extern atomic_unchecked_t fscache_n_acquires_oom;
62661
62662 -extern atomic_t fscache_n_invalidates;
62663 -extern atomic_t fscache_n_invalidates_run;
62664 +extern atomic_unchecked_t fscache_n_invalidates;
62665 +extern atomic_unchecked_t fscache_n_invalidates_run;
62666
62667 -extern atomic_t fscache_n_updates;
62668 -extern atomic_t fscache_n_updates_null;
62669 -extern atomic_t fscache_n_updates_run;
62670 +extern atomic_unchecked_t fscache_n_updates;
62671 +extern atomic_unchecked_t fscache_n_updates_null;
62672 +extern atomic_unchecked_t fscache_n_updates_run;
62673
62674 -extern atomic_t fscache_n_relinquishes;
62675 -extern atomic_t fscache_n_relinquishes_null;
62676 -extern atomic_t fscache_n_relinquishes_waitcrt;
62677 -extern atomic_t fscache_n_relinquishes_retire;
62678 +extern atomic_unchecked_t fscache_n_relinquishes;
62679 +extern atomic_unchecked_t fscache_n_relinquishes_null;
62680 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
62681 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
62682
62683 -extern atomic_t fscache_n_cookie_index;
62684 -extern atomic_t fscache_n_cookie_data;
62685 -extern atomic_t fscache_n_cookie_special;
62686 +extern atomic_unchecked_t fscache_n_cookie_index;
62687 +extern atomic_unchecked_t fscache_n_cookie_data;
62688 +extern atomic_unchecked_t fscache_n_cookie_special;
62689
62690 -extern atomic_t fscache_n_object_alloc;
62691 -extern atomic_t fscache_n_object_no_alloc;
62692 -extern atomic_t fscache_n_object_lookups;
62693 -extern atomic_t fscache_n_object_lookups_negative;
62694 -extern atomic_t fscache_n_object_lookups_positive;
62695 -extern atomic_t fscache_n_object_lookups_timed_out;
62696 -extern atomic_t fscache_n_object_created;
62697 -extern atomic_t fscache_n_object_avail;
62698 -extern atomic_t fscache_n_object_dead;
62699 +extern atomic_unchecked_t fscache_n_object_alloc;
62700 +extern atomic_unchecked_t fscache_n_object_no_alloc;
62701 +extern atomic_unchecked_t fscache_n_object_lookups;
62702 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
62703 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
62704 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
62705 +extern atomic_unchecked_t fscache_n_object_created;
62706 +extern atomic_unchecked_t fscache_n_object_avail;
62707 +extern atomic_unchecked_t fscache_n_object_dead;
62708
62709 -extern atomic_t fscache_n_checkaux_none;
62710 -extern atomic_t fscache_n_checkaux_okay;
62711 -extern atomic_t fscache_n_checkaux_update;
62712 -extern atomic_t fscache_n_checkaux_obsolete;
62713 +extern atomic_unchecked_t fscache_n_checkaux_none;
62714 +extern atomic_unchecked_t fscache_n_checkaux_okay;
62715 +extern atomic_unchecked_t fscache_n_checkaux_update;
62716 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
62717
62718 extern atomic_t fscache_n_cop_alloc_object;
62719 extern atomic_t fscache_n_cop_lookup_object;
62720 @@ -276,6 +276,11 @@ static inline void fscache_stat(atomic_t *stat)
62721 atomic_inc(stat);
62722 }
62723
62724 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
62725 +{
62726 + atomic_inc_unchecked(stat);
62727 +}
62728 +
62729 static inline void fscache_stat_d(atomic_t *stat)
62730 {
62731 atomic_dec(stat);
62732 @@ -288,6 +293,7 @@ extern const struct file_operations fscache_stats_fops;
62733
62734 #define __fscache_stat(stat) (NULL)
62735 #define fscache_stat(stat) do {} while (0)
62736 +#define fscache_stat_unchecked(stat) do {} while (0)
62737 #define fscache_stat_d(stat) do {} while (0)
62738 #endif
62739
62740 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
62741 index da032da..0076ce7 100644
62742 --- a/fs/fscache/object.c
62743 +++ b/fs/fscache/object.c
62744 @@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
62745 _debug("LOOKUP \"%s\" in \"%s\"",
62746 cookie->def->name, object->cache->tag->name);
62747
62748 - fscache_stat(&fscache_n_object_lookups);
62749 + fscache_stat_unchecked(&fscache_n_object_lookups);
62750 fscache_stat(&fscache_n_cop_lookup_object);
62751 ret = object->cache->ops->lookup_object(object);
62752 fscache_stat_d(&fscache_n_cop_lookup_object);
62753 @@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
62754 if (ret == -ETIMEDOUT) {
62755 /* probably stuck behind another object, so move this one to
62756 * the back of the queue */
62757 - fscache_stat(&fscache_n_object_lookups_timed_out);
62758 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
62759 _leave(" [timeout]");
62760 return NO_TRANSIT;
62761 }
62762 @@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
62763 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
62764
62765 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
62766 - fscache_stat(&fscache_n_object_lookups_negative);
62767 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
62768
62769 /* Allow write requests to begin stacking up and read requests to begin
62770 * returning ENODATA.
62771 @@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
62772 /* if we were still looking up, then we must have a positive lookup
62773 * result, in which case there may be data available */
62774 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
62775 - fscache_stat(&fscache_n_object_lookups_positive);
62776 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
62777
62778 /* We do (presumably) have data */
62779 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
62780 @@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
62781 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
62782 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
62783 } else {
62784 - fscache_stat(&fscache_n_object_created);
62785 + fscache_stat_unchecked(&fscache_n_object_created);
62786 }
62787
62788 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
62789 @@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
62790 fscache_stat_d(&fscache_n_cop_lookup_complete);
62791
62792 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
62793 - fscache_stat(&fscache_n_object_avail);
62794 + fscache_stat_unchecked(&fscache_n_object_avail);
62795
62796 _leave("");
62797 return transit_to(JUMPSTART_DEPS);
62798 @@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
62799
62800 /* this just shifts the object release to the work processor */
62801 fscache_put_object(object);
62802 - fscache_stat(&fscache_n_object_dead);
62803 + fscache_stat_unchecked(&fscache_n_object_dead);
62804
62805 _leave("");
62806 return transit_to(OBJECT_DEAD);
62807 @@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
62808 enum fscache_checkaux result;
62809
62810 if (!object->cookie->def->check_aux) {
62811 - fscache_stat(&fscache_n_checkaux_none);
62812 + fscache_stat_unchecked(&fscache_n_checkaux_none);
62813 return FSCACHE_CHECKAUX_OKAY;
62814 }
62815
62816 @@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
62817 switch (result) {
62818 /* entry okay as is */
62819 case FSCACHE_CHECKAUX_OKAY:
62820 - fscache_stat(&fscache_n_checkaux_okay);
62821 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
62822 break;
62823
62824 /* entry requires update */
62825 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
62826 - fscache_stat(&fscache_n_checkaux_update);
62827 + fscache_stat_unchecked(&fscache_n_checkaux_update);
62828 break;
62829
62830 /* entry requires deletion */
62831 case FSCACHE_CHECKAUX_OBSOLETE:
62832 - fscache_stat(&fscache_n_checkaux_obsolete);
62833 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
62834 break;
62835
62836 default:
62837 @@ -993,7 +993,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
62838 {
62839 const struct fscache_state *s;
62840
62841 - fscache_stat(&fscache_n_invalidates_run);
62842 + fscache_stat_unchecked(&fscache_n_invalidates_run);
62843 fscache_stat(&fscache_n_cop_invalidate_object);
62844 s = _fscache_invalidate_object(object, event);
62845 fscache_stat_d(&fscache_n_cop_invalidate_object);
62846 @@ -1008,7 +1008,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
62847 {
62848 _enter("{OBJ%x},%d", object->debug_id, event);
62849
62850 - fscache_stat(&fscache_n_updates_run);
62851 + fscache_stat_unchecked(&fscache_n_updates_run);
62852 fscache_stat(&fscache_n_cop_update_object);
62853 object->cache->ops->update_object(object);
62854 fscache_stat_d(&fscache_n_cop_update_object);
62855 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
62856 index e7b87a0..a85d47a 100644
62857 --- a/fs/fscache/operation.c
62858 +++ b/fs/fscache/operation.c
62859 @@ -17,7 +17,7 @@
62860 #include <linux/slab.h>
62861 #include "internal.h"
62862
62863 -atomic_t fscache_op_debug_id;
62864 +atomic_unchecked_t fscache_op_debug_id;
62865 EXPORT_SYMBOL(fscache_op_debug_id);
62866
62867 /**
62868 @@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
62869 ASSERTCMP(atomic_read(&op->usage), >, 0);
62870 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
62871
62872 - fscache_stat(&fscache_n_op_enqueue);
62873 + fscache_stat_unchecked(&fscache_n_op_enqueue);
62874 switch (op->flags & FSCACHE_OP_TYPE) {
62875 case FSCACHE_OP_ASYNC:
62876 _debug("queue async");
62877 @@ -72,7 +72,7 @@ static void fscache_run_op(struct fscache_object *object,
62878 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
62879 if (op->processor)
62880 fscache_enqueue_operation(op);
62881 - fscache_stat(&fscache_n_op_run);
62882 + fscache_stat_unchecked(&fscache_n_op_run);
62883 }
62884
62885 /*
62886 @@ -104,11 +104,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
62887 if (object->n_in_progress > 0) {
62888 atomic_inc(&op->usage);
62889 list_add_tail(&op->pend_link, &object->pending_ops);
62890 - fscache_stat(&fscache_n_op_pend);
62891 + fscache_stat_unchecked(&fscache_n_op_pend);
62892 } else if (!list_empty(&object->pending_ops)) {
62893 atomic_inc(&op->usage);
62894 list_add_tail(&op->pend_link, &object->pending_ops);
62895 - fscache_stat(&fscache_n_op_pend);
62896 + fscache_stat_unchecked(&fscache_n_op_pend);
62897 fscache_start_operations(object);
62898 } else {
62899 ASSERTCMP(object->n_in_progress, ==, 0);
62900 @@ -124,7 +124,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
62901 object->n_exclusive++; /* reads and writes must wait */
62902 atomic_inc(&op->usage);
62903 list_add_tail(&op->pend_link, &object->pending_ops);
62904 - fscache_stat(&fscache_n_op_pend);
62905 + fscache_stat_unchecked(&fscache_n_op_pend);
62906 ret = 0;
62907 } else {
62908 /* If we're in any other state, there must have been an I/O
62909 @@ -211,11 +211,11 @@ int fscache_submit_op(struct fscache_object *object,
62910 if (object->n_exclusive > 0) {
62911 atomic_inc(&op->usage);
62912 list_add_tail(&op->pend_link, &object->pending_ops);
62913 - fscache_stat(&fscache_n_op_pend);
62914 + fscache_stat_unchecked(&fscache_n_op_pend);
62915 } else if (!list_empty(&object->pending_ops)) {
62916 atomic_inc(&op->usage);
62917 list_add_tail(&op->pend_link, &object->pending_ops);
62918 - fscache_stat(&fscache_n_op_pend);
62919 + fscache_stat_unchecked(&fscache_n_op_pend);
62920 fscache_start_operations(object);
62921 } else {
62922 ASSERTCMP(object->n_exclusive, ==, 0);
62923 @@ -227,10 +227,10 @@ int fscache_submit_op(struct fscache_object *object,
62924 object->n_ops++;
62925 atomic_inc(&op->usage);
62926 list_add_tail(&op->pend_link, &object->pending_ops);
62927 - fscache_stat(&fscache_n_op_pend);
62928 + fscache_stat_unchecked(&fscache_n_op_pend);
62929 ret = 0;
62930 } else if (fscache_object_is_dying(object)) {
62931 - fscache_stat(&fscache_n_op_rejected);
62932 + fscache_stat_unchecked(&fscache_n_op_rejected);
62933 op->state = FSCACHE_OP_ST_CANCELLED;
62934 ret = -ENOBUFS;
62935 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
62936 @@ -309,7 +309,7 @@ int fscache_cancel_op(struct fscache_operation *op,
62937 ret = -EBUSY;
62938 if (op->state == FSCACHE_OP_ST_PENDING) {
62939 ASSERT(!list_empty(&op->pend_link));
62940 - fscache_stat(&fscache_n_op_cancelled);
62941 + fscache_stat_unchecked(&fscache_n_op_cancelled);
62942 list_del_init(&op->pend_link);
62943 if (do_cancel)
62944 do_cancel(op);
62945 @@ -341,7 +341,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
62946 while (!list_empty(&object->pending_ops)) {
62947 op = list_entry(object->pending_ops.next,
62948 struct fscache_operation, pend_link);
62949 - fscache_stat(&fscache_n_op_cancelled);
62950 + fscache_stat_unchecked(&fscache_n_op_cancelled);
62951 list_del_init(&op->pend_link);
62952
62953 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
62954 @@ -413,7 +413,7 @@ void fscache_put_operation(struct fscache_operation *op)
62955 op->state, ==, FSCACHE_OP_ST_CANCELLED);
62956 op->state = FSCACHE_OP_ST_DEAD;
62957
62958 - fscache_stat(&fscache_n_op_release);
62959 + fscache_stat_unchecked(&fscache_n_op_release);
62960
62961 if (op->release) {
62962 op->release(op);
62963 @@ -432,7 +432,7 @@ void fscache_put_operation(struct fscache_operation *op)
62964 * lock, and defer it otherwise */
62965 if (!spin_trylock(&object->lock)) {
62966 _debug("defer put");
62967 - fscache_stat(&fscache_n_op_deferred_release);
62968 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
62969
62970 cache = object->cache;
62971 spin_lock(&cache->op_gc_list_lock);
62972 @@ -485,7 +485,7 @@ void fscache_operation_gc(struct work_struct *work)
62973
62974 _debug("GC DEFERRED REL OBJ%x OP%x",
62975 object->debug_id, op->debug_id);
62976 - fscache_stat(&fscache_n_op_gc);
62977 + fscache_stat_unchecked(&fscache_n_op_gc);
62978
62979 ASSERTCMP(atomic_read(&op->usage), ==, 0);
62980 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
62981 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
62982 index de33b3f..8be4d29 100644
62983 --- a/fs/fscache/page.c
62984 +++ b/fs/fscache/page.c
62985 @@ -74,7 +74,7 @@ try_again:
62986 val = radix_tree_lookup(&cookie->stores, page->index);
62987 if (!val) {
62988 rcu_read_unlock();
62989 - fscache_stat(&fscache_n_store_vmscan_not_storing);
62990 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
62991 __fscache_uncache_page(cookie, page);
62992 return true;
62993 }
62994 @@ -104,11 +104,11 @@ try_again:
62995 spin_unlock(&cookie->stores_lock);
62996
62997 if (xpage) {
62998 - fscache_stat(&fscache_n_store_vmscan_cancelled);
62999 - fscache_stat(&fscache_n_store_radix_deletes);
63000 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
63001 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
63002 ASSERTCMP(xpage, ==, page);
63003 } else {
63004 - fscache_stat(&fscache_n_store_vmscan_gone);
63005 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
63006 }
63007
63008 wake_up_bit(&cookie->flags, 0);
63009 @@ -123,11 +123,11 @@ page_busy:
63010 * sleeping on memory allocation, so we may need to impose a timeout
63011 * too. */
63012 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
63013 - fscache_stat(&fscache_n_store_vmscan_busy);
63014 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
63015 return false;
63016 }
63017
63018 - fscache_stat(&fscache_n_store_vmscan_wait);
63019 + fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
63020 if (!release_page_wait_timeout(cookie, page))
63021 _debug("fscache writeout timeout page: %p{%lx}",
63022 page, page->index);
63023 @@ -156,7 +156,7 @@ static void fscache_end_page_write(struct fscache_object *object,
63024 FSCACHE_COOKIE_STORING_TAG);
63025 if (!radix_tree_tag_get(&cookie->stores, page->index,
63026 FSCACHE_COOKIE_PENDING_TAG)) {
63027 - fscache_stat(&fscache_n_store_radix_deletes);
63028 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
63029 xpage = radix_tree_delete(&cookie->stores, page->index);
63030 }
63031 spin_unlock(&cookie->stores_lock);
63032 @@ -177,7 +177,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
63033
63034 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
63035
63036 - fscache_stat(&fscache_n_attr_changed_calls);
63037 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
63038
63039 if (fscache_object_is_active(object)) {
63040 fscache_stat(&fscache_n_cop_attr_changed);
63041 @@ -204,11 +204,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
63042
63043 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
63044
63045 - fscache_stat(&fscache_n_attr_changed);
63046 + fscache_stat_unchecked(&fscache_n_attr_changed);
63047
63048 op = kzalloc(sizeof(*op), GFP_KERNEL);
63049 if (!op) {
63050 - fscache_stat(&fscache_n_attr_changed_nomem);
63051 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
63052 _leave(" = -ENOMEM");
63053 return -ENOMEM;
63054 }
63055 @@ -230,7 +230,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
63056 if (fscache_submit_exclusive_op(object, op) < 0)
63057 goto nobufs_dec;
63058 spin_unlock(&cookie->lock);
63059 - fscache_stat(&fscache_n_attr_changed_ok);
63060 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
63061 fscache_put_operation(op);
63062 _leave(" = 0");
63063 return 0;
63064 @@ -242,7 +242,7 @@ nobufs:
63065 kfree(op);
63066 if (wake_cookie)
63067 __fscache_wake_unused_cookie(cookie);
63068 - fscache_stat(&fscache_n_attr_changed_nobufs);
63069 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
63070 _leave(" = %d", -ENOBUFS);
63071 return -ENOBUFS;
63072 }
63073 @@ -281,7 +281,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
63074 /* allocate a retrieval operation and attempt to submit it */
63075 op = kzalloc(sizeof(*op), GFP_NOIO);
63076 if (!op) {
63077 - fscache_stat(&fscache_n_retrievals_nomem);
63078 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63079 return NULL;
63080 }
63081
63082 @@ -311,12 +311,12 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
63083 return 0;
63084 }
63085
63086 - fscache_stat(&fscache_n_retrievals_wait);
63087 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
63088
63089 jif = jiffies;
63090 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
63091 TASK_INTERRUPTIBLE) != 0) {
63092 - fscache_stat(&fscache_n_retrievals_intr);
63093 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
63094 _leave(" = -ERESTARTSYS");
63095 return -ERESTARTSYS;
63096 }
63097 @@ -345,8 +345,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
63098 */
63099 int fscache_wait_for_operation_activation(struct fscache_object *object,
63100 struct fscache_operation *op,
63101 - atomic_t *stat_op_waits,
63102 - atomic_t *stat_object_dead,
63103 + atomic_unchecked_t *stat_op_waits,
63104 + atomic_unchecked_t *stat_object_dead,
63105 void (*do_cancel)(struct fscache_operation *))
63106 {
63107 int ret;
63108 @@ -356,7 +356,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
63109
63110 _debug(">>> WT");
63111 if (stat_op_waits)
63112 - fscache_stat(stat_op_waits);
63113 + fscache_stat_unchecked(stat_op_waits);
63114 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
63115 TASK_INTERRUPTIBLE) != 0) {
63116 ret = fscache_cancel_op(op, do_cancel);
63117 @@ -373,7 +373,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
63118 check_if_dead:
63119 if (op->state == FSCACHE_OP_ST_CANCELLED) {
63120 if (stat_object_dead)
63121 - fscache_stat(stat_object_dead);
63122 + fscache_stat_unchecked(stat_object_dead);
63123 _leave(" = -ENOBUFS [cancelled]");
63124 return -ENOBUFS;
63125 }
63126 @@ -381,7 +381,7 @@ check_if_dead:
63127 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
63128 fscache_cancel_op(op, do_cancel);
63129 if (stat_object_dead)
63130 - fscache_stat(stat_object_dead);
63131 + fscache_stat_unchecked(stat_object_dead);
63132 return -ENOBUFS;
63133 }
63134 return 0;
63135 @@ -409,7 +409,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63136
63137 _enter("%p,%p,,,", cookie, page);
63138
63139 - fscache_stat(&fscache_n_retrievals);
63140 + fscache_stat_unchecked(&fscache_n_retrievals);
63141
63142 if (hlist_empty(&cookie->backing_objects))
63143 goto nobufs;
63144 @@ -451,7 +451,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63145 goto nobufs_unlock_dec;
63146 spin_unlock(&cookie->lock);
63147
63148 - fscache_stat(&fscache_n_retrieval_ops);
63149 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
63150
63151 /* pin the netfs read context in case we need to do the actual netfs
63152 * read because we've encountered a cache read failure */
63153 @@ -482,15 +482,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63154
63155 error:
63156 if (ret == -ENOMEM)
63157 - fscache_stat(&fscache_n_retrievals_nomem);
63158 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63159 else if (ret == -ERESTARTSYS)
63160 - fscache_stat(&fscache_n_retrievals_intr);
63161 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
63162 else if (ret == -ENODATA)
63163 - fscache_stat(&fscache_n_retrievals_nodata);
63164 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
63165 else if (ret < 0)
63166 - fscache_stat(&fscache_n_retrievals_nobufs);
63167 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63168 else
63169 - fscache_stat(&fscache_n_retrievals_ok);
63170 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
63171
63172 fscache_put_retrieval(op);
63173 _leave(" = %d", ret);
63174 @@ -505,7 +505,7 @@ nobufs_unlock:
63175 __fscache_wake_unused_cookie(cookie);
63176 kfree(op);
63177 nobufs:
63178 - fscache_stat(&fscache_n_retrievals_nobufs);
63179 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63180 _leave(" = -ENOBUFS");
63181 return -ENOBUFS;
63182 }
63183 @@ -544,7 +544,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63184
63185 _enter("%p,,%d,,,", cookie, *nr_pages);
63186
63187 - fscache_stat(&fscache_n_retrievals);
63188 + fscache_stat_unchecked(&fscache_n_retrievals);
63189
63190 if (hlist_empty(&cookie->backing_objects))
63191 goto nobufs;
63192 @@ -582,7 +582,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63193 goto nobufs_unlock_dec;
63194 spin_unlock(&cookie->lock);
63195
63196 - fscache_stat(&fscache_n_retrieval_ops);
63197 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
63198
63199 /* pin the netfs read context in case we need to do the actual netfs
63200 * read because we've encountered a cache read failure */
63201 @@ -613,15 +613,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63202
63203 error:
63204 if (ret == -ENOMEM)
63205 - fscache_stat(&fscache_n_retrievals_nomem);
63206 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63207 else if (ret == -ERESTARTSYS)
63208 - fscache_stat(&fscache_n_retrievals_intr);
63209 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
63210 else if (ret == -ENODATA)
63211 - fscache_stat(&fscache_n_retrievals_nodata);
63212 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
63213 else if (ret < 0)
63214 - fscache_stat(&fscache_n_retrievals_nobufs);
63215 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63216 else
63217 - fscache_stat(&fscache_n_retrievals_ok);
63218 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
63219
63220 fscache_put_retrieval(op);
63221 _leave(" = %d", ret);
63222 @@ -636,7 +636,7 @@ nobufs_unlock:
63223 if (wake_cookie)
63224 __fscache_wake_unused_cookie(cookie);
63225 nobufs:
63226 - fscache_stat(&fscache_n_retrievals_nobufs);
63227 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63228 _leave(" = -ENOBUFS");
63229 return -ENOBUFS;
63230 }
63231 @@ -661,7 +661,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63232
63233 _enter("%p,%p,,,", cookie, page);
63234
63235 - fscache_stat(&fscache_n_allocs);
63236 + fscache_stat_unchecked(&fscache_n_allocs);
63237
63238 if (hlist_empty(&cookie->backing_objects))
63239 goto nobufs;
63240 @@ -695,7 +695,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63241 goto nobufs_unlock_dec;
63242 spin_unlock(&cookie->lock);
63243
63244 - fscache_stat(&fscache_n_alloc_ops);
63245 + fscache_stat_unchecked(&fscache_n_alloc_ops);
63246
63247 ret = fscache_wait_for_operation_activation(
63248 object, &op->op,
63249 @@ -712,11 +712,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63250
63251 error:
63252 if (ret == -ERESTARTSYS)
63253 - fscache_stat(&fscache_n_allocs_intr);
63254 + fscache_stat_unchecked(&fscache_n_allocs_intr);
63255 else if (ret < 0)
63256 - fscache_stat(&fscache_n_allocs_nobufs);
63257 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
63258 else
63259 - fscache_stat(&fscache_n_allocs_ok);
63260 + fscache_stat_unchecked(&fscache_n_allocs_ok);
63261
63262 fscache_put_retrieval(op);
63263 _leave(" = %d", ret);
63264 @@ -730,7 +730,7 @@ nobufs_unlock:
63265 if (wake_cookie)
63266 __fscache_wake_unused_cookie(cookie);
63267 nobufs:
63268 - fscache_stat(&fscache_n_allocs_nobufs);
63269 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
63270 _leave(" = -ENOBUFS");
63271 return -ENOBUFS;
63272 }
63273 @@ -806,7 +806,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63274
63275 spin_lock(&cookie->stores_lock);
63276
63277 - fscache_stat(&fscache_n_store_calls);
63278 + fscache_stat_unchecked(&fscache_n_store_calls);
63279
63280 /* find a page to store */
63281 page = NULL;
63282 @@ -817,7 +817,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63283 page = results[0];
63284 _debug("gang %d [%lx]", n, page->index);
63285 if (page->index > op->store_limit) {
63286 - fscache_stat(&fscache_n_store_pages_over_limit);
63287 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
63288 goto superseded;
63289 }
63290
63291 @@ -829,7 +829,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63292 spin_unlock(&cookie->stores_lock);
63293 spin_unlock(&object->lock);
63294
63295 - fscache_stat(&fscache_n_store_pages);
63296 + fscache_stat_unchecked(&fscache_n_store_pages);
63297 fscache_stat(&fscache_n_cop_write_page);
63298 ret = object->cache->ops->write_page(op, page);
63299 fscache_stat_d(&fscache_n_cop_write_page);
63300 @@ -933,7 +933,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63301 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
63302 ASSERT(PageFsCache(page));
63303
63304 - fscache_stat(&fscache_n_stores);
63305 + fscache_stat_unchecked(&fscache_n_stores);
63306
63307 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
63308 _leave(" = -ENOBUFS [invalidating]");
63309 @@ -992,7 +992,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63310 spin_unlock(&cookie->stores_lock);
63311 spin_unlock(&object->lock);
63312
63313 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
63314 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
63315 op->store_limit = object->store_limit;
63316
63317 __fscache_use_cookie(cookie);
63318 @@ -1001,8 +1001,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63319
63320 spin_unlock(&cookie->lock);
63321 radix_tree_preload_end();
63322 - fscache_stat(&fscache_n_store_ops);
63323 - fscache_stat(&fscache_n_stores_ok);
63324 + fscache_stat_unchecked(&fscache_n_store_ops);
63325 + fscache_stat_unchecked(&fscache_n_stores_ok);
63326
63327 /* the work queue now carries its own ref on the object */
63328 fscache_put_operation(&op->op);
63329 @@ -1010,14 +1010,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63330 return 0;
63331
63332 already_queued:
63333 - fscache_stat(&fscache_n_stores_again);
63334 + fscache_stat_unchecked(&fscache_n_stores_again);
63335 already_pending:
63336 spin_unlock(&cookie->stores_lock);
63337 spin_unlock(&object->lock);
63338 spin_unlock(&cookie->lock);
63339 radix_tree_preload_end();
63340 kfree(op);
63341 - fscache_stat(&fscache_n_stores_ok);
63342 + fscache_stat_unchecked(&fscache_n_stores_ok);
63343 _leave(" = 0");
63344 return 0;
63345
63346 @@ -1039,14 +1039,14 @@ nobufs:
63347 kfree(op);
63348 if (wake_cookie)
63349 __fscache_wake_unused_cookie(cookie);
63350 - fscache_stat(&fscache_n_stores_nobufs);
63351 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
63352 _leave(" = -ENOBUFS");
63353 return -ENOBUFS;
63354
63355 nomem_free:
63356 kfree(op);
63357 nomem:
63358 - fscache_stat(&fscache_n_stores_oom);
63359 + fscache_stat_unchecked(&fscache_n_stores_oom);
63360 _leave(" = -ENOMEM");
63361 return -ENOMEM;
63362 }
63363 @@ -1064,7 +1064,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
63364 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
63365 ASSERTCMP(page, !=, NULL);
63366
63367 - fscache_stat(&fscache_n_uncaches);
63368 + fscache_stat_unchecked(&fscache_n_uncaches);
63369
63370 /* cache withdrawal may beat us to it */
63371 if (!PageFsCache(page))
63372 @@ -1115,7 +1115,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
63373 struct fscache_cookie *cookie = op->op.object->cookie;
63374
63375 #ifdef CONFIG_FSCACHE_STATS
63376 - atomic_inc(&fscache_n_marks);
63377 + atomic_inc_unchecked(&fscache_n_marks);
63378 #endif
63379
63380 _debug("- mark %p{%lx}", page, page->index);
63381 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
63382 index 40d13c7..ddf52b9 100644
63383 --- a/fs/fscache/stats.c
63384 +++ b/fs/fscache/stats.c
63385 @@ -18,99 +18,99 @@
63386 /*
63387 * operation counters
63388 */
63389 -atomic_t fscache_n_op_pend;
63390 -atomic_t fscache_n_op_run;
63391 -atomic_t fscache_n_op_enqueue;
63392 -atomic_t fscache_n_op_requeue;
63393 -atomic_t fscache_n_op_deferred_release;
63394 -atomic_t fscache_n_op_release;
63395 -atomic_t fscache_n_op_gc;
63396 -atomic_t fscache_n_op_cancelled;
63397 -atomic_t fscache_n_op_rejected;
63398 +atomic_unchecked_t fscache_n_op_pend;
63399 +atomic_unchecked_t fscache_n_op_run;
63400 +atomic_unchecked_t fscache_n_op_enqueue;
63401 +atomic_unchecked_t fscache_n_op_requeue;
63402 +atomic_unchecked_t fscache_n_op_deferred_release;
63403 +atomic_unchecked_t fscache_n_op_release;
63404 +atomic_unchecked_t fscache_n_op_gc;
63405 +atomic_unchecked_t fscache_n_op_cancelled;
63406 +atomic_unchecked_t fscache_n_op_rejected;
63407
63408 -atomic_t fscache_n_attr_changed;
63409 -atomic_t fscache_n_attr_changed_ok;
63410 -atomic_t fscache_n_attr_changed_nobufs;
63411 -atomic_t fscache_n_attr_changed_nomem;
63412 -atomic_t fscache_n_attr_changed_calls;
63413 +atomic_unchecked_t fscache_n_attr_changed;
63414 +atomic_unchecked_t fscache_n_attr_changed_ok;
63415 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
63416 +atomic_unchecked_t fscache_n_attr_changed_nomem;
63417 +atomic_unchecked_t fscache_n_attr_changed_calls;
63418
63419 -atomic_t fscache_n_allocs;
63420 -atomic_t fscache_n_allocs_ok;
63421 -atomic_t fscache_n_allocs_wait;
63422 -atomic_t fscache_n_allocs_nobufs;
63423 -atomic_t fscache_n_allocs_intr;
63424 -atomic_t fscache_n_allocs_object_dead;
63425 -atomic_t fscache_n_alloc_ops;
63426 -atomic_t fscache_n_alloc_op_waits;
63427 +atomic_unchecked_t fscache_n_allocs;
63428 +atomic_unchecked_t fscache_n_allocs_ok;
63429 +atomic_unchecked_t fscache_n_allocs_wait;
63430 +atomic_unchecked_t fscache_n_allocs_nobufs;
63431 +atomic_unchecked_t fscache_n_allocs_intr;
63432 +atomic_unchecked_t fscache_n_allocs_object_dead;
63433 +atomic_unchecked_t fscache_n_alloc_ops;
63434 +atomic_unchecked_t fscache_n_alloc_op_waits;
63435
63436 -atomic_t fscache_n_retrievals;
63437 -atomic_t fscache_n_retrievals_ok;
63438 -atomic_t fscache_n_retrievals_wait;
63439 -atomic_t fscache_n_retrievals_nodata;
63440 -atomic_t fscache_n_retrievals_nobufs;
63441 -atomic_t fscache_n_retrievals_intr;
63442 -atomic_t fscache_n_retrievals_nomem;
63443 -atomic_t fscache_n_retrievals_object_dead;
63444 -atomic_t fscache_n_retrieval_ops;
63445 -atomic_t fscache_n_retrieval_op_waits;
63446 +atomic_unchecked_t fscache_n_retrievals;
63447 +atomic_unchecked_t fscache_n_retrievals_ok;
63448 +atomic_unchecked_t fscache_n_retrievals_wait;
63449 +atomic_unchecked_t fscache_n_retrievals_nodata;
63450 +atomic_unchecked_t fscache_n_retrievals_nobufs;
63451 +atomic_unchecked_t fscache_n_retrievals_intr;
63452 +atomic_unchecked_t fscache_n_retrievals_nomem;
63453 +atomic_unchecked_t fscache_n_retrievals_object_dead;
63454 +atomic_unchecked_t fscache_n_retrieval_ops;
63455 +atomic_unchecked_t fscache_n_retrieval_op_waits;
63456
63457 -atomic_t fscache_n_stores;
63458 -atomic_t fscache_n_stores_ok;
63459 -atomic_t fscache_n_stores_again;
63460 -atomic_t fscache_n_stores_nobufs;
63461 -atomic_t fscache_n_stores_oom;
63462 -atomic_t fscache_n_store_ops;
63463 -atomic_t fscache_n_store_calls;
63464 -atomic_t fscache_n_store_pages;
63465 -atomic_t fscache_n_store_radix_deletes;
63466 -atomic_t fscache_n_store_pages_over_limit;
63467 +atomic_unchecked_t fscache_n_stores;
63468 +atomic_unchecked_t fscache_n_stores_ok;
63469 +atomic_unchecked_t fscache_n_stores_again;
63470 +atomic_unchecked_t fscache_n_stores_nobufs;
63471 +atomic_unchecked_t fscache_n_stores_oom;
63472 +atomic_unchecked_t fscache_n_store_ops;
63473 +atomic_unchecked_t fscache_n_store_calls;
63474 +atomic_unchecked_t fscache_n_store_pages;
63475 +atomic_unchecked_t fscache_n_store_radix_deletes;
63476 +atomic_unchecked_t fscache_n_store_pages_over_limit;
63477
63478 -atomic_t fscache_n_store_vmscan_not_storing;
63479 -atomic_t fscache_n_store_vmscan_gone;
63480 -atomic_t fscache_n_store_vmscan_busy;
63481 -atomic_t fscache_n_store_vmscan_cancelled;
63482 -atomic_t fscache_n_store_vmscan_wait;
63483 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
63484 +atomic_unchecked_t fscache_n_store_vmscan_gone;
63485 +atomic_unchecked_t fscache_n_store_vmscan_busy;
63486 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
63487 +atomic_unchecked_t fscache_n_store_vmscan_wait;
63488
63489 -atomic_t fscache_n_marks;
63490 -atomic_t fscache_n_uncaches;
63491 +atomic_unchecked_t fscache_n_marks;
63492 +atomic_unchecked_t fscache_n_uncaches;
63493
63494 -atomic_t fscache_n_acquires;
63495 -atomic_t fscache_n_acquires_null;
63496 -atomic_t fscache_n_acquires_no_cache;
63497 -atomic_t fscache_n_acquires_ok;
63498 -atomic_t fscache_n_acquires_nobufs;
63499 -atomic_t fscache_n_acquires_oom;
63500 +atomic_unchecked_t fscache_n_acquires;
63501 +atomic_unchecked_t fscache_n_acquires_null;
63502 +atomic_unchecked_t fscache_n_acquires_no_cache;
63503 +atomic_unchecked_t fscache_n_acquires_ok;
63504 +atomic_unchecked_t fscache_n_acquires_nobufs;
63505 +atomic_unchecked_t fscache_n_acquires_oom;
63506
63507 -atomic_t fscache_n_invalidates;
63508 -atomic_t fscache_n_invalidates_run;
63509 +atomic_unchecked_t fscache_n_invalidates;
63510 +atomic_unchecked_t fscache_n_invalidates_run;
63511
63512 -atomic_t fscache_n_updates;
63513 -atomic_t fscache_n_updates_null;
63514 -atomic_t fscache_n_updates_run;
63515 +atomic_unchecked_t fscache_n_updates;
63516 +atomic_unchecked_t fscache_n_updates_null;
63517 +atomic_unchecked_t fscache_n_updates_run;
63518
63519 -atomic_t fscache_n_relinquishes;
63520 -atomic_t fscache_n_relinquishes_null;
63521 -atomic_t fscache_n_relinquishes_waitcrt;
63522 -atomic_t fscache_n_relinquishes_retire;
63523 +atomic_unchecked_t fscache_n_relinquishes;
63524 +atomic_unchecked_t fscache_n_relinquishes_null;
63525 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
63526 +atomic_unchecked_t fscache_n_relinquishes_retire;
63527
63528 -atomic_t fscache_n_cookie_index;
63529 -atomic_t fscache_n_cookie_data;
63530 -atomic_t fscache_n_cookie_special;
63531 +atomic_unchecked_t fscache_n_cookie_index;
63532 +atomic_unchecked_t fscache_n_cookie_data;
63533 +atomic_unchecked_t fscache_n_cookie_special;
63534
63535 -atomic_t fscache_n_object_alloc;
63536 -atomic_t fscache_n_object_no_alloc;
63537 -atomic_t fscache_n_object_lookups;
63538 -atomic_t fscache_n_object_lookups_negative;
63539 -atomic_t fscache_n_object_lookups_positive;
63540 -atomic_t fscache_n_object_lookups_timed_out;
63541 -atomic_t fscache_n_object_created;
63542 -atomic_t fscache_n_object_avail;
63543 -atomic_t fscache_n_object_dead;
63544 +atomic_unchecked_t fscache_n_object_alloc;
63545 +atomic_unchecked_t fscache_n_object_no_alloc;
63546 +atomic_unchecked_t fscache_n_object_lookups;
63547 +atomic_unchecked_t fscache_n_object_lookups_negative;
63548 +atomic_unchecked_t fscache_n_object_lookups_positive;
63549 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
63550 +atomic_unchecked_t fscache_n_object_created;
63551 +atomic_unchecked_t fscache_n_object_avail;
63552 +atomic_unchecked_t fscache_n_object_dead;
63553
63554 -atomic_t fscache_n_checkaux_none;
63555 -atomic_t fscache_n_checkaux_okay;
63556 -atomic_t fscache_n_checkaux_update;
63557 -atomic_t fscache_n_checkaux_obsolete;
63558 +atomic_unchecked_t fscache_n_checkaux_none;
63559 +atomic_unchecked_t fscache_n_checkaux_okay;
63560 +atomic_unchecked_t fscache_n_checkaux_update;
63561 +atomic_unchecked_t fscache_n_checkaux_obsolete;
63562
63563 atomic_t fscache_n_cop_alloc_object;
63564 atomic_t fscache_n_cop_lookup_object;
63565 @@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
63566 seq_puts(m, "FS-Cache statistics\n");
63567
63568 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
63569 - atomic_read(&fscache_n_cookie_index),
63570 - atomic_read(&fscache_n_cookie_data),
63571 - atomic_read(&fscache_n_cookie_special));
63572 + atomic_read_unchecked(&fscache_n_cookie_index),
63573 + atomic_read_unchecked(&fscache_n_cookie_data),
63574 + atomic_read_unchecked(&fscache_n_cookie_special));
63575
63576 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
63577 - atomic_read(&fscache_n_object_alloc),
63578 - atomic_read(&fscache_n_object_no_alloc),
63579 - atomic_read(&fscache_n_object_avail),
63580 - atomic_read(&fscache_n_object_dead));
63581 + atomic_read_unchecked(&fscache_n_object_alloc),
63582 + atomic_read_unchecked(&fscache_n_object_no_alloc),
63583 + atomic_read_unchecked(&fscache_n_object_avail),
63584 + atomic_read_unchecked(&fscache_n_object_dead));
63585 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
63586 - atomic_read(&fscache_n_checkaux_none),
63587 - atomic_read(&fscache_n_checkaux_okay),
63588 - atomic_read(&fscache_n_checkaux_update),
63589 - atomic_read(&fscache_n_checkaux_obsolete));
63590 + atomic_read_unchecked(&fscache_n_checkaux_none),
63591 + atomic_read_unchecked(&fscache_n_checkaux_okay),
63592 + atomic_read_unchecked(&fscache_n_checkaux_update),
63593 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
63594
63595 seq_printf(m, "Pages : mrk=%u unc=%u\n",
63596 - atomic_read(&fscache_n_marks),
63597 - atomic_read(&fscache_n_uncaches));
63598 + atomic_read_unchecked(&fscache_n_marks),
63599 + atomic_read_unchecked(&fscache_n_uncaches));
63600
63601 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
63602 " oom=%u\n",
63603 - atomic_read(&fscache_n_acquires),
63604 - atomic_read(&fscache_n_acquires_null),
63605 - atomic_read(&fscache_n_acquires_no_cache),
63606 - atomic_read(&fscache_n_acquires_ok),
63607 - atomic_read(&fscache_n_acquires_nobufs),
63608 - atomic_read(&fscache_n_acquires_oom));
63609 + atomic_read_unchecked(&fscache_n_acquires),
63610 + atomic_read_unchecked(&fscache_n_acquires_null),
63611 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
63612 + atomic_read_unchecked(&fscache_n_acquires_ok),
63613 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
63614 + atomic_read_unchecked(&fscache_n_acquires_oom));
63615
63616 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
63617 - atomic_read(&fscache_n_object_lookups),
63618 - atomic_read(&fscache_n_object_lookups_negative),
63619 - atomic_read(&fscache_n_object_lookups_positive),
63620 - atomic_read(&fscache_n_object_created),
63621 - atomic_read(&fscache_n_object_lookups_timed_out));
63622 + atomic_read_unchecked(&fscache_n_object_lookups),
63623 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
63624 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
63625 + atomic_read_unchecked(&fscache_n_object_created),
63626 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
63627
63628 seq_printf(m, "Invals : n=%u run=%u\n",
63629 - atomic_read(&fscache_n_invalidates),
63630 - atomic_read(&fscache_n_invalidates_run));
63631 + atomic_read_unchecked(&fscache_n_invalidates),
63632 + atomic_read_unchecked(&fscache_n_invalidates_run));
63633
63634 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
63635 - atomic_read(&fscache_n_updates),
63636 - atomic_read(&fscache_n_updates_null),
63637 - atomic_read(&fscache_n_updates_run));
63638 + atomic_read_unchecked(&fscache_n_updates),
63639 + atomic_read_unchecked(&fscache_n_updates_null),
63640 + atomic_read_unchecked(&fscache_n_updates_run));
63641
63642 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
63643 - atomic_read(&fscache_n_relinquishes),
63644 - atomic_read(&fscache_n_relinquishes_null),
63645 - atomic_read(&fscache_n_relinquishes_waitcrt),
63646 - atomic_read(&fscache_n_relinquishes_retire));
63647 + atomic_read_unchecked(&fscache_n_relinquishes),
63648 + atomic_read_unchecked(&fscache_n_relinquishes_null),
63649 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
63650 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
63651
63652 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
63653 - atomic_read(&fscache_n_attr_changed),
63654 - atomic_read(&fscache_n_attr_changed_ok),
63655 - atomic_read(&fscache_n_attr_changed_nobufs),
63656 - atomic_read(&fscache_n_attr_changed_nomem),
63657 - atomic_read(&fscache_n_attr_changed_calls));
63658 + atomic_read_unchecked(&fscache_n_attr_changed),
63659 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
63660 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
63661 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
63662 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
63663
63664 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
63665 - atomic_read(&fscache_n_allocs),
63666 - atomic_read(&fscache_n_allocs_ok),
63667 - atomic_read(&fscache_n_allocs_wait),
63668 - atomic_read(&fscache_n_allocs_nobufs),
63669 - atomic_read(&fscache_n_allocs_intr));
63670 + atomic_read_unchecked(&fscache_n_allocs),
63671 + atomic_read_unchecked(&fscache_n_allocs_ok),
63672 + atomic_read_unchecked(&fscache_n_allocs_wait),
63673 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
63674 + atomic_read_unchecked(&fscache_n_allocs_intr));
63675 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
63676 - atomic_read(&fscache_n_alloc_ops),
63677 - atomic_read(&fscache_n_alloc_op_waits),
63678 - atomic_read(&fscache_n_allocs_object_dead));
63679 + atomic_read_unchecked(&fscache_n_alloc_ops),
63680 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
63681 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
63682
63683 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
63684 " int=%u oom=%u\n",
63685 - atomic_read(&fscache_n_retrievals),
63686 - atomic_read(&fscache_n_retrievals_ok),
63687 - atomic_read(&fscache_n_retrievals_wait),
63688 - atomic_read(&fscache_n_retrievals_nodata),
63689 - atomic_read(&fscache_n_retrievals_nobufs),
63690 - atomic_read(&fscache_n_retrievals_intr),
63691 - atomic_read(&fscache_n_retrievals_nomem));
63692 + atomic_read_unchecked(&fscache_n_retrievals),
63693 + atomic_read_unchecked(&fscache_n_retrievals_ok),
63694 + atomic_read_unchecked(&fscache_n_retrievals_wait),
63695 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
63696 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
63697 + atomic_read_unchecked(&fscache_n_retrievals_intr),
63698 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
63699 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
63700 - atomic_read(&fscache_n_retrieval_ops),
63701 - atomic_read(&fscache_n_retrieval_op_waits),
63702 - atomic_read(&fscache_n_retrievals_object_dead));
63703 + atomic_read_unchecked(&fscache_n_retrieval_ops),
63704 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
63705 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
63706
63707 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
63708 - atomic_read(&fscache_n_stores),
63709 - atomic_read(&fscache_n_stores_ok),
63710 - atomic_read(&fscache_n_stores_again),
63711 - atomic_read(&fscache_n_stores_nobufs),
63712 - atomic_read(&fscache_n_stores_oom));
63713 + atomic_read_unchecked(&fscache_n_stores),
63714 + atomic_read_unchecked(&fscache_n_stores_ok),
63715 + atomic_read_unchecked(&fscache_n_stores_again),
63716 + atomic_read_unchecked(&fscache_n_stores_nobufs),
63717 + atomic_read_unchecked(&fscache_n_stores_oom));
63718 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
63719 - atomic_read(&fscache_n_store_ops),
63720 - atomic_read(&fscache_n_store_calls),
63721 - atomic_read(&fscache_n_store_pages),
63722 - atomic_read(&fscache_n_store_radix_deletes),
63723 - atomic_read(&fscache_n_store_pages_over_limit));
63724 + atomic_read_unchecked(&fscache_n_store_ops),
63725 + atomic_read_unchecked(&fscache_n_store_calls),
63726 + atomic_read_unchecked(&fscache_n_store_pages),
63727 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
63728 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
63729
63730 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
63731 - atomic_read(&fscache_n_store_vmscan_not_storing),
63732 - atomic_read(&fscache_n_store_vmscan_gone),
63733 - atomic_read(&fscache_n_store_vmscan_busy),
63734 - atomic_read(&fscache_n_store_vmscan_cancelled),
63735 - atomic_read(&fscache_n_store_vmscan_wait));
63736 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
63737 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
63738 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
63739 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
63740 + atomic_read_unchecked(&fscache_n_store_vmscan_wait));
63741
63742 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
63743 - atomic_read(&fscache_n_op_pend),
63744 - atomic_read(&fscache_n_op_run),
63745 - atomic_read(&fscache_n_op_enqueue),
63746 - atomic_read(&fscache_n_op_cancelled),
63747 - atomic_read(&fscache_n_op_rejected));
63748 + atomic_read_unchecked(&fscache_n_op_pend),
63749 + atomic_read_unchecked(&fscache_n_op_run),
63750 + atomic_read_unchecked(&fscache_n_op_enqueue),
63751 + atomic_read_unchecked(&fscache_n_op_cancelled),
63752 + atomic_read_unchecked(&fscache_n_op_rejected));
63753 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
63754 - atomic_read(&fscache_n_op_deferred_release),
63755 - atomic_read(&fscache_n_op_release),
63756 - atomic_read(&fscache_n_op_gc));
63757 + atomic_read_unchecked(&fscache_n_op_deferred_release),
63758 + atomic_read_unchecked(&fscache_n_op_release),
63759 + atomic_read_unchecked(&fscache_n_op_gc));
63760
63761 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
63762 atomic_read(&fscache_n_cop_alloc_object),
63763 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
63764 index 966ace8..030a03a 100644
63765 --- a/fs/fuse/cuse.c
63766 +++ b/fs/fuse/cuse.c
63767 @@ -611,10 +611,12 @@ static int __init cuse_init(void)
63768 INIT_LIST_HEAD(&cuse_conntbl[i]);
63769
63770 /* inherit and extend fuse_dev_operations */
63771 - cuse_channel_fops = fuse_dev_operations;
63772 - cuse_channel_fops.owner = THIS_MODULE;
63773 - cuse_channel_fops.open = cuse_channel_open;
63774 - cuse_channel_fops.release = cuse_channel_release;
63775 + pax_open_kernel();
63776 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
63777 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
63778 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
63779 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
63780 + pax_close_kernel();
63781
63782 cuse_class = class_create(THIS_MODULE, "cuse");
63783 if (IS_ERR(cuse_class))
63784 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
63785 index ca88731..8e9c55d 100644
63786 --- a/fs/fuse/dev.c
63787 +++ b/fs/fuse/dev.c
63788 @@ -1318,7 +1318,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
63789 ret = 0;
63790 pipe_lock(pipe);
63791
63792 - if (!pipe->readers) {
63793 + if (!atomic_read(&pipe->readers)) {
63794 send_sig(SIGPIPE, current, 0);
63795 if (!ret)
63796 ret = -EPIPE;
63797 @@ -1347,7 +1347,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
63798 page_nr++;
63799 ret += buf->len;
63800
63801 - if (pipe->files)
63802 + if (atomic_read(&pipe->files))
63803 do_wakeup = 1;
63804 }
63805
63806 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
63807 index de1d84a..fd69c0c 100644
63808 --- a/fs/fuse/dir.c
63809 +++ b/fs/fuse/dir.c
63810 @@ -1479,7 +1479,7 @@ static char *read_link(struct dentry *dentry)
63811 return link;
63812 }
63813
63814 -static void free_link(char *link)
63815 +static void free_link(const char *link)
63816 {
63817 if (!IS_ERR(link))
63818 free_page((unsigned long) link);
63819 diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
63820 index fd62cae..3494dfa 100644
63821 --- a/fs/hostfs/hostfs_kern.c
63822 +++ b/fs/hostfs/hostfs_kern.c
63823 @@ -908,7 +908,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
63824
63825 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
63826 {
63827 - char *s = nd_get_link(nd);
63828 + const char *s = nd_get_link(nd);
63829 if (!IS_ERR(s))
63830 __putname(s);
63831 }
63832 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
63833 index 1e2872b..7aea000 100644
63834 --- a/fs/hugetlbfs/inode.c
63835 +++ b/fs/hugetlbfs/inode.c
63836 @@ -154,6 +154,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
63837 struct mm_struct *mm = current->mm;
63838 struct vm_area_struct *vma;
63839 struct hstate *h = hstate_file(file);
63840 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
63841 struct vm_unmapped_area_info info;
63842
63843 if (len & ~huge_page_mask(h))
63844 @@ -167,17 +168,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
63845 return addr;
63846 }
63847
63848 +#ifdef CONFIG_PAX_RANDMMAP
63849 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
63850 +#endif
63851 +
63852 if (addr) {
63853 addr = ALIGN(addr, huge_page_size(h));
63854 vma = find_vma(mm, addr);
63855 - if (TASK_SIZE - len >= addr &&
63856 - (!vma || addr + len <= vma->vm_start))
63857 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
63858 return addr;
63859 }
63860
63861 info.flags = 0;
63862 info.length = len;
63863 info.low_limit = TASK_UNMAPPED_BASE;
63864 +
63865 +#ifdef CONFIG_PAX_RANDMMAP
63866 + if (mm->pax_flags & MF_PAX_RANDMMAP)
63867 + info.low_limit += mm->delta_mmap;
63868 +#endif
63869 +
63870 info.high_limit = TASK_SIZE;
63871 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
63872 info.align_offset = 0;
63873 @@ -919,7 +929,7 @@ static struct file_system_type hugetlbfs_fs_type = {
63874 };
63875 MODULE_ALIAS_FS("hugetlbfs");
63876
63877 -static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
63878 +struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
63879
63880 static int can_do_hugetlb_shm(void)
63881 {
63882 diff --git a/fs/inode.c b/fs/inode.c
63883 index 26753ba..d19eb34 100644
63884 --- a/fs/inode.c
63885 +++ b/fs/inode.c
63886 @@ -840,16 +840,20 @@ unsigned int get_next_ino(void)
63887 unsigned int *p = &get_cpu_var(last_ino);
63888 unsigned int res = *p;
63889
63890 +start:
63891 +
63892 #ifdef CONFIG_SMP
63893 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
63894 - static atomic_t shared_last_ino;
63895 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
63896 + static atomic_unchecked_t shared_last_ino;
63897 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
63898
63899 res = next - LAST_INO_BATCH;
63900 }
63901 #endif
63902
63903 - *p = ++res;
63904 + if (unlikely(!++res))
63905 + goto start; /* never zero */
63906 + *p = res;
63907 put_cpu_var(last_ino);
63908 return res;
63909 }
63910 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
63911 index 4a6cf28..d3a29d3 100644
63912 --- a/fs/jffs2/erase.c
63913 +++ b/fs/jffs2/erase.c
63914 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
63915 struct jffs2_unknown_node marker = {
63916 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
63917 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
63918 - .totlen = cpu_to_je32(c->cleanmarker_size)
63919 + .totlen = cpu_to_je32(c->cleanmarker_size),
63920 + .hdr_crc = cpu_to_je32(0)
63921 };
63922
63923 jffs2_prealloc_raw_node_refs(c, jeb, 1);
63924 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
63925 index 09ed551..45684f8 100644
63926 --- a/fs/jffs2/wbuf.c
63927 +++ b/fs/jffs2/wbuf.c
63928 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
63929 {
63930 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
63931 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
63932 - .totlen = constant_cpu_to_je32(8)
63933 + .totlen = constant_cpu_to_je32(8),
63934 + .hdr_crc = constant_cpu_to_je32(0)
63935 };
63936
63937 /*
63938 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
63939 index adf8cb0..bb935fa 100644
63940 --- a/fs/jfs/super.c
63941 +++ b/fs/jfs/super.c
63942 @@ -893,7 +893,7 @@ static int __init init_jfs_fs(void)
63943
63944 jfs_inode_cachep =
63945 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
63946 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
63947 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
63948 init_once);
63949 if (jfs_inode_cachep == NULL)
63950 return -ENOMEM;
63951 diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
63952 index a693f5b..82276a1 100644
63953 --- a/fs/kernfs/dir.c
63954 +++ b/fs/kernfs/dir.c
63955 @@ -182,7 +182,7 @@ struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn)
63956 *
63957 * Returns 31 bit hash of ns + name (so it fits in an off_t )
63958 */
63959 -static unsigned int kernfs_name_hash(const char *name, const void *ns)
63960 +static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
63961 {
63962 unsigned long hash = init_name_hash();
63963 unsigned int len = strlen(name);
63964 diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
63965 index 4429d6d..9831f52 100644
63966 --- a/fs/kernfs/file.c
63967 +++ b/fs/kernfs/file.c
63968 @@ -34,7 +34,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
63969
63970 struct kernfs_open_node {
63971 atomic_t refcnt;
63972 - atomic_t event;
63973 + atomic_unchecked_t event;
63974 wait_queue_head_t poll;
63975 struct list_head files; /* goes through kernfs_open_file.list */
63976 };
63977 @@ -163,7 +163,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
63978 {
63979 struct kernfs_open_file *of = sf->private;
63980
63981 - of->event = atomic_read(&of->kn->attr.open->event);
63982 + of->event = atomic_read_unchecked(&of->kn->attr.open->event);
63983
63984 return of->kn->attr.ops->seq_show(sf, v);
63985 }
63986 @@ -375,12 +375,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
63987 return ret;
63988 }
63989
63990 -static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
63991 - void *buf, int len, int write)
63992 +static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
63993 + void *buf, size_t len, int write)
63994 {
63995 struct file *file = vma->vm_file;
63996 struct kernfs_open_file *of = kernfs_of(file);
63997 - int ret;
63998 + ssize_t ret;
63999
64000 if (!of->vm_ops)
64001 return -EINVAL;
64002 @@ -581,7 +581,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
64003 return -ENOMEM;
64004
64005 atomic_set(&new_on->refcnt, 0);
64006 - atomic_set(&new_on->event, 1);
64007 + atomic_set_unchecked(&new_on->event, 1);
64008 init_waitqueue_head(&new_on->poll);
64009 INIT_LIST_HEAD(&new_on->files);
64010 goto retry;
64011 @@ -787,7 +787,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
64012
64013 kernfs_put_active(kn);
64014
64015 - if (of->event != atomic_read(&on->event))
64016 + if (of->event != atomic_read_unchecked(&on->event))
64017 goto trigger;
64018
64019 return DEFAULT_POLLMASK;
64020 @@ -818,7 +818,7 @@ repeat:
64021
64022 on = kn->attr.open;
64023 if (on) {
64024 - atomic_inc(&on->event);
64025 + atomic_inc_unchecked(&on->event);
64026 wake_up_interruptible(&on->poll);
64027 }
64028
64029 diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
64030 index 8a19889..4c3069a 100644
64031 --- a/fs/kernfs/symlink.c
64032 +++ b/fs/kernfs/symlink.c
64033 @@ -128,7 +128,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
64034 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
64035 void *cookie)
64036 {
64037 - char *page = nd_get_link(nd);
64038 + const char *page = nd_get_link(nd);
64039 if (!IS_ERR(page))
64040 free_page((unsigned long)page);
64041 }
64042 diff --git a/fs/libfs.c b/fs/libfs.c
64043 index 88e3e00..979c262 100644
64044 --- a/fs/libfs.c
64045 +++ b/fs/libfs.c
64046 @@ -160,6 +160,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
64047
64048 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
64049 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
64050 + char d_name[sizeof(next->d_iname)];
64051 + const unsigned char *name;
64052 +
64053 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
64054 if (!simple_positive(next)) {
64055 spin_unlock(&next->d_lock);
64056 @@ -168,7 +171,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
64057
64058 spin_unlock(&next->d_lock);
64059 spin_unlock(&dentry->d_lock);
64060 - if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
64061 + name = next->d_name.name;
64062 + if (name == next->d_iname) {
64063 + memcpy(d_name, name, next->d_name.len);
64064 + name = d_name;
64065 + }
64066 + if (!dir_emit(ctx, name, next->d_name.len,
64067 next->d_inode->i_ino, dt_type(next->d_inode)))
64068 return 0;
64069 spin_lock(&dentry->d_lock);
64070 @@ -1027,7 +1035,7 @@ EXPORT_SYMBOL(noop_fsync);
64071 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
64072 void *cookie)
64073 {
64074 - char *s = nd_get_link(nd);
64075 + const char *s = nd_get_link(nd);
64076 if (!IS_ERR(s))
64077 kfree(s);
64078 }
64079 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
64080 index acd3947..1f896e2 100644
64081 --- a/fs/lockd/clntproc.c
64082 +++ b/fs/lockd/clntproc.c
64083 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
64084 /*
64085 * Cookie counter for NLM requests
64086 */
64087 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
64088 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
64089
64090 void nlmclnt_next_cookie(struct nlm_cookie *c)
64091 {
64092 - u32 cookie = atomic_inc_return(&nlm_cookie);
64093 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
64094
64095 memcpy(c->data, &cookie, 4);
64096 c->len=4;
64097 diff --git a/fs/locks.c b/fs/locks.c
64098 index bb08857..f65e8bf 100644
64099 --- a/fs/locks.c
64100 +++ b/fs/locks.c
64101 @@ -2350,7 +2350,7 @@ void locks_remove_file(struct file *filp)
64102 locks_remove_posix(filp, filp);
64103
64104 if (filp->f_op->flock) {
64105 - struct file_lock fl = {
64106 + struct file_lock flock = {
64107 .fl_owner = filp,
64108 .fl_pid = current->tgid,
64109 .fl_file = filp,
64110 @@ -2358,9 +2358,9 @@ void locks_remove_file(struct file *filp)
64111 .fl_type = F_UNLCK,
64112 .fl_end = OFFSET_MAX,
64113 };
64114 - filp->f_op->flock(filp, F_SETLKW, &fl);
64115 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
64116 - fl.fl_ops->fl_release_private(&fl);
64117 + filp->f_op->flock(filp, F_SETLKW, &flock);
64118 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
64119 + flock.fl_ops->fl_release_private(&flock);
64120 }
64121
64122 spin_lock(&inode->i_lock);
64123 diff --git a/fs/mount.h b/fs/mount.h
64124 index 6740a62..ccb472f 100644
64125 --- a/fs/mount.h
64126 +++ b/fs/mount.h
64127 @@ -11,7 +11,7 @@ struct mnt_namespace {
64128 u64 seq; /* Sequence number to prevent loops */
64129 wait_queue_head_t poll;
64130 u64 event;
64131 -};
64132 +} __randomize_layout;
64133
64134 struct mnt_pcp {
64135 int mnt_count;
64136 @@ -57,7 +57,7 @@ struct mount {
64137 int mnt_expiry_mark; /* true if marked for expiry */
64138 struct hlist_head mnt_pins;
64139 struct path mnt_ex_mountpoint;
64140 -};
64141 +} __randomize_layout;
64142
64143 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
64144
64145 diff --git a/fs/namei.c b/fs/namei.c
64146 index bb02687..79cba2c 100644
64147 --- a/fs/namei.c
64148 +++ b/fs/namei.c
64149 @@ -331,17 +331,32 @@ int generic_permission(struct inode *inode, int mask)
64150 if (ret != -EACCES)
64151 return ret;
64152
64153 +#ifdef CONFIG_GRKERNSEC
64154 + /* we'll block if we have to log due to a denied capability use */
64155 + if (mask & MAY_NOT_BLOCK)
64156 + return -ECHILD;
64157 +#endif
64158 +
64159 if (S_ISDIR(inode->i_mode)) {
64160 /* DACs are overridable for directories */
64161 - if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
64162 - return 0;
64163 if (!(mask & MAY_WRITE))
64164 - if (capable_wrt_inode_uidgid(inode,
64165 - CAP_DAC_READ_SEARCH))
64166 + if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
64167 + capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
64168 return 0;
64169 + if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
64170 + return 0;
64171 return -EACCES;
64172 }
64173 /*
64174 + * Searching includes executable on directories, else just read.
64175 + */
64176 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
64177 + if (mask == MAY_READ)
64178 + if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
64179 + capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
64180 + return 0;
64181 +
64182 + /*
64183 * Read/write DACs are always overridable.
64184 * Executable DACs are overridable when there is
64185 * at least one exec bit set.
64186 @@ -350,14 +365,6 @@ int generic_permission(struct inode *inode, int mask)
64187 if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
64188 return 0;
64189
64190 - /*
64191 - * Searching includes executable on directories, else just read.
64192 - */
64193 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
64194 - if (mask == MAY_READ)
64195 - if (capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
64196 - return 0;
64197 -
64198 return -EACCES;
64199 }
64200 EXPORT_SYMBOL(generic_permission);
64201 @@ -823,7 +830,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
64202 {
64203 struct dentry *dentry = link->dentry;
64204 int error;
64205 - char *s;
64206 + const char *s;
64207
64208 BUG_ON(nd->flags & LOOKUP_RCU);
64209
64210 @@ -844,6 +851,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
64211 if (error)
64212 goto out_put_nd_path;
64213
64214 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
64215 + dentry->d_inode, dentry, nd->path.mnt)) {
64216 + error = -EACCES;
64217 + goto out_put_nd_path;
64218 + }
64219 +
64220 nd->last_type = LAST_BIND;
64221 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
64222 error = PTR_ERR(*p);
64223 @@ -1607,6 +1620,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
64224 if (res)
64225 break;
64226 res = walk_component(nd, path, LOOKUP_FOLLOW);
64227 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
64228 + res = -EACCES;
64229 put_link(nd, &link, cookie);
64230 } while (res > 0);
64231
64232 @@ -1679,7 +1694,7 @@ EXPORT_SYMBOL(full_name_hash);
64233 static inline u64 hash_name(const char *name)
64234 {
64235 unsigned long a, b, adata, bdata, mask, hash, len;
64236 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
64237 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
64238
64239 hash = a = 0;
64240 len = -sizeof(unsigned long);
64241 @@ -1968,6 +1983,8 @@ static int path_lookupat(int dfd, const char *name,
64242 if (err)
64243 break;
64244 err = lookup_last(nd, &path);
64245 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
64246 + err = -EACCES;
64247 put_link(nd, &link, cookie);
64248 }
64249 }
64250 @@ -1975,6 +1992,13 @@ static int path_lookupat(int dfd, const char *name,
64251 if (!err)
64252 err = complete_walk(nd);
64253
64254 + if (!err && !(nd->flags & LOOKUP_PARENT)) {
64255 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
64256 + path_put(&nd->path);
64257 + err = -ENOENT;
64258 + }
64259 + }
64260 +
64261 if (!err && nd->flags & LOOKUP_DIRECTORY) {
64262 if (!d_can_lookup(nd->path.dentry)) {
64263 path_put(&nd->path);
64264 @@ -2002,8 +2026,15 @@ static int filename_lookup(int dfd, struct filename *name,
64265 retval = path_lookupat(dfd, name->name,
64266 flags | LOOKUP_REVAL, nd);
64267
64268 - if (likely(!retval))
64269 + if (likely(!retval)) {
64270 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
64271 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
64272 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
64273 + path_put(&nd->path);
64274 + return -ENOENT;
64275 + }
64276 + }
64277 + }
64278 return retval;
64279 }
64280
64281 @@ -2585,6 +2616,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
64282 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
64283 return -EPERM;
64284
64285 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
64286 + return -EPERM;
64287 + if (gr_handle_rawio(inode))
64288 + return -EPERM;
64289 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
64290 + return -EACCES;
64291 +
64292 return 0;
64293 }
64294
64295 @@ -2816,7 +2854,7 @@ looked_up:
64296 * cleared otherwise prior to returning.
64297 */
64298 static int lookup_open(struct nameidata *nd, struct path *path,
64299 - struct file *file,
64300 + struct path *link, struct file *file,
64301 const struct open_flags *op,
64302 bool got_write, int *opened)
64303 {
64304 @@ -2851,6 +2889,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
64305 /* Negative dentry, just create the file */
64306 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
64307 umode_t mode = op->mode;
64308 +
64309 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
64310 + error = -EACCES;
64311 + goto out_dput;
64312 + }
64313 +
64314 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
64315 + error = -EACCES;
64316 + goto out_dput;
64317 + }
64318 +
64319 if (!IS_POSIXACL(dir->d_inode))
64320 mode &= ~current_umask();
64321 /*
64322 @@ -2872,6 +2921,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
64323 nd->flags & LOOKUP_EXCL);
64324 if (error)
64325 goto out_dput;
64326 + else
64327 + gr_handle_create(dentry, nd->path.mnt);
64328 }
64329 out_no_open:
64330 path->dentry = dentry;
64331 @@ -2886,7 +2937,7 @@ out_dput:
64332 /*
64333 * Handle the last step of open()
64334 */
64335 -static int do_last(struct nameidata *nd, struct path *path,
64336 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
64337 struct file *file, const struct open_flags *op,
64338 int *opened, struct filename *name)
64339 {
64340 @@ -2936,6 +2987,15 @@ static int do_last(struct nameidata *nd, struct path *path,
64341 if (error)
64342 return error;
64343
64344 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
64345 + error = -ENOENT;
64346 + goto out;
64347 + }
64348 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
64349 + error = -EACCES;
64350 + goto out;
64351 + }
64352 +
64353 audit_inode(name, dir, LOOKUP_PARENT);
64354 error = -EISDIR;
64355 /* trailing slashes? */
64356 @@ -2955,7 +3015,7 @@ retry_lookup:
64357 */
64358 }
64359 mutex_lock(&dir->d_inode->i_mutex);
64360 - error = lookup_open(nd, path, file, op, got_write, opened);
64361 + error = lookup_open(nd, path, link, file, op, got_write, opened);
64362 mutex_unlock(&dir->d_inode->i_mutex);
64363
64364 if (error <= 0) {
64365 @@ -2979,11 +3039,28 @@ retry_lookup:
64366 goto finish_open_created;
64367 }
64368
64369 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
64370 + error = -ENOENT;
64371 + goto exit_dput;
64372 + }
64373 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
64374 + error = -EACCES;
64375 + goto exit_dput;
64376 + }
64377 +
64378 /*
64379 * create/update audit record if it already exists.
64380 */
64381 - if (d_is_positive(path->dentry))
64382 + if (d_is_positive(path->dentry)) {
64383 + /* only check if O_CREAT is specified, all other checks need to go
64384 + into may_open */
64385 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
64386 + error = -EACCES;
64387 + goto exit_dput;
64388 + }
64389 +
64390 audit_inode(name, path->dentry, 0);
64391 + }
64392
64393 /*
64394 * If atomic_open() acquired write access it is dropped now due to
64395 @@ -3024,6 +3101,11 @@ finish_lookup:
64396 }
64397 }
64398 BUG_ON(inode != path->dentry->d_inode);
64399 + /* if we're resolving a symlink to another symlink */
64400 + if (link && gr_handle_symlink_owner(link, inode)) {
64401 + error = -EACCES;
64402 + goto out;
64403 + }
64404 return 1;
64405 }
64406
64407 @@ -3033,7 +3115,6 @@ finish_lookup:
64408 save_parent.dentry = nd->path.dentry;
64409 save_parent.mnt = mntget(path->mnt);
64410 nd->path.dentry = path->dentry;
64411 -
64412 }
64413 nd->inode = inode;
64414 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
64415 @@ -3043,7 +3124,18 @@ finish_open:
64416 path_put(&save_parent);
64417 return error;
64418 }
64419 +
64420 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
64421 + error = -ENOENT;
64422 + goto out;
64423 + }
64424 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
64425 + error = -EACCES;
64426 + goto out;
64427 + }
64428 +
64429 audit_inode(name, nd->path.dentry, 0);
64430 +
64431 error = -EISDIR;
64432 if ((open_flag & O_CREAT) && d_is_dir(nd->path.dentry))
64433 goto out;
64434 @@ -3207,7 +3299,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
64435 if (unlikely(error))
64436 goto out;
64437
64438 - error = do_last(nd, &path, file, op, &opened, pathname);
64439 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
64440 while (unlikely(error > 0)) { /* trailing symlink */
64441 struct path link = path;
64442 void *cookie;
64443 @@ -3225,7 +3317,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
64444 error = follow_link(&link, nd, &cookie);
64445 if (unlikely(error))
64446 break;
64447 - error = do_last(nd, &path, file, op, &opened, pathname);
64448 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
64449 put_link(nd, &link, cookie);
64450 }
64451 out:
64452 @@ -3325,9 +3417,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
64453 goto unlock;
64454
64455 error = -EEXIST;
64456 - if (d_is_positive(dentry))
64457 + if (d_is_positive(dentry)) {
64458 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
64459 + error = -ENOENT;
64460 goto fail;
64461 -
64462 + }
64463 /*
64464 * Special case - lookup gave negative, but... we had foo/bar/
64465 * From the vfs_mknod() POV we just have a negative dentry -
64466 @@ -3379,6 +3473,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
64467 }
64468 EXPORT_SYMBOL(user_path_create);
64469
64470 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
64471 +{
64472 + struct filename *tmp = getname(pathname);
64473 + struct dentry *res;
64474 + if (IS_ERR(tmp))
64475 + return ERR_CAST(tmp);
64476 + res = kern_path_create(dfd, tmp->name, path, lookup_flags);
64477 + if (IS_ERR(res))
64478 + putname(tmp);
64479 + else
64480 + *to = tmp;
64481 + return res;
64482 +}
64483 +
64484 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
64485 {
64486 int error = may_create(dir, dentry);
64487 @@ -3442,6 +3550,17 @@ retry:
64488
64489 if (!IS_POSIXACL(path.dentry->d_inode))
64490 mode &= ~current_umask();
64491 +
64492 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
64493 + error = -EPERM;
64494 + goto out;
64495 + }
64496 +
64497 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
64498 + error = -EACCES;
64499 + goto out;
64500 + }
64501 +
64502 error = security_path_mknod(&path, dentry, mode, dev);
64503 if (error)
64504 goto out;
64505 @@ -3457,6 +3576,8 @@ retry:
64506 error = vfs_mknod(path.dentry->d_inode,dentry,mode,0);
64507 break;
64508 }
64509 + if (!error)
64510 + gr_handle_create(dentry, path.mnt);
64511 out:
64512 done_path_create(&path, dentry);
64513 if (retry_estale(error, lookup_flags)) {
64514 @@ -3511,9 +3632,16 @@ retry:
64515
64516 if (!IS_POSIXACL(path.dentry->d_inode))
64517 mode &= ~current_umask();
64518 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
64519 + error = -EACCES;
64520 + goto out;
64521 + }
64522 error = security_path_mkdir(&path, dentry, mode);
64523 if (!error)
64524 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
64525 + if (!error)
64526 + gr_handle_create(dentry, path.mnt);
64527 +out:
64528 done_path_create(&path, dentry);
64529 if (retry_estale(error, lookup_flags)) {
64530 lookup_flags |= LOOKUP_REVAL;
64531 @@ -3596,6 +3724,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
64532 struct filename *name;
64533 struct dentry *dentry;
64534 struct nameidata nd;
64535 + ino_t saved_ino = 0;
64536 + dev_t saved_dev = 0;
64537 unsigned int lookup_flags = 0;
64538 retry:
64539 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
64540 @@ -3628,10 +3758,21 @@ retry:
64541 error = -ENOENT;
64542 goto exit3;
64543 }
64544 +
64545 + saved_ino = dentry->d_inode->i_ino;
64546 + saved_dev = gr_get_dev_from_dentry(dentry);
64547 +
64548 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
64549 + error = -EACCES;
64550 + goto exit3;
64551 + }
64552 +
64553 error = security_path_rmdir(&nd.path, dentry);
64554 if (error)
64555 goto exit3;
64556 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
64557 + if (!error && (saved_dev || saved_ino))
64558 + gr_handle_delete(saved_ino, saved_dev);
64559 exit3:
64560 dput(dentry);
64561 exit2:
64562 @@ -3722,6 +3863,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
64563 struct nameidata nd;
64564 struct inode *inode = NULL;
64565 struct inode *delegated_inode = NULL;
64566 + ino_t saved_ino = 0;
64567 + dev_t saved_dev = 0;
64568 unsigned int lookup_flags = 0;
64569 retry:
64570 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
64571 @@ -3748,10 +3891,22 @@ retry_deleg:
64572 if (d_is_negative(dentry))
64573 goto slashes;
64574 ihold(inode);
64575 +
64576 + if (inode->i_nlink <= 1) {
64577 + saved_ino = inode->i_ino;
64578 + saved_dev = gr_get_dev_from_dentry(dentry);
64579 + }
64580 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
64581 + error = -EACCES;
64582 + goto exit2;
64583 + }
64584 +
64585 error = security_path_unlink(&nd.path, dentry);
64586 if (error)
64587 goto exit2;
64588 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
64589 + if (!error && (saved_ino || saved_dev))
64590 + gr_handle_delete(saved_ino, saved_dev);
64591 exit2:
64592 dput(dentry);
64593 }
64594 @@ -3840,9 +3995,17 @@ retry:
64595 if (IS_ERR(dentry))
64596 goto out_putname;
64597
64598 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
64599 + error = -EACCES;
64600 + goto out;
64601 + }
64602 +
64603 error = security_path_symlink(&path, dentry, from->name);
64604 if (!error)
64605 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
64606 + if (!error)
64607 + gr_handle_create(dentry, path.mnt);
64608 +out:
64609 done_path_create(&path, dentry);
64610 if (retry_estale(error, lookup_flags)) {
64611 lookup_flags |= LOOKUP_REVAL;
64612 @@ -3946,6 +4109,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
64613 struct dentry *new_dentry;
64614 struct path old_path, new_path;
64615 struct inode *delegated_inode = NULL;
64616 + struct filename *to = NULL;
64617 int how = 0;
64618 int error;
64619
64620 @@ -3969,7 +4133,7 @@ retry:
64621 if (error)
64622 return error;
64623
64624 - new_dentry = user_path_create(newdfd, newname, &new_path,
64625 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
64626 (how & LOOKUP_REVAL));
64627 error = PTR_ERR(new_dentry);
64628 if (IS_ERR(new_dentry))
64629 @@ -3981,11 +4145,28 @@ retry:
64630 error = may_linkat(&old_path);
64631 if (unlikely(error))
64632 goto out_dput;
64633 +
64634 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
64635 + old_path.dentry->d_inode,
64636 + old_path.dentry->d_inode->i_mode, to)) {
64637 + error = -EACCES;
64638 + goto out_dput;
64639 + }
64640 +
64641 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
64642 + old_path.dentry, old_path.mnt, to)) {
64643 + error = -EACCES;
64644 + goto out_dput;
64645 + }
64646 +
64647 error = security_path_link(old_path.dentry, &new_path, new_dentry);
64648 if (error)
64649 goto out_dput;
64650 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
64651 + if (!error)
64652 + gr_handle_create(new_dentry, new_path.mnt);
64653 out_dput:
64654 + putname(to);
64655 done_path_create(&new_path, new_dentry);
64656 if (delegated_inode) {
64657 error = break_deleg_wait(&delegated_inode);
64658 @@ -4296,6 +4477,12 @@ retry_deleg:
64659 if (new_dentry == trap)
64660 goto exit5;
64661
64662 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
64663 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
64664 + to, flags);
64665 + if (error)
64666 + goto exit5;
64667 +
64668 error = security_path_rename(&oldnd.path, old_dentry,
64669 &newnd.path, new_dentry, flags);
64670 if (error)
64671 @@ -4303,6 +4490,9 @@ retry_deleg:
64672 error = vfs_rename(old_dir->d_inode, old_dentry,
64673 new_dir->d_inode, new_dentry,
64674 &delegated_inode, flags);
64675 + if (!error)
64676 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
64677 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0, flags);
64678 exit5:
64679 dput(new_dentry);
64680 exit4:
64681 @@ -4345,14 +4535,24 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
64682
64683 int readlink_copy(char __user *buffer, int buflen, const char *link)
64684 {
64685 + char tmpbuf[64];
64686 + const char *newlink;
64687 int len = PTR_ERR(link);
64688 +
64689 if (IS_ERR(link))
64690 goto out;
64691
64692 len = strlen(link);
64693 if (len > (unsigned) buflen)
64694 len = buflen;
64695 - if (copy_to_user(buffer, link, len))
64696 +
64697 + if (len < sizeof(tmpbuf)) {
64698 + memcpy(tmpbuf, link, len);
64699 + newlink = tmpbuf;
64700 + } else
64701 + newlink = link;
64702 +
64703 + if (copy_to_user(buffer, newlink, len))
64704 len = -EFAULT;
64705 out:
64706 return len;
64707 diff --git a/fs/namespace.c b/fs/namespace.c
64708 index 550dbff..c4ad324 100644
64709 --- a/fs/namespace.c
64710 +++ b/fs/namespace.c
64711 @@ -1362,6 +1362,9 @@ static int do_umount(struct mount *mnt, int flags)
64712 if (!(sb->s_flags & MS_RDONLY))
64713 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
64714 up_write(&sb->s_umount);
64715 +
64716 + gr_log_remount(mnt->mnt_devname, retval);
64717 +
64718 return retval;
64719 }
64720
64721 @@ -1384,6 +1387,9 @@ static int do_umount(struct mount *mnt, int flags)
64722 }
64723 unlock_mount_hash();
64724 namespace_unlock();
64725 +
64726 + gr_log_unmount(mnt->mnt_devname, retval);
64727 +
64728 return retval;
64729 }
64730
64731 @@ -1403,7 +1409,7 @@ static inline bool may_mount(void)
64732 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
64733 */
64734
64735 -SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
64736 +SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
64737 {
64738 struct path path;
64739 struct mount *mnt;
64740 @@ -1445,7 +1451,7 @@ out:
64741 /*
64742 * The 2.0 compatible umount. No flags.
64743 */
64744 -SYSCALL_DEFINE1(oldumount, char __user *, name)
64745 +SYSCALL_DEFINE1(oldumount, const char __user *, name)
64746 {
64747 return sys_umount(name, 0);
64748 }
64749 @@ -2494,6 +2500,16 @@ long do_mount(const char *dev_name, const char *dir_name,
64750 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
64751 MS_STRICTATIME);
64752
64753 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
64754 + retval = -EPERM;
64755 + goto dput_out;
64756 + }
64757 +
64758 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
64759 + retval = -EPERM;
64760 + goto dput_out;
64761 + }
64762 +
64763 if (flags & MS_REMOUNT)
64764 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
64765 data_page);
64766 @@ -2508,6 +2524,9 @@ long do_mount(const char *dev_name, const char *dir_name,
64767 dev_name, data_page);
64768 dput_out:
64769 path_put(&path);
64770 +
64771 + gr_log_mount(dev_name, dir_name, retval);
64772 +
64773 return retval;
64774 }
64775
64776 @@ -2525,7 +2544,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
64777 * number incrementing at 10Ghz will take 12,427 years to wrap which
64778 * is effectively never, so we can ignore the possibility.
64779 */
64780 -static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
64781 +static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
64782
64783 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
64784 {
64785 @@ -2540,7 +2559,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
64786 kfree(new_ns);
64787 return ERR_PTR(ret);
64788 }
64789 - new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
64790 + new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
64791 atomic_set(&new_ns->count, 1);
64792 new_ns->root = NULL;
64793 INIT_LIST_HEAD(&new_ns->list);
64794 @@ -2550,7 +2569,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
64795 return new_ns;
64796 }
64797
64798 -struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
64799 +__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
64800 struct user_namespace *user_ns, struct fs_struct *new_fs)
64801 {
64802 struct mnt_namespace *new_ns;
64803 @@ -2671,8 +2690,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
64804 }
64805 EXPORT_SYMBOL(mount_subtree);
64806
64807 -SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
64808 - char __user *, type, unsigned long, flags, void __user *, data)
64809 +SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
64810 + const char __user *, type, unsigned long, flags, void __user *, data)
64811 {
64812 int ret;
64813 char *kernel_type;
64814 @@ -2785,6 +2804,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
64815 if (error)
64816 goto out2;
64817
64818 + if (gr_handle_chroot_pivot()) {
64819 + error = -EPERM;
64820 + goto out2;
64821 + }
64822 +
64823 get_fs_root(current->fs, &root);
64824 old_mp = lock_mount(&old);
64825 error = PTR_ERR(old_mp);
64826 @@ -3056,7 +3080,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
64827 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
64828 return -EPERM;
64829
64830 - if (fs->users != 1)
64831 + if (atomic_read(&fs->users) != 1)
64832 return -EINVAL;
64833
64834 get_mnt_ns(mnt_ns);
64835 diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
64836 index f4ccfe6..a5cf064 100644
64837 --- a/fs/nfs/callback_xdr.c
64838 +++ b/fs/nfs/callback_xdr.c
64839 @@ -51,7 +51,7 @@ struct callback_op {
64840 callback_decode_arg_t decode_args;
64841 callback_encode_res_t encode_res;
64842 long res_maxsize;
64843 -};
64844 +} __do_const;
64845
64846 static struct callback_op callback_ops[];
64847
64848 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
64849 index 0689aa5..299386e 100644
64850 --- a/fs/nfs/inode.c
64851 +++ b/fs/nfs/inode.c
64852 @@ -1228,16 +1228,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
64853 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
64854 }
64855
64856 -static atomic_long_t nfs_attr_generation_counter;
64857 +static atomic_long_unchecked_t nfs_attr_generation_counter;
64858
64859 static unsigned long nfs_read_attr_generation_counter(void)
64860 {
64861 - return atomic_long_read(&nfs_attr_generation_counter);
64862 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
64863 }
64864
64865 unsigned long nfs_inc_attr_generation_counter(void)
64866 {
64867 - return atomic_long_inc_return(&nfs_attr_generation_counter);
64868 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
64869 }
64870
64871 void nfs_fattr_init(struct nfs_fattr *fattr)
64872 diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
64873 index 1d3cb47..2b8ed89 100644
64874 --- a/fs/nfsd/nfs4proc.c
64875 +++ b/fs/nfsd/nfs4proc.c
64876 @@ -1155,7 +1155,7 @@ struct nfsd4_operation {
64877 nfsd4op_rsize op_rsize_bop;
64878 stateid_getter op_get_currentstateid;
64879 stateid_setter op_set_currentstateid;
64880 -};
64881 +} __do_const;
64882
64883 static struct nfsd4_operation nfsd4_ops[];
64884
64885 diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
64886 index 353aac8..32035ee 100644
64887 --- a/fs/nfsd/nfs4xdr.c
64888 +++ b/fs/nfsd/nfs4xdr.c
64889 @@ -1534,7 +1534,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
64890
64891 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
64892
64893 -static nfsd4_dec nfsd4_dec_ops[] = {
64894 +static const nfsd4_dec nfsd4_dec_ops[] = {
64895 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
64896 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
64897 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
64898 diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
64899 index ff95676..96cf3f62 100644
64900 --- a/fs/nfsd/nfscache.c
64901 +++ b/fs/nfsd/nfscache.c
64902 @@ -527,17 +527,20 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
64903 {
64904 struct svc_cacherep *rp = rqstp->rq_cacherep;
64905 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
64906 - int len;
64907 + long len;
64908 size_t bufsize = 0;
64909
64910 if (!rp)
64911 return;
64912
64913 - len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
64914 - len >>= 2;
64915 + if (statp) {
64916 + len = (char*)statp - (char*)resv->iov_base;
64917 + len = resv->iov_len - len;
64918 + len >>= 2;
64919 + }
64920
64921 /* Don't cache excessive amounts of data and XDR failures */
64922 - if (!statp || len > (256 >> 2)) {
64923 + if (!statp || len > (256 >> 2) || len < 0) {
64924 nfsd_reply_cache_free(rp);
64925 return;
64926 }
64927 @@ -545,7 +548,7 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
64928 switch (cachetype) {
64929 case RC_REPLSTAT:
64930 if (len != 1)
64931 - printk("nfsd: RC_REPLSTAT/reply len %d!\n",len);
64932 + printk("nfsd: RC_REPLSTAT/reply len %ld!\n",len);
64933 rp->c_replstat = *statp;
64934 break;
64935 case RC_REPLBUFF:
64936 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
64937 index 6ab077b..5ac7f0b 100644
64938 --- a/fs/nfsd/vfs.c
64939 +++ b/fs/nfsd/vfs.c
64940 @@ -855,7 +855,7 @@ __be32 nfsd_readv(struct file *file, loff_t offset, struct kvec *vec, int vlen,
64941
64942 oldfs = get_fs();
64943 set_fs(KERNEL_DS);
64944 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
64945 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
64946 set_fs(oldfs);
64947 return nfsd_finish_read(file, count, host_err);
64948 }
64949 @@ -943,7 +943,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
64950
64951 /* Write the data. */
64952 oldfs = get_fs(); set_fs(KERNEL_DS);
64953 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
64954 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
64955 set_fs(oldfs);
64956 if (host_err < 0)
64957 goto out_nfserr;
64958 @@ -1485,7 +1485,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
64959 */
64960
64961 oldfs = get_fs(); set_fs(KERNEL_DS);
64962 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
64963 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
64964 set_fs(oldfs);
64965
64966 if (host_err < 0)
64967 diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
64968 index 52ccd34..7a6b202 100644
64969 --- a/fs/nls/nls_base.c
64970 +++ b/fs/nls/nls_base.c
64971 @@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
64972
64973 int __register_nls(struct nls_table *nls, struct module *owner)
64974 {
64975 - struct nls_table ** tmp = &tables;
64976 + struct nls_table *tmp = tables;
64977
64978 if (nls->next)
64979 return -EBUSY;
64980
64981 - nls->owner = owner;
64982 + pax_open_kernel();
64983 + *(void **)&nls->owner = owner;
64984 + pax_close_kernel();
64985 spin_lock(&nls_lock);
64986 - while (*tmp) {
64987 - if (nls == *tmp) {
64988 + while (tmp) {
64989 + if (nls == tmp) {
64990 spin_unlock(&nls_lock);
64991 return -EBUSY;
64992 }
64993 - tmp = &(*tmp)->next;
64994 + tmp = tmp->next;
64995 }
64996 - nls->next = tables;
64997 + pax_open_kernel();
64998 + *(struct nls_table **)&nls->next = tables;
64999 + pax_close_kernel();
65000 tables = nls;
65001 spin_unlock(&nls_lock);
65002 return 0;
65003 @@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
65004
65005 int unregister_nls(struct nls_table * nls)
65006 {
65007 - struct nls_table ** tmp = &tables;
65008 + struct nls_table * const * tmp = &tables;
65009
65010 spin_lock(&nls_lock);
65011 while (*tmp) {
65012 if (nls == *tmp) {
65013 - *tmp = nls->next;
65014 + pax_open_kernel();
65015 + *(struct nls_table **)tmp = nls->next;
65016 + pax_close_kernel();
65017 spin_unlock(&nls_lock);
65018 return 0;
65019 }
65020 @@ -272,7 +278,7 @@ int unregister_nls(struct nls_table * nls)
65021 return -EINVAL;
65022 }
65023
65024 -static struct nls_table *find_nls(char *charset)
65025 +static struct nls_table *find_nls(const char *charset)
65026 {
65027 struct nls_table *nls;
65028 spin_lock(&nls_lock);
65029 @@ -288,7 +294,7 @@ static struct nls_table *find_nls(char *charset)
65030 return nls;
65031 }
65032
65033 -struct nls_table *load_nls(char *charset)
65034 +struct nls_table *load_nls(const char *charset)
65035 {
65036 return try_then_request_module(find_nls(charset), "nls_%s", charset);
65037 }
65038 diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
65039 index 162b3f1..6076a7c 100644
65040 --- a/fs/nls/nls_euc-jp.c
65041 +++ b/fs/nls/nls_euc-jp.c
65042 @@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
65043 p_nls = load_nls("cp932");
65044
65045 if (p_nls) {
65046 - table.charset2upper = p_nls->charset2upper;
65047 - table.charset2lower = p_nls->charset2lower;
65048 + pax_open_kernel();
65049 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
65050 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
65051 + pax_close_kernel();
65052 return register_nls(&table);
65053 }
65054
65055 diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
65056 index a80a741..7b96e1b 100644
65057 --- a/fs/nls/nls_koi8-ru.c
65058 +++ b/fs/nls/nls_koi8-ru.c
65059 @@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
65060 p_nls = load_nls("koi8-u");
65061
65062 if (p_nls) {
65063 - table.charset2upper = p_nls->charset2upper;
65064 - table.charset2lower = p_nls->charset2lower;
65065 + pax_open_kernel();
65066 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
65067 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
65068 + pax_close_kernel();
65069 return register_nls(&table);
65070 }
65071
65072 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
65073 index c991616..5ae51af 100644
65074 --- a/fs/notify/fanotify/fanotify_user.c
65075 +++ b/fs/notify/fanotify/fanotify_user.c
65076 @@ -216,8 +216,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
65077
65078 fd = fanotify_event_metadata.fd;
65079 ret = -EFAULT;
65080 - if (copy_to_user(buf, &fanotify_event_metadata,
65081 - fanotify_event_metadata.event_len))
65082 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
65083 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
65084 goto out_close_fd;
65085
65086 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
65087 diff --git a/fs/notify/inotify/inotify_fsnotify.c b/fs/notify/inotify/inotify_fsnotify.c
65088 index 0f88bc0..7d888d7 100644
65089 --- a/fs/notify/inotify/inotify_fsnotify.c
65090 +++ b/fs/notify/inotify/inotify_fsnotify.c
65091 @@ -165,8 +165,10 @@ static void inotify_free_group_priv(struct fsnotify_group *group)
65092 /* ideally the idr is empty and we won't hit the BUG in the callback */
65093 idr_for_each(&group->inotify_data.idr, idr_callback, group);
65094 idr_destroy(&group->inotify_data.idr);
65095 - atomic_dec(&group->inotify_data.user->inotify_devs);
65096 - free_uid(group->inotify_data.user);
65097 + if (group->inotify_data.user) {
65098 + atomic_dec(&group->inotify_data.user->inotify_devs);
65099 + free_uid(group->inotify_data.user);
65100 + }
65101 }
65102
65103 static void inotify_free_event(struct fsnotify_event *fsn_event)
65104 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
65105 index a95d8e0..a91a5fd 100644
65106 --- a/fs/notify/notification.c
65107 +++ b/fs/notify/notification.c
65108 @@ -48,7 +48,7 @@
65109 #include <linux/fsnotify_backend.h>
65110 #include "fsnotify.h"
65111
65112 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
65113 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
65114
65115 /**
65116 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
65117 @@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
65118 */
65119 u32 fsnotify_get_cookie(void)
65120 {
65121 - return atomic_inc_return(&fsnotify_sync_cookie);
65122 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
65123 }
65124 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
65125
65126 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
65127 index 9e38daf..5727cae 100644
65128 --- a/fs/ntfs/dir.c
65129 +++ b/fs/ntfs/dir.c
65130 @@ -1310,7 +1310,7 @@ find_next_index_buffer:
65131 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
65132 ~(s64)(ndir->itype.index.block_size - 1)));
65133 /* Bounds checks. */
65134 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
65135 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
65136 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
65137 "inode 0x%lx or driver bug.", vdir->i_ino);
65138 goto err_out;
65139 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
65140 index f5ec1ce..807fd78 100644
65141 --- a/fs/ntfs/file.c
65142 +++ b/fs/ntfs/file.c
65143 @@ -1279,7 +1279,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
65144 char *addr;
65145 size_t total = 0;
65146 unsigned len;
65147 - int left;
65148 + unsigned left;
65149
65150 do {
65151 len = PAGE_CACHE_SIZE - ofs;
65152 diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
65153 index 6c3296e..c0b99f0 100644
65154 --- a/fs/ntfs/super.c
65155 +++ b/fs/ntfs/super.c
65156 @@ -688,7 +688,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
65157 if (!silent)
65158 ntfs_error(sb, "Primary boot sector is invalid.");
65159 } else if (!silent)
65160 - ntfs_error(sb, read_err_str, "primary");
65161 + ntfs_error(sb, read_err_str, "%s", "primary");
65162 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
65163 if (bh_primary)
65164 brelse(bh_primary);
65165 @@ -704,7 +704,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
65166 goto hotfix_primary_boot_sector;
65167 brelse(bh_backup);
65168 } else if (!silent)
65169 - ntfs_error(sb, read_err_str, "backup");
65170 + ntfs_error(sb, read_err_str, "%s", "backup");
65171 /* Try to read NT3.51- backup boot sector. */
65172 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
65173 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
65174 @@ -715,7 +715,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
65175 "sector.");
65176 brelse(bh_backup);
65177 } else if (!silent)
65178 - ntfs_error(sb, read_err_str, "backup");
65179 + ntfs_error(sb, read_err_str, "%s", "backup");
65180 /* We failed. Cleanup and return. */
65181 if (bh_primary)
65182 brelse(bh_primary);
65183 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
65184 index 0440134..d52c93a 100644
65185 --- a/fs/ocfs2/localalloc.c
65186 +++ b/fs/ocfs2/localalloc.c
65187 @@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
65188 goto bail;
65189 }
65190
65191 - atomic_inc(&osb->alloc_stats.moves);
65192 + atomic_inc_unchecked(&osb->alloc_stats.moves);
65193
65194 bail:
65195 if (handle)
65196 diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c
65197 index 8add6f1..b931e04 100644
65198 --- a/fs/ocfs2/namei.c
65199 +++ b/fs/ocfs2/namei.c
65200 @@ -158,7 +158,7 @@ bail_add:
65201 * NOTE: This dentry already has ->d_op set from
65202 * ocfs2_get_parent() and ocfs2_get_dentry()
65203 */
65204 - if (ret)
65205 + if (!IS_ERR_OR_NULL(ret))
65206 dentry = ret;
65207
65208 status = ocfs2_dentry_attach_lock(dentry, inode,
65209 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
65210 index bbec539..7b266d5 100644
65211 --- a/fs/ocfs2/ocfs2.h
65212 +++ b/fs/ocfs2/ocfs2.h
65213 @@ -236,11 +236,11 @@ enum ocfs2_vol_state
65214
65215 struct ocfs2_alloc_stats
65216 {
65217 - atomic_t moves;
65218 - atomic_t local_data;
65219 - atomic_t bitmap_data;
65220 - atomic_t bg_allocs;
65221 - atomic_t bg_extends;
65222 + atomic_unchecked_t moves;
65223 + atomic_unchecked_t local_data;
65224 + atomic_unchecked_t bitmap_data;
65225 + atomic_unchecked_t bg_allocs;
65226 + atomic_unchecked_t bg_extends;
65227 };
65228
65229 enum ocfs2_local_alloc_state
65230 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
65231 index 0cb889a..6a26b24 100644
65232 --- a/fs/ocfs2/suballoc.c
65233 +++ b/fs/ocfs2/suballoc.c
65234 @@ -867,7 +867,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
65235 mlog_errno(status);
65236 goto bail;
65237 }
65238 - atomic_inc(&osb->alloc_stats.bg_extends);
65239 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
65240
65241 /* You should never ask for this much metadata */
65242 BUG_ON(bits_wanted >
65243 @@ -2014,7 +2014,7 @@ int ocfs2_claim_metadata(handle_t *handle,
65244 mlog_errno(status);
65245 goto bail;
65246 }
65247 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65248 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65249
65250 *suballoc_loc = res.sr_bg_blkno;
65251 *suballoc_bit_start = res.sr_bit_offset;
65252 @@ -2180,7 +2180,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
65253 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
65254 res->sr_bits);
65255
65256 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65257 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65258
65259 BUG_ON(res->sr_bits != 1);
65260
65261 @@ -2222,7 +2222,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
65262 mlog_errno(status);
65263 goto bail;
65264 }
65265 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65266 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65267
65268 BUG_ON(res.sr_bits != 1);
65269
65270 @@ -2326,7 +2326,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
65271 cluster_start,
65272 num_clusters);
65273 if (!status)
65274 - atomic_inc(&osb->alloc_stats.local_data);
65275 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
65276 } else {
65277 if (min_clusters > (osb->bitmap_cpg - 1)) {
65278 /* The only paths asking for contiguousness
65279 @@ -2352,7 +2352,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
65280 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
65281 res.sr_bg_blkno,
65282 res.sr_bit_offset);
65283 - atomic_inc(&osb->alloc_stats.bitmap_data);
65284 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
65285 *num_clusters = res.sr_bits;
65286 }
65287 }
65288 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
65289 index 4142546..69375a9 100644
65290 --- a/fs/ocfs2/super.c
65291 +++ b/fs/ocfs2/super.c
65292 @@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
65293 "%10s => GlobalAllocs: %d LocalAllocs: %d "
65294 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
65295 "Stats",
65296 - atomic_read(&osb->alloc_stats.bitmap_data),
65297 - atomic_read(&osb->alloc_stats.local_data),
65298 - atomic_read(&osb->alloc_stats.bg_allocs),
65299 - atomic_read(&osb->alloc_stats.moves),
65300 - atomic_read(&osb->alloc_stats.bg_extends));
65301 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
65302 + atomic_read_unchecked(&osb->alloc_stats.local_data),
65303 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
65304 + atomic_read_unchecked(&osb->alloc_stats.moves),
65305 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
65306
65307 out += snprintf(buf + out, len - out,
65308 "%10s => State: %u Descriptor: %llu Size: %u bits "
65309 @@ -2100,11 +2100,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
65310
65311 mutex_init(&osb->system_file_mutex);
65312
65313 - atomic_set(&osb->alloc_stats.moves, 0);
65314 - atomic_set(&osb->alloc_stats.local_data, 0);
65315 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
65316 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
65317 - atomic_set(&osb->alloc_stats.bg_extends, 0);
65318 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
65319 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
65320 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
65321 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
65322 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
65323
65324 /* Copy the blockcheck stats from the superblock probe */
65325 osb->osb_ecc_stats = *stats;
65326 diff --git a/fs/open.c b/fs/open.c
65327 index d6fd3ac..6ccf474 100644
65328 --- a/fs/open.c
65329 +++ b/fs/open.c
65330 @@ -32,6 +32,8 @@
65331 #include <linux/dnotify.h>
65332 #include <linux/compat.h>
65333
65334 +#define CREATE_TRACE_POINTS
65335 +#include <trace/events/fs.h>
65336 #include "internal.h"
65337
65338 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
65339 @@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
65340 error = locks_verify_truncate(inode, NULL, length);
65341 if (!error)
65342 error = security_path_truncate(path);
65343 + if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
65344 + error = -EACCES;
65345 if (!error)
65346 error = do_truncate(path->dentry, length, 0, NULL);
65347
65348 @@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
65349 error = locks_verify_truncate(inode, f.file, length);
65350 if (!error)
65351 error = security_path_truncate(&f.file->f_path);
65352 + if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
65353 + error = -EACCES;
65354 if (!error)
65355 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
65356 sb_end_write(inode->i_sb);
65357 @@ -380,6 +386,9 @@ retry:
65358 if (__mnt_is_readonly(path.mnt))
65359 res = -EROFS;
65360
65361 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
65362 + res = -EACCES;
65363 +
65364 out_path_release:
65365 path_put(&path);
65366 if (retry_estale(res, lookup_flags)) {
65367 @@ -411,6 +420,8 @@ retry:
65368 if (error)
65369 goto dput_and_out;
65370
65371 + gr_log_chdir(path.dentry, path.mnt);
65372 +
65373 set_fs_pwd(current->fs, &path);
65374
65375 dput_and_out:
65376 @@ -440,6 +451,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
65377 goto out_putf;
65378
65379 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
65380 +
65381 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
65382 + error = -EPERM;
65383 +
65384 + if (!error)
65385 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
65386 +
65387 if (!error)
65388 set_fs_pwd(current->fs, &f.file->f_path);
65389 out_putf:
65390 @@ -469,7 +487,13 @@ retry:
65391 if (error)
65392 goto dput_and_out;
65393
65394 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
65395 + goto dput_and_out;
65396 +
65397 set_fs_root(current->fs, &path);
65398 +
65399 + gr_handle_chroot_chdir(&path);
65400 +
65401 error = 0;
65402 dput_and_out:
65403 path_put(&path);
65404 @@ -493,6 +517,16 @@ static int chmod_common(struct path *path, umode_t mode)
65405 return error;
65406 retry_deleg:
65407 mutex_lock(&inode->i_mutex);
65408 +
65409 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
65410 + error = -EACCES;
65411 + goto out_unlock;
65412 + }
65413 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
65414 + error = -EACCES;
65415 + goto out_unlock;
65416 + }
65417 +
65418 error = security_path_chmod(path, mode);
65419 if (error)
65420 goto out_unlock;
65421 @@ -558,6 +592,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
65422 uid = make_kuid(current_user_ns(), user);
65423 gid = make_kgid(current_user_ns(), group);
65424
65425 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
65426 + return -EACCES;
65427 +
65428 newattrs.ia_valid = ATTR_CTIME;
65429 if (user != (uid_t) -1) {
65430 if (!uid_valid(uid))
65431 @@ -983,6 +1020,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
65432 } else {
65433 fsnotify_open(f);
65434 fd_install(fd, f);
65435 + trace_do_sys_open(tmp->name, flags, mode);
65436 }
65437 }
65438 putname(tmp);
65439 diff --git a/fs/pipe.c b/fs/pipe.c
65440 index 21981e5..3d5f55c 100644
65441 --- a/fs/pipe.c
65442 +++ b/fs/pipe.c
65443 @@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
65444
65445 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
65446 {
65447 - if (pipe->files)
65448 + if (atomic_read(&pipe->files))
65449 mutex_lock_nested(&pipe->mutex, subclass);
65450 }
65451
65452 @@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
65453
65454 void pipe_unlock(struct pipe_inode_info *pipe)
65455 {
65456 - if (pipe->files)
65457 + if (atomic_read(&pipe->files))
65458 mutex_unlock(&pipe->mutex);
65459 }
65460 EXPORT_SYMBOL(pipe_unlock);
65461 @@ -292,9 +292,9 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to)
65462 }
65463 if (bufs) /* More to do? */
65464 continue;
65465 - if (!pipe->writers)
65466 + if (!atomic_read(&pipe->writers))
65467 break;
65468 - if (!pipe->waiting_writers) {
65469 + if (!atomic_read(&pipe->waiting_writers)) {
65470 /* syscall merging: Usually we must not sleep
65471 * if O_NONBLOCK is set, or if we got some data.
65472 * But if a writer sleeps in kernel space, then
65473 @@ -351,7 +351,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65474
65475 __pipe_lock(pipe);
65476
65477 - if (!pipe->readers) {
65478 + if (!atomic_read(&pipe->readers)) {
65479 send_sig(SIGPIPE, current, 0);
65480 ret = -EPIPE;
65481 goto out;
65482 @@ -387,7 +387,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65483 for (;;) {
65484 int bufs;
65485
65486 - if (!pipe->readers) {
65487 + if (!atomic_read(&pipe->readers)) {
65488 send_sig(SIGPIPE, current, 0);
65489 if (!ret)
65490 ret = -EPIPE;
65491 @@ -455,9 +455,9 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65492 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
65493 do_wakeup = 0;
65494 }
65495 - pipe->waiting_writers++;
65496 + atomic_inc(&pipe->waiting_writers);
65497 pipe_wait(pipe);
65498 - pipe->waiting_writers--;
65499 + atomic_dec(&pipe->waiting_writers);
65500 }
65501 out:
65502 __pipe_unlock(pipe);
65503 @@ -512,7 +512,7 @@ pipe_poll(struct file *filp, poll_table *wait)
65504 mask = 0;
65505 if (filp->f_mode & FMODE_READ) {
65506 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
65507 - if (!pipe->writers && filp->f_version != pipe->w_counter)
65508 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
65509 mask |= POLLHUP;
65510 }
65511
65512 @@ -522,7 +522,7 @@ pipe_poll(struct file *filp, poll_table *wait)
65513 * Most Unices do not set POLLERR for FIFOs but on Linux they
65514 * behave exactly like pipes for poll().
65515 */
65516 - if (!pipe->readers)
65517 + if (!atomic_read(&pipe->readers))
65518 mask |= POLLERR;
65519 }
65520
65521 @@ -534,7 +534,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
65522 int kill = 0;
65523
65524 spin_lock(&inode->i_lock);
65525 - if (!--pipe->files) {
65526 + if (atomic_dec_and_test(&pipe->files)) {
65527 inode->i_pipe = NULL;
65528 kill = 1;
65529 }
65530 @@ -551,11 +551,11 @@ pipe_release(struct inode *inode, struct file *file)
65531
65532 __pipe_lock(pipe);
65533 if (file->f_mode & FMODE_READ)
65534 - pipe->readers--;
65535 + atomic_dec(&pipe->readers);
65536 if (file->f_mode & FMODE_WRITE)
65537 - pipe->writers--;
65538 + atomic_dec(&pipe->writers);
65539
65540 - if (pipe->readers || pipe->writers) {
65541 + if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
65542 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
65543 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
65544 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
65545 @@ -620,7 +620,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
65546 kfree(pipe);
65547 }
65548
65549 -static struct vfsmount *pipe_mnt __read_mostly;
65550 +struct vfsmount *pipe_mnt __read_mostly;
65551
65552 /*
65553 * pipefs_dname() is called from d_path().
65554 @@ -650,8 +650,9 @@ static struct inode * get_pipe_inode(void)
65555 goto fail_iput;
65556
65557 inode->i_pipe = pipe;
65558 - pipe->files = 2;
65559 - pipe->readers = pipe->writers = 1;
65560 + atomic_set(&pipe->files, 2);
65561 + atomic_set(&pipe->readers, 1);
65562 + atomic_set(&pipe->writers, 1);
65563 inode->i_fop = &pipefifo_fops;
65564
65565 /*
65566 @@ -830,17 +831,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
65567 spin_lock(&inode->i_lock);
65568 if (inode->i_pipe) {
65569 pipe = inode->i_pipe;
65570 - pipe->files++;
65571 + atomic_inc(&pipe->files);
65572 spin_unlock(&inode->i_lock);
65573 } else {
65574 spin_unlock(&inode->i_lock);
65575 pipe = alloc_pipe_info();
65576 if (!pipe)
65577 return -ENOMEM;
65578 - pipe->files = 1;
65579 + atomic_set(&pipe->files, 1);
65580 spin_lock(&inode->i_lock);
65581 if (unlikely(inode->i_pipe)) {
65582 - inode->i_pipe->files++;
65583 + atomic_inc(&inode->i_pipe->files);
65584 spin_unlock(&inode->i_lock);
65585 free_pipe_info(pipe);
65586 pipe = inode->i_pipe;
65587 @@ -865,10 +866,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
65588 * opened, even when there is no process writing the FIFO.
65589 */
65590 pipe->r_counter++;
65591 - if (pipe->readers++ == 0)
65592 + if (atomic_inc_return(&pipe->readers) == 1)
65593 wake_up_partner(pipe);
65594
65595 - if (!is_pipe && !pipe->writers) {
65596 + if (!is_pipe && !atomic_read(&pipe->writers)) {
65597 if ((filp->f_flags & O_NONBLOCK)) {
65598 /* suppress POLLHUP until we have
65599 * seen a writer */
65600 @@ -887,14 +888,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
65601 * errno=ENXIO when there is no process reading the FIFO.
65602 */
65603 ret = -ENXIO;
65604 - if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
65605 + if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
65606 goto err;
65607
65608 pipe->w_counter++;
65609 - if (!pipe->writers++)
65610 + if (atomic_inc_return(&pipe->writers) == 1)
65611 wake_up_partner(pipe);
65612
65613 - if (!is_pipe && !pipe->readers) {
65614 + if (!is_pipe && !atomic_read(&pipe->readers)) {
65615 if (wait_for_partner(pipe, &pipe->r_counter))
65616 goto err_wr;
65617 }
65618 @@ -908,11 +909,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
65619 * the process can at least talk to itself.
65620 */
65621
65622 - pipe->readers++;
65623 - pipe->writers++;
65624 + atomic_inc(&pipe->readers);
65625 + atomic_inc(&pipe->writers);
65626 pipe->r_counter++;
65627 pipe->w_counter++;
65628 - if (pipe->readers == 1 || pipe->writers == 1)
65629 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
65630 wake_up_partner(pipe);
65631 break;
65632
65633 @@ -926,13 +927,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
65634 return 0;
65635
65636 err_rd:
65637 - if (!--pipe->readers)
65638 + if (atomic_dec_and_test(&pipe->readers))
65639 wake_up_interruptible(&pipe->wait);
65640 ret = -ERESTARTSYS;
65641 goto err;
65642
65643 err_wr:
65644 - if (!--pipe->writers)
65645 + if (atomic_dec_and_test(&pipe->writers))
65646 wake_up_interruptible(&pipe->wait);
65647 ret = -ERESTARTSYS;
65648 goto err;
65649 diff --git a/fs/posix_acl.c b/fs/posix_acl.c
65650 index 0855f77..6787d50 100644
65651 --- a/fs/posix_acl.c
65652 +++ b/fs/posix_acl.c
65653 @@ -20,6 +20,7 @@
65654 #include <linux/xattr.h>
65655 #include <linux/export.h>
65656 #include <linux/user_namespace.h>
65657 +#include <linux/grsecurity.h>
65658
65659 struct posix_acl **acl_by_type(struct inode *inode, int type)
65660 {
65661 @@ -277,7 +278,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
65662 }
65663 }
65664 if (mode_p)
65665 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
65666 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
65667 return not_equiv;
65668 }
65669 EXPORT_SYMBOL(posix_acl_equiv_mode);
65670 @@ -427,7 +428,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
65671 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
65672 }
65673
65674 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
65675 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
65676 return not_equiv;
65677 }
65678
65679 @@ -485,6 +486,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
65680 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
65681 int err = -ENOMEM;
65682 if (clone) {
65683 + *mode_p &= ~gr_acl_umask();
65684 +
65685 err = posix_acl_create_masq(clone, mode_p);
65686 if (err < 0) {
65687 posix_acl_release(clone);
65688 @@ -659,11 +662,12 @@ struct posix_acl *
65689 posix_acl_from_xattr(struct user_namespace *user_ns,
65690 const void *value, size_t size)
65691 {
65692 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
65693 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
65694 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
65695 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
65696 int count;
65697 struct posix_acl *acl;
65698 struct posix_acl_entry *acl_e;
65699 + umode_t umask = gr_acl_umask();
65700
65701 if (!value)
65702 return NULL;
65703 @@ -689,12 +693,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
65704
65705 switch(acl_e->e_tag) {
65706 case ACL_USER_OBJ:
65707 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
65708 + break;
65709 case ACL_GROUP_OBJ:
65710 case ACL_MASK:
65711 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
65712 + break;
65713 case ACL_OTHER:
65714 + acl_e->e_perm &= ~(umask & S_IRWXO);
65715 break;
65716
65717 case ACL_USER:
65718 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
65719 acl_e->e_uid =
65720 make_kuid(user_ns,
65721 le32_to_cpu(entry->e_id));
65722 @@ -702,6 +712,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
65723 goto fail;
65724 break;
65725 case ACL_GROUP:
65726 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
65727 acl_e->e_gid =
65728 make_kgid(user_ns,
65729 le32_to_cpu(entry->e_id));
65730 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
65731 index 2183fcf..3c32a98 100644
65732 --- a/fs/proc/Kconfig
65733 +++ b/fs/proc/Kconfig
65734 @@ -30,7 +30,7 @@ config PROC_FS
65735
65736 config PROC_KCORE
65737 bool "/proc/kcore support" if !ARM
65738 - depends on PROC_FS && MMU
65739 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
65740 help
65741 Provides a virtual ELF core file of the live kernel. This can
65742 be read with gdb and other ELF tools. No modifications can be
65743 @@ -38,8 +38,8 @@ config PROC_KCORE
65744
65745 config PROC_VMCORE
65746 bool "/proc/vmcore support"
65747 - depends on PROC_FS && CRASH_DUMP
65748 - default y
65749 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
65750 + default n
65751 help
65752 Exports the dump image of crashed kernel in ELF format.
65753
65754 @@ -63,8 +63,8 @@ config PROC_SYSCTL
65755 limited in memory.
65756
65757 config PROC_PAGE_MONITOR
65758 - default y
65759 - depends on PROC_FS && MMU
65760 + default n
65761 + depends on PROC_FS && MMU && !GRKERNSEC
65762 bool "Enable /proc page monitoring" if EXPERT
65763 help
65764 Various /proc files exist to monitor process memory utilization:
65765 diff --git a/fs/proc/array.c b/fs/proc/array.c
65766 index cd3653e..9b9b79a 100644
65767 --- a/fs/proc/array.c
65768 +++ b/fs/proc/array.c
65769 @@ -60,6 +60,7 @@
65770 #include <linux/tty.h>
65771 #include <linux/string.h>
65772 #include <linux/mman.h>
65773 +#include <linux/grsecurity.h>
65774 #include <linux/proc_fs.h>
65775 #include <linux/ioport.h>
65776 #include <linux/uaccess.h>
65777 @@ -347,6 +348,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
65778 seq_putc(m, '\n');
65779 }
65780
65781 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
65782 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
65783 +{
65784 + if (p->mm)
65785 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
65786 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
65787 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
65788 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
65789 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
65790 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
65791 + else
65792 + seq_printf(m, "PaX:\t-----\n");
65793 +}
65794 +#endif
65795 +
65796 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
65797 struct pid *pid, struct task_struct *task)
65798 {
65799 @@ -365,9 +381,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
65800 task_cpus_allowed(m, task);
65801 cpuset_task_status_allowed(m, task);
65802 task_context_switch_counts(m, task);
65803 +
65804 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
65805 + task_pax(m, task);
65806 +#endif
65807 +
65808 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
65809 + task_grsec_rbac(m, task);
65810 +#endif
65811 +
65812 return 0;
65813 }
65814
65815 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65816 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
65817 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
65818 + _mm->pax_flags & MF_PAX_SEGMEXEC))
65819 +#endif
65820 +
65821 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65822 struct pid *pid, struct task_struct *task, int whole)
65823 {
65824 @@ -389,6 +420,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65825 char tcomm[sizeof(task->comm)];
65826 unsigned long flags;
65827
65828 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65829 + if (current->exec_id != m->exec_id) {
65830 + gr_log_badprocpid("stat");
65831 + return 0;
65832 + }
65833 +#endif
65834 +
65835 state = *get_task_state(task);
65836 vsize = eip = esp = 0;
65837 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
65838 @@ -459,6 +497,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65839 gtime = task_gtime(task);
65840 }
65841
65842 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65843 + if (PAX_RAND_FLAGS(mm)) {
65844 + eip = 0;
65845 + esp = 0;
65846 + wchan = 0;
65847 + }
65848 +#endif
65849 +#ifdef CONFIG_GRKERNSEC_HIDESYM
65850 + wchan = 0;
65851 + eip =0;
65852 + esp =0;
65853 +#endif
65854 +
65855 /* scale priority and nice values from timeslices to -20..20 */
65856 /* to make it look like a "normal" Unix priority/nice value */
65857 priority = task_prio(task);
65858 @@ -490,9 +541,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65859 seq_put_decimal_ull(m, ' ', vsize);
65860 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
65861 seq_put_decimal_ull(m, ' ', rsslim);
65862 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65863 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
65864 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
65865 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
65866 +#else
65867 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
65868 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
65869 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
65870 +#endif
65871 seq_put_decimal_ull(m, ' ', esp);
65872 seq_put_decimal_ull(m, ' ', eip);
65873 /* The signal information here is obsolete.
65874 @@ -514,7 +571,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65875 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
65876 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
65877
65878 - if (mm && permitted) {
65879 + if (mm && permitted
65880 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65881 + && !PAX_RAND_FLAGS(mm)
65882 +#endif
65883 + ) {
65884 seq_put_decimal_ull(m, ' ', mm->start_data);
65885 seq_put_decimal_ull(m, ' ', mm->end_data);
65886 seq_put_decimal_ull(m, ' ', mm->start_brk);
65887 @@ -552,8 +613,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
65888 struct pid *pid, struct task_struct *task)
65889 {
65890 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
65891 - struct mm_struct *mm = get_task_mm(task);
65892 + struct mm_struct *mm;
65893
65894 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65895 + if (current->exec_id != m->exec_id) {
65896 + gr_log_badprocpid("statm");
65897 + return 0;
65898 + }
65899 +#endif
65900 + mm = get_task_mm(task);
65901 if (mm) {
65902 size = task_statm(mm, &shared, &text, &data, &resident);
65903 mmput(mm);
65904 @@ -576,6 +644,20 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
65905 return 0;
65906 }
65907
65908 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
65909 +int proc_pid_ipaddr(struct seq_file *m, struct pid_namespace *ns, struct pid *pid, struct task_struct *task)
65910 +{
65911 + unsigned long flags;
65912 + u32 curr_ip = 0;
65913 +
65914 + if (lock_task_sighand(task, &flags)) {
65915 + curr_ip = task->signal->curr_ip;
65916 + unlock_task_sighand(task, &flags);
65917 + }
65918 + return seq_printf(m, "%pI4\n", &curr_ip);
65919 +}
65920 +#endif
65921 +
65922 #ifdef CONFIG_CHECKPOINT_RESTORE
65923 static struct pid *
65924 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
65925 diff --git a/fs/proc/base.c b/fs/proc/base.c
65926 index baf852b..03fe930 100644
65927 --- a/fs/proc/base.c
65928 +++ b/fs/proc/base.c
65929 @@ -113,6 +113,14 @@ struct pid_entry {
65930 union proc_op op;
65931 };
65932
65933 +struct getdents_callback {
65934 + struct linux_dirent __user * current_dir;
65935 + struct linux_dirent __user * previous;
65936 + struct file * file;
65937 + int count;
65938 + int error;
65939 +};
65940 +
65941 #define NOD(NAME, MODE, IOP, FOP, OP) { \
65942 .name = (NAME), \
65943 .len = sizeof(NAME) - 1, \
65944 @@ -208,12 +216,28 @@ static int proc_pid_cmdline(struct seq_file *m, struct pid_namespace *ns,
65945 return 0;
65946 }
65947
65948 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65949 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
65950 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
65951 + _mm->pax_flags & MF_PAX_SEGMEXEC))
65952 +#endif
65953 +
65954 static int proc_pid_auxv(struct seq_file *m, struct pid_namespace *ns,
65955 struct pid *pid, struct task_struct *task)
65956 {
65957 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
65958 if (mm && !IS_ERR(mm)) {
65959 unsigned int nwords = 0;
65960 +
65961 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65962 + /* allow if we're currently ptracing this task */
65963 + if (PAX_RAND_FLAGS(mm) &&
65964 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
65965 + mmput(mm);
65966 + return 0;
65967 + }
65968 +#endif
65969 +
65970 do {
65971 nwords += 2;
65972 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
65973 @@ -225,7 +249,7 @@ static int proc_pid_auxv(struct seq_file *m, struct pid_namespace *ns,
65974 }
65975
65976
65977 -#ifdef CONFIG_KALLSYMS
65978 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65979 /*
65980 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
65981 * Returns the resolved symbol. If that fails, simply return the address.
65982 @@ -265,7 +289,7 @@ static void unlock_trace(struct task_struct *task)
65983 mutex_unlock(&task->signal->cred_guard_mutex);
65984 }
65985
65986 -#ifdef CONFIG_STACKTRACE
65987 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65988
65989 #define MAX_STACK_TRACE_DEPTH 64
65990
65991 @@ -487,7 +511,7 @@ static int proc_pid_limits(struct seq_file *m, struct pid_namespace *ns,
65992 return 0;
65993 }
65994
65995 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
65996 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
65997 static int proc_pid_syscall(struct seq_file *m, struct pid_namespace *ns,
65998 struct pid *pid, struct task_struct *task)
65999 {
66000 @@ -517,7 +541,7 @@ static int proc_pid_syscall(struct seq_file *m, struct pid_namespace *ns,
66001 /************************************************************************/
66002
66003 /* permission checks */
66004 -static int proc_fd_access_allowed(struct inode *inode)
66005 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
66006 {
66007 struct task_struct *task;
66008 int allowed = 0;
66009 @@ -527,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
66010 */
66011 task = get_proc_task(inode);
66012 if (task) {
66013 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
66014 + if (log)
66015 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
66016 + else
66017 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
66018 put_task_struct(task);
66019 }
66020 return allowed;
66021 @@ -558,10 +585,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
66022 struct task_struct *task,
66023 int hide_pid_min)
66024 {
66025 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66026 + return false;
66027 +
66028 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66029 + rcu_read_lock();
66030 + {
66031 + const struct cred *tmpcred = current_cred();
66032 + const struct cred *cred = __task_cred(task);
66033 +
66034 + if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
66035 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66036 + || in_group_p(grsec_proc_gid)
66037 +#endif
66038 + ) {
66039 + rcu_read_unlock();
66040 + return true;
66041 + }
66042 + }
66043 + rcu_read_unlock();
66044 +
66045 + if (!pid->hide_pid)
66046 + return false;
66047 +#endif
66048 +
66049 if (pid->hide_pid < hide_pid_min)
66050 return true;
66051 if (in_group_p(pid->pid_gid))
66052 return true;
66053 +
66054 return ptrace_may_access(task, PTRACE_MODE_READ);
66055 }
66056
66057 @@ -579,7 +631,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
66058 put_task_struct(task);
66059
66060 if (!has_perms) {
66061 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66062 + {
66063 +#else
66064 if (pid->hide_pid == 2) {
66065 +#endif
66066 /*
66067 * Let's make getdents(), stat(), and open()
66068 * consistent with each other. If a process
66069 @@ -640,6 +696,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
66070 if (!task)
66071 return -ESRCH;
66072
66073 + if (gr_acl_handle_procpidmem(task)) {
66074 + put_task_struct(task);
66075 + return -EPERM;
66076 + }
66077 +
66078 mm = mm_access(task, mode);
66079 put_task_struct(task);
66080
66081 @@ -655,6 +716,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
66082
66083 file->private_data = mm;
66084
66085 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66086 + file->f_version = current->exec_id;
66087 +#endif
66088 +
66089 return 0;
66090 }
66091
66092 @@ -676,6 +741,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
66093 ssize_t copied;
66094 char *page;
66095
66096 +#ifdef CONFIG_GRKERNSEC
66097 + if (write)
66098 + return -EPERM;
66099 +#endif
66100 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66101 + if (file->f_version != current->exec_id) {
66102 + gr_log_badprocpid("mem");
66103 + return 0;
66104 + }
66105 +#endif
66106 +
66107 if (!mm)
66108 return 0;
66109
66110 @@ -688,7 +764,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
66111 goto free;
66112
66113 while (count > 0) {
66114 - int this_len = min_t(int, count, PAGE_SIZE);
66115 + ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
66116
66117 if (write && copy_from_user(page, buf, this_len)) {
66118 copied = -EFAULT;
66119 @@ -780,6 +856,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
66120 if (!mm)
66121 return 0;
66122
66123 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66124 + if (file->f_version != current->exec_id) {
66125 + gr_log_badprocpid("environ");
66126 + return 0;
66127 + }
66128 +#endif
66129 +
66130 page = (char *)__get_free_page(GFP_TEMPORARY);
66131 if (!page)
66132 return -ENOMEM;
66133 @@ -789,7 +872,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
66134 goto free;
66135 while (count > 0) {
66136 size_t this_len, max_len;
66137 - int retval;
66138 + ssize_t retval;
66139
66140 if (src >= (mm->env_end - mm->env_start))
66141 break;
66142 @@ -1403,7 +1486,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
66143 int error = -EACCES;
66144
66145 /* Are we allowed to snoop on the tasks file descriptors? */
66146 - if (!proc_fd_access_allowed(inode))
66147 + if (!proc_fd_access_allowed(inode, 0))
66148 goto out;
66149
66150 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
66151 @@ -1447,8 +1530,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
66152 struct path path;
66153
66154 /* Are we allowed to snoop on the tasks file descriptors? */
66155 - if (!proc_fd_access_allowed(inode))
66156 - goto out;
66157 + /* logging this is needed for learning on chromium to work properly,
66158 + but we don't want to flood the logs from 'ps' which does a readlink
66159 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
66160 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
66161 + */
66162 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
66163 + if (!proc_fd_access_allowed(inode,0))
66164 + goto out;
66165 + } else {
66166 + if (!proc_fd_access_allowed(inode,1))
66167 + goto out;
66168 + }
66169
66170 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
66171 if (error)
66172 @@ -1498,7 +1591,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
66173 rcu_read_lock();
66174 cred = __task_cred(task);
66175 inode->i_uid = cred->euid;
66176 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66177 + inode->i_gid = grsec_proc_gid;
66178 +#else
66179 inode->i_gid = cred->egid;
66180 +#endif
66181 rcu_read_unlock();
66182 }
66183 security_task_to_inode(task, inode);
66184 @@ -1534,10 +1631,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
66185 return -ENOENT;
66186 }
66187 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
66188 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66189 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
66190 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66191 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
66192 +#endif
66193 task_dumpable(task)) {
66194 cred = __task_cred(task);
66195 stat->uid = cred->euid;
66196 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66197 + stat->gid = grsec_proc_gid;
66198 +#else
66199 stat->gid = cred->egid;
66200 +#endif
66201 }
66202 }
66203 rcu_read_unlock();
66204 @@ -1575,11 +1681,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
66205
66206 if (task) {
66207 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
66208 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66209 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
66210 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66211 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
66212 +#endif
66213 task_dumpable(task)) {
66214 rcu_read_lock();
66215 cred = __task_cred(task);
66216 inode->i_uid = cred->euid;
66217 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66218 + inode->i_gid = grsec_proc_gid;
66219 +#else
66220 inode->i_gid = cred->egid;
66221 +#endif
66222 rcu_read_unlock();
66223 } else {
66224 inode->i_uid = GLOBAL_ROOT_UID;
66225 @@ -2114,6 +2229,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
66226 if (!task)
66227 goto out_no_task;
66228
66229 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66230 + goto out;
66231 +
66232 /*
66233 * Yes, it does not scale. And it should not. Don't add
66234 * new entries into /proc/<tgid>/ without very good reasons.
66235 @@ -2144,6 +2262,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
66236 if (!task)
66237 return -ENOENT;
66238
66239 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66240 + goto out;
66241 +
66242 if (!dir_emit_dots(file, ctx))
66243 goto out;
66244
66245 @@ -2535,7 +2656,7 @@ static const struct pid_entry tgid_base_stuff[] = {
66246 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
66247 #endif
66248 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
66249 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
66250 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
66251 ONE("syscall", S_IRUSR, proc_pid_syscall),
66252 #endif
66253 ONE("cmdline", S_IRUGO, proc_pid_cmdline),
66254 @@ -2560,10 +2681,10 @@ static const struct pid_entry tgid_base_stuff[] = {
66255 #ifdef CONFIG_SECURITY
66256 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
66257 #endif
66258 -#ifdef CONFIG_KALLSYMS
66259 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66260 ONE("wchan", S_IRUGO, proc_pid_wchan),
66261 #endif
66262 -#ifdef CONFIG_STACKTRACE
66263 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66264 ONE("stack", S_IRUSR, proc_pid_stack),
66265 #endif
66266 #ifdef CONFIG_SCHEDSTATS
66267 @@ -2597,6 +2718,9 @@ static const struct pid_entry tgid_base_stuff[] = {
66268 #ifdef CONFIG_HARDWALL
66269 ONE("hardwall", S_IRUGO, proc_pid_hardwall),
66270 #endif
66271 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
66272 + ONE("ipaddr", S_IRUSR, proc_pid_ipaddr),
66273 +#endif
66274 #ifdef CONFIG_USER_NS
66275 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
66276 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
66277 @@ -2727,7 +2851,14 @@ static int proc_pid_instantiate(struct inode *dir,
66278 if (!inode)
66279 goto out;
66280
66281 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66282 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
66283 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66284 + inode->i_gid = grsec_proc_gid;
66285 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
66286 +#else
66287 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
66288 +#endif
66289 inode->i_op = &proc_tgid_base_inode_operations;
66290 inode->i_fop = &proc_tgid_base_operations;
66291 inode->i_flags|=S_IMMUTABLE;
66292 @@ -2765,7 +2896,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
66293 if (!task)
66294 goto out;
66295
66296 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66297 + goto out_put_task;
66298 +
66299 result = proc_pid_instantiate(dir, dentry, task, NULL);
66300 +out_put_task:
66301 put_task_struct(task);
66302 out:
66303 return ERR_PTR(result);
66304 @@ -2879,7 +3014,7 @@ static const struct pid_entry tid_base_stuff[] = {
66305 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
66306 #endif
66307 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
66308 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
66309 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
66310 ONE("syscall", S_IRUSR, proc_pid_syscall),
66311 #endif
66312 ONE("cmdline", S_IRUGO, proc_pid_cmdline),
66313 @@ -2906,10 +3041,10 @@ static const struct pid_entry tid_base_stuff[] = {
66314 #ifdef CONFIG_SECURITY
66315 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
66316 #endif
66317 -#ifdef CONFIG_KALLSYMS
66318 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66319 ONE("wchan", S_IRUGO, proc_pid_wchan),
66320 #endif
66321 -#ifdef CONFIG_STACKTRACE
66322 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66323 ONE("stack", S_IRUSR, proc_pid_stack),
66324 #endif
66325 #ifdef CONFIG_SCHEDSTATS
66326 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
66327 index cbd82df..c0407d2 100644
66328 --- a/fs/proc/cmdline.c
66329 +++ b/fs/proc/cmdline.c
66330 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
66331
66332 static int __init proc_cmdline_init(void)
66333 {
66334 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66335 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
66336 +#else
66337 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
66338 +#endif
66339 return 0;
66340 }
66341 fs_initcall(proc_cmdline_init);
66342 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
66343 index 50493ed..248166b 100644
66344 --- a/fs/proc/devices.c
66345 +++ b/fs/proc/devices.c
66346 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
66347
66348 static int __init proc_devices_init(void)
66349 {
66350 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66351 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
66352 +#else
66353 proc_create("devices", 0, NULL, &proc_devinfo_operations);
66354 +#endif
66355 return 0;
66356 }
66357 fs_initcall(proc_devices_init);
66358 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
66359 index 955bb55..71948bd 100644
66360 --- a/fs/proc/fd.c
66361 +++ b/fs/proc/fd.c
66362 @@ -26,7 +26,8 @@ static int seq_show(struct seq_file *m, void *v)
66363 if (!task)
66364 return -ENOENT;
66365
66366 - files = get_files_struct(task);
66367 + if (!gr_acl_handle_procpidmem(task))
66368 + files = get_files_struct(task);
66369 put_task_struct(task);
66370
66371 if (files) {
66372 @@ -285,11 +286,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
66373 */
66374 int proc_fd_permission(struct inode *inode, int mask)
66375 {
66376 + struct task_struct *task;
66377 int rv = generic_permission(inode, mask);
66378 - if (rv == 0)
66379 - return 0;
66380 +
66381 if (task_tgid(current) == proc_pid(inode))
66382 rv = 0;
66383 +
66384 + task = get_proc_task(inode);
66385 + if (task == NULL)
66386 + return rv;
66387 +
66388 + if (gr_acl_handle_procpidmem(task))
66389 + rv = -EACCES;
66390 +
66391 + put_task_struct(task);
66392 +
66393 return rv;
66394 }
66395
66396 diff --git a/fs/proc/generic.c b/fs/proc/generic.c
66397 index 317b726..e329aed 100644
66398 --- a/fs/proc/generic.c
66399 +++ b/fs/proc/generic.c
66400 @@ -23,6 +23,7 @@
66401 #include <linux/bitops.h>
66402 #include <linux/spinlock.h>
66403 #include <linux/completion.h>
66404 +#include <linux/grsecurity.h>
66405 #include <asm/uaccess.h>
66406
66407 #include "internal.h"
66408 @@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
66409 return proc_lookup_de(PDE(dir), dir, dentry);
66410 }
66411
66412 +struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
66413 + unsigned int flags)
66414 +{
66415 + if (gr_proc_is_restricted())
66416 + return ERR_PTR(-EACCES);
66417 +
66418 + return proc_lookup_de(PDE(dir), dir, dentry);
66419 +}
66420 +
66421 /*
66422 * This returns non-zero if at EOF, so that the /proc
66423 * root directory can use this and check if it should
66424 @@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
66425 return proc_readdir_de(PDE(inode), file, ctx);
66426 }
66427
66428 +int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
66429 +{
66430 + struct inode *inode = file_inode(file);
66431 +
66432 + if (gr_proc_is_restricted())
66433 + return -EACCES;
66434 +
66435 + return proc_readdir_de(PDE(inode), file, ctx);
66436 +}
66437 +
66438 /*
66439 * These are the generic /proc directory operations. They
66440 * use the in-memory "struct proc_dir_entry" tree to parse
66441 @@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
66442 .iterate = proc_readdir,
66443 };
66444
66445 +static const struct file_operations proc_dir_restricted_operations = {
66446 + .llseek = generic_file_llseek,
66447 + .read = generic_read_dir,
66448 + .iterate = proc_readdir_restrict,
66449 +};
66450 +
66451 /*
66452 * proc directories can do almost nothing..
66453 */
66454 @@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
66455 .setattr = proc_notify_change,
66456 };
66457
66458 +static const struct inode_operations proc_dir_restricted_inode_operations = {
66459 + .lookup = proc_lookup_restrict,
66460 + .getattr = proc_getattr,
66461 + .setattr = proc_notify_change,
66462 +};
66463 +
66464 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
66465 {
66466 struct proc_dir_entry *tmp;
66467 @@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
66468 return ret;
66469
66470 if (S_ISDIR(dp->mode)) {
66471 - dp->proc_fops = &proc_dir_operations;
66472 - dp->proc_iops = &proc_dir_inode_operations;
66473 + if (dp->restricted) {
66474 + dp->proc_fops = &proc_dir_restricted_operations;
66475 + dp->proc_iops = &proc_dir_restricted_inode_operations;
66476 + } else {
66477 + dp->proc_fops = &proc_dir_operations;
66478 + dp->proc_iops = &proc_dir_inode_operations;
66479 + }
66480 dir->nlink++;
66481 } else if (S_ISLNK(dp->mode)) {
66482 dp->proc_iops = &proc_link_inode_operations;
66483 @@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
66484 }
66485 EXPORT_SYMBOL_GPL(proc_mkdir_data);
66486
66487 +struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
66488 + struct proc_dir_entry *parent, void *data)
66489 +{
66490 + struct proc_dir_entry *ent;
66491 +
66492 + if (mode == 0)
66493 + mode = S_IRUGO | S_IXUGO;
66494 +
66495 + ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
66496 + if (ent) {
66497 + ent->data = data;
66498 + ent->restricted = 1;
66499 + if (proc_register(parent, ent) < 0) {
66500 + kfree(ent);
66501 + ent = NULL;
66502 + }
66503 + }
66504 + return ent;
66505 +}
66506 +EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
66507 +
66508 struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
66509 struct proc_dir_entry *parent)
66510 {
66511 @@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
66512 }
66513 EXPORT_SYMBOL(proc_mkdir);
66514
66515 +struct proc_dir_entry *proc_mkdir_restrict(const char *name,
66516 + struct proc_dir_entry *parent)
66517 +{
66518 + return proc_mkdir_data_restrict(name, 0, parent, NULL);
66519 +}
66520 +EXPORT_SYMBOL(proc_mkdir_restrict);
66521 +
66522 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
66523 struct proc_dir_entry *parent,
66524 const struct file_operations *proc_fops,
66525 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
66526 index 333080d..0a35ec4 100644
66527 --- a/fs/proc/inode.c
66528 +++ b/fs/proc/inode.c
66529 @@ -23,11 +23,17 @@
66530 #include <linux/slab.h>
66531 #include <linux/mount.h>
66532 #include <linux/magic.h>
66533 +#include <linux/grsecurity.h>
66534
66535 #include <asm/uaccess.h>
66536
66537 #include "internal.h"
66538
66539 +#ifdef CONFIG_PROC_SYSCTL
66540 +extern const struct inode_operations proc_sys_inode_operations;
66541 +extern const struct inode_operations proc_sys_dir_operations;
66542 +#endif
66543 +
66544 static void proc_evict_inode(struct inode *inode)
66545 {
66546 struct proc_dir_entry *de;
66547 @@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
66548 ns = PROC_I(inode)->ns.ns;
66549 if (ns_ops && ns)
66550 ns_ops->put(ns);
66551 +
66552 +#ifdef CONFIG_PROC_SYSCTL
66553 + if (inode->i_op == &proc_sys_inode_operations ||
66554 + inode->i_op == &proc_sys_dir_operations)
66555 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
66556 +#endif
66557 +
66558 }
66559
66560 static struct kmem_cache * proc_inode_cachep;
66561 @@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
66562 if (de->mode) {
66563 inode->i_mode = de->mode;
66564 inode->i_uid = de->uid;
66565 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66566 + inode->i_gid = grsec_proc_gid;
66567 +#else
66568 inode->i_gid = de->gid;
66569 +#endif
66570 }
66571 if (de->size)
66572 inode->i_size = de->size;
66573 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
66574 index 7da13e4..68d0981 100644
66575 --- a/fs/proc/internal.h
66576 +++ b/fs/proc/internal.h
66577 @@ -46,9 +46,10 @@ struct proc_dir_entry {
66578 struct completion *pde_unload_completion;
66579 struct list_head pde_openers; /* who did ->open, but not ->release */
66580 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
66581 + u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
66582 u8 namelen;
66583 char name[];
66584 -};
66585 +} __randomize_layout;
66586
66587 union proc_op {
66588 int (*proc_get_link)(struct dentry *, struct path *);
66589 @@ -66,7 +67,7 @@ struct proc_inode {
66590 struct ctl_table *sysctl_entry;
66591 struct proc_ns ns;
66592 struct inode vfs_inode;
66593 -};
66594 +} __randomize_layout;
66595
66596 /*
66597 * General functions
66598 @@ -154,6 +155,10 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
66599 struct pid *, struct task_struct *);
66600 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
66601 struct pid *, struct task_struct *);
66602 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
66603 +extern int proc_pid_ipaddr(struct seq_file *, struct pid_namespace *,
66604 + struct pid *, struct task_struct *);
66605 +#endif
66606
66607 /*
66608 * base.c
66609 @@ -178,9 +183,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
66610 * generic.c
66611 */
66612 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
66613 +extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
66614 extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
66615 struct dentry *);
66616 extern int proc_readdir(struct file *, struct dir_context *);
66617 +extern int proc_readdir_restrict(struct file *, struct dir_context *);
66618 extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
66619
66620 static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
66621 diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
66622 index a352d57..cb94a5c 100644
66623 --- a/fs/proc/interrupts.c
66624 +++ b/fs/proc/interrupts.c
66625 @@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
66626
66627 static int __init proc_interrupts_init(void)
66628 {
66629 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66630 + proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
66631 +#else
66632 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
66633 +#endif
66634 return 0;
66635 }
66636 fs_initcall(proc_interrupts_init);
66637 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
66638 index 6df8d07..3321060 100644
66639 --- a/fs/proc/kcore.c
66640 +++ b/fs/proc/kcore.c
66641 @@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66642 * the addresses in the elf_phdr on our list.
66643 */
66644 start = kc_offset_to_vaddr(*fpos - elf_buflen);
66645 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
66646 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
66647 + if (tsz > buflen)
66648 tsz = buflen;
66649 -
66650 +
66651 while (buflen) {
66652 struct kcore_list *m;
66653
66654 @@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66655 kfree(elf_buf);
66656 } else {
66657 if (kern_addr_valid(start)) {
66658 - unsigned long n;
66659 + char *elf_buf;
66660 + mm_segment_t oldfs;
66661
66662 - n = copy_to_user(buffer, (char *)start, tsz);
66663 - /*
66664 - * We cannot distinguish between fault on source
66665 - * and fault on destination. When this happens
66666 - * we clear too and hope it will trigger the
66667 - * EFAULT again.
66668 - */
66669 - if (n) {
66670 - if (clear_user(buffer + tsz - n,
66671 - n))
66672 + elf_buf = kmalloc(tsz, GFP_KERNEL);
66673 + if (!elf_buf)
66674 + return -ENOMEM;
66675 + oldfs = get_fs();
66676 + set_fs(KERNEL_DS);
66677 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
66678 + set_fs(oldfs);
66679 + if (copy_to_user(buffer, elf_buf, tsz)) {
66680 + kfree(elf_buf);
66681 return -EFAULT;
66682 + }
66683 }
66684 + set_fs(oldfs);
66685 + kfree(elf_buf);
66686 } else {
66687 if (clear_user(buffer, tsz))
66688 return -EFAULT;
66689 @@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66690
66691 static int open_kcore(struct inode *inode, struct file *filp)
66692 {
66693 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66694 + return -EPERM;
66695 +#endif
66696 if (!capable(CAP_SYS_RAWIO))
66697 return -EPERM;
66698 if (kcore_need_update)
66699 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
66700 index aa1eee0..03dda72 100644
66701 --- a/fs/proc/meminfo.c
66702 +++ b/fs/proc/meminfo.c
66703 @@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
66704 vmi.used >> 10,
66705 vmi.largest_chunk >> 10
66706 #ifdef CONFIG_MEMORY_FAILURE
66707 - ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
66708 + ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
66709 #endif
66710 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
66711 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
66712 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
66713 index d4a3574..b421ce9 100644
66714 --- a/fs/proc/nommu.c
66715 +++ b/fs/proc/nommu.c
66716 @@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
66717
66718 if (file) {
66719 seq_pad(m, ' ');
66720 - seq_path(m, &file->f_path, "");
66721 + seq_path(m, &file->f_path, "\n\\");
66722 }
66723
66724 seq_putc(m, '\n');
66725 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
66726 index a63af3e..b4f262a 100644
66727 --- a/fs/proc/proc_net.c
66728 +++ b/fs/proc/proc_net.c
66729 @@ -23,9 +23,27 @@
66730 #include <linux/nsproxy.h>
66731 #include <net/net_namespace.h>
66732 #include <linux/seq_file.h>
66733 +#include <linux/grsecurity.h>
66734
66735 #include "internal.h"
66736
66737 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
66738 +static struct seq_operations *ipv6_seq_ops_addr;
66739 +
66740 +void register_ipv6_seq_ops_addr(struct seq_operations *addr)
66741 +{
66742 + ipv6_seq_ops_addr = addr;
66743 +}
66744 +
66745 +void unregister_ipv6_seq_ops_addr(void)
66746 +{
66747 + ipv6_seq_ops_addr = NULL;
66748 +}
66749 +
66750 +EXPORT_SYMBOL_GPL(register_ipv6_seq_ops_addr);
66751 +EXPORT_SYMBOL_GPL(unregister_ipv6_seq_ops_addr);
66752 +#endif
66753 +
66754 static inline struct net *PDE_NET(struct proc_dir_entry *pde)
66755 {
66756 return pde->parent->data;
66757 @@ -36,6 +54,8 @@ static struct net *get_proc_net(const struct inode *inode)
66758 return maybe_get_net(PDE_NET(PDE(inode)));
66759 }
66760
66761 +extern const struct seq_operations dev_seq_ops;
66762 +
66763 int seq_open_net(struct inode *ino, struct file *f,
66764 const struct seq_operations *ops, int size)
66765 {
66766 @@ -44,6 +64,14 @@ int seq_open_net(struct inode *ino, struct file *f,
66767
66768 BUG_ON(size < sizeof(*p));
66769
66770 + /* only permit access to /proc/net/dev */
66771 + if (
66772 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
66773 + ops != ipv6_seq_ops_addr &&
66774 +#endif
66775 + ops != &dev_seq_ops && gr_proc_is_restricted())
66776 + return -EACCES;
66777 +
66778 net = get_proc_net(ino);
66779 if (net == NULL)
66780 return -ENXIO;
66781 @@ -66,6 +94,9 @@ int single_open_net(struct inode *inode, struct file *file,
66782 int err;
66783 struct net *net;
66784
66785 + if (gr_proc_is_restricted())
66786 + return -EACCES;
66787 +
66788 err = -ENXIO;
66789 net = get_proc_net(inode);
66790 if (net == NULL)
66791 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
66792 index f92d5dd..26398ac 100644
66793 --- a/fs/proc/proc_sysctl.c
66794 +++ b/fs/proc/proc_sysctl.c
66795 @@ -11,13 +11,21 @@
66796 #include <linux/namei.h>
66797 #include <linux/mm.h>
66798 #include <linux/module.h>
66799 +#include <linux/nsproxy.h>
66800 +#ifdef CONFIG_GRKERNSEC
66801 +#include <net/net_namespace.h>
66802 +#endif
66803 #include "internal.h"
66804
66805 +extern int gr_handle_chroot_sysctl(const int op);
66806 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
66807 + const int op);
66808 +
66809 static const struct dentry_operations proc_sys_dentry_operations;
66810 static const struct file_operations proc_sys_file_operations;
66811 -static const struct inode_operations proc_sys_inode_operations;
66812 +const struct inode_operations proc_sys_inode_operations;
66813 static const struct file_operations proc_sys_dir_file_operations;
66814 -static const struct inode_operations proc_sys_dir_operations;
66815 +const struct inode_operations proc_sys_dir_operations;
66816
66817 void proc_sys_poll_notify(struct ctl_table_poll *poll)
66818 {
66819 @@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
66820
66821 err = NULL;
66822 d_set_d_op(dentry, &proc_sys_dentry_operations);
66823 +
66824 + gr_handle_proc_create(dentry, inode);
66825 +
66826 d_add(dentry, inode);
66827
66828 out:
66829 @@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
66830 struct inode *inode = file_inode(filp);
66831 struct ctl_table_header *head = grab_header(inode);
66832 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
66833 + int op = write ? MAY_WRITE : MAY_READ;
66834 ssize_t error;
66835 size_t res;
66836
66837 @@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
66838 * and won't be until we finish.
66839 */
66840 error = -EPERM;
66841 - if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
66842 + if (sysctl_perm(head, table, op))
66843 goto out;
66844
66845 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
66846 @@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
66847 if (!table->proc_handler)
66848 goto out;
66849
66850 +#ifdef CONFIG_GRKERNSEC
66851 + error = -EPERM;
66852 + if (gr_handle_chroot_sysctl(op))
66853 + goto out;
66854 + dget(filp->f_path.dentry);
66855 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
66856 + dput(filp->f_path.dentry);
66857 + goto out;
66858 + }
66859 + dput(filp->f_path.dentry);
66860 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
66861 + goto out;
66862 + if (write) {
66863 + if (current->nsproxy->net_ns != table->extra2) {
66864 + if (!capable(CAP_SYS_ADMIN))
66865 + goto out;
66866 + } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
66867 + goto out;
66868 + }
66869 +#endif
66870 +
66871 /* careful: calling conventions are nasty here */
66872 res = count;
66873 error = table->proc_handler(table, write, buf, &res, ppos);
66874 @@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
66875 return false;
66876 } else {
66877 d_set_d_op(child, &proc_sys_dentry_operations);
66878 +
66879 + gr_handle_proc_create(child, inode);
66880 +
66881 d_add(child, inode);
66882 }
66883 } else {
66884 @@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, struct ctl_table *table,
66885 if ((*pos)++ < ctx->pos)
66886 return true;
66887
66888 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
66889 + return 0;
66890 +
66891 if (unlikely(S_ISLNK(table->mode)))
66892 res = proc_sys_link_fill_cache(file, ctx, head, table);
66893 else
66894 @@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
66895 if (IS_ERR(head))
66896 return PTR_ERR(head);
66897
66898 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
66899 + return -ENOENT;
66900 +
66901 generic_fillattr(inode, stat);
66902 if (table)
66903 stat->mode = (stat->mode & S_IFMT) | table->mode;
66904 @@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
66905 .llseek = generic_file_llseek,
66906 };
66907
66908 -static const struct inode_operations proc_sys_inode_operations = {
66909 +const struct inode_operations proc_sys_inode_operations = {
66910 .permission = proc_sys_permission,
66911 .setattr = proc_sys_setattr,
66912 .getattr = proc_sys_getattr,
66913 };
66914
66915 -static const struct inode_operations proc_sys_dir_operations = {
66916 +const struct inode_operations proc_sys_dir_operations = {
66917 .lookup = proc_sys_lookup,
66918 .permission = proc_sys_permission,
66919 .setattr = proc_sys_setattr,
66920 @@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
66921 static struct ctl_dir *new_dir(struct ctl_table_set *set,
66922 const char *name, int namelen)
66923 {
66924 - struct ctl_table *table;
66925 + ctl_table_no_const *table;
66926 struct ctl_dir *new;
66927 struct ctl_node *node;
66928 char *new_name;
66929 @@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
66930 return NULL;
66931
66932 node = (struct ctl_node *)(new + 1);
66933 - table = (struct ctl_table *)(node + 1);
66934 + table = (ctl_table_no_const *)(node + 1);
66935 new_name = (char *)(table + 2);
66936 memcpy(new_name, name, namelen);
66937 new_name[namelen] = '\0';
66938 @@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
66939 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
66940 struct ctl_table_root *link_root)
66941 {
66942 - struct ctl_table *link_table, *entry, *link;
66943 + ctl_table_no_const *link_table, *link;
66944 + struct ctl_table *entry;
66945 struct ctl_table_header *links;
66946 struct ctl_node *node;
66947 char *link_name;
66948 @@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
66949 return NULL;
66950
66951 node = (struct ctl_node *)(links + 1);
66952 - link_table = (struct ctl_table *)(node + nr_entries);
66953 + link_table = (ctl_table_no_const *)(node + nr_entries);
66954 link_name = (char *)&link_table[nr_entries + 1];
66955
66956 for (link = link_table, entry = table; entry->procname; link++, entry++) {
66957 @@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
66958 struct ctl_table_header ***subheader, struct ctl_table_set *set,
66959 struct ctl_table *table)
66960 {
66961 - struct ctl_table *ctl_table_arg = NULL;
66962 - struct ctl_table *entry, *files;
66963 + ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
66964 + struct ctl_table *entry;
66965 int nr_files = 0;
66966 int nr_dirs = 0;
66967 int err = -ENOMEM;
66968 @@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
66969 nr_files++;
66970 }
66971
66972 - files = table;
66973 /* If there are mixed files and directories we need a new table */
66974 if (nr_dirs && nr_files) {
66975 - struct ctl_table *new;
66976 + ctl_table_no_const *new;
66977 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
66978 GFP_KERNEL);
66979 if (!files)
66980 @@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
66981 /* Register everything except a directory full of subdirectories */
66982 if (nr_files || !nr_dirs) {
66983 struct ctl_table_header *header;
66984 - header = __register_sysctl_table(set, path, files);
66985 + header = __register_sysctl_table(set, path, files ? files : table);
66986 if (!header) {
66987 kfree(ctl_table_arg);
66988 goto out;
66989 diff --git a/fs/proc/root.c b/fs/proc/root.c
66990 index 094e44d..085a877 100644
66991 --- a/fs/proc/root.c
66992 +++ b/fs/proc/root.c
66993 @@ -188,7 +188,15 @@ void __init proc_root_init(void)
66994 proc_mkdir("openprom", NULL);
66995 #endif
66996 proc_tty_init();
66997 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66998 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66999 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
67000 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67001 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
67002 +#endif
67003 +#else
67004 proc_mkdir("bus", NULL);
67005 +#endif
67006 proc_sys_init();
67007 }
67008
67009 diff --git a/fs/proc/stat.c b/fs/proc/stat.c
67010 index bf2d03f..f058f9c 100644
67011 --- a/fs/proc/stat.c
67012 +++ b/fs/proc/stat.c
67013 @@ -11,6 +11,7 @@
67014 #include <linux/irqnr.h>
67015 #include <linux/cputime.h>
67016 #include <linux/tick.h>
67017 +#include <linux/grsecurity.h>
67018
67019 #ifndef arch_irq_stat_cpu
67020 #define arch_irq_stat_cpu(cpu) 0
67021 @@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
67022 u64 sum_softirq = 0;
67023 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
67024 struct timespec boottime;
67025 + int unrestricted = 1;
67026 +
67027 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
67028 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67029 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
67030 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
67031 + && !in_group_p(grsec_proc_gid)
67032 +#endif
67033 + )
67034 + unrestricted = 0;
67035 +#endif
67036 +#endif
67037
67038 user = nice = system = idle = iowait =
67039 irq = softirq = steal = 0;
67040 @@ -99,23 +112,25 @@ static int show_stat(struct seq_file *p, void *v)
67041 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
67042 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
67043 idle += get_idle_time(i);
67044 - iowait += get_iowait_time(i);
67045 - irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67046 - softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67047 - steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67048 - guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67049 - guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67050 - sum += kstat_cpu_irqs_sum(i);
67051 - sum += arch_irq_stat_cpu(i);
67052 + if (unrestricted) {
67053 + iowait += get_iowait_time(i);
67054 + irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67055 + softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67056 + steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67057 + guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67058 + guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67059 + sum += kstat_cpu_irqs_sum(i);
67060 + sum += arch_irq_stat_cpu(i);
67061 + for (j = 0; j < NR_SOFTIRQS; j++) {
67062 + unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
67063
67064 - for (j = 0; j < NR_SOFTIRQS; j++) {
67065 - unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
67066 -
67067 - per_softirq_sums[j] += softirq_stat;
67068 - sum_softirq += softirq_stat;
67069 + per_softirq_sums[j] += softirq_stat;
67070 + sum_softirq += softirq_stat;
67071 + }
67072 }
67073 }
67074 - sum += arch_irq_stat();
67075 + if (unrestricted)
67076 + sum += arch_irq_stat();
67077
67078 seq_puts(p, "cpu ");
67079 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
67080 @@ -136,12 +151,14 @@ static int show_stat(struct seq_file *p, void *v)
67081 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
67082 system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
67083 idle = get_idle_time(i);
67084 - iowait = get_iowait_time(i);
67085 - irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67086 - softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67087 - steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67088 - guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67089 - guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67090 + if (unrestricted) {
67091 + iowait = get_iowait_time(i);
67092 + irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67093 + softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67094 + steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67095 + guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67096 + guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67097 + }
67098 seq_printf(p, "cpu%d", i);
67099 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
67100 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
67101 @@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
67102
67103 /* sum again ? it could be updated? */
67104 for_each_irq_nr(j)
67105 - seq_put_decimal_ull(p, ' ', kstat_irqs(j));
67106 + seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
67107
67108 seq_printf(p,
67109 "\nctxt %llu\n"
67110 @@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
67111 "processes %lu\n"
67112 "procs_running %lu\n"
67113 "procs_blocked %lu\n",
67114 - nr_context_switches(),
67115 + unrestricted ? nr_context_switches() : 0ULL,
67116 (unsigned long)jif,
67117 - total_forks,
67118 - nr_running(),
67119 - nr_iowait());
67120 + unrestricted ? total_forks : 0UL,
67121 + unrestricted ? nr_running() : 0UL,
67122 + unrestricted ? nr_iowait() : 0UL);
67123
67124 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
67125
67126 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
67127 index c341568..75852a2 100644
67128 --- a/fs/proc/task_mmu.c
67129 +++ b/fs/proc/task_mmu.c
67130 @@ -13,12 +13,19 @@
67131 #include <linux/swap.h>
67132 #include <linux/swapops.h>
67133 #include <linux/mmu_notifier.h>
67134 +#include <linux/grsecurity.h>
67135
67136 #include <asm/elf.h>
67137 #include <asm/uaccess.h>
67138 #include <asm/tlbflush.h>
67139 #include "internal.h"
67140
67141 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67142 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
67143 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
67144 + _mm->pax_flags & MF_PAX_SEGMEXEC))
67145 +#endif
67146 +
67147 void task_mem(struct seq_file *m, struct mm_struct *mm)
67148 {
67149 unsigned long data, text, lib, swap;
67150 @@ -54,8 +61,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
67151 "VmExe:\t%8lu kB\n"
67152 "VmLib:\t%8lu kB\n"
67153 "VmPTE:\t%8lu kB\n"
67154 - "VmSwap:\t%8lu kB\n",
67155 - hiwater_vm << (PAGE_SHIFT-10),
67156 + "VmSwap:\t%8lu kB\n"
67157 +
67158 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
67159 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
67160 +#endif
67161 +
67162 + ,hiwater_vm << (PAGE_SHIFT-10),
67163 total_vm << (PAGE_SHIFT-10),
67164 mm->locked_vm << (PAGE_SHIFT-10),
67165 mm->pinned_vm << (PAGE_SHIFT-10),
67166 @@ -65,7 +77,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
67167 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
67168 (PTRS_PER_PTE * sizeof(pte_t) *
67169 atomic_long_read(&mm->nr_ptes)) >> 10,
67170 - swap << (PAGE_SHIFT-10));
67171 + swap << (PAGE_SHIFT-10)
67172 +
67173 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
67174 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67175 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
67176 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
67177 +#else
67178 + , mm->context.user_cs_base
67179 + , mm->context.user_cs_limit
67180 +#endif
67181 +#endif
67182 +
67183 + );
67184 }
67185
67186 unsigned long task_vsize(struct mm_struct *mm)
67187 @@ -271,13 +295,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67188 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
67189 }
67190
67191 - /* We don't show the stack guard page in /proc/maps */
67192 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67193 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
67194 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
67195 +#else
67196 start = vma->vm_start;
67197 - if (stack_guard_page_start(vma, start))
67198 - start += PAGE_SIZE;
67199 end = vma->vm_end;
67200 - if (stack_guard_page_end(vma, end))
67201 - end -= PAGE_SIZE;
67202 +#endif
67203
67204 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
67205 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
67206 @@ -287,7 +311,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67207 flags & VM_WRITE ? 'w' : '-',
67208 flags & VM_EXEC ? 'x' : '-',
67209 flags & VM_MAYSHARE ? 's' : 'p',
67210 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67211 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
67212 +#else
67213 pgoff,
67214 +#endif
67215 MAJOR(dev), MINOR(dev), ino);
67216
67217 /*
67218 @@ -296,7 +324,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67219 */
67220 if (file) {
67221 seq_pad(m, ' ');
67222 - seq_path(m, &file->f_path, "\n");
67223 + seq_path(m, &file->f_path, "\n\\");
67224 goto done;
67225 }
67226
67227 @@ -328,8 +356,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67228 * Thread stack in /proc/PID/task/TID/maps or
67229 * the main process stack.
67230 */
67231 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
67232 - vma->vm_end >= mm->start_stack)) {
67233 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
67234 + (vma->vm_start <= mm->start_stack &&
67235 + vma->vm_end >= mm->start_stack)) {
67236 name = "[stack]";
67237 } else {
67238 /* Thread stack in /proc/PID/maps */
67239 @@ -353,6 +382,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
67240 struct proc_maps_private *priv = m->private;
67241 struct task_struct *task = priv->task;
67242
67243 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67244 + if (current->exec_id != m->exec_id) {
67245 + gr_log_badprocpid("maps");
67246 + return 0;
67247 + }
67248 +#endif
67249 +
67250 show_map_vma(m, vma, is_pid);
67251
67252 if (m->count < m->size) /* vma is copied successfully */
67253 @@ -593,12 +629,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
67254 .private = &mss,
67255 };
67256
67257 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67258 + if (current->exec_id != m->exec_id) {
67259 + gr_log_badprocpid("smaps");
67260 + return 0;
67261 + }
67262 +#endif
67263 memset(&mss, 0, sizeof mss);
67264 - mss.vma = vma;
67265 - /* mmap_sem is held in m_start */
67266 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
67267 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
67268 -
67269 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67270 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
67271 +#endif
67272 + mss.vma = vma;
67273 + /* mmap_sem is held in m_start */
67274 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
67275 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
67276 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67277 + }
67278 +#endif
67279 show_map_vma(m, vma, is_pid);
67280
67281 seq_printf(m,
67282 @@ -616,7 +663,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
67283 "KernelPageSize: %8lu kB\n"
67284 "MMUPageSize: %8lu kB\n"
67285 "Locked: %8lu kB\n",
67286 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67287 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
67288 +#else
67289 (vma->vm_end - vma->vm_start) >> 10,
67290 +#endif
67291 mss.resident >> 10,
67292 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
67293 mss.shared_clean >> 10,
67294 @@ -1422,6 +1473,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
67295 char buffer[64];
67296 int nid;
67297
67298 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67299 + if (current->exec_id != m->exec_id) {
67300 + gr_log_badprocpid("numa_maps");
67301 + return 0;
67302 + }
67303 +#endif
67304 +
67305 if (!mm)
67306 return 0;
67307
67308 @@ -1439,11 +1497,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
67309 mpol_to_str(buffer, sizeof(buffer), pol);
67310 mpol_cond_put(pol);
67311
67312 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67313 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
67314 +#else
67315 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
67316 +#endif
67317
67318 if (file) {
67319 seq_puts(m, " file=");
67320 - seq_path(m, &file->f_path, "\n\t= ");
67321 + seq_path(m, &file->f_path, "\n\t\\= ");
67322 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
67323 seq_puts(m, " heap");
67324 } else {
67325 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
67326 index 678455d..ebd3245 100644
67327 --- a/fs/proc/task_nommu.c
67328 +++ b/fs/proc/task_nommu.c
67329 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
67330 else
67331 bytes += kobjsize(mm);
67332
67333 - if (current->fs && current->fs->users > 1)
67334 + if (current->fs && atomic_read(&current->fs->users) > 1)
67335 sbytes += kobjsize(current->fs);
67336 else
67337 bytes += kobjsize(current->fs);
67338 @@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
67339
67340 if (file) {
67341 seq_pad(m, ' ');
67342 - seq_path(m, &file->f_path, "");
67343 + seq_path(m, &file->f_path, "\n\\");
67344 } else if (mm) {
67345 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
67346
67347 diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
67348 index a90d6d35..d08047c 100644
67349 --- a/fs/proc/vmcore.c
67350 +++ b/fs/proc/vmcore.c
67351 @@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
67352 nr_bytes = count;
67353
67354 /* If pfn is not ram, return zeros for sparse dump files */
67355 - if (pfn_is_ram(pfn) == 0)
67356 - memset(buf, 0, nr_bytes);
67357 - else {
67358 + if (pfn_is_ram(pfn) == 0) {
67359 + if (userbuf) {
67360 + if (clear_user((char __force_user *)buf, nr_bytes))
67361 + return -EFAULT;
67362 + } else
67363 + memset(buf, 0, nr_bytes);
67364 + } else {
67365 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
67366 offset, userbuf);
67367 if (tmp < 0)
67368 @@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
67369 static int copy_to(void *target, void *src, size_t size, int userbuf)
67370 {
67371 if (userbuf) {
67372 - if (copy_to_user((char __user *) target, src, size))
67373 + if (copy_to_user((char __force_user *) target, src, size))
67374 return -EFAULT;
67375 } else {
67376 memcpy(target, src, size);
67377 @@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
67378 if (*fpos < m->offset + m->size) {
67379 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
67380 start = m->paddr + *fpos - m->offset;
67381 - tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
67382 + tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
67383 if (tmp < 0)
67384 return tmp;
67385 buflen -= tsz;
67386 @@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
67387 static ssize_t read_vmcore(struct file *file, char __user *buffer,
67388 size_t buflen, loff_t *fpos)
67389 {
67390 - return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
67391 + return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
67392 }
67393
67394 /*
67395 diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
67396 index d3fb2b6..43a8140 100644
67397 --- a/fs/qnx6/qnx6.h
67398 +++ b/fs/qnx6/qnx6.h
67399 @@ -74,7 +74,7 @@ enum {
67400 BYTESEX_BE,
67401 };
67402
67403 -static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
67404 +static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
67405 {
67406 if (sbi->s_bytesex == BYTESEX_LE)
67407 return le64_to_cpu((__force __le64)n);
67408 @@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
67409 return (__force __fs64)cpu_to_be64(n);
67410 }
67411
67412 -static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
67413 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
67414 {
67415 if (sbi->s_bytesex == BYTESEX_LE)
67416 return le32_to_cpu((__force __le32)n);
67417 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
67418 index bb2869f..d34ada8 100644
67419 --- a/fs/quota/netlink.c
67420 +++ b/fs/quota/netlink.c
67421 @@ -44,7 +44,7 @@ static struct genl_family quota_genl_family = {
67422 void quota_send_warning(struct kqid qid, dev_t dev,
67423 const char warntype)
67424 {
67425 - static atomic_t seq;
67426 + static atomic_unchecked_t seq;
67427 struct sk_buff *skb;
67428 void *msg_head;
67429 int ret;
67430 @@ -60,7 +60,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
67431 "VFS: Not enough memory to send quota warning.\n");
67432 return;
67433 }
67434 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
67435 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
67436 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
67437 if (!msg_head) {
67438 printk(KERN_ERR
67439 diff --git a/fs/read_write.c b/fs/read_write.c
67440 index 009d854..16ce214 100644
67441 --- a/fs/read_write.c
67442 +++ b/fs/read_write.c
67443 @@ -495,7 +495,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
67444
67445 old_fs = get_fs();
67446 set_fs(get_ds());
67447 - p = (__force const char __user *)buf;
67448 + p = (const char __force_user *)buf;
67449 if (count > MAX_RW_COUNT)
67450 count = MAX_RW_COUNT;
67451 if (file->f_op->write)
67452 diff --git a/fs/readdir.c b/fs/readdir.c
67453 index 33fd922..e0d6094 100644
67454 --- a/fs/readdir.c
67455 +++ b/fs/readdir.c
67456 @@ -18,6 +18,7 @@
67457 #include <linux/security.h>
67458 #include <linux/syscalls.h>
67459 #include <linux/unistd.h>
67460 +#include <linux/namei.h>
67461
67462 #include <asm/uaccess.h>
67463
67464 @@ -71,6 +72,7 @@ struct old_linux_dirent {
67465 struct readdir_callback {
67466 struct dir_context ctx;
67467 struct old_linux_dirent __user * dirent;
67468 + struct file * file;
67469 int result;
67470 };
67471
67472 @@ -88,6 +90,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
67473 buf->result = -EOVERFLOW;
67474 return -EOVERFLOW;
67475 }
67476 +
67477 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67478 + return 0;
67479 +
67480 buf->result++;
67481 dirent = buf->dirent;
67482 if (!access_ok(VERIFY_WRITE, dirent,
67483 @@ -119,6 +125,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
67484 if (!f.file)
67485 return -EBADF;
67486
67487 + buf.file = f.file;
67488 error = iterate_dir(f.file, &buf.ctx);
67489 if (buf.result)
67490 error = buf.result;
67491 @@ -144,6 +151,7 @@ struct getdents_callback {
67492 struct dir_context ctx;
67493 struct linux_dirent __user * current_dir;
67494 struct linux_dirent __user * previous;
67495 + struct file * file;
67496 int count;
67497 int error;
67498 };
67499 @@ -165,6 +173,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
67500 buf->error = -EOVERFLOW;
67501 return -EOVERFLOW;
67502 }
67503 +
67504 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67505 + return 0;
67506 +
67507 dirent = buf->previous;
67508 if (dirent) {
67509 if (__put_user(offset, &dirent->d_off))
67510 @@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
67511 if (!f.file)
67512 return -EBADF;
67513
67514 + buf.file = f.file;
67515 error = iterate_dir(f.file, &buf.ctx);
67516 if (error >= 0)
67517 error = buf.error;
67518 @@ -228,6 +241,7 @@ struct getdents_callback64 {
67519 struct dir_context ctx;
67520 struct linux_dirent64 __user * current_dir;
67521 struct linux_dirent64 __user * previous;
67522 + struct file *file;
67523 int count;
67524 int error;
67525 };
67526 @@ -243,6 +257,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
67527 buf->error = -EINVAL; /* only used if we fail.. */
67528 if (reclen > buf->count)
67529 return -EINVAL;
67530 +
67531 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67532 + return 0;
67533 +
67534 dirent = buf->previous;
67535 if (dirent) {
67536 if (__put_user(offset, &dirent->d_off))
67537 @@ -290,6 +308,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
67538 if (!f.file)
67539 return -EBADF;
67540
67541 + buf.file = f.file;
67542 error = iterate_dir(f.file, &buf.ctx);
67543 if (error >= 0)
67544 error = buf.error;
67545 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
67546 index 9c02d96..6562c10 100644
67547 --- a/fs/reiserfs/do_balan.c
67548 +++ b/fs/reiserfs/do_balan.c
67549 @@ -1887,7 +1887,7 @@ void do_balance(struct tree_balance *tb, struct item_head *ih,
67550 return;
67551 }
67552
67553 - atomic_inc(&fs_generation(tb->tb_sb));
67554 + atomic_inc_unchecked(&fs_generation(tb->tb_sb));
67555 do_balance_starts(tb);
67556
67557 /*
67558 diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
67559 index aca73dd..e3c558d 100644
67560 --- a/fs/reiserfs/item_ops.c
67561 +++ b/fs/reiserfs/item_ops.c
67562 @@ -724,18 +724,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
67563 }
67564
67565 static struct item_operations errcatch_ops = {
67566 - errcatch_bytes_number,
67567 - errcatch_decrement_key,
67568 - errcatch_is_left_mergeable,
67569 - errcatch_print_item,
67570 - errcatch_check_item,
67571 + .bytes_number = errcatch_bytes_number,
67572 + .decrement_key = errcatch_decrement_key,
67573 + .is_left_mergeable = errcatch_is_left_mergeable,
67574 + .print_item = errcatch_print_item,
67575 + .check_item = errcatch_check_item,
67576
67577 - errcatch_create_vi,
67578 - errcatch_check_left,
67579 - errcatch_check_right,
67580 - errcatch_part_size,
67581 - errcatch_unit_num,
67582 - errcatch_print_vi
67583 + .create_vi = errcatch_create_vi,
67584 + .check_left = errcatch_check_left,
67585 + .check_right = errcatch_check_right,
67586 + .part_size = errcatch_part_size,
67587 + .unit_num = errcatch_unit_num,
67588 + .print_vi = errcatch_print_vi
67589 };
67590
67591 #if ! (TYPE_STAT_DATA == 0 && TYPE_INDIRECT == 1 && TYPE_DIRECT == 2 && TYPE_DIRENTRY == 3)
67592 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
67593 index 621b9f3..af527fd 100644
67594 --- a/fs/reiserfs/procfs.c
67595 +++ b/fs/reiserfs/procfs.c
67596 @@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
67597 "SMALL_TAILS " : "NO_TAILS ",
67598 replay_only(sb) ? "REPLAY_ONLY " : "",
67599 convert_reiserfs(sb) ? "CONV " : "",
67600 - atomic_read(&r->s_generation_counter),
67601 + atomic_read_unchecked(&r->s_generation_counter),
67602 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
67603 SF(s_do_balance), SF(s_unneeded_left_neighbor),
67604 SF(s_good_search_by_key_reada), SF(s_bmaps),
67605 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
67606 index 735c2c2..81b91af 100644
67607 --- a/fs/reiserfs/reiserfs.h
67608 +++ b/fs/reiserfs/reiserfs.h
67609 @@ -573,7 +573,7 @@ struct reiserfs_sb_info {
67610 /* Comment? -Hans */
67611 wait_queue_head_t s_wait;
67612 /* increased by one every time the tree gets re-balanced */
67613 - atomic_t s_generation_counter;
67614 + atomic_unchecked_t s_generation_counter;
67615
67616 /* File system properties. Currently holds on-disk FS format */
67617 unsigned long s_properties;
67618 @@ -2294,7 +2294,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
67619 #define REISERFS_USER_MEM 1 /* user memory mode */
67620
67621 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
67622 -#define get_generation(s) atomic_read (&fs_generation(s))
67623 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
67624 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
67625 #define __fs_changed(gen,s) (gen != get_generation (s))
67626 #define fs_changed(gen,s) \
67627 diff --git a/fs/select.c b/fs/select.c
67628 index 467bb1c..cf9d65a 100644
67629 --- a/fs/select.c
67630 +++ b/fs/select.c
67631 @@ -20,6 +20,7 @@
67632 #include <linux/export.h>
67633 #include <linux/slab.h>
67634 #include <linux/poll.h>
67635 +#include <linux/security.h>
67636 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
67637 #include <linux/file.h>
67638 #include <linux/fdtable.h>
67639 @@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
67640 struct poll_list *walk = head;
67641 unsigned long todo = nfds;
67642
67643 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
67644 if (nfds > rlimit(RLIMIT_NOFILE))
67645 return -EINVAL;
67646
67647 diff --git a/fs/seq_file.c b/fs/seq_file.c
67648 index 3857b72..0b7281e 100644
67649 --- a/fs/seq_file.c
67650 +++ b/fs/seq_file.c
67651 @@ -12,6 +12,8 @@
67652 #include <linux/slab.h>
67653 #include <linux/cred.h>
67654 #include <linux/mm.h>
67655 +#include <linux/sched.h>
67656 +#include <linux/grsecurity.h>
67657
67658 #include <asm/uaccess.h>
67659 #include <asm/page.h>
67660 @@ -34,12 +36,7 @@ static void seq_set_overflow(struct seq_file *m)
67661
67662 static void *seq_buf_alloc(unsigned long size)
67663 {
67664 - void *buf;
67665 -
67666 - buf = kmalloc(size, GFP_KERNEL | __GFP_NOWARN);
67667 - if (!buf && size > PAGE_SIZE)
67668 - buf = vmalloc(size);
67669 - return buf;
67670 + return kmalloc(size, GFP_KERNEL | GFP_USERCOPY);
67671 }
67672
67673 /**
67674 @@ -72,6 +69,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
67675 #ifdef CONFIG_USER_NS
67676 p->user_ns = file->f_cred->user_ns;
67677 #endif
67678 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67679 + p->exec_id = current->exec_id;
67680 +#endif
67681
67682 /*
67683 * Wrappers around seq_open(e.g. swaps_open) need to be
67684 @@ -94,6 +94,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
67685 }
67686 EXPORT_SYMBOL(seq_open);
67687
67688 +
67689 +int seq_open_restrict(struct file *file, const struct seq_operations *op)
67690 +{
67691 + if (gr_proc_is_restricted())
67692 + return -EACCES;
67693 +
67694 + return seq_open(file, op);
67695 +}
67696 +EXPORT_SYMBOL(seq_open_restrict);
67697 +
67698 static int traverse(struct seq_file *m, loff_t offset)
67699 {
67700 loff_t pos = 0, index;
67701 @@ -165,7 +175,7 @@ Eoverflow:
67702 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
67703 {
67704 struct seq_file *m = file->private_data;
67705 - size_t copied = 0;
67706 + ssize_t copied = 0;
67707 loff_t pos;
67708 size_t n;
67709 void *p;
67710 @@ -596,7 +606,7 @@ static void single_stop(struct seq_file *p, void *v)
67711 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
67712 void *data)
67713 {
67714 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
67715 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
67716 int res = -ENOMEM;
67717
67718 if (op) {
67719 @@ -632,6 +642,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
67720 }
67721 EXPORT_SYMBOL(single_open_size);
67722
67723 +int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
67724 + void *data)
67725 +{
67726 + if (gr_proc_is_restricted())
67727 + return -EACCES;
67728 +
67729 + return single_open(file, show, data);
67730 +}
67731 +EXPORT_SYMBOL(single_open_restrict);
67732 +
67733 +
67734 int single_release(struct inode *inode, struct file *file)
67735 {
67736 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
67737 diff --git a/fs/splice.c b/fs/splice.c
67738 index f5cb9ba..8ddb1e9 100644
67739 --- a/fs/splice.c
67740 +++ b/fs/splice.c
67741 @@ -193,7 +193,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
67742 pipe_lock(pipe);
67743
67744 for (;;) {
67745 - if (!pipe->readers) {
67746 + if (!atomic_read(&pipe->readers)) {
67747 send_sig(SIGPIPE, current, 0);
67748 if (!ret)
67749 ret = -EPIPE;
67750 @@ -216,7 +216,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
67751 page_nr++;
67752 ret += buf->len;
67753
67754 - if (pipe->files)
67755 + if (atomic_read(&pipe->files))
67756 do_wakeup = 1;
67757
67758 if (!--spd->nr_pages)
67759 @@ -247,9 +247,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
67760 do_wakeup = 0;
67761 }
67762
67763 - pipe->waiting_writers++;
67764 + atomic_inc(&pipe->waiting_writers);
67765 pipe_wait(pipe);
67766 - pipe->waiting_writers--;
67767 + atomic_dec(&pipe->waiting_writers);
67768 }
67769
67770 pipe_unlock(pipe);
67771 @@ -576,7 +576,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
67772 old_fs = get_fs();
67773 set_fs(get_ds());
67774 /* The cast to a user pointer is valid due to the set_fs() */
67775 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
67776 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
67777 set_fs(old_fs);
67778
67779 return res;
67780 @@ -591,7 +591,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
67781 old_fs = get_fs();
67782 set_fs(get_ds());
67783 /* The cast to a user pointer is valid due to the set_fs() */
67784 - res = vfs_write(file, (__force const char __user *)buf, count, &pos);
67785 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
67786 set_fs(old_fs);
67787
67788 return res;
67789 @@ -644,7 +644,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
67790 goto err;
67791
67792 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
67793 - vec[i].iov_base = (void __user *) page_address(page);
67794 + vec[i].iov_base = (void __force_user *) page_address(page);
67795 vec[i].iov_len = this_len;
67796 spd.pages[i] = page;
67797 spd.nr_pages++;
67798 @@ -783,7 +783,7 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
67799 ops->release(pipe, buf);
67800 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
67801 pipe->nrbufs--;
67802 - if (pipe->files)
67803 + if (atomic_read(&pipe->files))
67804 sd->need_wakeup = true;
67805 }
67806
67807 @@ -807,10 +807,10 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
67808 static int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
67809 {
67810 while (!pipe->nrbufs) {
67811 - if (!pipe->writers)
67812 + if (!atomic_read(&pipe->writers))
67813 return 0;
67814
67815 - if (!pipe->waiting_writers && sd->num_spliced)
67816 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
67817 return 0;
67818
67819 if (sd->flags & SPLICE_F_NONBLOCK)
67820 @@ -1040,7 +1040,7 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
67821 ops->release(pipe, buf);
67822 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
67823 pipe->nrbufs--;
67824 - if (pipe->files)
67825 + if (atomic_read(&pipe->files))
67826 sd.need_wakeup = true;
67827 } else {
67828 buf->offset += ret;
67829 @@ -1200,7 +1200,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
67830 * out of the pipe right after the splice_to_pipe(). So set
67831 * PIPE_READERS appropriately.
67832 */
67833 - pipe->readers = 1;
67834 + atomic_set(&pipe->readers, 1);
67835
67836 current->splice_pipe = pipe;
67837 }
67838 @@ -1496,6 +1496,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
67839
67840 partial[buffers].offset = off;
67841 partial[buffers].len = plen;
67842 + partial[buffers].private = 0;
67843
67844 off = 0;
67845 len -= plen;
67846 @@ -1732,9 +1733,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
67847 ret = -ERESTARTSYS;
67848 break;
67849 }
67850 - if (!pipe->writers)
67851 + if (!atomic_read(&pipe->writers))
67852 break;
67853 - if (!pipe->waiting_writers) {
67854 + if (!atomic_read(&pipe->waiting_writers)) {
67855 if (flags & SPLICE_F_NONBLOCK) {
67856 ret = -EAGAIN;
67857 break;
67858 @@ -1766,7 +1767,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
67859 pipe_lock(pipe);
67860
67861 while (pipe->nrbufs >= pipe->buffers) {
67862 - if (!pipe->readers) {
67863 + if (!atomic_read(&pipe->readers)) {
67864 send_sig(SIGPIPE, current, 0);
67865 ret = -EPIPE;
67866 break;
67867 @@ -1779,9 +1780,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
67868 ret = -ERESTARTSYS;
67869 break;
67870 }
67871 - pipe->waiting_writers++;
67872 + atomic_inc(&pipe->waiting_writers);
67873 pipe_wait(pipe);
67874 - pipe->waiting_writers--;
67875 + atomic_dec(&pipe->waiting_writers);
67876 }
67877
67878 pipe_unlock(pipe);
67879 @@ -1817,14 +1818,14 @@ retry:
67880 pipe_double_lock(ipipe, opipe);
67881
67882 do {
67883 - if (!opipe->readers) {
67884 + if (!atomic_read(&opipe->readers)) {
67885 send_sig(SIGPIPE, current, 0);
67886 if (!ret)
67887 ret = -EPIPE;
67888 break;
67889 }
67890
67891 - if (!ipipe->nrbufs && !ipipe->writers)
67892 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
67893 break;
67894
67895 /*
67896 @@ -1921,7 +1922,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
67897 pipe_double_lock(ipipe, opipe);
67898
67899 do {
67900 - if (!opipe->readers) {
67901 + if (!atomic_read(&opipe->readers)) {
67902 send_sig(SIGPIPE, current, 0);
67903 if (!ret)
67904 ret = -EPIPE;
67905 @@ -1966,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
67906 * return EAGAIN if we have the potential of some data in the
67907 * future, otherwise just return 0
67908 */
67909 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
67910 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
67911 ret = -EAGAIN;
67912
67913 pipe_unlock(ipipe);
67914 diff --git a/fs/stat.c b/fs/stat.c
67915 index ae0c3ce..9ee641c 100644
67916 --- a/fs/stat.c
67917 +++ b/fs/stat.c
67918 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
67919 stat->gid = inode->i_gid;
67920 stat->rdev = inode->i_rdev;
67921 stat->size = i_size_read(inode);
67922 - stat->atime = inode->i_atime;
67923 - stat->mtime = inode->i_mtime;
67924 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
67925 + stat->atime = inode->i_ctime;
67926 + stat->mtime = inode->i_ctime;
67927 + } else {
67928 + stat->atime = inode->i_atime;
67929 + stat->mtime = inode->i_mtime;
67930 + }
67931 stat->ctime = inode->i_ctime;
67932 stat->blksize = (1 << inode->i_blkbits);
67933 stat->blocks = inode->i_blocks;
67934 @@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
67935 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
67936 {
67937 struct inode *inode = path->dentry->d_inode;
67938 + int retval;
67939
67940 - if (inode->i_op->getattr)
67941 - return inode->i_op->getattr(path->mnt, path->dentry, stat);
67942 + if (inode->i_op->getattr) {
67943 + retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
67944 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
67945 + stat->atime = stat->ctime;
67946 + stat->mtime = stat->ctime;
67947 + }
67948 + return retval;
67949 + }
67950
67951 generic_fillattr(inode, stat);
67952 return 0;
67953 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
67954 index 0b45ff4..847de5b 100644
67955 --- a/fs/sysfs/dir.c
67956 +++ b/fs/sysfs/dir.c
67957 @@ -41,9 +41,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
67958 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
67959 {
67960 struct kernfs_node *parent, *kn;
67961 + const char *name;
67962 + umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
67963 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
67964 + const char *parent_name;
67965 +#endif
67966
67967 BUG_ON(!kobj);
67968
67969 + name = kobject_name(kobj);
67970 +
67971 if (kobj->parent)
67972 parent = kobj->parent->sd;
67973 else
67974 @@ -52,11 +59,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
67975 if (!parent)
67976 return -ENOENT;
67977
67978 - kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
67979 - S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
67980 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
67981 + parent_name = parent->name;
67982 + mode = S_IRWXU;
67983 +
67984 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
67985 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
67986 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
67987 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
67988 + mode = S_IRWXU | S_IRUGO | S_IXUGO;
67989 +#endif
67990 +
67991 + kn = kernfs_create_dir_ns(parent, name,
67992 + mode, kobj, ns);
67993 if (IS_ERR(kn)) {
67994 if (PTR_ERR(kn) == -EEXIST)
67995 - sysfs_warn_dup(parent, kobject_name(kobj));
67996 + sysfs_warn_dup(parent, name);
67997 return PTR_ERR(kn);
67998 }
67999
68000 diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
68001 index 69d4889..a810bd4 100644
68002 --- a/fs/sysv/sysv.h
68003 +++ b/fs/sysv/sysv.h
68004 @@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
68005 #endif
68006 }
68007
68008 -static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
68009 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
68010 {
68011 if (sbi->s_bytesex == BYTESEX_PDP)
68012 return PDP_swab((__force __u32)n);
68013 diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
68014 index fb08b0c..65fcc7e 100644
68015 --- a/fs/ubifs/io.c
68016 +++ b/fs/ubifs/io.c
68017 @@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
68018 return err;
68019 }
68020
68021 -int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
68022 +int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
68023 {
68024 int err;
68025
68026 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
68027 index c175b4d..8f36a16 100644
68028 --- a/fs/udf/misc.c
68029 +++ b/fs/udf/misc.c
68030 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
68031
68032 u8 udf_tag_checksum(const struct tag *t)
68033 {
68034 - u8 *data = (u8 *)t;
68035 + const u8 *data = (const u8 *)t;
68036 u8 checksum = 0;
68037 int i;
68038 for (i = 0; i < sizeof(struct tag); ++i)
68039 diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
68040 index 8d974c4..b82f6ec 100644
68041 --- a/fs/ufs/swab.h
68042 +++ b/fs/ufs/swab.h
68043 @@ -22,7 +22,7 @@ enum {
68044 BYTESEX_BE
68045 };
68046
68047 -static inline u64
68048 +static inline u64 __intentional_overflow(-1)
68049 fs64_to_cpu(struct super_block *sbp, __fs64 n)
68050 {
68051 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
68052 @@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
68053 return (__force __fs64)cpu_to_be64(n);
68054 }
68055
68056 -static inline u32
68057 +static inline u32 __intentional_overflow(-1)
68058 fs32_to_cpu(struct super_block *sbp, __fs32 n)
68059 {
68060 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
68061 diff --git a/fs/utimes.c b/fs/utimes.c
68062 index aa138d6..5f3a811 100644
68063 --- a/fs/utimes.c
68064 +++ b/fs/utimes.c
68065 @@ -1,6 +1,7 @@
68066 #include <linux/compiler.h>
68067 #include <linux/file.h>
68068 #include <linux/fs.h>
68069 +#include <linux/security.h>
68070 #include <linux/linkage.h>
68071 #include <linux/mount.h>
68072 #include <linux/namei.h>
68073 @@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
68074 }
68075 }
68076 retry_deleg:
68077 +
68078 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
68079 + error = -EACCES;
68080 + goto mnt_drop_write_and_out;
68081 + }
68082 +
68083 mutex_lock(&inode->i_mutex);
68084 error = notify_change(path->dentry, &newattrs, &delegated_inode);
68085 mutex_unlock(&inode->i_mutex);
68086 diff --git a/fs/xattr.c b/fs/xattr.c
68087 index c69e6d4..cc56af5 100644
68088 --- a/fs/xattr.c
68089 +++ b/fs/xattr.c
68090 @@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
68091 return rc;
68092 }
68093
68094 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
68095 +ssize_t
68096 +pax_getxattr(struct dentry *dentry, void *value, size_t size)
68097 +{
68098 + struct inode *inode = dentry->d_inode;
68099 + ssize_t error;
68100 +
68101 + error = inode_permission(inode, MAY_EXEC);
68102 + if (error)
68103 + return error;
68104 +
68105 + if (inode->i_op->getxattr)
68106 + error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
68107 + else
68108 + error = -EOPNOTSUPP;
68109 +
68110 + return error;
68111 +}
68112 +EXPORT_SYMBOL(pax_getxattr);
68113 +#endif
68114 +
68115 ssize_t
68116 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
68117 {
68118 @@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
68119 * Extended attribute SET operations
68120 */
68121 static long
68122 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
68123 +setxattr(struct path *path, const char __user *name, const void __user *value,
68124 size_t size, int flags)
68125 {
68126 int error;
68127 @@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
68128 posix_acl_fix_xattr_from_user(kvalue, size);
68129 }
68130
68131 - error = vfs_setxattr(d, kname, kvalue, size, flags);
68132 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
68133 + error = -EACCES;
68134 + goto out;
68135 + }
68136 +
68137 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
68138 out:
68139 if (vvalue)
68140 vfree(vvalue);
68141 @@ -377,7 +403,7 @@ retry:
68142 return error;
68143 error = mnt_want_write(path.mnt);
68144 if (!error) {
68145 - error = setxattr(path.dentry, name, value, size, flags);
68146 + error = setxattr(&path, name, value, size, flags);
68147 mnt_drop_write(path.mnt);
68148 }
68149 path_put(&path);
68150 @@ -401,7 +427,7 @@ retry:
68151 return error;
68152 error = mnt_want_write(path.mnt);
68153 if (!error) {
68154 - error = setxattr(path.dentry, name, value, size, flags);
68155 + error = setxattr(&path, name, value, size, flags);
68156 mnt_drop_write(path.mnt);
68157 }
68158 path_put(&path);
68159 @@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
68160 const void __user *,value, size_t, size, int, flags)
68161 {
68162 struct fd f = fdget(fd);
68163 - struct dentry *dentry;
68164 int error = -EBADF;
68165
68166 if (!f.file)
68167 return error;
68168 - dentry = f.file->f_path.dentry;
68169 - audit_inode(NULL, dentry, 0);
68170 + audit_inode(NULL, f.file->f_path.dentry, 0);
68171 error = mnt_want_write_file(f.file);
68172 if (!error) {
68173 - error = setxattr(dentry, name, value, size, flags);
68174 + error = setxattr(&f.file->f_path, name, value, size, flags);
68175 mnt_drop_write_file(f.file);
68176 }
68177 fdput(f);
68178 @@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
68179 * Extended attribute REMOVE operations
68180 */
68181 static long
68182 -removexattr(struct dentry *d, const char __user *name)
68183 +removexattr(struct path *path, const char __user *name)
68184 {
68185 int error;
68186 char kname[XATTR_NAME_MAX + 1];
68187 @@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
68188 if (error < 0)
68189 return error;
68190
68191 - return vfs_removexattr(d, kname);
68192 + if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
68193 + return -EACCES;
68194 +
68195 + return vfs_removexattr(path->dentry, kname);
68196 }
68197
68198 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
68199 @@ -652,7 +679,7 @@ retry:
68200 return error;
68201 error = mnt_want_write(path.mnt);
68202 if (!error) {
68203 - error = removexattr(path.dentry, name);
68204 + error = removexattr(&path, name);
68205 mnt_drop_write(path.mnt);
68206 }
68207 path_put(&path);
68208 @@ -675,7 +702,7 @@ retry:
68209 return error;
68210 error = mnt_want_write(path.mnt);
68211 if (!error) {
68212 - error = removexattr(path.dentry, name);
68213 + error = removexattr(&path, name);
68214 mnt_drop_write(path.mnt);
68215 }
68216 path_put(&path);
68217 @@ -689,16 +716,16 @@ retry:
68218 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
68219 {
68220 struct fd f = fdget(fd);
68221 - struct dentry *dentry;
68222 + struct path *path;
68223 int error = -EBADF;
68224
68225 if (!f.file)
68226 return error;
68227 - dentry = f.file->f_path.dentry;
68228 - audit_inode(NULL, dentry, 0);
68229 + path = &f.file->f_path;
68230 + audit_inode(NULL, path->dentry, 0);
68231 error = mnt_want_write_file(f.file);
68232 if (!error) {
68233 - error = removexattr(dentry, name);
68234 + error = removexattr(path, name);
68235 mnt_drop_write_file(f.file);
68236 }
68237 fdput(f);
68238 diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
68239 index 86df952..ac430d6 100644
68240 --- a/fs/xfs/libxfs/xfs_bmap.c
68241 +++ b/fs/xfs/libxfs/xfs_bmap.c
68242 @@ -583,7 +583,7 @@ xfs_bmap_validate_ret(
68243
68244 #else
68245 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
68246 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
68247 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
68248 #endif /* DEBUG */
68249
68250 /*
68251 diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
68252 index f1b69ed..3d0222f 100644
68253 --- a/fs/xfs/xfs_dir2_readdir.c
68254 +++ b/fs/xfs/xfs_dir2_readdir.c
68255 @@ -159,7 +159,12 @@ xfs_dir2_sf_getdents(
68256 ino = dp->d_ops->sf_get_ino(sfp, sfep);
68257 filetype = dp->d_ops->sf_get_ftype(sfep);
68258 ctx->pos = off & 0x7fffffff;
68259 - if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
68260 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
68261 + char name[sfep->namelen];
68262 + memcpy(name, sfep->name, sfep->namelen);
68263 + if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(dp->i_mount, filetype)))
68264 + return 0;
68265 + } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
68266 xfs_dir3_get_dtype(dp->i_mount, filetype)))
68267 return 0;
68268 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
68269 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
68270 index 3799695..0ddc953 100644
68271 --- a/fs/xfs/xfs_ioctl.c
68272 +++ b/fs/xfs/xfs_ioctl.c
68273 @@ -122,7 +122,7 @@ xfs_find_handle(
68274 }
68275
68276 error = -EFAULT;
68277 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
68278 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
68279 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
68280 goto out_put;
68281
68282 diff --git a/fs/xfs/xfs_linux.h b/fs/xfs/xfs_linux.h
68283 index d10dc8f..56b3430 100644
68284 --- a/fs/xfs/xfs_linux.h
68285 +++ b/fs/xfs/xfs_linux.h
68286 @@ -230,7 +230,7 @@ static inline kgid_t xfs_gid_to_kgid(__uint32_t gid)
68287 * of the compiler which do not like us using do_div in the middle
68288 * of large functions.
68289 */
68290 -static inline __u32 xfs_do_div(void *a, __u32 b, int n)
68291 +static inline __u32 __intentional_overflow(-1) xfs_do_div(void *a, __u32 b, int n)
68292 {
68293 __u32 mod;
68294
68295 @@ -286,7 +286,7 @@ static inline __u32 xfs_do_mod(void *a, __u32 b, int n)
68296 return 0;
68297 }
68298 #else
68299 -static inline __u32 xfs_do_div(void *a, __u32 b, int n)
68300 +static inline __u32 __intentional_overflow(-1) xfs_do_div(void *a, __u32 b, int n)
68301 {
68302 __u32 mod;
68303
68304 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
68305 new file mode 100644
68306 index 0000000..f27264e
68307 --- /dev/null
68308 +++ b/grsecurity/Kconfig
68309 @@ -0,0 +1,1166 @@
68310 +#
68311 +# grecurity configuration
68312 +#
68313 +menu "Memory Protections"
68314 +depends on GRKERNSEC
68315 +
68316 +config GRKERNSEC_KMEM
68317 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
68318 + default y if GRKERNSEC_CONFIG_AUTO
68319 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
68320 + help
68321 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
68322 + be written to or read from to modify or leak the contents of the running
68323 + kernel. /dev/port will also not be allowed to be opened, writing to
68324 + /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
68325 + If you have module support disabled, enabling this will close up several
68326 + ways that are currently used to insert malicious code into the running
68327 + kernel.
68328 +
68329 + Even with this feature enabled, we still highly recommend that
68330 + you use the RBAC system, as it is still possible for an attacker to
68331 + modify the running kernel through other more obscure methods.
68332 +
68333 + It is highly recommended that you say Y here if you meet all the
68334 + conditions above.
68335 +
68336 +config GRKERNSEC_VM86
68337 + bool "Restrict VM86 mode"
68338 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68339 + depends on X86_32
68340 +
68341 + help
68342 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
68343 + make use of a special execution mode on 32bit x86 processors called
68344 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
68345 + video cards and will still work with this option enabled. The purpose
68346 + of the option is to prevent exploitation of emulation errors in
68347 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
68348 + Nearly all users should be able to enable this option.
68349 +
68350 +config GRKERNSEC_IO
68351 + bool "Disable privileged I/O"
68352 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68353 + depends on X86
68354 + select RTC_CLASS
68355 + select RTC_INTF_DEV
68356 + select RTC_DRV_CMOS
68357 +
68358 + help
68359 + If you say Y here, all ioperm and iopl calls will return an error.
68360 + Ioperm and iopl can be used to modify the running kernel.
68361 + Unfortunately, some programs need this access to operate properly,
68362 + the most notable of which are XFree86 and hwclock. hwclock can be
68363 + remedied by having RTC support in the kernel, so real-time
68364 + clock support is enabled if this option is enabled, to ensure
68365 + that hwclock operates correctly. If hwclock still does not work,
68366 + either update udev or symlink /dev/rtc to /dev/rtc0.
68367 +
68368 + If you're using XFree86 or a version of Xorg from 2012 or earlier,
68369 + you may not be able to boot into a graphical environment with this
68370 + option enabled. In this case, you should use the RBAC system instead.
68371 +
68372 +config GRKERNSEC_BPF_HARDEN
68373 + bool "Harden BPF interpreter"
68374 + default y if GRKERNSEC_CONFIG_AUTO
68375 + help
68376 + Unlike previous versions of grsecurity that hardened both the BPF
68377 + interpreted code against corruption at rest as well as the JIT code
68378 + against JIT-spray attacks and attacker-controlled immediate values
68379 + for ROP, this feature will enforce disabling of the new eBPF JIT engine
68380 + and will ensure the interpreted code is read-only at rest. This feature
68381 + may be removed at a later time when eBPF stabilizes to entirely revert
68382 + back to the more secure pre-3.16 BPF interpreter/JIT.
68383 +
68384 + If you're using KERNEXEC, it's recommended that you enable this option
68385 + to supplement the hardening of the kernel.
68386 +
68387 +config GRKERNSEC_PERF_HARDEN
68388 + bool "Disable unprivileged PERF_EVENTS usage by default"
68389 + default y if GRKERNSEC_CONFIG_AUTO
68390 + depends on PERF_EVENTS
68391 + help
68392 + If you say Y here, the range of acceptable values for the
68393 + /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
68394 + default to a new value: 3. When the sysctl is set to this value, no
68395 + unprivileged use of the PERF_EVENTS syscall interface will be permitted.
68396 +
68397 + Though PERF_EVENTS can be used legitimately for performance monitoring
68398 + and low-level application profiling, it is forced on regardless of
68399 + configuration, has been at fault for several vulnerabilities, and
68400 + creates new opportunities for side channels and other information leaks.
68401 +
68402 + This feature puts PERF_EVENTS into a secure default state and permits
68403 + the administrator to change out of it temporarily if unprivileged
68404 + application profiling is needed.
68405 +
68406 +config GRKERNSEC_RAND_THREADSTACK
68407 + bool "Insert random gaps between thread stacks"
68408 + default y if GRKERNSEC_CONFIG_AUTO
68409 + depends on PAX_RANDMMAP && !PPC
68410 + help
68411 + If you say Y here, a random-sized gap will be enforced between allocated
68412 + thread stacks. Glibc's NPTL and other threading libraries that
68413 + pass MAP_STACK to the kernel for thread stack allocation are supported.
68414 + The implementation currently provides 8 bits of entropy for the gap.
68415 +
68416 + Many distributions do not compile threaded remote services with the
68417 + -fstack-check argument to GCC, causing the variable-sized stack-based
68418 + allocator, alloca(), to not probe the stack on allocation. This
68419 + permits an unbounded alloca() to skip over any guard page and potentially
68420 + modify another thread's stack reliably. An enforced random gap
68421 + reduces the reliability of such an attack and increases the chance
68422 + that such a read/write to another thread's stack instead lands in
68423 + an unmapped area, causing a crash and triggering grsecurity's
68424 + anti-bruteforcing logic.
68425 +
68426 +config GRKERNSEC_PROC_MEMMAP
68427 + bool "Harden ASLR against information leaks and entropy reduction"
68428 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
68429 + depends on PAX_NOEXEC || PAX_ASLR
68430 + help
68431 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
68432 + give no information about the addresses of its mappings if
68433 + PaX features that rely on random addresses are enabled on the task.
68434 + In addition to sanitizing this information and disabling other
68435 + dangerous sources of information, this option causes reads of sensitive
68436 + /proc/<pid> entries where the file descriptor was opened in a different
68437 + task than the one performing the read. Such attempts are logged.
68438 + This option also limits argv/env strings for suid/sgid binaries
68439 + to 512KB to prevent a complete exhaustion of the stack entropy provided
68440 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
68441 + binaries to prevent alternative mmap layouts from being abused.
68442 +
68443 + If you use PaX it is essential that you say Y here as it closes up
68444 + several holes that make full ASLR useless locally.
68445 +
68446 +
68447 +config GRKERNSEC_KSTACKOVERFLOW
68448 + bool "Prevent kernel stack overflows"
68449 + default y if GRKERNSEC_CONFIG_AUTO
68450 + depends on !IA64 && 64BIT
68451 + help
68452 + If you say Y here, the kernel's process stacks will be allocated
68453 + with vmalloc instead of the kernel's default allocator. This
68454 + introduces guard pages that in combination with the alloca checking
68455 + of the STACKLEAK feature prevents all forms of kernel process stack
68456 + overflow abuse. Note that this is different from kernel stack
68457 + buffer overflows.
68458 +
68459 +config GRKERNSEC_BRUTE
68460 + bool "Deter exploit bruteforcing"
68461 + default y if GRKERNSEC_CONFIG_AUTO
68462 + help
68463 + If you say Y here, attempts to bruteforce exploits against forking
68464 + daemons such as apache or sshd, as well as against suid/sgid binaries
68465 + will be deterred. When a child of a forking daemon is killed by PaX
68466 + or crashes due to an illegal instruction or other suspicious signal,
68467 + the parent process will be delayed 30 seconds upon every subsequent
68468 + fork until the administrator is able to assess the situation and
68469 + restart the daemon.
68470 + In the suid/sgid case, the attempt is logged, the user has all their
68471 + existing instances of the suid/sgid binary terminated and will
68472 + be unable to execute any suid/sgid binaries for 15 minutes.
68473 +
68474 + It is recommended that you also enable signal logging in the auditing
68475 + section so that logs are generated when a process triggers a suspicious
68476 + signal.
68477 + If the sysctl option is enabled, a sysctl option with name
68478 + "deter_bruteforce" is created.
68479 +
68480 +config GRKERNSEC_MODHARDEN
68481 + bool "Harden module auto-loading"
68482 + default y if GRKERNSEC_CONFIG_AUTO
68483 + depends on MODULES
68484 + help
68485 + If you say Y here, module auto-loading in response to use of some
68486 + feature implemented by an unloaded module will be restricted to
68487 + root users. Enabling this option helps defend against attacks
68488 + by unprivileged users who abuse the auto-loading behavior to
68489 + cause a vulnerable module to load that is then exploited.
68490 +
68491 + If this option prevents a legitimate use of auto-loading for a
68492 + non-root user, the administrator can execute modprobe manually
68493 + with the exact name of the module mentioned in the alert log.
68494 + Alternatively, the administrator can add the module to the list
68495 + of modules loaded at boot by modifying init scripts.
68496 +
68497 + Modification of init scripts will most likely be needed on
68498 + Ubuntu servers with encrypted home directory support enabled,
68499 + as the first non-root user logging in will cause the ecb(aes),
68500 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
68501 +
68502 +config GRKERNSEC_HIDESYM
68503 + bool "Hide kernel symbols"
68504 + default y if GRKERNSEC_CONFIG_AUTO
68505 + select PAX_USERCOPY_SLABS
68506 + help
68507 + If you say Y here, getting information on loaded modules, and
68508 + displaying all kernel symbols through a syscall will be restricted
68509 + to users with CAP_SYS_MODULE. For software compatibility reasons,
68510 + /proc/kallsyms will be restricted to the root user. The RBAC
68511 + system can hide that entry even from root.
68512 +
68513 + This option also prevents leaking of kernel addresses through
68514 + several /proc entries.
68515 +
68516 + Note that this option is only effective provided the following
68517 + conditions are met:
68518 + 1) The kernel using grsecurity is not precompiled by some distribution
68519 + 2) You have also enabled GRKERNSEC_DMESG
68520 + 3) You are using the RBAC system and hiding other files such as your
68521 + kernel image and System.map. Alternatively, enabling this option
68522 + causes the permissions on /boot, /lib/modules, and the kernel
68523 + source directory to change at compile time to prevent
68524 + reading by non-root users.
68525 + If the above conditions are met, this option will aid in providing a
68526 + useful protection against local kernel exploitation of overflows
68527 + and arbitrary read/write vulnerabilities.
68528 +
68529 + It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
68530 + in addition to this feature.
68531 +
68532 +config GRKERNSEC_RANDSTRUCT
68533 + bool "Randomize layout of sensitive kernel structures"
68534 + default y if GRKERNSEC_CONFIG_AUTO
68535 + select GRKERNSEC_HIDESYM
68536 + select MODVERSIONS if MODULES
68537 + help
68538 + If you say Y here, the layouts of a number of sensitive kernel
68539 + structures (task, fs, cred, etc) and all structures composed entirely
68540 + of function pointers (aka "ops" structs) will be randomized at compile-time.
68541 + This can introduce the requirement of an additional infoleak
68542 + vulnerability for exploits targeting these structure types.
68543 +
68544 + Enabling this feature will introduce some performance impact, slightly
68545 + increase memory usage, and prevent the use of forensic tools like
68546 + Volatility against the system (unless the kernel source tree isn't
68547 + cleaned after kernel installation).
68548 +
68549 + The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
68550 + It remains after a make clean to allow for external modules to be compiled
68551 + with the existing seed and will be removed by a make mrproper or
68552 + make distclean.
68553 +
68554 + Note that the implementation requires gcc 4.6.4. or newer. You may need
68555 + to install the supporting headers explicitly in addition to the normal
68556 + gcc package.
68557 +
68558 +config GRKERNSEC_RANDSTRUCT_PERFORMANCE
68559 + bool "Use cacheline-aware structure randomization"
68560 + depends on GRKERNSEC_RANDSTRUCT
68561 + default y if GRKERNSEC_CONFIG_PRIORITY_PERF
68562 + help
68563 + If you say Y here, the RANDSTRUCT randomization will make a best effort
68564 + at restricting randomization to cacheline-sized groups of elements. It
68565 + will further not randomize bitfields in structures. This reduces the
68566 + performance hit of RANDSTRUCT at the cost of weakened randomization.
68567 +
68568 +config GRKERNSEC_KERN_LOCKOUT
68569 + bool "Active kernel exploit response"
68570 + default y if GRKERNSEC_CONFIG_AUTO
68571 + depends on X86 || ARM || PPC || SPARC
68572 + help
68573 + If you say Y here, when a PaX alert is triggered due to suspicious
68574 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
68575 + or an OOPS occurs due to bad memory accesses, instead of just
68576 + terminating the offending process (and potentially allowing
68577 + a subsequent exploit from the same user), we will take one of two
68578 + actions:
68579 + If the user was root, we will panic the system
68580 + If the user was non-root, we will log the attempt, terminate
68581 + all processes owned by the user, then prevent them from creating
68582 + any new processes until the system is restarted
68583 + This deters repeated kernel exploitation/bruteforcing attempts
68584 + and is useful for later forensics.
68585 +
68586 +config GRKERNSEC_OLD_ARM_USERLAND
68587 + bool "Old ARM userland compatibility"
68588 + depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
68589 + help
68590 + If you say Y here, stubs of executable code to perform such operations
68591 + as "compare-exchange" will be placed at fixed locations in the ARM vector
68592 + table. This is unfortunately needed for old ARM userland meant to run
68593 + across a wide range of processors. Without this option enabled,
68594 + the get_tls and data memory barrier stubs will be emulated by the kernel,
68595 + which is enough for Linaro userlands or other userlands designed for v6
68596 + and newer ARM CPUs. It's recommended that you try without this option enabled
68597 + first, and only enable it if your userland does not boot (it will likely fail
68598 + at init time).
68599 +
68600 +endmenu
68601 +menu "Role Based Access Control Options"
68602 +depends on GRKERNSEC
68603 +
68604 +config GRKERNSEC_RBAC_DEBUG
68605 + bool
68606 +
68607 +config GRKERNSEC_NO_RBAC
68608 + bool "Disable RBAC system"
68609 + help
68610 + If you say Y here, the /dev/grsec device will be removed from the kernel,
68611 + preventing the RBAC system from being enabled. You should only say Y
68612 + here if you have no intention of using the RBAC system, so as to prevent
68613 + an attacker with root access from misusing the RBAC system to hide files
68614 + and processes when loadable module support and /dev/[k]mem have been
68615 + locked down.
68616 +
68617 +config GRKERNSEC_ACL_HIDEKERN
68618 + bool "Hide kernel processes"
68619 + help
68620 + If you say Y here, all kernel threads will be hidden to all
68621 + processes but those whose subject has the "view hidden processes"
68622 + flag.
68623 +
68624 +config GRKERNSEC_ACL_MAXTRIES
68625 + int "Maximum tries before password lockout"
68626 + default 3
68627 + help
68628 + This option enforces the maximum number of times a user can attempt
68629 + to authorize themselves with the grsecurity RBAC system before being
68630 + denied the ability to attempt authorization again for a specified time.
68631 + The lower the number, the harder it will be to brute-force a password.
68632 +
68633 +config GRKERNSEC_ACL_TIMEOUT
68634 + int "Time to wait after max password tries, in seconds"
68635 + default 30
68636 + help
68637 + This option specifies the time the user must wait after attempting to
68638 + authorize to the RBAC system with the maximum number of invalid
68639 + passwords. The higher the number, the harder it will be to brute-force
68640 + a password.
68641 +
68642 +endmenu
68643 +menu "Filesystem Protections"
68644 +depends on GRKERNSEC
68645 +
68646 +config GRKERNSEC_PROC
68647 + bool "Proc restrictions"
68648 + default y if GRKERNSEC_CONFIG_AUTO
68649 + help
68650 + If you say Y here, the permissions of the /proc filesystem
68651 + will be altered to enhance system security and privacy. You MUST
68652 + choose either a user only restriction or a user and group restriction.
68653 + Depending upon the option you choose, you can either restrict users to
68654 + see only the processes they themselves run, or choose a group that can
68655 + view all processes and files normally restricted to root if you choose
68656 + the "restrict to user only" option. NOTE: If you're running identd or
68657 + ntpd as a non-root user, you will have to run it as the group you
68658 + specify here.
68659 +
68660 +config GRKERNSEC_PROC_USER
68661 + bool "Restrict /proc to user only"
68662 + depends on GRKERNSEC_PROC
68663 + help
68664 + If you say Y here, non-root users will only be able to view their own
68665 + processes, and restricts them from viewing network-related information,
68666 + and viewing kernel symbol and module information.
68667 +
68668 +config GRKERNSEC_PROC_USERGROUP
68669 + bool "Allow special group"
68670 + default y if GRKERNSEC_CONFIG_AUTO
68671 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
68672 + help
68673 + If you say Y here, you will be able to select a group that will be
68674 + able to view all processes and network-related information. If you've
68675 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
68676 + remain hidden. This option is useful if you want to run identd as
68677 + a non-root user. The group you select may also be chosen at boot time
68678 + via "grsec_proc_gid=" on the kernel commandline.
68679 +
68680 +config GRKERNSEC_PROC_GID
68681 + int "GID for special group"
68682 + depends on GRKERNSEC_PROC_USERGROUP
68683 + default 1001
68684 +
68685 +config GRKERNSEC_PROC_ADD
68686 + bool "Additional restrictions"
68687 + default y if GRKERNSEC_CONFIG_AUTO
68688 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
68689 + help
68690 + If you say Y here, additional restrictions will be placed on
68691 + /proc that keep normal users from viewing device information and
68692 + slabinfo information that could be useful for exploits.
68693 +
68694 +config GRKERNSEC_LINK
68695 + bool "Linking restrictions"
68696 + default y if GRKERNSEC_CONFIG_AUTO
68697 + help
68698 + If you say Y here, /tmp race exploits will be prevented, since users
68699 + will no longer be able to follow symlinks owned by other users in
68700 + world-writable +t directories (e.g. /tmp), unless the owner of the
68701 + symlink is the owner of the directory. users will also not be
68702 + able to hardlink to files they do not own. If the sysctl option is
68703 + enabled, a sysctl option with name "linking_restrictions" is created.
68704 +
68705 +config GRKERNSEC_SYMLINKOWN
68706 + bool "Kernel-enforced SymlinksIfOwnerMatch"
68707 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
68708 + help
68709 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
68710 + that prevents it from being used as a security feature. As Apache
68711 + verifies the symlink by performing a stat() against the target of
68712 + the symlink before it is followed, an attacker can setup a symlink
68713 + to point to a same-owned file, then replace the symlink with one
68714 + that targets another user's file just after Apache "validates" the
68715 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
68716 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
68717 + will be in place for the group you specify. If the sysctl option
68718 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
68719 + created.
68720 +
68721 +config GRKERNSEC_SYMLINKOWN_GID
68722 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
68723 + depends on GRKERNSEC_SYMLINKOWN
68724 + default 1006
68725 + help
68726 + Setting this GID determines what group kernel-enforced
68727 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
68728 + is enabled, a sysctl option with name "symlinkown_gid" is created.
68729 +
68730 +config GRKERNSEC_FIFO
68731 + bool "FIFO restrictions"
68732 + default y if GRKERNSEC_CONFIG_AUTO
68733 + help
68734 + If you say Y here, users will not be able to write to FIFOs they don't
68735 + own in world-writable +t directories (e.g. /tmp), unless the owner of
68736 + the FIFO is the same owner of the directory it's held in. If the sysctl
68737 + option is enabled, a sysctl option with name "fifo_restrictions" is
68738 + created.
68739 +
68740 +config GRKERNSEC_SYSFS_RESTRICT
68741 + bool "Sysfs/debugfs restriction"
68742 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68743 + depends on SYSFS
68744 + help
68745 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
68746 + any filesystem normally mounted under it (e.g. debugfs) will be
68747 + mostly accessible only by root. These filesystems generally provide access
68748 + to hardware and debug information that isn't appropriate for unprivileged
68749 + users of the system. Sysfs and debugfs have also become a large source
68750 + of new vulnerabilities, ranging from infoleaks to local compromise.
68751 + There has been very little oversight with an eye toward security involved
68752 + in adding new exporters of information to these filesystems, so their
68753 + use is discouraged.
68754 + For reasons of compatibility, a few directories have been whitelisted
68755 + for access by non-root users:
68756 + /sys/fs/selinux
68757 + /sys/fs/fuse
68758 + /sys/devices/system/cpu
68759 +
68760 +config GRKERNSEC_ROFS
68761 + bool "Runtime read-only mount protection"
68762 + depends on SYSCTL
68763 + help
68764 + If you say Y here, a sysctl option with name "romount_protect" will
68765 + be created. By setting this option to 1 at runtime, filesystems
68766 + will be protected in the following ways:
68767 + * No new writable mounts will be allowed
68768 + * Existing read-only mounts won't be able to be remounted read/write
68769 + * Write operations will be denied on all block devices
68770 + This option acts independently of grsec_lock: once it is set to 1,
68771 + it cannot be turned off. Therefore, please be mindful of the resulting
68772 + behavior if this option is enabled in an init script on a read-only
68773 + filesystem.
68774 + Also be aware that as with other root-focused features, GRKERNSEC_KMEM
68775 + and GRKERNSEC_IO should be enabled and module loading disabled via
68776 + config or at runtime.
68777 + This feature is mainly intended for secure embedded systems.
68778 +
68779 +
68780 +config GRKERNSEC_DEVICE_SIDECHANNEL
68781 + bool "Eliminate stat/notify-based device sidechannels"
68782 + default y if GRKERNSEC_CONFIG_AUTO
68783 + help
68784 + If you say Y here, timing analyses on block or character
68785 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
68786 + will be thwarted for unprivileged users. If a process without
68787 + CAP_MKNOD stats such a device, the last access and last modify times
68788 + will match the device's create time. No access or modify events
68789 + will be triggered through inotify/dnotify/fanotify for such devices.
68790 + This feature will prevent attacks that may at a minimum
68791 + allow an attacker to determine the administrator's password length.
68792 +
68793 +config GRKERNSEC_CHROOT
68794 + bool "Chroot jail restrictions"
68795 + default y if GRKERNSEC_CONFIG_AUTO
68796 + help
68797 + If you say Y here, you will be able to choose several options that will
68798 + make breaking out of a chrooted jail much more difficult. If you
68799 + encounter no software incompatibilities with the following options, it
68800 + is recommended that you enable each one.
68801 +
68802 + Note that the chroot restrictions are not intended to apply to "chroots"
68803 + to directories that are simple bind mounts of the global root filesystem.
68804 + For several other reasons, a user shouldn't expect any significant
68805 + security by performing such a chroot.
68806 +
68807 +config GRKERNSEC_CHROOT_MOUNT
68808 + bool "Deny mounts"
68809 + default y if GRKERNSEC_CONFIG_AUTO
68810 + depends on GRKERNSEC_CHROOT
68811 + help
68812 + If you say Y here, processes inside a chroot will not be able to
68813 + mount or remount filesystems. If the sysctl option is enabled, a
68814 + sysctl option with name "chroot_deny_mount" is created.
68815 +
68816 +config GRKERNSEC_CHROOT_DOUBLE
68817 + bool "Deny double-chroots"
68818 + default y if GRKERNSEC_CONFIG_AUTO
68819 + depends on GRKERNSEC_CHROOT
68820 + help
68821 + If you say Y here, processes inside a chroot will not be able to chroot
68822 + again outside the chroot. This is a widely used method of breaking
68823 + out of a chroot jail and should not be allowed. If the sysctl
68824 + option is enabled, a sysctl option with name
68825 + "chroot_deny_chroot" is created.
68826 +
68827 +config GRKERNSEC_CHROOT_PIVOT
68828 + bool "Deny pivot_root in chroot"
68829 + default y if GRKERNSEC_CONFIG_AUTO
68830 + depends on GRKERNSEC_CHROOT
68831 + help
68832 + If you say Y here, processes inside a chroot will not be able to use
68833 + a function called pivot_root() that was introduced in Linux 2.3.41. It
68834 + works similar to chroot in that it changes the root filesystem. This
68835 + function could be misused in a chrooted process to attempt to break out
68836 + of the chroot, and therefore should not be allowed. If the sysctl
68837 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
68838 + created.
68839 +
68840 +config GRKERNSEC_CHROOT_CHDIR
68841 + bool "Enforce chdir(\"/\") on all chroots"
68842 + default y if GRKERNSEC_CONFIG_AUTO
68843 + depends on GRKERNSEC_CHROOT
68844 + help
68845 + If you say Y here, the current working directory of all newly-chrooted
68846 + applications will be set to the the root directory of the chroot.
68847 + The man page on chroot(2) states:
68848 + Note that this call does not change the current working
68849 + directory, so that `.' can be outside the tree rooted at
68850 + `/'. In particular, the super-user can escape from a
68851 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
68852 +
68853 + It is recommended that you say Y here, since it's not known to break
68854 + any software. If the sysctl option is enabled, a sysctl option with
68855 + name "chroot_enforce_chdir" is created.
68856 +
68857 +config GRKERNSEC_CHROOT_CHMOD
68858 + bool "Deny (f)chmod +s"
68859 + default y if GRKERNSEC_CONFIG_AUTO
68860 + depends on GRKERNSEC_CHROOT
68861 + help
68862 + If you say Y here, processes inside a chroot will not be able to chmod
68863 + or fchmod files to make them have suid or sgid bits. This protects
68864 + against another published method of breaking a chroot. If the sysctl
68865 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
68866 + created.
68867 +
68868 +config GRKERNSEC_CHROOT_FCHDIR
68869 + bool "Deny fchdir and fhandle out of chroot"
68870 + default y if GRKERNSEC_CONFIG_AUTO
68871 + depends on GRKERNSEC_CHROOT
68872 + help
68873 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
68874 + to a file descriptor of the chrooting process that points to a directory
68875 + outside the filesystem will be stopped. Additionally, this option prevents
68876 + use of the recently-created syscall for opening files by a guessable "file
68877 + handle" inside a chroot. If the sysctl option is enabled, a sysctl option
68878 + with name "chroot_deny_fchdir" is created.
68879 +
68880 +config GRKERNSEC_CHROOT_MKNOD
68881 + bool "Deny mknod"
68882 + default y if GRKERNSEC_CONFIG_AUTO
68883 + depends on GRKERNSEC_CHROOT
68884 + help
68885 + If you say Y here, processes inside a chroot will not be allowed to
68886 + mknod. The problem with using mknod inside a chroot is that it
68887 + would allow an attacker to create a device entry that is the same
68888 + as one on the physical root of your system, which could range from
68889 + anything from the console device to a device for your harddrive (which
68890 + they could then use to wipe the drive or steal data). It is recommended
68891 + that you say Y here, unless you run into software incompatibilities.
68892 + If the sysctl option is enabled, a sysctl option with name
68893 + "chroot_deny_mknod" is created.
68894 +
68895 +config GRKERNSEC_CHROOT_SHMAT
68896 + bool "Deny shmat() out of chroot"
68897 + default y if GRKERNSEC_CONFIG_AUTO
68898 + depends on GRKERNSEC_CHROOT
68899 + help
68900 + If you say Y here, processes inside a chroot will not be able to attach
68901 + to shared memory segments that were created outside of the chroot jail.
68902 + It is recommended that you say Y here. If the sysctl option is enabled,
68903 + a sysctl option with name "chroot_deny_shmat" is created.
68904 +
68905 +config GRKERNSEC_CHROOT_UNIX
68906 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
68907 + default y if GRKERNSEC_CONFIG_AUTO
68908 + depends on GRKERNSEC_CHROOT
68909 + help
68910 + If you say Y here, processes inside a chroot will not be able to
68911 + connect to abstract (meaning not belonging to a filesystem) Unix
68912 + domain sockets that were bound outside of a chroot. It is recommended
68913 + that you say Y here. If the sysctl option is enabled, a sysctl option
68914 + with name "chroot_deny_unix" is created.
68915 +
68916 +config GRKERNSEC_CHROOT_FINDTASK
68917 + bool "Protect outside processes"
68918 + default y if GRKERNSEC_CONFIG_AUTO
68919 + depends on GRKERNSEC_CHROOT
68920 + help
68921 + If you say Y here, processes inside a chroot will not be able to
68922 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
68923 + getsid, or view any process outside of the chroot. If the sysctl
68924 + option is enabled, a sysctl option with name "chroot_findtask" is
68925 + created.
68926 +
68927 +config GRKERNSEC_CHROOT_NICE
68928 + bool "Restrict priority changes"
68929 + default y if GRKERNSEC_CONFIG_AUTO
68930 + depends on GRKERNSEC_CHROOT
68931 + help
68932 + If you say Y here, processes inside a chroot will not be able to raise
68933 + the priority of processes in the chroot, or alter the priority of
68934 + processes outside the chroot. This provides more security than simply
68935 + removing CAP_SYS_NICE from the process' capability set. If the
68936 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
68937 + is created.
68938 +
68939 +config GRKERNSEC_CHROOT_SYSCTL
68940 + bool "Deny sysctl writes"
68941 + default y if GRKERNSEC_CONFIG_AUTO
68942 + depends on GRKERNSEC_CHROOT
68943 + help
68944 + If you say Y here, an attacker in a chroot will not be able to
68945 + write to sysctl entries, either by sysctl(2) or through a /proc
68946 + interface. It is strongly recommended that you say Y here. If the
68947 + sysctl option is enabled, a sysctl option with name
68948 + "chroot_deny_sysctl" is created.
68949 +
68950 +config GRKERNSEC_CHROOT_CAPS
68951 + bool "Capability restrictions"
68952 + default y if GRKERNSEC_CONFIG_AUTO
68953 + depends on GRKERNSEC_CHROOT
68954 + help
68955 + If you say Y here, the capabilities on all processes within a
68956 + chroot jail will be lowered to stop module insertion, raw i/o,
68957 + system and net admin tasks, rebooting the system, modifying immutable
68958 + files, modifying IPC owned by another, and changing the system time.
68959 + This is left an option because it can break some apps. Disable this
68960 + if your chrooted apps are having problems performing those kinds of
68961 + tasks. If the sysctl option is enabled, a sysctl option with
68962 + name "chroot_caps" is created.
68963 +
68964 +config GRKERNSEC_CHROOT_INITRD
68965 + bool "Exempt initrd tasks from restrictions"
68966 + default y if GRKERNSEC_CONFIG_AUTO
68967 + depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
68968 + help
68969 + If you say Y here, tasks started prior to init will be exempted from
68970 + grsecurity's chroot restrictions. This option is mainly meant to
68971 + resolve Plymouth's performing privileged operations unnecessarily
68972 + in a chroot.
68973 +
68974 +endmenu
68975 +menu "Kernel Auditing"
68976 +depends on GRKERNSEC
68977 +
68978 +config GRKERNSEC_AUDIT_GROUP
68979 + bool "Single group for auditing"
68980 + help
68981 + If you say Y here, the exec and chdir logging features will only operate
68982 + on a group you specify. This option is recommended if you only want to
68983 + watch certain users instead of having a large amount of logs from the
68984 + entire system. If the sysctl option is enabled, a sysctl option with
68985 + name "audit_group" is created.
68986 +
68987 +config GRKERNSEC_AUDIT_GID
68988 + int "GID for auditing"
68989 + depends on GRKERNSEC_AUDIT_GROUP
68990 + default 1007
68991 +
68992 +config GRKERNSEC_EXECLOG
68993 + bool "Exec logging"
68994 + help
68995 + If you say Y here, all execve() calls will be logged (since the
68996 + other exec*() calls are frontends to execve(), all execution
68997 + will be logged). Useful for shell-servers that like to keep track
68998 + of their users. If the sysctl option is enabled, a sysctl option with
68999 + name "exec_logging" is created.
69000 + WARNING: This option when enabled will produce a LOT of logs, especially
69001 + on an active system.
69002 +
69003 +config GRKERNSEC_RESLOG
69004 + bool "Resource logging"
69005 + default y if GRKERNSEC_CONFIG_AUTO
69006 + help
69007 + If you say Y here, all attempts to overstep resource limits will
69008 + be logged with the resource name, the requested size, and the current
69009 + limit. It is highly recommended that you say Y here. If the sysctl
69010 + option is enabled, a sysctl option with name "resource_logging" is
69011 + created. If the RBAC system is enabled, the sysctl value is ignored.
69012 +
69013 +config GRKERNSEC_CHROOT_EXECLOG
69014 + bool "Log execs within chroot"
69015 + help
69016 + If you say Y here, all executions inside a chroot jail will be logged
69017 + to syslog. This can cause a large amount of logs if certain
69018 + applications (eg. djb's daemontools) are installed on the system, and
69019 + is therefore left as an option. If the sysctl option is enabled, a
69020 + sysctl option with name "chroot_execlog" is created.
69021 +
69022 +config GRKERNSEC_AUDIT_PTRACE
69023 + bool "Ptrace logging"
69024 + help
69025 + If you say Y here, all attempts to attach to a process via ptrace
69026 + will be logged. If the sysctl option is enabled, a sysctl option
69027 + with name "audit_ptrace" is created.
69028 +
69029 +config GRKERNSEC_AUDIT_CHDIR
69030 + bool "Chdir logging"
69031 + help
69032 + If you say Y here, all chdir() calls will be logged. If the sysctl
69033 + option is enabled, a sysctl option with name "audit_chdir" is created.
69034 +
69035 +config GRKERNSEC_AUDIT_MOUNT
69036 + bool "(Un)Mount logging"
69037 + help
69038 + If you say Y here, all mounts and unmounts will be logged. If the
69039 + sysctl option is enabled, a sysctl option with name "audit_mount" is
69040 + created.
69041 +
69042 +config GRKERNSEC_SIGNAL
69043 + bool "Signal logging"
69044 + default y if GRKERNSEC_CONFIG_AUTO
69045 + help
69046 + If you say Y here, certain important signals will be logged, such as
69047 + SIGSEGV, which will as a result inform you of when a error in a program
69048 + occurred, which in some cases could mean a possible exploit attempt.
69049 + If the sysctl option is enabled, a sysctl option with name
69050 + "signal_logging" is created.
69051 +
69052 +config GRKERNSEC_FORKFAIL
69053 + bool "Fork failure logging"
69054 + help
69055 + If you say Y here, all failed fork() attempts will be logged.
69056 + This could suggest a fork bomb, or someone attempting to overstep
69057 + their process limit. If the sysctl option is enabled, a sysctl option
69058 + with name "forkfail_logging" is created.
69059 +
69060 +config GRKERNSEC_TIME
69061 + bool "Time change logging"
69062 + default y if GRKERNSEC_CONFIG_AUTO
69063 + help
69064 + If you say Y here, any changes of the system clock will be logged.
69065 + If the sysctl option is enabled, a sysctl option with name
69066 + "timechange_logging" is created.
69067 +
69068 +config GRKERNSEC_PROC_IPADDR
69069 + bool "/proc/<pid>/ipaddr support"
69070 + default y if GRKERNSEC_CONFIG_AUTO
69071 + help
69072 + If you say Y here, a new entry will be added to each /proc/<pid>
69073 + directory that contains the IP address of the person using the task.
69074 + The IP is carried across local TCP and AF_UNIX stream sockets.
69075 + This information can be useful for IDS/IPSes to perform remote response
69076 + to a local attack. The entry is readable by only the owner of the
69077 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
69078 + the RBAC system), and thus does not create privacy concerns.
69079 +
69080 +config GRKERNSEC_RWXMAP_LOG
69081 + bool 'Denied RWX mmap/mprotect logging'
69082 + default y if GRKERNSEC_CONFIG_AUTO
69083 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
69084 + help
69085 + If you say Y here, calls to mmap() and mprotect() with explicit
69086 + usage of PROT_WRITE and PROT_EXEC together will be logged when
69087 + denied by the PAX_MPROTECT feature. This feature will also
69088 + log other problematic scenarios that can occur when PAX_MPROTECT
69089 + is enabled on a binary, like textrels and PT_GNU_STACK. If the
69090 + sysctl option is enabled, a sysctl option with name "rwxmap_logging"
69091 + is created.
69092 +
69093 +endmenu
69094 +
69095 +menu "Executable Protections"
69096 +depends on GRKERNSEC
69097 +
69098 +config GRKERNSEC_DMESG
69099 + bool "Dmesg(8) restriction"
69100 + default y if GRKERNSEC_CONFIG_AUTO
69101 + help
69102 + If you say Y here, non-root users will not be able to use dmesg(8)
69103 + to view the contents of the kernel's circular log buffer.
69104 + The kernel's log buffer often contains kernel addresses and other
69105 + identifying information useful to an attacker in fingerprinting a
69106 + system for a targeted exploit.
69107 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
69108 + created.
69109 +
69110 +config GRKERNSEC_HARDEN_PTRACE
69111 + bool "Deter ptrace-based process snooping"
69112 + default y if GRKERNSEC_CONFIG_AUTO
69113 + help
69114 + If you say Y here, TTY sniffers and other malicious monitoring
69115 + programs implemented through ptrace will be defeated. If you
69116 + have been using the RBAC system, this option has already been
69117 + enabled for several years for all users, with the ability to make
69118 + fine-grained exceptions.
69119 +
69120 + This option only affects the ability of non-root users to ptrace
69121 + processes that are not a descendent of the ptracing process.
69122 + This means that strace ./binary and gdb ./binary will still work,
69123 + but attaching to arbitrary processes will not. If the sysctl
69124 + option is enabled, a sysctl option with name "harden_ptrace" is
69125 + created.
69126 +
69127 +config GRKERNSEC_PTRACE_READEXEC
69128 + bool "Require read access to ptrace sensitive binaries"
69129 + default y if GRKERNSEC_CONFIG_AUTO
69130 + help
69131 + If you say Y here, unprivileged users will not be able to ptrace unreadable
69132 + binaries. This option is useful in environments that
69133 + remove the read bits (e.g. file mode 4711) from suid binaries to
69134 + prevent infoleaking of their contents. This option adds
69135 + consistency to the use of that file mode, as the binary could normally
69136 + be read out when run without privileges while ptracing.
69137 +
69138 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
69139 + is created.
69140 +
69141 +config GRKERNSEC_SETXID
69142 + bool "Enforce consistent multithreaded privileges"
69143 + default y if GRKERNSEC_CONFIG_AUTO
69144 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
69145 + help
69146 + If you say Y here, a change from a root uid to a non-root uid
69147 + in a multithreaded application will cause the resulting uids,
69148 + gids, supplementary groups, and capabilities in that thread
69149 + to be propagated to the other threads of the process. In most
69150 + cases this is unnecessary, as glibc will emulate this behavior
69151 + on behalf of the application. Other libcs do not act in the
69152 + same way, allowing the other threads of the process to continue
69153 + running with root privileges. If the sysctl option is enabled,
69154 + a sysctl option with name "consistent_setxid" is created.
69155 +
69156 +config GRKERNSEC_HARDEN_IPC
69157 + bool "Disallow access to overly-permissive IPC objects"
69158 + default y if GRKERNSEC_CONFIG_AUTO
69159 + depends on SYSVIPC
69160 + help
69161 + If you say Y here, access to overly-permissive IPC objects (shared
69162 + memory, message queues, and semaphores) will be denied for processes
69163 + given the following criteria beyond normal permission checks:
69164 + 1) If the IPC object is world-accessible and the euid doesn't match
69165 + that of the creator or current uid for the IPC object
69166 + 2) If the IPC object is group-accessible and the egid doesn't
69167 + match that of the creator or current gid for the IPC object
69168 + It's a common error to grant too much permission to these objects,
69169 + with impact ranging from denial of service and information leaking to
69170 + privilege escalation. This feature was developed in response to
69171 + research by Tim Brown:
69172 + http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
69173 + who found hundreds of such insecure usages. Processes with
69174 + CAP_IPC_OWNER are still permitted to access these IPC objects.
69175 + If the sysctl option is enabled, a sysctl option with name
69176 + "harden_ipc" is created.
69177 +
69178 +config GRKERNSEC_TPE
69179 + bool "Trusted Path Execution (TPE)"
69180 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
69181 + help
69182 + If you say Y here, you will be able to choose a gid to add to the
69183 + supplementary groups of users you want to mark as "untrusted."
69184 + These users will not be able to execute any files that are not in
69185 + root-owned directories writable only by root. If the sysctl option
69186 + is enabled, a sysctl option with name "tpe" is created.
69187 +
69188 +config GRKERNSEC_TPE_ALL
69189 + bool "Partially restrict all non-root users"
69190 + depends on GRKERNSEC_TPE
69191 + help
69192 + If you say Y here, all non-root users will be covered under
69193 + a weaker TPE restriction. This is separate from, and in addition to,
69194 + the main TPE options that you have selected elsewhere. Thus, if a
69195 + "trusted" GID is chosen, this restriction applies to even that GID.
69196 + Under this restriction, all non-root users will only be allowed to
69197 + execute files in directories they own that are not group or
69198 + world-writable, or in directories owned by root and writable only by
69199 + root. If the sysctl option is enabled, a sysctl option with name
69200 + "tpe_restrict_all" is created.
69201 +
69202 +config GRKERNSEC_TPE_INVERT
69203 + bool "Invert GID option"
69204 + depends on GRKERNSEC_TPE
69205 + help
69206 + If you say Y here, the group you specify in the TPE configuration will
69207 + decide what group TPE restrictions will be *disabled* for. This
69208 + option is useful if you want TPE restrictions to be applied to most
69209 + users on the system. If the sysctl option is enabled, a sysctl option
69210 + with name "tpe_invert" is created. Unlike other sysctl options, this
69211 + entry will default to on for backward-compatibility.
69212 +
69213 +config GRKERNSEC_TPE_GID
69214 + int
69215 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
69216 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
69217 +
69218 +config GRKERNSEC_TPE_UNTRUSTED_GID
69219 + int "GID for TPE-untrusted users"
69220 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
69221 + default 1005
69222 + help
69223 + Setting this GID determines what group TPE restrictions will be
69224 + *enabled* for. If the sysctl option is enabled, a sysctl option
69225 + with name "tpe_gid" is created.
69226 +
69227 +config GRKERNSEC_TPE_TRUSTED_GID
69228 + int "GID for TPE-trusted users"
69229 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
69230 + default 1005
69231 + help
69232 + Setting this GID determines what group TPE restrictions will be
69233 + *disabled* for. If the sysctl option is enabled, a sysctl option
69234 + with name "tpe_gid" is created.
69235 +
69236 +endmenu
69237 +menu "Network Protections"
69238 +depends on GRKERNSEC
69239 +
69240 +config GRKERNSEC_BLACKHOLE
69241 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
69242 + default y if GRKERNSEC_CONFIG_AUTO
69243 + depends on NET
69244 + help
69245 + If you say Y here, neither TCP resets nor ICMP
69246 + destination-unreachable packets will be sent in response to packets
69247 + sent to ports for which no associated listening process exists.
69248 + It will also prevent the sending of ICMP protocol unreachable packets
69249 + in response to packets with unknown protocols.
69250 + This feature supports both IPV4 and IPV6 and exempts the
69251 + loopback interface from blackholing. Enabling this feature
69252 + makes a host more resilient to DoS attacks and reduces network
69253 + visibility against scanners.
69254 +
69255 + The blackhole feature as-implemented is equivalent to the FreeBSD
69256 + blackhole feature, as it prevents RST responses to all packets, not
69257 + just SYNs. Under most application behavior this causes no
69258 + problems, but applications (like haproxy) may not close certain
69259 + connections in a way that cleanly terminates them on the remote
69260 + end, leaving the remote host in LAST_ACK state. Because of this
69261 + side-effect and to prevent intentional LAST_ACK DoSes, this
69262 + feature also adds automatic mitigation against such attacks.
69263 + The mitigation drastically reduces the amount of time a socket
69264 + can spend in LAST_ACK state. If you're using haproxy and not
69265 + all servers it connects to have this option enabled, consider
69266 + disabling this feature on the haproxy host.
69267 +
69268 + If the sysctl option is enabled, two sysctl options with names
69269 + "ip_blackhole" and "lastack_retries" will be created.
69270 + While "ip_blackhole" takes the standard zero/non-zero on/off
69271 + toggle, "lastack_retries" uses the same kinds of values as
69272 + "tcp_retries1" and "tcp_retries2". The default value of 4
69273 + prevents a socket from lasting more than 45 seconds in LAST_ACK
69274 + state.
69275 +
69276 +config GRKERNSEC_NO_SIMULT_CONNECT
69277 + bool "Disable TCP Simultaneous Connect"
69278 + default y if GRKERNSEC_CONFIG_AUTO
69279 + depends on NET
69280 + help
69281 + If you say Y here, a feature by Willy Tarreau will be enabled that
69282 + removes a weakness in Linux's strict implementation of TCP that
69283 + allows two clients to connect to each other without either entering
69284 + a listening state. The weakness allows an attacker to easily prevent
69285 + a client from connecting to a known server provided the source port
69286 + for the connection is guessed correctly.
69287 +
69288 + As the weakness could be used to prevent an antivirus or IPS from
69289 + fetching updates, or prevent an SSL gateway from fetching a CRL,
69290 + it should be eliminated by enabling this option. Though Linux is
69291 + one of few operating systems supporting simultaneous connect, it
69292 + has no legitimate use in practice and is rarely supported by firewalls.
69293 +
69294 +config GRKERNSEC_SOCKET
69295 + bool "Socket restrictions"
69296 + depends on NET
69297 + help
69298 + If you say Y here, you will be able to choose from several options.
69299 + If you assign a GID on your system and add it to the supplementary
69300 + groups of users you want to restrict socket access to, this patch
69301 + will perform up to three things, based on the option(s) you choose.
69302 +
69303 +config GRKERNSEC_SOCKET_ALL
69304 + bool "Deny any sockets to group"
69305 + depends on GRKERNSEC_SOCKET
69306 + help
69307 + If you say Y here, you will be able to choose a GID of whose users will
69308 + be unable to connect to other hosts from your machine or run server
69309 + applications from your machine. If the sysctl option is enabled, a
69310 + sysctl option with name "socket_all" is created.
69311 +
69312 +config GRKERNSEC_SOCKET_ALL_GID
69313 + int "GID to deny all sockets for"
69314 + depends on GRKERNSEC_SOCKET_ALL
69315 + default 1004
69316 + help
69317 + Here you can choose the GID to disable socket access for. Remember to
69318 + add the users you want socket access disabled for to the GID
69319 + specified here. If the sysctl option is enabled, a sysctl option
69320 + with name "socket_all_gid" is created.
69321 +
69322 +config GRKERNSEC_SOCKET_CLIENT
69323 + bool "Deny client sockets to group"
69324 + depends on GRKERNSEC_SOCKET
69325 + help
69326 + If you say Y here, you will be able to choose a GID of whose users will
69327 + be unable to connect to other hosts from your machine, but will be
69328 + able to run servers. If this option is enabled, all users in the group
69329 + you specify will have to use passive mode when initiating ftp transfers
69330 + from the shell on your machine. If the sysctl option is enabled, a
69331 + sysctl option with name "socket_client" is created.
69332 +
69333 +config GRKERNSEC_SOCKET_CLIENT_GID
69334 + int "GID to deny client sockets for"
69335 + depends on GRKERNSEC_SOCKET_CLIENT
69336 + default 1003
69337 + help
69338 + Here you can choose the GID to disable client socket access for.
69339 + Remember to add the users you want client socket access disabled for to
69340 + the GID specified here. If the sysctl option is enabled, a sysctl
69341 + option with name "socket_client_gid" is created.
69342 +
69343 +config GRKERNSEC_SOCKET_SERVER
69344 + bool "Deny server sockets to group"
69345 + depends on GRKERNSEC_SOCKET
69346 + help
69347 + If you say Y here, you will be able to choose a GID of whose users will
69348 + be unable to run server applications from your machine. If the sysctl
69349 + option is enabled, a sysctl option with name "socket_server" is created.
69350 +
69351 +config GRKERNSEC_SOCKET_SERVER_GID
69352 + int "GID to deny server sockets for"
69353 + depends on GRKERNSEC_SOCKET_SERVER
69354 + default 1002
69355 + help
69356 + Here you can choose the GID to disable server socket access for.
69357 + Remember to add the users you want server socket access disabled for to
69358 + the GID specified here. If the sysctl option is enabled, a sysctl
69359 + option with name "socket_server_gid" is created.
69360 +
69361 +endmenu
69362 +
69363 +menu "Physical Protections"
69364 +depends on GRKERNSEC
69365 +
69366 +config GRKERNSEC_DENYUSB
69367 + bool "Deny new USB connections after toggle"
69368 + default y if GRKERNSEC_CONFIG_AUTO
69369 + depends on SYSCTL && USB_SUPPORT
69370 + help
69371 + If you say Y here, a new sysctl option with name "deny_new_usb"
69372 + will be created. Setting its value to 1 will prevent any new
69373 + USB devices from being recognized by the OS. Any attempted USB
69374 + device insertion will be logged. This option is intended to be
69375 + used against custom USB devices designed to exploit vulnerabilities
69376 + in various USB device drivers.
69377 +
69378 + For greatest effectiveness, this sysctl should be set after any
69379 + relevant init scripts. This option is safe to enable in distros
69380 + as each user can choose whether or not to toggle the sysctl.
69381 +
69382 +config GRKERNSEC_DENYUSB_FORCE
69383 + bool "Reject all USB devices not connected at boot"
69384 + select USB
69385 + depends on GRKERNSEC_DENYUSB
69386 + help
69387 + If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
69388 + that doesn't involve a sysctl entry. This option should only be
69389 + enabled if you're sure you want to deny all new USB connections
69390 + at runtime and don't want to modify init scripts. This should not
69391 + be enabled by distros. It forces the core USB code to be built
69392 + into the kernel image so that all devices connected at boot time
69393 + can be recognized and new USB device connections can be prevented
69394 + prior to init running.
69395 +
69396 +endmenu
69397 +
69398 +menu "Sysctl Support"
69399 +depends on GRKERNSEC && SYSCTL
69400 +
69401 +config GRKERNSEC_SYSCTL
69402 + bool "Sysctl support"
69403 + default y if GRKERNSEC_CONFIG_AUTO
69404 + help
69405 + If you say Y here, you will be able to change the options that
69406 + grsecurity runs with at bootup, without having to recompile your
69407 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
69408 + to enable (1) or disable (0) various features. All the sysctl entries
69409 + are mutable until the "grsec_lock" entry is set to a non-zero value.
69410 + All features enabled in the kernel configuration are disabled at boot
69411 + if you do not say Y to the "Turn on features by default" option.
69412 + All options should be set at startup, and the grsec_lock entry should
69413 + be set to a non-zero value after all the options are set.
69414 + *THIS IS EXTREMELY IMPORTANT*
69415 +
69416 +config GRKERNSEC_SYSCTL_DISTRO
69417 + bool "Extra sysctl support for distro makers (READ HELP)"
69418 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
69419 + help
69420 + If you say Y here, additional sysctl options will be created
69421 + for features that affect processes running as root. Therefore,
69422 + it is critical when using this option that the grsec_lock entry be
69423 + enabled after boot. Only distros with prebuilt kernel packages
69424 + with this option enabled that can ensure grsec_lock is enabled
69425 + after boot should use this option.
69426 + *Failure to set grsec_lock after boot makes all grsec features
69427 + this option covers useless*
69428 +
69429 + Currently this option creates the following sysctl entries:
69430 + "Disable Privileged I/O": "disable_priv_io"
69431 +
69432 +config GRKERNSEC_SYSCTL_ON
69433 + bool "Turn on features by default"
69434 + default y if GRKERNSEC_CONFIG_AUTO
69435 + depends on GRKERNSEC_SYSCTL
69436 + help
69437 + If you say Y here, instead of having all features enabled in the
69438 + kernel configuration disabled at boot time, the features will be
69439 + enabled at boot time. It is recommended you say Y here unless
69440 + there is some reason you would want all sysctl-tunable features to
69441 + be disabled by default. As mentioned elsewhere, it is important
69442 + to enable the grsec_lock entry once you have finished modifying
69443 + the sysctl entries.
69444 +
69445 +endmenu
69446 +menu "Logging Options"
69447 +depends on GRKERNSEC
69448 +
69449 +config GRKERNSEC_FLOODTIME
69450 + int "Seconds in between log messages (minimum)"
69451 + default 10
69452 + help
69453 + This option allows you to enforce the number of seconds between
69454 + grsecurity log messages. The default should be suitable for most
69455 + people, however, if you choose to change it, choose a value small enough
69456 + to allow informative logs to be produced, but large enough to
69457 + prevent flooding.
69458 +
69459 + Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
69460 + any rate limiting on grsecurity log messages.
69461 +
69462 +config GRKERNSEC_FLOODBURST
69463 + int "Number of messages in a burst (maximum)"
69464 + default 6
69465 + help
69466 + This option allows you to choose the maximum number of messages allowed
69467 + within the flood time interval you chose in a separate option. The
69468 + default should be suitable for most people, however if you find that
69469 + many of your logs are being interpreted as flooding, you may want to
69470 + raise this value.
69471 +
69472 + Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
69473 + any rate limiting on grsecurity log messages.
69474 +
69475 +endmenu
69476 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
69477 new file mode 100644
69478 index 0000000..30ababb
69479 --- /dev/null
69480 +++ b/grsecurity/Makefile
69481 @@ -0,0 +1,54 @@
69482 +# grsecurity – access control and security hardening for Linux
69483 +# All code in this directory and various hooks located throughout the Linux kernel are
69484 +# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
69485 +# http://www.grsecurity.net spender@grsecurity.net
69486 +#
69487 +# This program is free software; you can redistribute it and/or
69488 +# modify it under the terms of the GNU General Public License version 2
69489 +# as published by the Free Software Foundation.
69490 +#
69491 +# This program is distributed in the hope that it will be useful,
69492 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
69493 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
69494 +# GNU General Public License for more details.
69495 +#
69496 +# You should have received a copy of the GNU General Public License
69497 +# along with this program; if not, write to the Free Software
69498 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
69499 +
69500 +KBUILD_CFLAGS += -Werror
69501 +
69502 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
69503 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
69504 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
69505 + grsec_usb.o grsec_ipc.o grsec_proc.o
69506 +
69507 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
69508 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
69509 + gracl_learn.o grsec_log.o gracl_policy.o
69510 +ifdef CONFIG_COMPAT
69511 +obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
69512 +endif
69513 +
69514 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
69515 +
69516 +ifdef CONFIG_NET
69517 +obj-y += grsec_sock.o
69518 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
69519 +endif
69520 +
69521 +ifndef CONFIG_GRKERNSEC
69522 +obj-y += grsec_disabled.o
69523 +endif
69524 +
69525 +ifdef CONFIG_GRKERNSEC_HIDESYM
69526 +extra-y := grsec_hidesym.o
69527 +$(obj)/grsec_hidesym.o:
69528 + @-chmod -f 500 /boot
69529 + @-chmod -f 500 /lib/modules
69530 + @-chmod -f 500 /lib64/modules
69531 + @-chmod -f 500 /lib32/modules
69532 + @-chmod -f 700 .
69533 + @-chmod -f 700 $(objtree)
69534 + @echo ' grsec: protected kernel image paths'
69535 +endif
69536 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
69537 new file mode 100644
69538 index 0000000..6ae3aa0
69539 --- /dev/null
69540 +++ b/grsecurity/gracl.c
69541 @@ -0,0 +1,2703 @@
69542 +#include <linux/kernel.h>
69543 +#include <linux/module.h>
69544 +#include <linux/sched.h>
69545 +#include <linux/mm.h>
69546 +#include <linux/file.h>
69547 +#include <linux/fs.h>
69548 +#include <linux/namei.h>
69549 +#include <linux/mount.h>
69550 +#include <linux/tty.h>
69551 +#include <linux/proc_fs.h>
69552 +#include <linux/lglock.h>
69553 +#include <linux/slab.h>
69554 +#include <linux/vmalloc.h>
69555 +#include <linux/types.h>
69556 +#include <linux/sysctl.h>
69557 +#include <linux/netdevice.h>
69558 +#include <linux/ptrace.h>
69559 +#include <linux/gracl.h>
69560 +#include <linux/gralloc.h>
69561 +#include <linux/security.h>
69562 +#include <linux/grinternal.h>
69563 +#include <linux/pid_namespace.h>
69564 +#include <linux/stop_machine.h>
69565 +#include <linux/fdtable.h>
69566 +#include <linux/percpu.h>
69567 +#include <linux/lglock.h>
69568 +#include <linux/hugetlb.h>
69569 +#include <linux/posix-timers.h>
69570 +#include <linux/prefetch.h>
69571 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
69572 +#include <linux/magic.h>
69573 +#include <linux/pagemap.h>
69574 +#include "../fs/btrfs/async-thread.h"
69575 +#include "../fs/btrfs/ctree.h"
69576 +#include "../fs/btrfs/btrfs_inode.h"
69577 +#endif
69578 +#include "../fs/mount.h"
69579 +
69580 +#include <asm/uaccess.h>
69581 +#include <asm/errno.h>
69582 +#include <asm/mman.h>
69583 +
69584 +#define FOR_EACH_ROLE_START(role) \
69585 + role = running_polstate.role_list; \
69586 + while (role) {
69587 +
69588 +#define FOR_EACH_ROLE_END(role) \
69589 + role = role->prev; \
69590 + }
69591 +
69592 +extern struct path gr_real_root;
69593 +
69594 +static struct gr_policy_state running_polstate;
69595 +struct gr_policy_state *polstate = &running_polstate;
69596 +extern struct gr_alloc_state *current_alloc_state;
69597 +
69598 +extern char *gr_shared_page[4];
69599 +DEFINE_RWLOCK(gr_inode_lock);
69600 +
69601 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
69602 +
69603 +#ifdef CONFIG_NET
69604 +extern struct vfsmount *sock_mnt;
69605 +#endif
69606 +
69607 +extern struct vfsmount *pipe_mnt;
69608 +extern struct vfsmount *shm_mnt;
69609 +
69610 +#ifdef CONFIG_HUGETLBFS
69611 +extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
69612 +#endif
69613 +
69614 +extern u16 acl_sp_role_value;
69615 +extern struct acl_object_label *fakefs_obj_rw;
69616 +extern struct acl_object_label *fakefs_obj_rwx;
69617 +
69618 +int gr_acl_is_enabled(void)
69619 +{
69620 + return (gr_status & GR_READY);
69621 +}
69622 +
69623 +void gr_enable_rbac_system(void)
69624 +{
69625 + pax_open_kernel();
69626 + gr_status |= GR_READY;
69627 + pax_close_kernel();
69628 +}
69629 +
69630 +int gr_rbac_disable(void *unused)
69631 +{
69632 + pax_open_kernel();
69633 + gr_status &= ~GR_READY;
69634 + pax_close_kernel();
69635 +
69636 + return 0;
69637 +}
69638 +
69639 +static inline dev_t __get_dev(const struct dentry *dentry)
69640 +{
69641 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
69642 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
69643 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
69644 + else
69645 +#endif
69646 + return dentry->d_sb->s_dev;
69647 +}
69648 +
69649 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
69650 +{
69651 + return __get_dev(dentry);
69652 +}
69653 +
69654 +static char gr_task_roletype_to_char(struct task_struct *task)
69655 +{
69656 + switch (task->role->roletype &
69657 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
69658 + GR_ROLE_SPECIAL)) {
69659 + case GR_ROLE_DEFAULT:
69660 + return 'D';
69661 + case GR_ROLE_USER:
69662 + return 'U';
69663 + case GR_ROLE_GROUP:
69664 + return 'G';
69665 + case GR_ROLE_SPECIAL:
69666 + return 'S';
69667 + }
69668 +
69669 + return 'X';
69670 +}
69671 +
69672 +char gr_roletype_to_char(void)
69673 +{
69674 + return gr_task_roletype_to_char(current);
69675 +}
69676 +
69677 +__inline__ int
69678 +gr_acl_tpe_check(void)
69679 +{
69680 + if (unlikely(!(gr_status & GR_READY)))
69681 + return 0;
69682 + if (current->role->roletype & GR_ROLE_TPE)
69683 + return 1;
69684 + else
69685 + return 0;
69686 +}
69687 +
69688 +int
69689 +gr_handle_rawio(const struct inode *inode)
69690 +{
69691 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69692 + if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
69693 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
69694 + !capable(CAP_SYS_RAWIO))
69695 + return 1;
69696 +#endif
69697 + return 0;
69698 +}
69699 +
69700 +int
69701 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
69702 +{
69703 + if (likely(lena != lenb))
69704 + return 0;
69705 +
69706 + return !memcmp(a, b, lena);
69707 +}
69708 +
69709 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
69710 +{
69711 + *buflen -= namelen;
69712 + if (*buflen < 0)
69713 + return -ENAMETOOLONG;
69714 + *buffer -= namelen;
69715 + memcpy(*buffer, str, namelen);
69716 + return 0;
69717 +}
69718 +
69719 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
69720 +{
69721 + return prepend(buffer, buflen, name->name, name->len);
69722 +}
69723 +
69724 +static int prepend_path(const struct path *path, struct path *root,
69725 + char **buffer, int *buflen)
69726 +{
69727 + struct dentry *dentry = path->dentry;
69728 + struct vfsmount *vfsmnt = path->mnt;
69729 + struct mount *mnt = real_mount(vfsmnt);
69730 + bool slash = false;
69731 + int error = 0;
69732 +
69733 + while (dentry != root->dentry || vfsmnt != root->mnt) {
69734 + struct dentry * parent;
69735 +
69736 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
69737 + /* Global root? */
69738 + if (!mnt_has_parent(mnt)) {
69739 + goto out;
69740 + }
69741 + dentry = mnt->mnt_mountpoint;
69742 + mnt = mnt->mnt_parent;
69743 + vfsmnt = &mnt->mnt;
69744 + continue;
69745 + }
69746 + parent = dentry->d_parent;
69747 + prefetch(parent);
69748 + spin_lock(&dentry->d_lock);
69749 + error = prepend_name(buffer, buflen, &dentry->d_name);
69750 + spin_unlock(&dentry->d_lock);
69751 + if (!error)
69752 + error = prepend(buffer, buflen, "/", 1);
69753 + if (error)
69754 + break;
69755 +
69756 + slash = true;
69757 + dentry = parent;
69758 + }
69759 +
69760 +out:
69761 + if (!error && !slash)
69762 + error = prepend(buffer, buflen, "/", 1);
69763 +
69764 + return error;
69765 +}
69766 +
69767 +/* this must be called with mount_lock and rename_lock held */
69768 +
69769 +static char *__our_d_path(const struct path *path, struct path *root,
69770 + char *buf, int buflen)
69771 +{
69772 + char *res = buf + buflen;
69773 + int error;
69774 +
69775 + prepend(&res, &buflen, "\0", 1);
69776 + error = prepend_path(path, root, &res, &buflen);
69777 + if (error)
69778 + return ERR_PTR(error);
69779 +
69780 + return res;
69781 +}
69782 +
69783 +static char *
69784 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
69785 +{
69786 + char *retval;
69787 +
69788 + retval = __our_d_path(path, root, buf, buflen);
69789 + if (unlikely(IS_ERR(retval)))
69790 + retval = strcpy(buf, "<path too long>");
69791 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
69792 + retval[1] = '\0';
69793 +
69794 + return retval;
69795 +}
69796 +
69797 +static char *
69798 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
69799 + char *buf, int buflen)
69800 +{
69801 + struct path path;
69802 + char *res;
69803 +
69804 + path.dentry = (struct dentry *)dentry;
69805 + path.mnt = (struct vfsmount *)vfsmnt;
69806 +
69807 + /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
69808 + by the RBAC system */
69809 + res = gen_full_path(&path, &gr_real_root, buf, buflen);
69810 +
69811 + return res;
69812 +}
69813 +
69814 +static char *
69815 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
69816 + char *buf, int buflen)
69817 +{
69818 + char *res;
69819 + struct path path;
69820 + struct path root;
69821 + struct task_struct *reaper = init_pid_ns.child_reaper;
69822 +
69823 + path.dentry = (struct dentry *)dentry;
69824 + path.mnt = (struct vfsmount *)vfsmnt;
69825 +
69826 + /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
69827 + get_fs_root(reaper->fs, &root);
69828 +
69829 + read_seqlock_excl(&mount_lock);
69830 + write_seqlock(&rename_lock);
69831 + res = gen_full_path(&path, &root, buf, buflen);
69832 + write_sequnlock(&rename_lock);
69833 + read_sequnlock_excl(&mount_lock);
69834 +
69835 + path_put(&root);
69836 + return res;
69837 +}
69838 +
69839 +char *
69840 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
69841 +{
69842 + char *ret;
69843 + read_seqlock_excl(&mount_lock);
69844 + write_seqlock(&rename_lock);
69845 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
69846 + PAGE_SIZE);
69847 + write_sequnlock(&rename_lock);
69848 + read_sequnlock_excl(&mount_lock);
69849 + return ret;
69850 +}
69851 +
69852 +static char *
69853 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
69854 +{
69855 + char *ret;
69856 + char *buf;
69857 + int buflen;
69858 +
69859 + read_seqlock_excl(&mount_lock);
69860 + write_seqlock(&rename_lock);
69861 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
69862 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
69863 + buflen = (int)(ret - buf);
69864 + if (buflen >= 5)
69865 + prepend(&ret, &buflen, "/proc", 5);
69866 + else
69867 + ret = strcpy(buf, "<path too long>");
69868 + write_sequnlock(&rename_lock);
69869 + read_sequnlock_excl(&mount_lock);
69870 + return ret;
69871 +}
69872 +
69873 +char *
69874 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
69875 +{
69876 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
69877 + PAGE_SIZE);
69878 +}
69879 +
69880 +char *
69881 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
69882 +{
69883 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
69884 + PAGE_SIZE);
69885 +}
69886 +
69887 +char *
69888 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
69889 +{
69890 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
69891 + PAGE_SIZE);
69892 +}
69893 +
69894 +char *
69895 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
69896 +{
69897 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
69898 + PAGE_SIZE);
69899 +}
69900 +
69901 +char *
69902 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
69903 +{
69904 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
69905 + PAGE_SIZE);
69906 +}
69907 +
69908 +__inline__ __u32
69909 +to_gr_audit(const __u32 reqmode)
69910 +{
69911 + /* masks off auditable permission flags, then shifts them to create
69912 + auditing flags, and adds the special case of append auditing if
69913 + we're requesting write */
69914 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
69915 +}
69916 +
69917 +struct acl_role_label *
69918 +__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
69919 + const gid_t gid)
69920 +{
69921 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
69922 + struct acl_role_label *match;
69923 + struct role_allowed_ip *ipp;
69924 + unsigned int x;
69925 + u32 curr_ip = task->signal->saved_ip;
69926 +
69927 + match = state->acl_role_set.r_hash[index];
69928 +
69929 + while (match) {
69930 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
69931 + for (x = 0; x < match->domain_child_num; x++) {
69932 + if (match->domain_children[x] == uid)
69933 + goto found;
69934 + }
69935 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
69936 + break;
69937 + match = match->next;
69938 + }
69939 +found:
69940 + if (match == NULL) {
69941 + try_group:
69942 + index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
69943 + match = state->acl_role_set.r_hash[index];
69944 +
69945 + while (match) {
69946 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
69947 + for (x = 0; x < match->domain_child_num; x++) {
69948 + if (match->domain_children[x] == gid)
69949 + goto found2;
69950 + }
69951 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
69952 + break;
69953 + match = match->next;
69954 + }
69955 +found2:
69956 + if (match == NULL)
69957 + match = state->default_role;
69958 + if (match->allowed_ips == NULL)
69959 + return match;
69960 + else {
69961 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
69962 + if (likely
69963 + ((ntohl(curr_ip) & ipp->netmask) ==
69964 + (ntohl(ipp->addr) & ipp->netmask)))
69965 + return match;
69966 + }
69967 + match = state->default_role;
69968 + }
69969 + } else if (match->allowed_ips == NULL) {
69970 + return match;
69971 + } else {
69972 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
69973 + if (likely
69974 + ((ntohl(curr_ip) & ipp->netmask) ==
69975 + (ntohl(ipp->addr) & ipp->netmask)))
69976 + return match;
69977 + }
69978 + goto try_group;
69979 + }
69980 +
69981 + return match;
69982 +}
69983 +
69984 +static struct acl_role_label *
69985 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
69986 + const gid_t gid)
69987 +{
69988 + return __lookup_acl_role_label(&running_polstate, task, uid, gid);
69989 +}
69990 +
69991 +struct acl_subject_label *
69992 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
69993 + const struct acl_role_label *role)
69994 +{
69995 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
69996 + struct acl_subject_label *match;
69997 +
69998 + match = role->subj_hash[index];
69999 +
70000 + while (match && (match->inode != ino || match->device != dev ||
70001 + (match->mode & GR_DELETED))) {
70002 + match = match->next;
70003 + }
70004 +
70005 + if (match && !(match->mode & GR_DELETED))
70006 + return match;
70007 + else
70008 + return NULL;
70009 +}
70010 +
70011 +struct acl_subject_label *
70012 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
70013 + const struct acl_role_label *role)
70014 +{
70015 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
70016 + struct acl_subject_label *match;
70017 +
70018 + match = role->subj_hash[index];
70019 +
70020 + while (match && (match->inode != ino || match->device != dev ||
70021 + !(match->mode & GR_DELETED))) {
70022 + match = match->next;
70023 + }
70024 +
70025 + if (match && (match->mode & GR_DELETED))
70026 + return match;
70027 + else
70028 + return NULL;
70029 +}
70030 +
70031 +static struct acl_object_label *
70032 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
70033 + const struct acl_subject_label *subj)
70034 +{
70035 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
70036 + struct acl_object_label *match;
70037 +
70038 + match = subj->obj_hash[index];
70039 +
70040 + while (match && (match->inode != ino || match->device != dev ||
70041 + (match->mode & GR_DELETED))) {
70042 + match = match->next;
70043 + }
70044 +
70045 + if (match && !(match->mode & GR_DELETED))
70046 + return match;
70047 + else
70048 + return NULL;
70049 +}
70050 +
70051 +static struct acl_object_label *
70052 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
70053 + const struct acl_subject_label *subj)
70054 +{
70055 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
70056 + struct acl_object_label *match;
70057 +
70058 + match = subj->obj_hash[index];
70059 +
70060 + while (match && (match->inode != ino || match->device != dev ||
70061 + !(match->mode & GR_DELETED))) {
70062 + match = match->next;
70063 + }
70064 +
70065 + if (match && (match->mode & GR_DELETED))
70066 + return match;
70067 +
70068 + match = subj->obj_hash[index];
70069 +
70070 + while (match && (match->inode != ino || match->device != dev ||
70071 + (match->mode & GR_DELETED))) {
70072 + match = match->next;
70073 + }
70074 +
70075 + if (match && !(match->mode & GR_DELETED))
70076 + return match;
70077 + else
70078 + return NULL;
70079 +}
70080 +
70081 +struct name_entry *
70082 +__lookup_name_entry(const struct gr_policy_state *state, const char *name)
70083 +{
70084 + unsigned int len = strlen(name);
70085 + unsigned int key = full_name_hash(name, len);
70086 + unsigned int index = key % state->name_set.n_size;
70087 + struct name_entry *match;
70088 +
70089 + match = state->name_set.n_hash[index];
70090 +
70091 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
70092 + match = match->next;
70093 +
70094 + return match;
70095 +}
70096 +
70097 +static struct name_entry *
70098 +lookup_name_entry(const char *name)
70099 +{
70100 + return __lookup_name_entry(&running_polstate, name);
70101 +}
70102 +
70103 +static struct name_entry *
70104 +lookup_name_entry_create(const char *name)
70105 +{
70106 + unsigned int len = strlen(name);
70107 + unsigned int key = full_name_hash(name, len);
70108 + unsigned int index = key % running_polstate.name_set.n_size;
70109 + struct name_entry *match;
70110 +
70111 + match = running_polstate.name_set.n_hash[index];
70112 +
70113 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
70114 + !match->deleted))
70115 + match = match->next;
70116 +
70117 + if (match && match->deleted)
70118 + return match;
70119 +
70120 + match = running_polstate.name_set.n_hash[index];
70121 +
70122 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
70123 + match->deleted))
70124 + match = match->next;
70125 +
70126 + if (match && !match->deleted)
70127 + return match;
70128 + else
70129 + return NULL;
70130 +}
70131 +
70132 +static struct inodev_entry *
70133 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
70134 +{
70135 + unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
70136 + struct inodev_entry *match;
70137 +
70138 + match = running_polstate.inodev_set.i_hash[index];
70139 +
70140 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
70141 + match = match->next;
70142 +
70143 + return match;
70144 +}
70145 +
70146 +void
70147 +__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
70148 +{
70149 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
70150 + state->inodev_set.i_size);
70151 + struct inodev_entry **curr;
70152 +
70153 + entry->prev = NULL;
70154 +
70155 + curr = &state->inodev_set.i_hash[index];
70156 + if (*curr != NULL)
70157 + (*curr)->prev = entry;
70158 +
70159 + entry->next = *curr;
70160 + *curr = entry;
70161 +
70162 + return;
70163 +}
70164 +
70165 +static void
70166 +insert_inodev_entry(struct inodev_entry *entry)
70167 +{
70168 + __insert_inodev_entry(&running_polstate, entry);
70169 +}
70170 +
70171 +void
70172 +insert_acl_obj_label(struct acl_object_label *obj,
70173 + struct acl_subject_label *subj)
70174 +{
70175 + unsigned int index =
70176 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
70177 + struct acl_object_label **curr;
70178 +
70179 + obj->prev = NULL;
70180 +
70181 + curr = &subj->obj_hash[index];
70182 + if (*curr != NULL)
70183 + (*curr)->prev = obj;
70184 +
70185 + obj->next = *curr;
70186 + *curr = obj;
70187 +
70188 + return;
70189 +}
70190 +
70191 +void
70192 +insert_acl_subj_label(struct acl_subject_label *obj,
70193 + struct acl_role_label *role)
70194 +{
70195 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
70196 + struct acl_subject_label **curr;
70197 +
70198 + obj->prev = NULL;
70199 +
70200 + curr = &role->subj_hash[index];
70201 + if (*curr != NULL)
70202 + (*curr)->prev = obj;
70203 +
70204 + obj->next = *curr;
70205 + *curr = obj;
70206 +
70207 + return;
70208 +}
70209 +
70210 +/* derived from glibc fnmatch() 0: match, 1: no match*/
70211 +
70212 +static int
70213 +glob_match(const char *p, const char *n)
70214 +{
70215 + char c;
70216 +
70217 + while ((c = *p++) != '\0') {
70218 + switch (c) {
70219 + case '?':
70220 + if (*n == '\0')
70221 + return 1;
70222 + else if (*n == '/')
70223 + return 1;
70224 + break;
70225 + case '\\':
70226 + if (*n != c)
70227 + return 1;
70228 + break;
70229 + case '*':
70230 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
70231 + if (*n == '/')
70232 + return 1;
70233 + else if (c == '?') {
70234 + if (*n == '\0')
70235 + return 1;
70236 + else
70237 + ++n;
70238 + }
70239 + }
70240 + if (c == '\0') {
70241 + return 0;
70242 + } else {
70243 + const char *endp;
70244 +
70245 + if ((endp = strchr(n, '/')) == NULL)
70246 + endp = n + strlen(n);
70247 +
70248 + if (c == '[') {
70249 + for (--p; n < endp; ++n)
70250 + if (!glob_match(p, n))
70251 + return 0;
70252 + } else if (c == '/') {
70253 + while (*n != '\0' && *n != '/')
70254 + ++n;
70255 + if (*n == '/' && !glob_match(p, n + 1))
70256 + return 0;
70257 + } else {
70258 + for (--p; n < endp; ++n)
70259 + if (*n == c && !glob_match(p, n))
70260 + return 0;
70261 + }
70262 +
70263 + return 1;
70264 + }
70265 + case '[':
70266 + {
70267 + int not;
70268 + char cold;
70269 +
70270 + if (*n == '\0' || *n == '/')
70271 + return 1;
70272 +
70273 + not = (*p == '!' || *p == '^');
70274 + if (not)
70275 + ++p;
70276 +
70277 + c = *p++;
70278 + for (;;) {
70279 + unsigned char fn = (unsigned char)*n;
70280 +
70281 + if (c == '\0')
70282 + return 1;
70283 + else {
70284 + if (c == fn)
70285 + goto matched;
70286 + cold = c;
70287 + c = *p++;
70288 +
70289 + if (c == '-' && *p != ']') {
70290 + unsigned char cend = *p++;
70291 +
70292 + if (cend == '\0')
70293 + return 1;
70294 +
70295 + if (cold <= fn && fn <= cend)
70296 + goto matched;
70297 +
70298 + c = *p++;
70299 + }
70300 + }
70301 +
70302 + if (c == ']')
70303 + break;
70304 + }
70305 + if (!not)
70306 + return 1;
70307 + break;
70308 + matched:
70309 + while (c != ']') {
70310 + if (c == '\0')
70311 + return 1;
70312 +
70313 + c = *p++;
70314 + }
70315 + if (not)
70316 + return 1;
70317 + }
70318 + break;
70319 + default:
70320 + if (c != *n)
70321 + return 1;
70322 + }
70323 +
70324 + ++n;
70325 + }
70326 +
70327 + if (*n == '\0')
70328 + return 0;
70329 +
70330 + if (*n == '/')
70331 + return 0;
70332 +
70333 + return 1;
70334 +}
70335 +
70336 +static struct acl_object_label *
70337 +chk_glob_label(struct acl_object_label *globbed,
70338 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
70339 +{
70340 + struct acl_object_label *tmp;
70341 +
70342 + if (*path == NULL)
70343 + *path = gr_to_filename_nolock(dentry, mnt);
70344 +
70345 + tmp = globbed;
70346 +
70347 + while (tmp) {
70348 + if (!glob_match(tmp->filename, *path))
70349 + return tmp;
70350 + tmp = tmp->next;
70351 + }
70352 +
70353 + return NULL;
70354 +}
70355 +
70356 +static struct acl_object_label *
70357 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
70358 + const ino_t curr_ino, const dev_t curr_dev,
70359 + const struct acl_subject_label *subj, char **path, const int checkglob)
70360 +{
70361 + struct acl_subject_label *tmpsubj;
70362 + struct acl_object_label *retval;
70363 + struct acl_object_label *retval2;
70364 +
70365 + tmpsubj = (struct acl_subject_label *) subj;
70366 + read_lock(&gr_inode_lock);
70367 + do {
70368 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
70369 + if (retval) {
70370 + if (checkglob && retval->globbed) {
70371 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
70372 + if (retval2)
70373 + retval = retval2;
70374 + }
70375 + break;
70376 + }
70377 + } while ((tmpsubj = tmpsubj->parent_subject));
70378 + read_unlock(&gr_inode_lock);
70379 +
70380 + return retval;
70381 +}
70382 +
70383 +static __inline__ struct acl_object_label *
70384 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
70385 + struct dentry *curr_dentry,
70386 + const struct acl_subject_label *subj, char **path, const int checkglob)
70387 +{
70388 + int newglob = checkglob;
70389 + ino_t inode;
70390 + dev_t device;
70391 +
70392 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
70393 + as we don't want a / * rule to match instead of the / object
70394 + don't do this for create lookups that call this function though, since they're looking up
70395 + on the parent and thus need globbing checks on all paths
70396 + */
70397 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
70398 + newglob = GR_NO_GLOB;
70399 +
70400 + spin_lock(&curr_dentry->d_lock);
70401 + inode = curr_dentry->d_inode->i_ino;
70402 + device = __get_dev(curr_dentry);
70403 + spin_unlock(&curr_dentry->d_lock);
70404 +
70405 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
70406 +}
70407 +
70408 +#ifdef CONFIG_HUGETLBFS
70409 +static inline bool
70410 +is_hugetlbfs_mnt(const struct vfsmount *mnt)
70411 +{
70412 + int i;
70413 + for (i = 0; i < HUGE_MAX_HSTATE; i++) {
70414 + if (unlikely(hugetlbfs_vfsmount[i] == mnt))
70415 + return true;
70416 + }
70417 +
70418 + return false;
70419 +}
70420 +#endif
70421 +
70422 +static struct acl_object_label *
70423 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70424 + const struct acl_subject_label *subj, char *path, const int checkglob)
70425 +{
70426 + struct dentry *dentry = (struct dentry *) l_dentry;
70427 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
70428 + struct mount *real_mnt = real_mount(mnt);
70429 + struct acl_object_label *retval;
70430 + struct dentry *parent;
70431 +
70432 + read_seqlock_excl(&mount_lock);
70433 + write_seqlock(&rename_lock);
70434 +
70435 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
70436 +#ifdef CONFIG_NET
70437 + mnt == sock_mnt ||
70438 +#endif
70439 +#ifdef CONFIG_HUGETLBFS
70440 + (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
70441 +#endif
70442 + /* ignore Eric Biederman */
70443 + IS_PRIVATE(l_dentry->d_inode))) {
70444 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
70445 + goto out;
70446 + }
70447 +
70448 + for (;;) {
70449 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
70450 + break;
70451 +
70452 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
70453 + if (!mnt_has_parent(real_mnt))
70454 + break;
70455 +
70456 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70457 + if (retval != NULL)
70458 + goto out;
70459 +
70460 + dentry = real_mnt->mnt_mountpoint;
70461 + real_mnt = real_mnt->mnt_parent;
70462 + mnt = &real_mnt->mnt;
70463 + continue;
70464 + }
70465 +
70466 + parent = dentry->d_parent;
70467 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70468 + if (retval != NULL)
70469 + goto out;
70470 +
70471 + dentry = parent;
70472 + }
70473 +
70474 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70475 +
70476 + /* gr_real_root is pinned so we don't have to hold a reference */
70477 + if (retval == NULL)
70478 + retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
70479 +out:
70480 + write_sequnlock(&rename_lock);
70481 + read_sequnlock_excl(&mount_lock);
70482 +
70483 + BUG_ON(retval == NULL);
70484 +
70485 + return retval;
70486 +}
70487 +
70488 +static __inline__ struct acl_object_label *
70489 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70490 + const struct acl_subject_label *subj)
70491 +{
70492 + char *path = NULL;
70493 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
70494 +}
70495 +
70496 +static __inline__ struct acl_object_label *
70497 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70498 + const struct acl_subject_label *subj)
70499 +{
70500 + char *path = NULL;
70501 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
70502 +}
70503 +
70504 +static __inline__ struct acl_object_label *
70505 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70506 + const struct acl_subject_label *subj, char *path)
70507 +{
70508 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
70509 +}
70510 +
70511 +struct acl_subject_label *
70512 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70513 + const struct acl_role_label *role)
70514 +{
70515 + struct dentry *dentry = (struct dentry *) l_dentry;
70516 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
70517 + struct mount *real_mnt = real_mount(mnt);
70518 + struct acl_subject_label *retval;
70519 + struct dentry *parent;
70520 +
70521 + read_seqlock_excl(&mount_lock);
70522 + write_seqlock(&rename_lock);
70523 +
70524 + for (;;) {
70525 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
70526 + break;
70527 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
70528 + if (!mnt_has_parent(real_mnt))
70529 + break;
70530 +
70531 + spin_lock(&dentry->d_lock);
70532 + read_lock(&gr_inode_lock);
70533 + retval =
70534 + lookup_acl_subj_label(dentry->d_inode->i_ino,
70535 + __get_dev(dentry), role);
70536 + read_unlock(&gr_inode_lock);
70537 + spin_unlock(&dentry->d_lock);
70538 + if (retval != NULL)
70539 + goto out;
70540 +
70541 + dentry = real_mnt->mnt_mountpoint;
70542 + real_mnt = real_mnt->mnt_parent;
70543 + mnt = &real_mnt->mnt;
70544 + continue;
70545 + }
70546 +
70547 + spin_lock(&dentry->d_lock);
70548 + read_lock(&gr_inode_lock);
70549 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
70550 + __get_dev(dentry), role);
70551 + read_unlock(&gr_inode_lock);
70552 + parent = dentry->d_parent;
70553 + spin_unlock(&dentry->d_lock);
70554 +
70555 + if (retval != NULL)
70556 + goto out;
70557 +
70558 + dentry = parent;
70559 + }
70560 +
70561 + spin_lock(&dentry->d_lock);
70562 + read_lock(&gr_inode_lock);
70563 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
70564 + __get_dev(dentry), role);
70565 + read_unlock(&gr_inode_lock);
70566 + spin_unlock(&dentry->d_lock);
70567 +
70568 + if (unlikely(retval == NULL)) {
70569 + /* gr_real_root is pinned, we don't need to hold a reference */
70570 + read_lock(&gr_inode_lock);
70571 + retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
70572 + __get_dev(gr_real_root.dentry), role);
70573 + read_unlock(&gr_inode_lock);
70574 + }
70575 +out:
70576 + write_sequnlock(&rename_lock);
70577 + read_sequnlock_excl(&mount_lock);
70578 +
70579 + BUG_ON(retval == NULL);
70580 +
70581 + return retval;
70582 +}
70583 +
70584 +void
70585 +assign_special_role(const char *rolename)
70586 +{
70587 + struct acl_object_label *obj;
70588 + struct acl_role_label *r;
70589 + struct acl_role_label *assigned = NULL;
70590 + struct task_struct *tsk;
70591 + struct file *filp;
70592 +
70593 + FOR_EACH_ROLE_START(r)
70594 + if (!strcmp(rolename, r->rolename) &&
70595 + (r->roletype & GR_ROLE_SPECIAL)) {
70596 + assigned = r;
70597 + break;
70598 + }
70599 + FOR_EACH_ROLE_END(r)
70600 +
70601 + if (!assigned)
70602 + return;
70603 +
70604 + read_lock(&tasklist_lock);
70605 + read_lock(&grsec_exec_file_lock);
70606 +
70607 + tsk = current->real_parent;
70608 + if (tsk == NULL)
70609 + goto out_unlock;
70610 +
70611 + filp = tsk->exec_file;
70612 + if (filp == NULL)
70613 + goto out_unlock;
70614 +
70615 + tsk->is_writable = 0;
70616 + tsk->inherited = 0;
70617 +
70618 + tsk->acl_sp_role = 1;
70619 + tsk->acl_role_id = ++acl_sp_role_value;
70620 + tsk->role = assigned;
70621 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
70622 +
70623 + /* ignore additional mmap checks for processes that are writable
70624 + by the default ACL */
70625 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
70626 + if (unlikely(obj->mode & GR_WRITE))
70627 + tsk->is_writable = 1;
70628 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
70629 + if (unlikely(obj->mode & GR_WRITE))
70630 + tsk->is_writable = 1;
70631 +
70632 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70633 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
70634 + tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
70635 +#endif
70636 +
70637 +out_unlock:
70638 + read_unlock(&grsec_exec_file_lock);
70639 + read_unlock(&tasklist_lock);
70640 + return;
70641 +}
70642 +
70643 +
70644 +static void
70645 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
70646 +{
70647 + struct task_struct *task = current;
70648 + const struct cred *cred = current_cred();
70649 +
70650 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
70651 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70652 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70653 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
70654 +
70655 + return;
70656 +}
70657 +
70658 +static void
70659 +gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
70660 +{
70661 + struct task_struct *task = current;
70662 + const struct cred *cred = current_cred();
70663 +
70664 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
70665 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70666 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70667 + 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
70668 +
70669 + return;
70670 +}
70671 +
70672 +static void
70673 +gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
70674 +{
70675 + struct task_struct *task = current;
70676 + const struct cred *cred = current_cred();
70677 +
70678 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
70679 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70680 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70681 + 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
70682 +
70683 + return;
70684 +}
70685 +
70686 +static void
70687 +gr_set_proc_res(struct task_struct *task)
70688 +{
70689 + struct acl_subject_label *proc;
70690 + unsigned short i;
70691 +
70692 + proc = task->acl;
70693 +
70694 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
70695 + return;
70696 +
70697 + for (i = 0; i < RLIM_NLIMITS; i++) {
70698 + if (!(proc->resmask & (1U << i)))
70699 + continue;
70700 +
70701 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
70702 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
70703 +
70704 + if (i == RLIMIT_CPU)
70705 + update_rlimit_cpu(task, proc->res[i].rlim_cur);
70706 + }
70707 +
70708 + return;
70709 +}
70710 +
70711 +/* both of the below must be called with
70712 + rcu_read_lock();
70713 + read_lock(&tasklist_lock);
70714 + read_lock(&grsec_exec_file_lock);
70715 +*/
70716 +
70717 +struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
70718 +{
70719 + char *tmpname;
70720 + struct acl_subject_label *tmpsubj;
70721 + struct file *filp;
70722 + struct name_entry *nmatch;
70723 +
70724 + filp = task->exec_file;
70725 + if (filp == NULL)
70726 + return NULL;
70727 +
70728 + /* the following is to apply the correct subject
70729 + on binaries running when the RBAC system
70730 + is enabled, when the binaries have been
70731 + replaced or deleted since their execution
70732 + -----
70733 + when the RBAC system starts, the inode/dev
70734 + from exec_file will be one the RBAC system
70735 + is unaware of. It only knows the inode/dev
70736 + of the present file on disk, or the absence
70737 + of it.
70738 + */
70739 +
70740 + if (filename)
70741 + nmatch = __lookup_name_entry(state, filename);
70742 + else {
70743 + preempt_disable();
70744 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
70745 +
70746 + nmatch = __lookup_name_entry(state, tmpname);
70747 + preempt_enable();
70748 + }
70749 + tmpsubj = NULL;
70750 + if (nmatch) {
70751 + if (nmatch->deleted)
70752 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
70753 + else
70754 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
70755 + }
70756 + /* this also works for the reload case -- if we don't match a potentially inherited subject
70757 + then we fall back to a normal lookup based on the binary's ino/dev
70758 + */
70759 + if (tmpsubj == NULL)
70760 + tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
70761 +
70762 + return tmpsubj;
70763 +}
70764 +
70765 +static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
70766 +{
70767 + return __gr_get_subject_for_task(&running_polstate, task, filename);
70768 +}
70769 +
70770 +void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
70771 +{
70772 + struct acl_object_label *obj;
70773 + struct file *filp;
70774 +
70775 + filp = task->exec_file;
70776 +
70777 + task->acl = subj;
70778 + task->is_writable = 0;
70779 + /* ignore additional mmap checks for processes that are writable
70780 + by the default ACL */
70781 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
70782 + if (unlikely(obj->mode & GR_WRITE))
70783 + task->is_writable = 1;
70784 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
70785 + if (unlikely(obj->mode & GR_WRITE))
70786 + task->is_writable = 1;
70787 +
70788 + gr_set_proc_res(task);
70789 +
70790 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70791 + 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);
70792 +#endif
70793 +}
70794 +
70795 +static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
70796 +{
70797 + __gr_apply_subject_to_task(&running_polstate, task, subj);
70798 +}
70799 +
70800 +__u32
70801 +gr_search_file(const struct dentry * dentry, const __u32 mode,
70802 + const struct vfsmount * mnt)
70803 +{
70804 + __u32 retval = mode;
70805 + struct acl_subject_label *curracl;
70806 + struct acl_object_label *currobj;
70807 +
70808 + if (unlikely(!(gr_status & GR_READY)))
70809 + return (mode & ~GR_AUDITS);
70810 +
70811 + curracl = current->acl;
70812 +
70813 + currobj = chk_obj_label(dentry, mnt, curracl);
70814 + retval = currobj->mode & mode;
70815 +
70816 + /* if we're opening a specified transfer file for writing
70817 + (e.g. /dev/initctl), then transfer our role to init
70818 + */
70819 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
70820 + current->role->roletype & GR_ROLE_PERSIST)) {
70821 + struct task_struct *task = init_pid_ns.child_reaper;
70822 +
70823 + if (task->role != current->role) {
70824 + struct acl_subject_label *subj;
70825 +
70826 + task->acl_sp_role = 0;
70827 + task->acl_role_id = current->acl_role_id;
70828 + task->role = current->role;
70829 + rcu_read_lock();
70830 + read_lock(&grsec_exec_file_lock);
70831 + subj = gr_get_subject_for_task(task, NULL);
70832 + gr_apply_subject_to_task(task, subj);
70833 + read_unlock(&grsec_exec_file_lock);
70834 + rcu_read_unlock();
70835 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
70836 + }
70837 + }
70838 +
70839 + if (unlikely
70840 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
70841 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
70842 + __u32 new_mode = mode;
70843 +
70844 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
70845 +
70846 + retval = new_mode;
70847 +
70848 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
70849 + new_mode |= GR_INHERIT;
70850 +
70851 + if (!(mode & GR_NOLEARN))
70852 + gr_log_learn(dentry, mnt, new_mode);
70853 + }
70854 +
70855 + return retval;
70856 +}
70857 +
70858 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
70859 + const struct dentry *parent,
70860 + const struct vfsmount *mnt)
70861 +{
70862 + struct name_entry *match;
70863 + struct acl_object_label *matchpo;
70864 + struct acl_subject_label *curracl;
70865 + char *path;
70866 +
70867 + if (unlikely(!(gr_status & GR_READY)))
70868 + return NULL;
70869 +
70870 + preempt_disable();
70871 + path = gr_to_filename_rbac(new_dentry, mnt);
70872 + match = lookup_name_entry_create(path);
70873 +
70874 + curracl = current->acl;
70875 +
70876 + if (match) {
70877 + read_lock(&gr_inode_lock);
70878 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
70879 + read_unlock(&gr_inode_lock);
70880 +
70881 + if (matchpo) {
70882 + preempt_enable();
70883 + return matchpo;
70884 + }
70885 + }
70886 +
70887 + // lookup parent
70888 +
70889 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
70890 +
70891 + preempt_enable();
70892 + return matchpo;
70893 +}
70894 +
70895 +__u32
70896 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
70897 + const struct vfsmount * mnt, const __u32 mode)
70898 +{
70899 + struct acl_object_label *matchpo;
70900 + __u32 retval;
70901 +
70902 + if (unlikely(!(gr_status & GR_READY)))
70903 + return (mode & ~GR_AUDITS);
70904 +
70905 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
70906 +
70907 + retval = matchpo->mode & mode;
70908 +
70909 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
70910 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
70911 + __u32 new_mode = mode;
70912 +
70913 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
70914 +
70915 + gr_log_learn(new_dentry, mnt, new_mode);
70916 + return new_mode;
70917 + }
70918 +
70919 + return retval;
70920 +}
70921 +
70922 +__u32
70923 +gr_check_link(const struct dentry * new_dentry,
70924 + const struct dentry * parent_dentry,
70925 + const struct vfsmount * parent_mnt,
70926 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
70927 +{
70928 + struct acl_object_label *obj;
70929 + __u32 oldmode, newmode;
70930 + __u32 needmode;
70931 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
70932 + GR_DELETE | GR_INHERIT;
70933 +
70934 + if (unlikely(!(gr_status & GR_READY)))
70935 + return (GR_CREATE | GR_LINK);
70936 +
70937 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
70938 + oldmode = obj->mode;
70939 +
70940 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
70941 + newmode = obj->mode;
70942 +
70943 + needmode = newmode & checkmodes;
70944 +
70945 + // old name for hardlink must have at least the permissions of the new name
70946 + if ((oldmode & needmode) != needmode)
70947 + goto bad;
70948 +
70949 + // if old name had restrictions/auditing, make sure the new name does as well
70950 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
70951 +
70952 + // don't allow hardlinking of suid/sgid/fcapped files without permission
70953 + if (is_privileged_binary(old_dentry))
70954 + needmode |= GR_SETID;
70955 +
70956 + if ((newmode & needmode) != needmode)
70957 + goto bad;
70958 +
70959 + // enforce minimum permissions
70960 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
70961 + return newmode;
70962 +bad:
70963 + needmode = oldmode;
70964 + if (is_privileged_binary(old_dentry))
70965 + needmode |= GR_SETID;
70966 +
70967 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
70968 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
70969 + return (GR_CREATE | GR_LINK);
70970 + } else if (newmode & GR_SUPPRESS)
70971 + return GR_SUPPRESS;
70972 + else
70973 + return 0;
70974 +}
70975 +
70976 +int
70977 +gr_check_hidden_task(const struct task_struct *task)
70978 +{
70979 + if (unlikely(!(gr_status & GR_READY)))
70980 + return 0;
70981 +
70982 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
70983 + return 1;
70984 +
70985 + return 0;
70986 +}
70987 +
70988 +int
70989 +gr_check_protected_task(const struct task_struct *task)
70990 +{
70991 + if (unlikely(!(gr_status & GR_READY) || !task))
70992 + return 0;
70993 +
70994 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
70995 + task->acl != current->acl)
70996 + return 1;
70997 +
70998 + return 0;
70999 +}
71000 +
71001 +int
71002 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
71003 +{
71004 + struct task_struct *p;
71005 + int ret = 0;
71006 +
71007 + if (unlikely(!(gr_status & GR_READY) || !pid))
71008 + return ret;
71009 +
71010 + read_lock(&tasklist_lock);
71011 + do_each_pid_task(pid, type, p) {
71012 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
71013 + p->acl != current->acl) {
71014 + ret = 1;
71015 + goto out;
71016 + }
71017 + } while_each_pid_task(pid, type, p);
71018 +out:
71019 + read_unlock(&tasklist_lock);
71020 +
71021 + return ret;
71022 +}
71023 +
71024 +void
71025 +gr_copy_label(struct task_struct *tsk)
71026 +{
71027 + struct task_struct *p = current;
71028 +
71029 + tsk->inherited = p->inherited;
71030 + tsk->acl_sp_role = 0;
71031 + tsk->acl_role_id = p->acl_role_id;
71032 + tsk->acl = p->acl;
71033 + tsk->role = p->role;
71034 + tsk->signal->used_accept = 0;
71035 + tsk->signal->curr_ip = p->signal->curr_ip;
71036 + tsk->signal->saved_ip = p->signal->saved_ip;
71037 + if (p->exec_file)
71038 + get_file(p->exec_file);
71039 + tsk->exec_file = p->exec_file;
71040 + tsk->is_writable = p->is_writable;
71041 + if (unlikely(p->signal->used_accept)) {
71042 + p->signal->curr_ip = 0;
71043 + p->signal->saved_ip = 0;
71044 + }
71045 +
71046 + return;
71047 +}
71048 +
71049 +extern int gr_process_kernel_setuid_ban(struct user_struct *user);
71050 +
71051 +int
71052 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
71053 +{
71054 + unsigned int i;
71055 + __u16 num;
71056 + uid_t *uidlist;
71057 + uid_t curuid;
71058 + int realok = 0;
71059 + int effectiveok = 0;
71060 + int fsok = 0;
71061 + uid_t globalreal, globaleffective, globalfs;
71062 +
71063 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
71064 + struct user_struct *user;
71065 +
71066 + if (!uid_valid(real))
71067 + goto skipit;
71068 +
71069 + /* find user based on global namespace */
71070 +
71071 + globalreal = GR_GLOBAL_UID(real);
71072 +
71073 + user = find_user(make_kuid(&init_user_ns, globalreal));
71074 + if (user == NULL)
71075 + goto skipit;
71076 +
71077 + if (gr_process_kernel_setuid_ban(user)) {
71078 + /* for find_user */
71079 + free_uid(user);
71080 + return 1;
71081 + }
71082 +
71083 + /* for find_user */
71084 + free_uid(user);
71085 +
71086 +skipit:
71087 +#endif
71088 +
71089 + if (unlikely(!(gr_status & GR_READY)))
71090 + return 0;
71091 +
71092 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
71093 + gr_log_learn_uid_change(real, effective, fs);
71094 +
71095 + num = current->acl->user_trans_num;
71096 + uidlist = current->acl->user_transitions;
71097 +
71098 + if (uidlist == NULL)
71099 + return 0;
71100 +
71101 + if (!uid_valid(real)) {
71102 + realok = 1;
71103 + globalreal = (uid_t)-1;
71104 + } else {
71105 + globalreal = GR_GLOBAL_UID(real);
71106 + }
71107 + if (!uid_valid(effective)) {
71108 + effectiveok = 1;
71109 + globaleffective = (uid_t)-1;
71110 + } else {
71111 + globaleffective = GR_GLOBAL_UID(effective);
71112 + }
71113 + if (!uid_valid(fs)) {
71114 + fsok = 1;
71115 + globalfs = (uid_t)-1;
71116 + } else {
71117 + globalfs = GR_GLOBAL_UID(fs);
71118 + }
71119 +
71120 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
71121 + for (i = 0; i < num; i++) {
71122 + curuid = uidlist[i];
71123 + if (globalreal == curuid)
71124 + realok = 1;
71125 + if (globaleffective == curuid)
71126 + effectiveok = 1;
71127 + if (globalfs == curuid)
71128 + fsok = 1;
71129 + }
71130 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
71131 + for (i = 0; i < num; i++) {
71132 + curuid = uidlist[i];
71133 + if (globalreal == curuid)
71134 + break;
71135 + if (globaleffective == curuid)
71136 + break;
71137 + if (globalfs == curuid)
71138 + break;
71139 + }
71140 + /* not in deny list */
71141 + if (i == num) {
71142 + realok = 1;
71143 + effectiveok = 1;
71144 + fsok = 1;
71145 + }
71146 + }
71147 +
71148 + if (realok && effectiveok && fsok)
71149 + return 0;
71150 + else {
71151 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
71152 + return 1;
71153 + }
71154 +}
71155 +
71156 +int
71157 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
71158 +{
71159 + unsigned int i;
71160 + __u16 num;
71161 + gid_t *gidlist;
71162 + gid_t curgid;
71163 + int realok = 0;
71164 + int effectiveok = 0;
71165 + int fsok = 0;
71166 + gid_t globalreal, globaleffective, globalfs;
71167 +
71168 + if (unlikely(!(gr_status & GR_READY)))
71169 + return 0;
71170 +
71171 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
71172 + gr_log_learn_gid_change(real, effective, fs);
71173 +
71174 + num = current->acl->group_trans_num;
71175 + gidlist = current->acl->group_transitions;
71176 +
71177 + if (gidlist == NULL)
71178 + return 0;
71179 +
71180 + if (!gid_valid(real)) {
71181 + realok = 1;
71182 + globalreal = (gid_t)-1;
71183 + } else {
71184 + globalreal = GR_GLOBAL_GID(real);
71185 + }
71186 + if (!gid_valid(effective)) {
71187 + effectiveok = 1;
71188 + globaleffective = (gid_t)-1;
71189 + } else {
71190 + globaleffective = GR_GLOBAL_GID(effective);
71191 + }
71192 + if (!gid_valid(fs)) {
71193 + fsok = 1;
71194 + globalfs = (gid_t)-1;
71195 + } else {
71196 + globalfs = GR_GLOBAL_GID(fs);
71197 + }
71198 +
71199 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
71200 + for (i = 0; i < num; i++) {
71201 + curgid = gidlist[i];
71202 + if (globalreal == curgid)
71203 + realok = 1;
71204 + if (globaleffective == curgid)
71205 + effectiveok = 1;
71206 + if (globalfs == curgid)
71207 + fsok = 1;
71208 + }
71209 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
71210 + for (i = 0; i < num; i++) {
71211 + curgid = gidlist[i];
71212 + if (globalreal == curgid)
71213 + break;
71214 + if (globaleffective == curgid)
71215 + break;
71216 + if (globalfs == curgid)
71217 + break;
71218 + }
71219 + /* not in deny list */
71220 + if (i == num) {
71221 + realok = 1;
71222 + effectiveok = 1;
71223 + fsok = 1;
71224 + }
71225 + }
71226 +
71227 + if (realok && effectiveok && fsok)
71228 + return 0;
71229 + else {
71230 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
71231 + return 1;
71232 + }
71233 +}
71234 +
71235 +extern int gr_acl_is_capable(const int cap);
71236 +
71237 +void
71238 +gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
71239 +{
71240 + struct acl_role_label *role = task->role;
71241 + struct acl_subject_label *subj = NULL;
71242 + struct acl_object_label *obj;
71243 + struct file *filp;
71244 + uid_t uid;
71245 + gid_t gid;
71246 +
71247 + if (unlikely(!(gr_status & GR_READY)))
71248 + return;
71249 +
71250 + uid = GR_GLOBAL_UID(kuid);
71251 + gid = GR_GLOBAL_GID(kgid);
71252 +
71253 + filp = task->exec_file;
71254 +
71255 + /* kernel process, we'll give them the kernel role */
71256 + if (unlikely(!filp)) {
71257 + task->role = running_polstate.kernel_role;
71258 + task->acl = running_polstate.kernel_role->root_label;
71259 + return;
71260 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
71261 + /* save the current ip at time of role lookup so that the proper
71262 + IP will be learned for role_allowed_ip */
71263 + task->signal->saved_ip = task->signal->curr_ip;
71264 + role = lookup_acl_role_label(task, uid, gid);
71265 + }
71266 +
71267 + /* don't change the role if we're not a privileged process */
71268 + if (role && task->role != role &&
71269 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
71270 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
71271 + return;
71272 +
71273 + /* perform subject lookup in possibly new role
71274 + we can use this result below in the case where role == task->role
71275 + */
71276 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
71277 +
71278 + /* if we changed uid/gid, but result in the same role
71279 + and are using inheritance, don't lose the inherited subject
71280 + if current subject is other than what normal lookup
71281 + would result in, we arrived via inheritance, don't
71282 + lose subject
71283 + */
71284 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
71285 + (subj == task->acl)))
71286 + task->acl = subj;
71287 +
71288 + /* leave task->inherited unaffected */
71289 +
71290 + task->role = role;
71291 +
71292 + task->is_writable = 0;
71293 +
71294 + /* ignore additional mmap checks for processes that are writable
71295 + by the default ACL */
71296 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
71297 + if (unlikely(obj->mode & GR_WRITE))
71298 + task->is_writable = 1;
71299 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
71300 + if (unlikely(obj->mode & GR_WRITE))
71301 + task->is_writable = 1;
71302 +
71303 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71304 + 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);
71305 +#endif
71306 +
71307 + gr_set_proc_res(task);
71308 +
71309 + return;
71310 +}
71311 +
71312 +int
71313 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
71314 + const int unsafe_flags)
71315 +{
71316 + struct task_struct *task = current;
71317 + struct acl_subject_label *newacl;
71318 + struct acl_object_label *obj;
71319 + __u32 retmode;
71320 +
71321 + if (unlikely(!(gr_status & GR_READY)))
71322 + return 0;
71323 +
71324 + newacl = chk_subj_label(dentry, mnt, task->role);
71325 +
71326 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
71327 + did an exec
71328 + */
71329 + rcu_read_lock();
71330 + read_lock(&tasklist_lock);
71331 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
71332 + (task->parent->acl->mode & GR_POVERRIDE))) {
71333 + read_unlock(&tasklist_lock);
71334 + rcu_read_unlock();
71335 + goto skip_check;
71336 + }
71337 + read_unlock(&tasklist_lock);
71338 + rcu_read_unlock();
71339 +
71340 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
71341 + !(task->role->roletype & GR_ROLE_GOD) &&
71342 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
71343 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
71344 + if (unsafe_flags & LSM_UNSAFE_SHARE)
71345 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
71346 + else
71347 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
71348 + return -EACCES;
71349 + }
71350 +
71351 +skip_check:
71352 +
71353 + obj = chk_obj_label(dentry, mnt, task->acl);
71354 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
71355 +
71356 + if (!(task->acl->mode & GR_INHERITLEARN) &&
71357 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
71358 + if (obj->nested)
71359 + task->acl = obj->nested;
71360 + else
71361 + task->acl = newacl;
71362 + task->inherited = 0;
71363 + } else {
71364 + task->inherited = 1;
71365 + if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
71366 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
71367 + }
71368 +
71369 + task->is_writable = 0;
71370 +
71371 + /* ignore additional mmap checks for processes that are writable
71372 + by the default ACL */
71373 + obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
71374 + if (unlikely(obj->mode & GR_WRITE))
71375 + task->is_writable = 1;
71376 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
71377 + if (unlikely(obj->mode & GR_WRITE))
71378 + task->is_writable = 1;
71379 +
71380 + gr_set_proc_res(task);
71381 +
71382 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71383 + 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);
71384 +#endif
71385 + return 0;
71386 +}
71387 +
71388 +/* always called with valid inodev ptr */
71389 +static void
71390 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
71391 +{
71392 + struct acl_object_label *matchpo;
71393 + struct acl_subject_label *matchps;
71394 + struct acl_subject_label *subj;
71395 + struct acl_role_label *role;
71396 + unsigned int x;
71397 +
71398 + FOR_EACH_ROLE_START(role)
71399 + FOR_EACH_SUBJECT_START(role, subj, x)
71400 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
71401 + matchpo->mode |= GR_DELETED;
71402 + FOR_EACH_SUBJECT_END(subj,x)
71403 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
71404 + /* nested subjects aren't in the role's subj_hash table */
71405 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
71406 + matchpo->mode |= GR_DELETED;
71407 + FOR_EACH_NESTED_SUBJECT_END(subj)
71408 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
71409 + matchps->mode |= GR_DELETED;
71410 + FOR_EACH_ROLE_END(role)
71411 +
71412 + inodev->nentry->deleted = 1;
71413 +
71414 + return;
71415 +}
71416 +
71417 +void
71418 +gr_handle_delete(const ino_t ino, const dev_t dev)
71419 +{
71420 + struct inodev_entry *inodev;
71421 +
71422 + if (unlikely(!(gr_status & GR_READY)))
71423 + return;
71424 +
71425 + write_lock(&gr_inode_lock);
71426 + inodev = lookup_inodev_entry(ino, dev);
71427 + if (inodev != NULL)
71428 + do_handle_delete(inodev, ino, dev);
71429 + write_unlock(&gr_inode_lock);
71430 +
71431 + return;
71432 +}
71433 +
71434 +static void
71435 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
71436 + const ino_t newinode, const dev_t newdevice,
71437 + struct acl_subject_label *subj)
71438 +{
71439 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
71440 + struct acl_object_label *match;
71441 +
71442 + match = subj->obj_hash[index];
71443 +
71444 + while (match && (match->inode != oldinode ||
71445 + match->device != olddevice ||
71446 + !(match->mode & GR_DELETED)))
71447 + match = match->next;
71448 +
71449 + if (match && (match->inode == oldinode)
71450 + && (match->device == olddevice)
71451 + && (match->mode & GR_DELETED)) {
71452 + if (match->prev == NULL) {
71453 + subj->obj_hash[index] = match->next;
71454 + if (match->next != NULL)
71455 + match->next->prev = NULL;
71456 + } else {
71457 + match->prev->next = match->next;
71458 + if (match->next != NULL)
71459 + match->next->prev = match->prev;
71460 + }
71461 + match->prev = NULL;
71462 + match->next = NULL;
71463 + match->inode = newinode;
71464 + match->device = newdevice;
71465 + match->mode &= ~GR_DELETED;
71466 +
71467 + insert_acl_obj_label(match, subj);
71468 + }
71469 +
71470 + return;
71471 +}
71472 +
71473 +static void
71474 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
71475 + const ino_t newinode, const dev_t newdevice,
71476 + struct acl_role_label *role)
71477 +{
71478 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
71479 + struct acl_subject_label *match;
71480 +
71481 + match = role->subj_hash[index];
71482 +
71483 + while (match && (match->inode != oldinode ||
71484 + match->device != olddevice ||
71485 + !(match->mode & GR_DELETED)))
71486 + match = match->next;
71487 +
71488 + if (match && (match->inode == oldinode)
71489 + && (match->device == olddevice)
71490 + && (match->mode & GR_DELETED)) {
71491 + if (match->prev == NULL) {
71492 + role->subj_hash[index] = match->next;
71493 + if (match->next != NULL)
71494 + match->next->prev = NULL;
71495 + } else {
71496 + match->prev->next = match->next;
71497 + if (match->next != NULL)
71498 + match->next->prev = match->prev;
71499 + }
71500 + match->prev = NULL;
71501 + match->next = NULL;
71502 + match->inode = newinode;
71503 + match->device = newdevice;
71504 + match->mode &= ~GR_DELETED;
71505 +
71506 + insert_acl_subj_label(match, role);
71507 + }
71508 +
71509 + return;
71510 +}
71511 +
71512 +static void
71513 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
71514 + const ino_t newinode, const dev_t newdevice)
71515 +{
71516 + unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
71517 + struct inodev_entry *match;
71518 +
71519 + match = running_polstate.inodev_set.i_hash[index];
71520 +
71521 + while (match && (match->nentry->inode != oldinode ||
71522 + match->nentry->device != olddevice || !match->nentry->deleted))
71523 + match = match->next;
71524 +
71525 + if (match && (match->nentry->inode == oldinode)
71526 + && (match->nentry->device == olddevice) &&
71527 + match->nentry->deleted) {
71528 + if (match->prev == NULL) {
71529 + running_polstate.inodev_set.i_hash[index] = match->next;
71530 + if (match->next != NULL)
71531 + match->next->prev = NULL;
71532 + } else {
71533 + match->prev->next = match->next;
71534 + if (match->next != NULL)
71535 + match->next->prev = match->prev;
71536 + }
71537 + match->prev = NULL;
71538 + match->next = NULL;
71539 + match->nentry->inode = newinode;
71540 + match->nentry->device = newdevice;
71541 + match->nentry->deleted = 0;
71542 +
71543 + insert_inodev_entry(match);
71544 + }
71545 +
71546 + return;
71547 +}
71548 +
71549 +static void
71550 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
71551 +{
71552 + struct acl_subject_label *subj;
71553 + struct acl_role_label *role;
71554 + unsigned int x;
71555 +
71556 + FOR_EACH_ROLE_START(role)
71557 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
71558 +
71559 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
71560 + if ((subj->inode == ino) && (subj->device == dev)) {
71561 + subj->inode = ino;
71562 + subj->device = dev;
71563 + }
71564 + /* nested subjects aren't in the role's subj_hash table */
71565 + update_acl_obj_label(matchn->inode, matchn->device,
71566 + ino, dev, subj);
71567 + FOR_EACH_NESTED_SUBJECT_END(subj)
71568 + FOR_EACH_SUBJECT_START(role, subj, x)
71569 + update_acl_obj_label(matchn->inode, matchn->device,
71570 + ino, dev, subj);
71571 + FOR_EACH_SUBJECT_END(subj,x)
71572 + FOR_EACH_ROLE_END(role)
71573 +
71574 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
71575 +
71576 + return;
71577 +}
71578 +
71579 +static void
71580 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
71581 + const struct vfsmount *mnt)
71582 +{
71583 + ino_t ino = dentry->d_inode->i_ino;
71584 + dev_t dev = __get_dev(dentry);
71585 +
71586 + __do_handle_create(matchn, ino, dev);
71587 +
71588 + return;
71589 +}
71590 +
71591 +void
71592 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
71593 +{
71594 + struct name_entry *matchn;
71595 +
71596 + if (unlikely(!(gr_status & GR_READY)))
71597 + return;
71598 +
71599 + preempt_disable();
71600 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
71601 +
71602 + if (unlikely((unsigned long)matchn)) {
71603 + write_lock(&gr_inode_lock);
71604 + do_handle_create(matchn, dentry, mnt);
71605 + write_unlock(&gr_inode_lock);
71606 + }
71607 + preempt_enable();
71608 +
71609 + return;
71610 +}
71611 +
71612 +void
71613 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
71614 +{
71615 + struct name_entry *matchn;
71616 +
71617 + if (unlikely(!(gr_status & GR_READY)))
71618 + return;
71619 +
71620 + preempt_disable();
71621 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
71622 +
71623 + if (unlikely((unsigned long)matchn)) {
71624 + write_lock(&gr_inode_lock);
71625 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
71626 + write_unlock(&gr_inode_lock);
71627 + }
71628 + preempt_enable();
71629 +
71630 + return;
71631 +}
71632 +
71633 +void
71634 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
71635 + struct dentry *old_dentry,
71636 + struct dentry *new_dentry,
71637 + struct vfsmount *mnt, const __u8 replace, unsigned int flags)
71638 +{
71639 + struct name_entry *matchn;
71640 + struct name_entry *matchn2 = NULL;
71641 + struct inodev_entry *inodev;
71642 + struct inode *inode = new_dentry->d_inode;
71643 + ino_t old_ino = old_dentry->d_inode->i_ino;
71644 + dev_t old_dev = __get_dev(old_dentry);
71645 + unsigned int exchange = flags & RENAME_EXCHANGE;
71646 +
71647 + /* vfs_rename swaps the name and parent link for old_dentry and
71648 + new_dentry
71649 + at this point, old_dentry has the new name, parent link, and inode
71650 + for the renamed file
71651 + if a file is being replaced by a rename, new_dentry has the inode
71652 + and name for the replaced file
71653 + */
71654 +
71655 + if (unlikely(!(gr_status & GR_READY)))
71656 + return;
71657 +
71658 + preempt_disable();
71659 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
71660 +
71661 + /* exchange cases:
71662 + a filename exists for the source, but not dest
71663 + do a recreate on source
71664 + a filename exists for the dest, but not source
71665 + do a recreate on dest
71666 + a filename exists for both source and dest
71667 + delete source and dest, then create source and dest
71668 + a filename exists for neither source nor dest
71669 + no updates needed
71670 +
71671 + the name entry lookups get us the old inode/dev associated with
71672 + each name, so do the deletes first (if possible) so that when
71673 + we do the create, we pick up on the right entries
71674 + */
71675 +
71676 + if (exchange)
71677 + matchn2 = lookup_name_entry(gr_to_filename_rbac(new_dentry, mnt));
71678 +
71679 + /* we wouldn't have to check d_inode if it weren't for
71680 + NFS silly-renaming
71681 + */
71682 +
71683 + write_lock(&gr_inode_lock);
71684 + if (unlikely((replace || exchange) && inode)) {
71685 + ino_t new_ino = inode->i_ino;
71686 + dev_t new_dev = __get_dev(new_dentry);
71687 +
71688 + inodev = lookup_inodev_entry(new_ino, new_dev);
71689 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
71690 + do_handle_delete(inodev, new_ino, new_dev);
71691 + }
71692 +
71693 + inodev = lookup_inodev_entry(old_ino, old_dev);
71694 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
71695 + do_handle_delete(inodev, old_ino, old_dev);
71696 +
71697 + if (unlikely(matchn != NULL))
71698 + do_handle_create(matchn, old_dentry, mnt);
71699 +
71700 + if (unlikely(matchn2 != NULL))
71701 + do_handle_create(matchn2, new_dentry, mnt);
71702 +
71703 + write_unlock(&gr_inode_lock);
71704 + preempt_enable();
71705 +
71706 + return;
71707 +}
71708 +
71709 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
71710 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
71711 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
71712 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
71713 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
71714 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
71715 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
71716 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
71717 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
71718 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
71719 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
71720 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
71721 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
71722 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
71723 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
71724 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
71725 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
71726 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
71727 +};
71728 +
71729 +void
71730 +gr_learn_resource(const struct task_struct *task,
71731 + const int res, const unsigned long wanted, const int gt)
71732 +{
71733 + struct acl_subject_label *acl;
71734 + const struct cred *cred;
71735 +
71736 + if (unlikely((gr_status & GR_READY) &&
71737 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
71738 + goto skip_reslog;
71739 +
71740 + gr_log_resource(task, res, wanted, gt);
71741 +skip_reslog:
71742 +
71743 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
71744 + return;
71745 +
71746 + acl = task->acl;
71747 +
71748 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
71749 + !(acl->resmask & (1U << (unsigned short) res))))
71750 + return;
71751 +
71752 + if (wanted >= acl->res[res].rlim_cur) {
71753 + unsigned long res_add;
71754 +
71755 + res_add = wanted + res_learn_bumps[res];
71756 +
71757 + acl->res[res].rlim_cur = res_add;
71758 +
71759 + if (wanted > acl->res[res].rlim_max)
71760 + acl->res[res].rlim_max = res_add;
71761 +
71762 + /* only log the subject filename, since resource logging is supported for
71763 + single-subject learning only */
71764 + rcu_read_lock();
71765 + cred = __task_cred(task);
71766 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
71767 + task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
71768 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
71769 + "", (unsigned long) res, &task->signal->saved_ip);
71770 + rcu_read_unlock();
71771 + }
71772 +
71773 + return;
71774 +}
71775 +EXPORT_SYMBOL_GPL(gr_learn_resource);
71776 +#endif
71777 +
71778 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
71779 +void
71780 +pax_set_initial_flags(struct linux_binprm *bprm)
71781 +{
71782 + struct task_struct *task = current;
71783 + struct acl_subject_label *proc;
71784 + unsigned long flags;
71785 +
71786 + if (unlikely(!(gr_status & GR_READY)))
71787 + return;
71788 +
71789 + flags = pax_get_flags(task);
71790 +
71791 + proc = task->acl;
71792 +
71793 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
71794 + flags &= ~MF_PAX_PAGEEXEC;
71795 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
71796 + flags &= ~MF_PAX_SEGMEXEC;
71797 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
71798 + flags &= ~MF_PAX_RANDMMAP;
71799 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
71800 + flags &= ~MF_PAX_EMUTRAMP;
71801 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
71802 + flags &= ~MF_PAX_MPROTECT;
71803 +
71804 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
71805 + flags |= MF_PAX_PAGEEXEC;
71806 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
71807 + flags |= MF_PAX_SEGMEXEC;
71808 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
71809 + flags |= MF_PAX_RANDMMAP;
71810 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
71811 + flags |= MF_PAX_EMUTRAMP;
71812 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
71813 + flags |= MF_PAX_MPROTECT;
71814 +
71815 + pax_set_flags(task, flags);
71816 +
71817 + return;
71818 +}
71819 +#endif
71820 +
71821 +int
71822 +gr_handle_proc_ptrace(struct task_struct *task)
71823 +{
71824 + struct file *filp;
71825 + struct task_struct *tmp = task;
71826 + struct task_struct *curtemp = current;
71827 + __u32 retmode;
71828 +
71829 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
71830 + if (unlikely(!(gr_status & GR_READY)))
71831 + return 0;
71832 +#endif
71833 +
71834 + read_lock(&tasklist_lock);
71835 + read_lock(&grsec_exec_file_lock);
71836 + filp = task->exec_file;
71837 +
71838 + while (task_pid_nr(tmp) > 0) {
71839 + if (tmp == curtemp)
71840 + break;
71841 + tmp = tmp->real_parent;
71842 + }
71843 +
71844 + if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
71845 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
71846 + read_unlock(&grsec_exec_file_lock);
71847 + read_unlock(&tasklist_lock);
71848 + return 1;
71849 + }
71850 +
71851 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
71852 + if (!(gr_status & GR_READY)) {
71853 + read_unlock(&grsec_exec_file_lock);
71854 + read_unlock(&tasklist_lock);
71855 + return 0;
71856 + }
71857 +#endif
71858 +
71859 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
71860 + read_unlock(&grsec_exec_file_lock);
71861 + read_unlock(&tasklist_lock);
71862 +
71863 + if (retmode & GR_NOPTRACE)
71864 + return 1;
71865 +
71866 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
71867 + && (current->acl != task->acl || (current->acl != current->role->root_label
71868 + && task_pid_nr(current) != task_pid_nr(task))))
71869 + return 1;
71870 +
71871 + return 0;
71872 +}
71873 +
71874 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
71875 +{
71876 + if (unlikely(!(gr_status & GR_READY)))
71877 + return;
71878 +
71879 + if (!(current->role->roletype & GR_ROLE_GOD))
71880 + return;
71881 +
71882 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
71883 + p->role->rolename, gr_task_roletype_to_char(p),
71884 + p->acl->filename);
71885 +}
71886 +
71887 +int
71888 +gr_handle_ptrace(struct task_struct *task, const long request)
71889 +{
71890 + struct task_struct *tmp = task;
71891 + struct task_struct *curtemp = current;
71892 + __u32 retmode;
71893 +
71894 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
71895 + if (unlikely(!(gr_status & GR_READY)))
71896 + return 0;
71897 +#endif
71898 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
71899 + read_lock(&tasklist_lock);
71900 + while (task_pid_nr(tmp) > 0) {
71901 + if (tmp == curtemp)
71902 + break;
71903 + tmp = tmp->real_parent;
71904 + }
71905 +
71906 + if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
71907 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
71908 + read_unlock(&tasklist_lock);
71909 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
71910 + return 1;
71911 + }
71912 + read_unlock(&tasklist_lock);
71913 + }
71914 +
71915 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
71916 + if (!(gr_status & GR_READY))
71917 + return 0;
71918 +#endif
71919 +
71920 + read_lock(&grsec_exec_file_lock);
71921 + if (unlikely(!task->exec_file)) {
71922 + read_unlock(&grsec_exec_file_lock);
71923 + return 0;
71924 + }
71925 +
71926 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
71927 + read_unlock(&grsec_exec_file_lock);
71928 +
71929 + if (retmode & GR_NOPTRACE) {
71930 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
71931 + return 1;
71932 + }
71933 +
71934 + if (retmode & GR_PTRACERD) {
71935 + switch (request) {
71936 + case PTRACE_SEIZE:
71937 + case PTRACE_POKETEXT:
71938 + case PTRACE_POKEDATA:
71939 + case PTRACE_POKEUSR:
71940 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
71941 + case PTRACE_SETREGS:
71942 + case PTRACE_SETFPREGS:
71943 +#endif
71944 +#ifdef CONFIG_X86
71945 + case PTRACE_SETFPXREGS:
71946 +#endif
71947 +#ifdef CONFIG_ALTIVEC
71948 + case PTRACE_SETVRREGS:
71949 +#endif
71950 + return 1;
71951 + default:
71952 + return 0;
71953 + }
71954 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
71955 + !(current->role->roletype & GR_ROLE_GOD) &&
71956 + (current->acl != task->acl)) {
71957 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
71958 + return 1;
71959 + }
71960 +
71961 + return 0;
71962 +}
71963 +
71964 +static int is_writable_mmap(const struct file *filp)
71965 +{
71966 + struct task_struct *task = current;
71967 + struct acl_object_label *obj, *obj2;
71968 +
71969 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
71970 + !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))) {
71971 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
71972 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
71973 + task->role->root_label);
71974 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
71975 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
71976 + return 1;
71977 + }
71978 + }
71979 + return 0;
71980 +}
71981 +
71982 +int
71983 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
71984 +{
71985 + __u32 mode;
71986 +
71987 + if (unlikely(!file || !(prot & PROT_EXEC)))
71988 + return 1;
71989 +
71990 + if (is_writable_mmap(file))
71991 + return 0;
71992 +
71993 + mode =
71994 + gr_search_file(file->f_path.dentry,
71995 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
71996 + file->f_path.mnt);
71997 +
71998 + if (!gr_tpe_allow(file))
71999 + return 0;
72000 +
72001 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
72002 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72003 + return 0;
72004 + } else if (unlikely(!(mode & GR_EXEC))) {
72005 + return 0;
72006 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
72007 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72008 + return 1;
72009 + }
72010 +
72011 + return 1;
72012 +}
72013 +
72014 +int
72015 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
72016 +{
72017 + __u32 mode;
72018 +
72019 + if (unlikely(!file || !(prot & PROT_EXEC)))
72020 + return 1;
72021 +
72022 + if (is_writable_mmap(file))
72023 + return 0;
72024 +
72025 + mode =
72026 + gr_search_file(file->f_path.dentry,
72027 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
72028 + file->f_path.mnt);
72029 +
72030 + if (!gr_tpe_allow(file))
72031 + return 0;
72032 +
72033 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
72034 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72035 + return 0;
72036 + } else if (unlikely(!(mode & GR_EXEC))) {
72037 + return 0;
72038 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
72039 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72040 + return 1;
72041 + }
72042 +
72043 + return 1;
72044 +}
72045 +
72046 +void
72047 +gr_acl_handle_psacct(struct task_struct *task, const long code)
72048 +{
72049 + unsigned long runtime, cputime;
72050 + cputime_t utime, stime;
72051 + unsigned int wday, cday;
72052 + __u8 whr, chr;
72053 + __u8 wmin, cmin;
72054 + __u8 wsec, csec;
72055 + struct timespec curtime, starttime;
72056 +
72057 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
72058 + !(task->acl->mode & GR_PROCACCT)))
72059 + return;
72060 +
72061 + curtime = ns_to_timespec(ktime_get_ns());
72062 + starttime = ns_to_timespec(task->start_time);
72063 + runtime = curtime.tv_sec - starttime.tv_sec;
72064 + wday = runtime / (60 * 60 * 24);
72065 + runtime -= wday * (60 * 60 * 24);
72066 + whr = runtime / (60 * 60);
72067 + runtime -= whr * (60 * 60);
72068 + wmin = runtime / 60;
72069 + runtime -= wmin * 60;
72070 + wsec = runtime;
72071 +
72072 + task_cputime(task, &utime, &stime);
72073 + cputime = cputime_to_secs(utime + stime);
72074 + cday = cputime / (60 * 60 * 24);
72075 + cputime -= cday * (60 * 60 * 24);
72076 + chr = cputime / (60 * 60);
72077 + cputime -= chr * (60 * 60);
72078 + cmin = cputime / 60;
72079 + cputime -= cmin * 60;
72080 + csec = cputime;
72081 +
72082 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
72083 +
72084 + return;
72085 +}
72086 +
72087 +#ifdef CONFIG_TASKSTATS
72088 +int gr_is_taskstats_denied(int pid)
72089 +{
72090 + struct task_struct *task;
72091 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72092 + const struct cred *cred;
72093 +#endif
72094 + int ret = 0;
72095 +
72096 + /* restrict taskstats viewing to un-chrooted root users
72097 + who have the 'view' subject flag if the RBAC system is enabled
72098 + */
72099 +
72100 + rcu_read_lock();
72101 + read_lock(&tasklist_lock);
72102 + task = find_task_by_vpid(pid);
72103 + if (task) {
72104 +#ifdef CONFIG_GRKERNSEC_CHROOT
72105 + if (proc_is_chrooted(task))
72106 + ret = -EACCES;
72107 +#endif
72108 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72109 + cred = __task_cred(task);
72110 +#ifdef CONFIG_GRKERNSEC_PROC_USER
72111 + if (gr_is_global_nonroot(cred->uid))
72112 + ret = -EACCES;
72113 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72114 + if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
72115 + ret = -EACCES;
72116 +#endif
72117 +#endif
72118 + if (gr_status & GR_READY) {
72119 + if (!(task->acl->mode & GR_VIEW))
72120 + ret = -EACCES;
72121 + }
72122 + } else
72123 + ret = -ENOENT;
72124 +
72125 + read_unlock(&tasklist_lock);
72126 + rcu_read_unlock();
72127 +
72128 + return ret;
72129 +}
72130 +#endif
72131 +
72132 +/* AUXV entries are filled via a descendant of search_binary_handler
72133 + after we've already applied the subject for the target
72134 +*/
72135 +int gr_acl_enable_at_secure(void)
72136 +{
72137 + if (unlikely(!(gr_status & GR_READY)))
72138 + return 0;
72139 +
72140 + if (current->acl->mode & GR_ATSECURE)
72141 + return 1;
72142 +
72143 + return 0;
72144 +}
72145 +
72146 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
72147 +{
72148 + struct task_struct *task = current;
72149 + struct dentry *dentry = file->f_path.dentry;
72150 + struct vfsmount *mnt = file->f_path.mnt;
72151 + struct acl_object_label *obj, *tmp;
72152 + struct acl_subject_label *subj;
72153 + unsigned int bufsize;
72154 + int is_not_root;
72155 + char *path;
72156 + dev_t dev = __get_dev(dentry);
72157 +
72158 + if (unlikely(!(gr_status & GR_READY)))
72159 + return 1;
72160 +
72161 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
72162 + return 1;
72163 +
72164 + /* ignore Eric Biederman */
72165 + if (IS_PRIVATE(dentry->d_inode))
72166 + return 1;
72167 +
72168 + subj = task->acl;
72169 + read_lock(&gr_inode_lock);
72170 + do {
72171 + obj = lookup_acl_obj_label(ino, dev, subj);
72172 + if (obj != NULL) {
72173 + read_unlock(&gr_inode_lock);
72174 + return (obj->mode & GR_FIND) ? 1 : 0;
72175 + }
72176 + } while ((subj = subj->parent_subject));
72177 + read_unlock(&gr_inode_lock);
72178 +
72179 + /* this is purely an optimization since we're looking for an object
72180 + for the directory we're doing a readdir on
72181 + if it's possible for any globbed object to match the entry we're
72182 + filling into the directory, then the object we find here will be
72183 + an anchor point with attached globbed objects
72184 + */
72185 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
72186 + if (obj->globbed == NULL)
72187 + return (obj->mode & GR_FIND) ? 1 : 0;
72188 +
72189 + is_not_root = ((obj->filename[0] == '/') &&
72190 + (obj->filename[1] == '\0')) ? 0 : 1;
72191 + bufsize = PAGE_SIZE - namelen - is_not_root;
72192 +
72193 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
72194 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
72195 + return 1;
72196 +
72197 + preempt_disable();
72198 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
72199 + bufsize);
72200 +
72201 + bufsize = strlen(path);
72202 +
72203 + /* if base is "/", don't append an additional slash */
72204 + if (is_not_root)
72205 + *(path + bufsize) = '/';
72206 + memcpy(path + bufsize + is_not_root, name, namelen);
72207 + *(path + bufsize + namelen + is_not_root) = '\0';
72208 +
72209 + tmp = obj->globbed;
72210 + while (tmp) {
72211 + if (!glob_match(tmp->filename, path)) {
72212 + preempt_enable();
72213 + return (tmp->mode & GR_FIND) ? 1 : 0;
72214 + }
72215 + tmp = tmp->next;
72216 + }
72217 + preempt_enable();
72218 + return (obj->mode & GR_FIND) ? 1 : 0;
72219 +}
72220 +
72221 +void gr_put_exec_file(struct task_struct *task)
72222 +{
72223 + struct file *filp;
72224 +
72225 + write_lock(&grsec_exec_file_lock);
72226 + filp = task->exec_file;
72227 + task->exec_file = NULL;
72228 + write_unlock(&grsec_exec_file_lock);
72229 +
72230 + if (filp)
72231 + fput(filp);
72232 +
72233 + return;
72234 +}
72235 +
72236 +
72237 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
72238 +EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
72239 +#endif
72240 +#ifdef CONFIG_SECURITY
72241 +EXPORT_SYMBOL_GPL(gr_check_user_change);
72242 +EXPORT_SYMBOL_GPL(gr_check_group_change);
72243 +#endif
72244 +
72245 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
72246 new file mode 100644
72247 index 0000000..18ffbbd
72248 --- /dev/null
72249 +++ b/grsecurity/gracl_alloc.c
72250 @@ -0,0 +1,105 @@
72251 +#include <linux/kernel.h>
72252 +#include <linux/mm.h>
72253 +#include <linux/slab.h>
72254 +#include <linux/vmalloc.h>
72255 +#include <linux/gracl.h>
72256 +#include <linux/grsecurity.h>
72257 +
72258 +static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
72259 +struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
72260 +
72261 +static __inline__ int
72262 +alloc_pop(void)
72263 +{
72264 + if (current_alloc_state->alloc_stack_next == 1)
72265 + return 0;
72266 +
72267 + kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
72268 +
72269 + current_alloc_state->alloc_stack_next--;
72270 +
72271 + return 1;
72272 +}
72273 +
72274 +static __inline__ int
72275 +alloc_push(void *buf)
72276 +{
72277 + if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
72278 + return 1;
72279 +
72280 + current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
72281 +
72282 + current_alloc_state->alloc_stack_next++;
72283 +
72284 + return 0;
72285 +}
72286 +
72287 +void *
72288 +acl_alloc(unsigned long len)
72289 +{
72290 + void *ret = NULL;
72291 +
72292 + if (!len || len > PAGE_SIZE)
72293 + goto out;
72294 +
72295 + ret = kmalloc(len, GFP_KERNEL);
72296 +
72297 + if (ret) {
72298 + if (alloc_push(ret)) {
72299 + kfree(ret);
72300 + ret = NULL;
72301 + }
72302 + }
72303 +
72304 +out:
72305 + return ret;
72306 +}
72307 +
72308 +void *
72309 +acl_alloc_num(unsigned long num, unsigned long len)
72310 +{
72311 + if (!len || (num > (PAGE_SIZE / len)))
72312 + return NULL;
72313 +
72314 + return acl_alloc(num * len);
72315 +}
72316 +
72317 +void
72318 +acl_free_all(void)
72319 +{
72320 + if (!current_alloc_state->alloc_stack)
72321 + return;
72322 +
72323 + while (alloc_pop()) ;
72324 +
72325 + if (current_alloc_state->alloc_stack) {
72326 + if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
72327 + kfree(current_alloc_state->alloc_stack);
72328 + else
72329 + vfree(current_alloc_state->alloc_stack);
72330 + }
72331 +
72332 + current_alloc_state->alloc_stack = NULL;
72333 + current_alloc_state->alloc_stack_size = 1;
72334 + current_alloc_state->alloc_stack_next = 1;
72335 +
72336 + return;
72337 +}
72338 +
72339 +int
72340 +acl_alloc_stack_init(unsigned long size)
72341 +{
72342 + if ((size * sizeof (void *)) <= PAGE_SIZE)
72343 + current_alloc_state->alloc_stack =
72344 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
72345 + else
72346 + current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
72347 +
72348 + current_alloc_state->alloc_stack_size = size;
72349 + current_alloc_state->alloc_stack_next = 1;
72350 +
72351 + if (!current_alloc_state->alloc_stack)
72352 + return 0;
72353 + else
72354 + return 1;
72355 +}
72356 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
72357 new file mode 100644
72358 index 0000000..1a94c11
72359 --- /dev/null
72360 +++ b/grsecurity/gracl_cap.c
72361 @@ -0,0 +1,127 @@
72362 +#include <linux/kernel.h>
72363 +#include <linux/module.h>
72364 +#include <linux/sched.h>
72365 +#include <linux/gracl.h>
72366 +#include <linux/grsecurity.h>
72367 +#include <linux/grinternal.h>
72368 +
72369 +extern const char *captab_log[];
72370 +extern int captab_log_entries;
72371 +
72372 +int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
72373 +{
72374 + struct acl_subject_label *curracl;
72375 +
72376 + if (!gr_acl_is_enabled())
72377 + return 1;
72378 +
72379 + curracl = task->acl;
72380 +
72381 + if (curracl->mode & (GR_LEARN | GR_INHERITLEARN)) {
72382 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
72383 + task->role->roletype, GR_GLOBAL_UID(cred->uid),
72384 + GR_GLOBAL_GID(cred->gid), task->exec_file ?
72385 + gr_to_filename(task->exec_file->f_path.dentry,
72386 + task->exec_file->f_path.mnt) : curracl->filename,
72387 + curracl->filename, 0UL,
72388 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
72389 + return 1;
72390 + }
72391 +
72392 + return 0;
72393 +}
72394 +
72395 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
72396 +{
72397 + struct acl_subject_label *curracl;
72398 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
72399 + kernel_cap_t cap_audit = __cap_empty_set;
72400 +
72401 + if (!gr_acl_is_enabled())
72402 + return 1;
72403 +
72404 + curracl = task->acl;
72405 +
72406 + cap_drop = curracl->cap_lower;
72407 + cap_mask = curracl->cap_mask;
72408 + cap_audit = curracl->cap_invert_audit;
72409 +
72410 + while ((curracl = curracl->parent_subject)) {
72411 + /* if the cap isn't specified in the current computed mask but is specified in the
72412 + current level subject, and is lowered in the current level subject, then add
72413 + it to the set of dropped capabilities
72414 + otherwise, add the current level subject's mask to the current computed mask
72415 + */
72416 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
72417 + cap_raise(cap_mask, cap);
72418 + if (cap_raised(curracl->cap_lower, cap))
72419 + cap_raise(cap_drop, cap);
72420 + if (cap_raised(curracl->cap_invert_audit, cap))
72421 + cap_raise(cap_audit, cap);
72422 + }
72423 + }
72424 +
72425 + if (!cap_raised(cap_drop, cap)) {
72426 + if (cap_raised(cap_audit, cap))
72427 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
72428 + return 1;
72429 + }
72430 +
72431 + /* only learn the capability use if the process has the capability in the
72432 + general case, the two uses in sys.c of gr_learn_cap are an exception
72433 + to this rule to ensure any role transition involves what the full-learned
72434 + policy believes in a privileged process
72435 + */
72436 + if (cap_raised(cred->cap_effective, cap) && gr_learn_cap(task, cred, cap))
72437 + return 1;
72438 +
72439 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
72440 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
72441 +
72442 + return 0;
72443 +}
72444 +
72445 +int
72446 +gr_acl_is_capable(const int cap)
72447 +{
72448 + return gr_task_acl_is_capable(current, current_cred(), cap);
72449 +}
72450 +
72451 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
72452 +{
72453 + struct acl_subject_label *curracl;
72454 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
72455 +
72456 + if (!gr_acl_is_enabled())
72457 + return 1;
72458 +
72459 + curracl = task->acl;
72460 +
72461 + cap_drop = curracl->cap_lower;
72462 + cap_mask = curracl->cap_mask;
72463 +
72464 + while ((curracl = curracl->parent_subject)) {
72465 + /* if the cap isn't specified in the current computed mask but is specified in the
72466 + current level subject, and is lowered in the current level subject, then add
72467 + it to the set of dropped capabilities
72468 + otherwise, add the current level subject's mask to the current computed mask
72469 + */
72470 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
72471 + cap_raise(cap_mask, cap);
72472 + if (cap_raised(curracl->cap_lower, cap))
72473 + cap_raise(cap_drop, cap);
72474 + }
72475 + }
72476 +
72477 + if (!cap_raised(cap_drop, cap))
72478 + return 1;
72479 +
72480 + return 0;
72481 +}
72482 +
72483 +int
72484 +gr_acl_is_capable_nolog(const int cap)
72485 +{
72486 + return gr_task_acl_is_capable_nolog(current, cap);
72487 +}
72488 +
72489 diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
72490 new file mode 100644
72491 index 0000000..ca25605
72492 --- /dev/null
72493 +++ b/grsecurity/gracl_compat.c
72494 @@ -0,0 +1,270 @@
72495 +#include <linux/kernel.h>
72496 +#include <linux/gracl.h>
72497 +#include <linux/compat.h>
72498 +#include <linux/gracl_compat.h>
72499 +
72500 +#include <asm/uaccess.h>
72501 +
72502 +int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
72503 +{
72504 + struct gr_arg_wrapper_compat uwrapcompat;
72505 +
72506 + if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
72507 + return -EFAULT;
72508 +
72509 + if (((uwrapcompat.version != GRSECURITY_VERSION) &&
72510 + (uwrapcompat.version != 0x2901)) ||
72511 + (uwrapcompat.size != sizeof(struct gr_arg_compat)))
72512 + return -EINVAL;
72513 +
72514 + uwrap->arg = compat_ptr(uwrapcompat.arg);
72515 + uwrap->version = uwrapcompat.version;
72516 + uwrap->size = sizeof(struct gr_arg);
72517 +
72518 + return 0;
72519 +}
72520 +
72521 +int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
72522 +{
72523 + struct gr_arg_compat argcompat;
72524 +
72525 + if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
72526 + return -EFAULT;
72527 +
72528 + arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
72529 + arg->role_db.num_pointers = argcompat.role_db.num_pointers;
72530 + arg->role_db.num_roles = argcompat.role_db.num_roles;
72531 + arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
72532 + arg->role_db.num_subjects = argcompat.role_db.num_subjects;
72533 + arg->role_db.num_objects = argcompat.role_db.num_objects;
72534 +
72535 + memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
72536 + memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
72537 + memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
72538 + memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
72539 + arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
72540 + arg->segv_device = argcompat.segv_device;
72541 + arg->segv_inode = argcompat.segv_inode;
72542 + arg->segv_uid = argcompat.segv_uid;
72543 + arg->num_sprole_pws = argcompat.num_sprole_pws;
72544 + arg->mode = argcompat.mode;
72545 +
72546 + return 0;
72547 +}
72548 +
72549 +int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
72550 +{
72551 + struct acl_object_label_compat objcompat;
72552 +
72553 + if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
72554 + return -EFAULT;
72555 +
72556 + obj->filename = compat_ptr(objcompat.filename);
72557 + obj->inode = objcompat.inode;
72558 + obj->device = objcompat.device;
72559 + obj->mode = objcompat.mode;
72560 +
72561 + obj->nested = compat_ptr(objcompat.nested);
72562 + obj->globbed = compat_ptr(objcompat.globbed);
72563 +
72564 + obj->prev = compat_ptr(objcompat.prev);
72565 + obj->next = compat_ptr(objcompat.next);
72566 +
72567 + return 0;
72568 +}
72569 +
72570 +int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
72571 +{
72572 + unsigned int i;
72573 + struct acl_subject_label_compat subjcompat;
72574 +
72575 + if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
72576 + return -EFAULT;
72577 +
72578 + subj->filename = compat_ptr(subjcompat.filename);
72579 + subj->inode = subjcompat.inode;
72580 + subj->device = subjcompat.device;
72581 + subj->mode = subjcompat.mode;
72582 + subj->cap_mask = subjcompat.cap_mask;
72583 + subj->cap_lower = subjcompat.cap_lower;
72584 + subj->cap_invert_audit = subjcompat.cap_invert_audit;
72585 +
72586 + for (i = 0; i < GR_NLIMITS; i++) {
72587 + if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
72588 + subj->res[i].rlim_cur = RLIM_INFINITY;
72589 + else
72590 + subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
72591 + if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
72592 + subj->res[i].rlim_max = RLIM_INFINITY;
72593 + else
72594 + subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
72595 + }
72596 + subj->resmask = subjcompat.resmask;
72597 +
72598 + subj->user_trans_type = subjcompat.user_trans_type;
72599 + subj->group_trans_type = subjcompat.group_trans_type;
72600 + subj->user_transitions = compat_ptr(subjcompat.user_transitions);
72601 + subj->group_transitions = compat_ptr(subjcompat.group_transitions);
72602 + subj->user_trans_num = subjcompat.user_trans_num;
72603 + subj->group_trans_num = subjcompat.group_trans_num;
72604 +
72605 + memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
72606 + memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
72607 + subj->ip_type = subjcompat.ip_type;
72608 + subj->ips = compat_ptr(subjcompat.ips);
72609 + subj->ip_num = subjcompat.ip_num;
72610 + subj->inaddr_any_override = subjcompat.inaddr_any_override;
72611 +
72612 + subj->crashes = subjcompat.crashes;
72613 + subj->expires = subjcompat.expires;
72614 +
72615 + subj->parent_subject = compat_ptr(subjcompat.parent_subject);
72616 + subj->hash = compat_ptr(subjcompat.hash);
72617 + subj->prev = compat_ptr(subjcompat.prev);
72618 + subj->next = compat_ptr(subjcompat.next);
72619 +
72620 + subj->obj_hash = compat_ptr(subjcompat.obj_hash);
72621 + subj->obj_hash_size = subjcompat.obj_hash_size;
72622 + subj->pax_flags = subjcompat.pax_flags;
72623 +
72624 + return 0;
72625 +}
72626 +
72627 +int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
72628 +{
72629 + struct acl_role_label_compat rolecompat;
72630 +
72631 + if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
72632 + return -EFAULT;
72633 +
72634 + role->rolename = compat_ptr(rolecompat.rolename);
72635 + role->uidgid = rolecompat.uidgid;
72636 + role->roletype = rolecompat.roletype;
72637 +
72638 + role->auth_attempts = rolecompat.auth_attempts;
72639 + role->expires = rolecompat.expires;
72640 +
72641 + role->root_label = compat_ptr(rolecompat.root_label);
72642 + role->hash = compat_ptr(rolecompat.hash);
72643 +
72644 + role->prev = compat_ptr(rolecompat.prev);
72645 + role->next = compat_ptr(rolecompat.next);
72646 +
72647 + role->transitions = compat_ptr(rolecompat.transitions);
72648 + role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
72649 + role->domain_children = compat_ptr(rolecompat.domain_children);
72650 + role->domain_child_num = rolecompat.domain_child_num;
72651 +
72652 + role->umask = rolecompat.umask;
72653 +
72654 + role->subj_hash = compat_ptr(rolecompat.subj_hash);
72655 + role->subj_hash_size = rolecompat.subj_hash_size;
72656 +
72657 + return 0;
72658 +}
72659 +
72660 +int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
72661 +{
72662 + struct role_allowed_ip_compat roleip_compat;
72663 +
72664 + if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
72665 + return -EFAULT;
72666 +
72667 + roleip->addr = roleip_compat.addr;
72668 + roleip->netmask = roleip_compat.netmask;
72669 +
72670 + roleip->prev = compat_ptr(roleip_compat.prev);
72671 + roleip->next = compat_ptr(roleip_compat.next);
72672 +
72673 + return 0;
72674 +}
72675 +
72676 +int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
72677 +{
72678 + struct role_transition_compat trans_compat;
72679 +
72680 + if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
72681 + return -EFAULT;
72682 +
72683 + trans->rolename = compat_ptr(trans_compat.rolename);
72684 +
72685 + trans->prev = compat_ptr(trans_compat.prev);
72686 + trans->next = compat_ptr(trans_compat.next);
72687 +
72688 + return 0;
72689 +
72690 +}
72691 +
72692 +int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
72693 +{
72694 + struct gr_hash_struct_compat hash_compat;
72695 +
72696 + if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
72697 + return -EFAULT;
72698 +
72699 + hash->table = compat_ptr(hash_compat.table);
72700 + hash->nametable = compat_ptr(hash_compat.nametable);
72701 + hash->first = compat_ptr(hash_compat.first);
72702 +
72703 + hash->table_size = hash_compat.table_size;
72704 + hash->used_size = hash_compat.used_size;
72705 +
72706 + hash->type = hash_compat.type;
72707 +
72708 + return 0;
72709 +}
72710 +
72711 +int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
72712 +{
72713 + compat_uptr_t ptrcompat;
72714 +
72715 + if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
72716 + return -EFAULT;
72717 +
72718 + *(void **)ptr = compat_ptr(ptrcompat);
72719 +
72720 + return 0;
72721 +}
72722 +
72723 +int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
72724 +{
72725 + struct acl_ip_label_compat ip_compat;
72726 +
72727 + if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
72728 + return -EFAULT;
72729 +
72730 + ip->iface = compat_ptr(ip_compat.iface);
72731 + ip->addr = ip_compat.addr;
72732 + ip->netmask = ip_compat.netmask;
72733 + ip->low = ip_compat.low;
72734 + ip->high = ip_compat.high;
72735 + ip->mode = ip_compat.mode;
72736 + ip->type = ip_compat.type;
72737 +
72738 + memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
72739 +
72740 + ip->prev = compat_ptr(ip_compat.prev);
72741 + ip->next = compat_ptr(ip_compat.next);
72742 +
72743 + return 0;
72744 +}
72745 +
72746 +int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
72747 +{
72748 + struct sprole_pw_compat pw_compat;
72749 +
72750 + if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
72751 + return -EFAULT;
72752 +
72753 + pw->rolename = compat_ptr(pw_compat.rolename);
72754 + memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
72755 + memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
72756 +
72757 + return 0;
72758 +}
72759 +
72760 +size_t get_gr_arg_wrapper_size_compat(void)
72761 +{
72762 + return sizeof(struct gr_arg_wrapper_compat);
72763 +}
72764 +
72765 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
72766 new file mode 100644
72767 index 0000000..4008fdc
72768 --- /dev/null
72769 +++ b/grsecurity/gracl_fs.c
72770 @@ -0,0 +1,445 @@
72771 +#include <linux/kernel.h>
72772 +#include <linux/sched.h>
72773 +#include <linux/types.h>
72774 +#include <linux/fs.h>
72775 +#include <linux/file.h>
72776 +#include <linux/stat.h>
72777 +#include <linux/grsecurity.h>
72778 +#include <linux/grinternal.h>
72779 +#include <linux/gracl.h>
72780 +
72781 +umode_t
72782 +gr_acl_umask(void)
72783 +{
72784 + if (unlikely(!gr_acl_is_enabled()))
72785 + return 0;
72786 +
72787 + return current->role->umask;
72788 +}
72789 +
72790 +__u32
72791 +gr_acl_handle_hidden_file(const struct dentry * dentry,
72792 + const struct vfsmount * mnt)
72793 +{
72794 + __u32 mode;
72795 +
72796 + if (unlikely(d_is_negative(dentry)))
72797 + return GR_FIND;
72798 +
72799 + mode =
72800 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
72801 +
72802 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
72803 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
72804 + return mode;
72805 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
72806 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
72807 + return 0;
72808 + } else if (unlikely(!(mode & GR_FIND)))
72809 + return 0;
72810 +
72811 + return GR_FIND;
72812 +}
72813 +
72814 +__u32
72815 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
72816 + int acc_mode)
72817 +{
72818 + __u32 reqmode = GR_FIND;
72819 + __u32 mode;
72820 +
72821 + if (unlikely(d_is_negative(dentry)))
72822 + return reqmode;
72823 +
72824 + if (acc_mode & MAY_APPEND)
72825 + reqmode |= GR_APPEND;
72826 + else if (acc_mode & MAY_WRITE)
72827 + reqmode |= GR_WRITE;
72828 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
72829 + reqmode |= GR_READ;
72830 +
72831 + mode =
72832 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
72833 + mnt);
72834 +
72835 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
72836 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
72837 + reqmode & GR_READ ? " reading" : "",
72838 + reqmode & GR_WRITE ? " writing" : reqmode &
72839 + GR_APPEND ? " appending" : "");
72840 + return reqmode;
72841 + } else
72842 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
72843 + {
72844 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
72845 + reqmode & GR_READ ? " reading" : "",
72846 + reqmode & GR_WRITE ? " writing" : reqmode &
72847 + GR_APPEND ? " appending" : "");
72848 + return 0;
72849 + } else if (unlikely((mode & reqmode) != reqmode))
72850 + return 0;
72851 +
72852 + return reqmode;
72853 +}
72854 +
72855 +__u32
72856 +gr_acl_handle_creat(const struct dentry * dentry,
72857 + const struct dentry * p_dentry,
72858 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
72859 + const int imode)
72860 +{
72861 + __u32 reqmode = GR_WRITE | GR_CREATE;
72862 + __u32 mode;
72863 +
72864 + if (acc_mode & MAY_APPEND)
72865 + reqmode |= GR_APPEND;
72866 + // if a directory was required or the directory already exists, then
72867 + // don't count this open as a read
72868 + if ((acc_mode & MAY_READ) &&
72869 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
72870 + reqmode |= GR_READ;
72871 + if ((open_flags & O_CREAT) &&
72872 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
72873 + reqmode |= GR_SETID;
72874 +
72875 + mode =
72876 + gr_check_create(dentry, p_dentry, p_mnt,
72877 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
72878 +
72879 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
72880 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
72881 + reqmode & GR_READ ? " reading" : "",
72882 + reqmode & GR_WRITE ? " writing" : reqmode &
72883 + GR_APPEND ? " appending" : "");
72884 + return reqmode;
72885 + } else
72886 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
72887 + {
72888 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
72889 + reqmode & GR_READ ? " reading" : "",
72890 + reqmode & GR_WRITE ? " writing" : reqmode &
72891 + GR_APPEND ? " appending" : "");
72892 + return 0;
72893 + } else if (unlikely((mode & reqmode) != reqmode))
72894 + return 0;
72895 +
72896 + return reqmode;
72897 +}
72898 +
72899 +__u32
72900 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
72901 + const int fmode)
72902 +{
72903 + __u32 mode, reqmode = GR_FIND;
72904 +
72905 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
72906 + reqmode |= GR_EXEC;
72907 + if (fmode & S_IWOTH)
72908 + reqmode |= GR_WRITE;
72909 + if (fmode & S_IROTH)
72910 + reqmode |= GR_READ;
72911 +
72912 + mode =
72913 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
72914 + mnt);
72915 +
72916 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
72917 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
72918 + reqmode & GR_READ ? " reading" : "",
72919 + reqmode & GR_WRITE ? " writing" : "",
72920 + reqmode & GR_EXEC ? " executing" : "");
72921 + return reqmode;
72922 + } else
72923 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
72924 + {
72925 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
72926 + reqmode & GR_READ ? " reading" : "",
72927 + reqmode & GR_WRITE ? " writing" : "",
72928 + reqmode & GR_EXEC ? " executing" : "");
72929 + return 0;
72930 + } else if (unlikely((mode & reqmode) != reqmode))
72931 + return 0;
72932 +
72933 + return reqmode;
72934 +}
72935 +
72936 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
72937 +{
72938 + __u32 mode;
72939 +
72940 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
72941 +
72942 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
72943 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
72944 + return mode;
72945 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
72946 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
72947 + return 0;
72948 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
72949 + return 0;
72950 +
72951 + return (reqmode);
72952 +}
72953 +
72954 +__u32
72955 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
72956 +{
72957 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
72958 +}
72959 +
72960 +__u32
72961 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
72962 +{
72963 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
72964 +}
72965 +
72966 +__u32
72967 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
72968 +{
72969 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
72970 +}
72971 +
72972 +__u32
72973 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
72974 +{
72975 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
72976 +}
72977 +
72978 +__u32
72979 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
72980 + umode_t *modeptr)
72981 +{
72982 + umode_t mode;
72983 +
72984 + *modeptr &= ~gr_acl_umask();
72985 + mode = *modeptr;
72986 +
72987 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
72988 + return 1;
72989 +
72990 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
72991 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
72992 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
72993 + GR_CHMOD_ACL_MSG);
72994 + } else {
72995 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
72996 + }
72997 +}
72998 +
72999 +__u32
73000 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
73001 +{
73002 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
73003 +}
73004 +
73005 +__u32
73006 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
73007 +{
73008 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
73009 +}
73010 +
73011 +__u32
73012 +gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
73013 +{
73014 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
73015 +}
73016 +
73017 +__u32
73018 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
73019 +{
73020 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
73021 +}
73022 +
73023 +__u32
73024 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
73025 +{
73026 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
73027 + GR_UNIXCONNECT_ACL_MSG);
73028 +}
73029 +
73030 +/* hardlinks require at minimum create and link permission,
73031 + any additional privilege required is based on the
73032 + privilege of the file being linked to
73033 +*/
73034 +__u32
73035 +gr_acl_handle_link(const struct dentry * new_dentry,
73036 + const struct dentry * parent_dentry,
73037 + const struct vfsmount * parent_mnt,
73038 + const struct dentry * old_dentry,
73039 + const struct vfsmount * old_mnt, const struct filename *to)
73040 +{
73041 + __u32 mode;
73042 + __u32 needmode = GR_CREATE | GR_LINK;
73043 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
73044 +
73045 + mode =
73046 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
73047 + old_mnt);
73048 +
73049 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
73050 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
73051 + return mode;
73052 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
73053 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
73054 + return 0;
73055 + } else if (unlikely((mode & needmode) != needmode))
73056 + return 0;
73057 +
73058 + return 1;
73059 +}
73060 +
73061 +__u32
73062 +gr_acl_handle_symlink(const struct dentry * new_dentry,
73063 + const struct dentry * parent_dentry,
73064 + const struct vfsmount * parent_mnt, const struct filename *from)
73065 +{
73066 + __u32 needmode = GR_WRITE | GR_CREATE;
73067 + __u32 mode;
73068 +
73069 + mode =
73070 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
73071 + GR_CREATE | GR_AUDIT_CREATE |
73072 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
73073 +
73074 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
73075 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
73076 + return mode;
73077 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
73078 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
73079 + return 0;
73080 + } else if (unlikely((mode & needmode) != needmode))
73081 + return 0;
73082 +
73083 + return (GR_WRITE | GR_CREATE);
73084 +}
73085 +
73086 +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)
73087 +{
73088 + __u32 mode;
73089 +
73090 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
73091 +
73092 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
73093 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
73094 + return mode;
73095 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
73096 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
73097 + return 0;
73098 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
73099 + return 0;
73100 +
73101 + return (reqmode);
73102 +}
73103 +
73104 +__u32
73105 +gr_acl_handle_mknod(const struct dentry * new_dentry,
73106 + const struct dentry * parent_dentry,
73107 + const struct vfsmount * parent_mnt,
73108 + const int mode)
73109 +{
73110 + __u32 reqmode = GR_WRITE | GR_CREATE;
73111 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
73112 + reqmode |= GR_SETID;
73113 +
73114 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
73115 + reqmode, GR_MKNOD_ACL_MSG);
73116 +}
73117 +
73118 +__u32
73119 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
73120 + const struct dentry *parent_dentry,
73121 + const struct vfsmount *parent_mnt)
73122 +{
73123 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
73124 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
73125 +}
73126 +
73127 +#define RENAME_CHECK_SUCCESS(old, new) \
73128 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
73129 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
73130 +
73131 +int
73132 +gr_acl_handle_rename(struct dentry *new_dentry,
73133 + struct dentry *parent_dentry,
73134 + const struct vfsmount *parent_mnt,
73135 + struct dentry *old_dentry,
73136 + struct inode *old_parent_inode,
73137 + struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags)
73138 +{
73139 + __u32 comp1, comp2;
73140 + int error = 0;
73141 +
73142 + if (unlikely(!gr_acl_is_enabled()))
73143 + return 0;
73144 +
73145 + if (flags & RENAME_EXCHANGE) {
73146 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
73147 + GR_AUDIT_READ | GR_AUDIT_WRITE |
73148 + GR_SUPPRESS, parent_mnt);
73149 + comp2 =
73150 + gr_search_file(old_dentry,
73151 + GR_READ | GR_WRITE | GR_AUDIT_READ |
73152 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
73153 + } else if (d_is_negative(new_dentry)) {
73154 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
73155 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
73156 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
73157 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
73158 + GR_DELETE | GR_AUDIT_DELETE |
73159 + GR_AUDIT_READ | GR_AUDIT_WRITE |
73160 + GR_SUPPRESS, old_mnt);
73161 + } else {
73162 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
73163 + GR_CREATE | GR_DELETE |
73164 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
73165 + GR_AUDIT_READ | GR_AUDIT_WRITE |
73166 + GR_SUPPRESS, parent_mnt);
73167 + comp2 =
73168 + gr_search_file(old_dentry,
73169 + GR_READ | GR_WRITE | GR_AUDIT_READ |
73170 + GR_DELETE | GR_AUDIT_DELETE |
73171 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
73172 + }
73173 +
73174 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
73175 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
73176 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
73177 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
73178 + && !(comp2 & GR_SUPPRESS)) {
73179 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
73180 + error = -EACCES;
73181 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
73182 + error = -EACCES;
73183 +
73184 + return error;
73185 +}
73186 +
73187 +void
73188 +gr_acl_handle_exit(void)
73189 +{
73190 + u16 id;
73191 + char *rolename;
73192 +
73193 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
73194 + !(current->role->roletype & GR_ROLE_PERSIST))) {
73195 + id = current->acl_role_id;
73196 + rolename = current->role->rolename;
73197 + gr_set_acls(1);
73198 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
73199 + }
73200 +
73201 + gr_put_exec_file(current);
73202 + return;
73203 +}
73204 +
73205 +int
73206 +gr_acl_handle_procpidmem(const struct task_struct *task)
73207 +{
73208 + if (unlikely(!gr_acl_is_enabled()))
73209 + return 0;
73210 +
73211 + if (task != current && task->acl->mode & GR_PROTPROCFD)
73212 + return -EACCES;
73213 +
73214 + return 0;
73215 +}
73216 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
73217 new file mode 100644
73218 index 0000000..f056b81
73219 --- /dev/null
73220 +++ b/grsecurity/gracl_ip.c
73221 @@ -0,0 +1,386 @@
73222 +#include <linux/kernel.h>
73223 +#include <asm/uaccess.h>
73224 +#include <asm/errno.h>
73225 +#include <net/sock.h>
73226 +#include <linux/file.h>
73227 +#include <linux/fs.h>
73228 +#include <linux/net.h>
73229 +#include <linux/in.h>
73230 +#include <linux/skbuff.h>
73231 +#include <linux/ip.h>
73232 +#include <linux/udp.h>
73233 +#include <linux/types.h>
73234 +#include <linux/sched.h>
73235 +#include <linux/netdevice.h>
73236 +#include <linux/inetdevice.h>
73237 +#include <linux/gracl.h>
73238 +#include <linux/grsecurity.h>
73239 +#include <linux/grinternal.h>
73240 +
73241 +#define GR_BIND 0x01
73242 +#define GR_CONNECT 0x02
73243 +#define GR_INVERT 0x04
73244 +#define GR_BINDOVERRIDE 0x08
73245 +#define GR_CONNECTOVERRIDE 0x10
73246 +#define GR_SOCK_FAMILY 0x20
73247 +
73248 +static const char * gr_protocols[IPPROTO_MAX] = {
73249 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
73250 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
73251 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
73252 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
73253 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
73254 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
73255 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
73256 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
73257 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
73258 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
73259 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
73260 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
73261 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
73262 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
73263 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
73264 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
73265 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
73266 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
73267 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
73268 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
73269 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
73270 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
73271 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
73272 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
73273 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
73274 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
73275 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
73276 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
73277 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
73278 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
73279 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
73280 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
73281 + };
73282 +
73283 +static const char * gr_socktypes[SOCK_MAX] = {
73284 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
73285 + "unknown:7", "unknown:8", "unknown:9", "packet"
73286 + };
73287 +
73288 +static const char * gr_sockfamilies[AF_MAX+1] = {
73289 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
73290 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
73291 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
73292 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
73293 + };
73294 +
73295 +const char *
73296 +gr_proto_to_name(unsigned char proto)
73297 +{
73298 + return gr_protocols[proto];
73299 +}
73300 +
73301 +const char *
73302 +gr_socktype_to_name(unsigned char type)
73303 +{
73304 + return gr_socktypes[type];
73305 +}
73306 +
73307 +const char *
73308 +gr_sockfamily_to_name(unsigned char family)
73309 +{
73310 + return gr_sockfamilies[family];
73311 +}
73312 +
73313 +extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
73314 +
73315 +int
73316 +gr_search_socket(const int domain, const int type, const int protocol)
73317 +{
73318 + struct acl_subject_label *curr;
73319 + const struct cred *cred = current_cred();
73320 +
73321 + if (unlikely(!gr_acl_is_enabled()))
73322 + goto exit;
73323 +
73324 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
73325 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
73326 + goto exit; // let the kernel handle it
73327 +
73328 + curr = current->acl;
73329 +
73330 + if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
73331 + /* the family is allowed, if this is PF_INET allow it only if
73332 + the extra sock type/protocol checks pass */
73333 + if (domain == PF_INET)
73334 + goto inet_check;
73335 + goto exit;
73336 + } else {
73337 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73338 + __u32 fakeip = 0;
73339 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73340 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
73341 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
73342 + gr_to_filename(current->exec_file->f_path.dentry,
73343 + current->exec_file->f_path.mnt) :
73344 + curr->filename, curr->filename,
73345 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
73346 + &current->signal->saved_ip);
73347 + goto exit;
73348 + }
73349 + goto exit_fail;
73350 + }
73351 +
73352 +inet_check:
73353 + /* the rest of this checking is for IPv4 only */
73354 + if (!curr->ips)
73355 + goto exit;
73356 +
73357 + if ((curr->ip_type & (1U << type)) &&
73358 + (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
73359 + goto exit;
73360 +
73361 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73362 + /* we don't place acls on raw sockets , and sometimes
73363 + dgram/ip sockets are opened for ioctl and not
73364 + bind/connect, so we'll fake a bind learn log */
73365 + if (type == SOCK_RAW || type == SOCK_PACKET) {
73366 + __u32 fakeip = 0;
73367 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73368 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
73369 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
73370 + gr_to_filename(current->exec_file->f_path.dentry,
73371 + current->exec_file->f_path.mnt) :
73372 + curr->filename, curr->filename,
73373 + &fakeip, 0, type,
73374 + protocol, GR_CONNECT, &current->signal->saved_ip);
73375 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
73376 + __u32 fakeip = 0;
73377 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73378 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
73379 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
73380 + gr_to_filename(current->exec_file->f_path.dentry,
73381 + current->exec_file->f_path.mnt) :
73382 + curr->filename, curr->filename,
73383 + &fakeip, 0, type,
73384 + protocol, GR_BIND, &current->signal->saved_ip);
73385 + }
73386 + /* we'll log when they use connect or bind */
73387 + goto exit;
73388 + }
73389 +
73390 +exit_fail:
73391 + if (domain == PF_INET)
73392 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
73393 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
73394 + else if (rcu_access_pointer(net_families[domain]) != NULL)
73395 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
73396 + gr_socktype_to_name(type), protocol);
73397 +
73398 + return 0;
73399 +exit:
73400 + return 1;
73401 +}
73402 +
73403 +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)
73404 +{
73405 + if ((ip->mode & mode) &&
73406 + (ip_port >= ip->low) &&
73407 + (ip_port <= ip->high) &&
73408 + ((ntohl(ip_addr) & our_netmask) ==
73409 + (ntohl(our_addr) & our_netmask))
73410 + && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
73411 + && (ip->type & (1U << type))) {
73412 + if (ip->mode & GR_INVERT)
73413 + return 2; // specifically denied
73414 + else
73415 + return 1; // allowed
73416 + }
73417 +
73418 + return 0; // not specifically allowed, may continue parsing
73419 +}
73420 +
73421 +static int
73422 +gr_search_connectbind(const int full_mode, struct sock *sk,
73423 + struct sockaddr_in *addr, const int type)
73424 +{
73425 + char iface[IFNAMSIZ] = {0};
73426 + struct acl_subject_label *curr;
73427 + struct acl_ip_label *ip;
73428 + struct inet_sock *isk;
73429 + struct net_device *dev;
73430 + struct in_device *idev;
73431 + unsigned long i;
73432 + int ret;
73433 + int mode = full_mode & (GR_BIND | GR_CONNECT);
73434 + __u32 ip_addr = 0;
73435 + __u32 our_addr;
73436 + __u32 our_netmask;
73437 + char *p;
73438 + __u16 ip_port = 0;
73439 + const struct cred *cred = current_cred();
73440 +
73441 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
73442 + return 0;
73443 +
73444 + curr = current->acl;
73445 + isk = inet_sk(sk);
73446 +
73447 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
73448 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
73449 + addr->sin_addr.s_addr = curr->inaddr_any_override;
73450 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
73451 + struct sockaddr_in saddr;
73452 + int err;
73453 +
73454 + saddr.sin_family = AF_INET;
73455 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
73456 + saddr.sin_port = isk->inet_sport;
73457 +
73458 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
73459 + if (err)
73460 + return err;
73461 +
73462 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
73463 + if (err)
73464 + return err;
73465 + }
73466 +
73467 + if (!curr->ips)
73468 + return 0;
73469 +
73470 + ip_addr = addr->sin_addr.s_addr;
73471 + ip_port = ntohs(addr->sin_port);
73472 +
73473 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73474 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73475 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
73476 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
73477 + gr_to_filename(current->exec_file->f_path.dentry,
73478 + current->exec_file->f_path.mnt) :
73479 + curr->filename, curr->filename,
73480 + &ip_addr, ip_port, type,
73481 + sk->sk_protocol, mode, &current->signal->saved_ip);
73482 + return 0;
73483 + }
73484 +
73485 + for (i = 0; i < curr->ip_num; i++) {
73486 + ip = *(curr->ips + i);
73487 + if (ip->iface != NULL) {
73488 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
73489 + p = strchr(iface, ':');
73490 + if (p != NULL)
73491 + *p = '\0';
73492 + dev = dev_get_by_name(sock_net(sk), iface);
73493 + if (dev == NULL)
73494 + continue;
73495 + idev = in_dev_get(dev);
73496 + if (idev == NULL) {
73497 + dev_put(dev);
73498 + continue;
73499 + }
73500 + rcu_read_lock();
73501 + for_ifa(idev) {
73502 + if (!strcmp(ip->iface, ifa->ifa_label)) {
73503 + our_addr = ifa->ifa_address;
73504 + our_netmask = 0xffffffff;
73505 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
73506 + if (ret == 1) {
73507 + rcu_read_unlock();
73508 + in_dev_put(idev);
73509 + dev_put(dev);
73510 + return 0;
73511 + } else if (ret == 2) {
73512 + rcu_read_unlock();
73513 + in_dev_put(idev);
73514 + dev_put(dev);
73515 + goto denied;
73516 + }
73517 + }
73518 + } endfor_ifa(idev);
73519 + rcu_read_unlock();
73520 + in_dev_put(idev);
73521 + dev_put(dev);
73522 + } else {
73523 + our_addr = ip->addr;
73524 + our_netmask = ip->netmask;
73525 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
73526 + if (ret == 1)
73527 + return 0;
73528 + else if (ret == 2)
73529 + goto denied;
73530 + }
73531 + }
73532 +
73533 +denied:
73534 + if (mode == GR_BIND)
73535 + 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));
73536 + else if (mode == GR_CONNECT)
73537 + 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));
73538 +
73539 + return -EACCES;
73540 +}
73541 +
73542 +int
73543 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
73544 +{
73545 + /* always allow disconnection of dgram sockets with connect */
73546 + if (addr->sin_family == AF_UNSPEC)
73547 + return 0;
73548 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
73549 +}
73550 +
73551 +int
73552 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
73553 +{
73554 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
73555 +}
73556 +
73557 +int gr_search_listen(struct socket *sock)
73558 +{
73559 + struct sock *sk = sock->sk;
73560 + struct sockaddr_in addr;
73561 +
73562 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
73563 + addr.sin_port = inet_sk(sk)->inet_sport;
73564 +
73565 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
73566 +}
73567 +
73568 +int gr_search_accept(struct socket *sock)
73569 +{
73570 + struct sock *sk = sock->sk;
73571 + struct sockaddr_in addr;
73572 +
73573 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
73574 + addr.sin_port = inet_sk(sk)->inet_sport;
73575 +
73576 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
73577 +}
73578 +
73579 +int
73580 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
73581 +{
73582 + if (addr)
73583 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
73584 + else {
73585 + struct sockaddr_in sin;
73586 + const struct inet_sock *inet = inet_sk(sk);
73587 +
73588 + sin.sin_addr.s_addr = inet->inet_daddr;
73589 + sin.sin_port = inet->inet_dport;
73590 +
73591 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
73592 + }
73593 +}
73594 +
73595 +int
73596 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
73597 +{
73598 + struct sockaddr_in sin;
73599 +
73600 + if (unlikely(skb->len < sizeof (struct udphdr)))
73601 + return 0; // skip this packet
73602 +
73603 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
73604 + sin.sin_port = udp_hdr(skb)->source;
73605 +
73606 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
73607 +}
73608 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
73609 new file mode 100644
73610 index 0000000..25f54ef
73611 --- /dev/null
73612 +++ b/grsecurity/gracl_learn.c
73613 @@ -0,0 +1,207 @@
73614 +#include <linux/kernel.h>
73615 +#include <linux/mm.h>
73616 +#include <linux/sched.h>
73617 +#include <linux/poll.h>
73618 +#include <linux/string.h>
73619 +#include <linux/file.h>
73620 +#include <linux/types.h>
73621 +#include <linux/vmalloc.h>
73622 +#include <linux/grinternal.h>
73623 +
73624 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
73625 + size_t count, loff_t *ppos);
73626 +extern int gr_acl_is_enabled(void);
73627 +
73628 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
73629 +static int gr_learn_attached;
73630 +
73631 +/* use a 512k buffer */
73632 +#define LEARN_BUFFER_SIZE (512 * 1024)
73633 +
73634 +static DEFINE_SPINLOCK(gr_learn_lock);
73635 +static DEFINE_MUTEX(gr_learn_user_mutex);
73636 +
73637 +/* we need to maintain two buffers, so that the kernel context of grlearn
73638 + uses a semaphore around the userspace copying, and the other kernel contexts
73639 + use a spinlock when copying into the buffer, since they cannot sleep
73640 +*/
73641 +static char *learn_buffer;
73642 +static char *learn_buffer_user;
73643 +static int learn_buffer_len;
73644 +static int learn_buffer_user_len;
73645 +
73646 +static ssize_t
73647 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
73648 +{
73649 + DECLARE_WAITQUEUE(wait, current);
73650 + ssize_t retval = 0;
73651 +
73652 + add_wait_queue(&learn_wait, &wait);
73653 + set_current_state(TASK_INTERRUPTIBLE);
73654 + do {
73655 + mutex_lock(&gr_learn_user_mutex);
73656 + spin_lock(&gr_learn_lock);
73657 + if (learn_buffer_len)
73658 + break;
73659 + spin_unlock(&gr_learn_lock);
73660 + mutex_unlock(&gr_learn_user_mutex);
73661 + if (file->f_flags & O_NONBLOCK) {
73662 + retval = -EAGAIN;
73663 + goto out;
73664 + }
73665 + if (signal_pending(current)) {
73666 + retval = -ERESTARTSYS;
73667 + goto out;
73668 + }
73669 +
73670 + schedule();
73671 + } while (1);
73672 +
73673 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
73674 + learn_buffer_user_len = learn_buffer_len;
73675 + retval = learn_buffer_len;
73676 + learn_buffer_len = 0;
73677 +
73678 + spin_unlock(&gr_learn_lock);
73679 +
73680 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
73681 + retval = -EFAULT;
73682 +
73683 + mutex_unlock(&gr_learn_user_mutex);
73684 +out:
73685 + set_current_state(TASK_RUNNING);
73686 + remove_wait_queue(&learn_wait, &wait);
73687 + return retval;
73688 +}
73689 +
73690 +static unsigned int
73691 +poll_learn(struct file * file, poll_table * wait)
73692 +{
73693 + poll_wait(file, &learn_wait, wait);
73694 +
73695 + if (learn_buffer_len)
73696 + return (POLLIN | POLLRDNORM);
73697 +
73698 + return 0;
73699 +}
73700 +
73701 +void
73702 +gr_clear_learn_entries(void)
73703 +{
73704 + char *tmp;
73705 +
73706 + mutex_lock(&gr_learn_user_mutex);
73707 + spin_lock(&gr_learn_lock);
73708 + tmp = learn_buffer;
73709 + learn_buffer = NULL;
73710 + spin_unlock(&gr_learn_lock);
73711 + if (tmp)
73712 + vfree(tmp);
73713 + if (learn_buffer_user != NULL) {
73714 + vfree(learn_buffer_user);
73715 + learn_buffer_user = NULL;
73716 + }
73717 + learn_buffer_len = 0;
73718 + mutex_unlock(&gr_learn_user_mutex);
73719 +
73720 + return;
73721 +}
73722 +
73723 +void
73724 +gr_add_learn_entry(const char *fmt, ...)
73725 +{
73726 + va_list args;
73727 + unsigned int len;
73728 +
73729 + if (!gr_learn_attached)
73730 + return;
73731 +
73732 + spin_lock(&gr_learn_lock);
73733 +
73734 + /* leave a gap at the end so we know when it's "full" but don't have to
73735 + compute the exact length of the string we're trying to append
73736 + */
73737 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
73738 + spin_unlock(&gr_learn_lock);
73739 + wake_up_interruptible(&learn_wait);
73740 + return;
73741 + }
73742 + if (learn_buffer == NULL) {
73743 + spin_unlock(&gr_learn_lock);
73744 + return;
73745 + }
73746 +
73747 + va_start(args, fmt);
73748 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
73749 + va_end(args);
73750 +
73751 + learn_buffer_len += len + 1;
73752 +
73753 + spin_unlock(&gr_learn_lock);
73754 + wake_up_interruptible(&learn_wait);
73755 +
73756 + return;
73757 +}
73758 +
73759 +static int
73760 +open_learn(struct inode *inode, struct file *file)
73761 +{
73762 + if (file->f_mode & FMODE_READ && gr_learn_attached)
73763 + return -EBUSY;
73764 + if (file->f_mode & FMODE_READ) {
73765 + int retval = 0;
73766 + mutex_lock(&gr_learn_user_mutex);
73767 + if (learn_buffer == NULL)
73768 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
73769 + if (learn_buffer_user == NULL)
73770 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
73771 + if (learn_buffer == NULL) {
73772 + retval = -ENOMEM;
73773 + goto out_error;
73774 + }
73775 + if (learn_buffer_user == NULL) {
73776 + retval = -ENOMEM;
73777 + goto out_error;
73778 + }
73779 + learn_buffer_len = 0;
73780 + learn_buffer_user_len = 0;
73781 + gr_learn_attached = 1;
73782 +out_error:
73783 + mutex_unlock(&gr_learn_user_mutex);
73784 + return retval;
73785 + }
73786 + return 0;
73787 +}
73788 +
73789 +static int
73790 +close_learn(struct inode *inode, struct file *file)
73791 +{
73792 + if (file->f_mode & FMODE_READ) {
73793 + char *tmp = NULL;
73794 + mutex_lock(&gr_learn_user_mutex);
73795 + spin_lock(&gr_learn_lock);
73796 + tmp = learn_buffer;
73797 + learn_buffer = NULL;
73798 + spin_unlock(&gr_learn_lock);
73799 + if (tmp)
73800 + vfree(tmp);
73801 + if (learn_buffer_user != NULL) {
73802 + vfree(learn_buffer_user);
73803 + learn_buffer_user = NULL;
73804 + }
73805 + learn_buffer_len = 0;
73806 + learn_buffer_user_len = 0;
73807 + gr_learn_attached = 0;
73808 + mutex_unlock(&gr_learn_user_mutex);
73809 + }
73810 +
73811 + return 0;
73812 +}
73813 +
73814 +const struct file_operations grsec_fops = {
73815 + .read = read_learn,
73816 + .write = write_grsec_handler,
73817 + .open = open_learn,
73818 + .release = close_learn,
73819 + .poll = poll_learn,
73820 +};
73821 diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
73822 new file mode 100644
73823 index 0000000..3f8ade0
73824 --- /dev/null
73825 +++ b/grsecurity/gracl_policy.c
73826 @@ -0,0 +1,1782 @@
73827 +#include <linux/kernel.h>
73828 +#include <linux/module.h>
73829 +#include <linux/sched.h>
73830 +#include <linux/mm.h>
73831 +#include <linux/file.h>
73832 +#include <linux/fs.h>
73833 +#include <linux/namei.h>
73834 +#include <linux/mount.h>
73835 +#include <linux/tty.h>
73836 +#include <linux/proc_fs.h>
73837 +#include <linux/lglock.h>
73838 +#include <linux/slab.h>
73839 +#include <linux/vmalloc.h>
73840 +#include <linux/types.h>
73841 +#include <linux/sysctl.h>
73842 +#include <linux/netdevice.h>
73843 +#include <linux/ptrace.h>
73844 +#include <linux/gracl.h>
73845 +#include <linux/gralloc.h>
73846 +#include <linux/security.h>
73847 +#include <linux/grinternal.h>
73848 +#include <linux/pid_namespace.h>
73849 +#include <linux/stop_machine.h>
73850 +#include <linux/fdtable.h>
73851 +#include <linux/percpu.h>
73852 +#include <linux/lglock.h>
73853 +#include <linux/hugetlb.h>
73854 +#include <linux/posix-timers.h>
73855 +#include "../fs/mount.h"
73856 +
73857 +#include <asm/uaccess.h>
73858 +#include <asm/errno.h>
73859 +#include <asm/mman.h>
73860 +
73861 +extern struct gr_policy_state *polstate;
73862 +
73863 +#define FOR_EACH_ROLE_START(role) \
73864 + role = polstate->role_list; \
73865 + while (role) {
73866 +
73867 +#define FOR_EACH_ROLE_END(role) \
73868 + role = role->prev; \
73869 + }
73870 +
73871 +struct path gr_real_root;
73872 +
73873 +extern struct gr_alloc_state *current_alloc_state;
73874 +
73875 +u16 acl_sp_role_value;
73876 +
73877 +static DEFINE_MUTEX(gr_dev_mutex);
73878 +
73879 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
73880 +extern void gr_clear_learn_entries(void);
73881 +
73882 +struct gr_arg *gr_usermode __read_only;
73883 +unsigned char *gr_system_salt __read_only;
73884 +unsigned char *gr_system_sum __read_only;
73885 +
73886 +static unsigned int gr_auth_attempts = 0;
73887 +static unsigned long gr_auth_expires = 0UL;
73888 +
73889 +struct acl_object_label *fakefs_obj_rw;
73890 +struct acl_object_label *fakefs_obj_rwx;
73891 +
73892 +extern int gr_init_uidset(void);
73893 +extern void gr_free_uidset(void);
73894 +extern void gr_remove_uid(uid_t uid);
73895 +extern int gr_find_uid(uid_t uid);
73896 +
73897 +extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
73898 +extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
73899 +extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
73900 +extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
73901 +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);
73902 +extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
73903 +extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
73904 +extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
73905 +extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
73906 +extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
73907 +extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
73908 +extern void assign_special_role(const char *rolename);
73909 +extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
73910 +extern int gr_rbac_disable(void *unused);
73911 +extern void gr_enable_rbac_system(void);
73912 +
73913 +static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
73914 +{
73915 + if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
73916 + return -EFAULT;
73917 +
73918 + return 0;
73919 +}
73920 +
73921 +static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
73922 +{
73923 + if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
73924 + return -EFAULT;
73925 +
73926 + return 0;
73927 +}
73928 +
73929 +static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
73930 +{
73931 + if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
73932 + return -EFAULT;
73933 +
73934 + return 0;
73935 +}
73936 +
73937 +static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
73938 +{
73939 + if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
73940 + return -EFAULT;
73941 +
73942 + return 0;
73943 +}
73944 +
73945 +static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
73946 +{
73947 + if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
73948 + return -EFAULT;
73949 +
73950 + return 0;
73951 +}
73952 +
73953 +static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
73954 +{
73955 + if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
73956 + return -EFAULT;
73957 +
73958 + return 0;
73959 +}
73960 +
73961 +static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
73962 +{
73963 + if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
73964 + return -EFAULT;
73965 +
73966 + return 0;
73967 +}
73968 +
73969 +static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
73970 +{
73971 + if (copy_from_user(trans, userp, sizeof(struct role_transition)))
73972 + return -EFAULT;
73973 +
73974 + return 0;
73975 +}
73976 +
73977 +int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
73978 +{
73979 + if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
73980 + return -EFAULT;
73981 +
73982 + return 0;
73983 +}
73984 +
73985 +static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
73986 +{
73987 + if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
73988 + return -EFAULT;
73989 +
73990 + if (((uwrap->version != GRSECURITY_VERSION) &&
73991 + (uwrap->version != 0x2901)) ||
73992 + (uwrap->size != sizeof(struct gr_arg)))
73993 + return -EINVAL;
73994 +
73995 + return 0;
73996 +}
73997 +
73998 +static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
73999 +{
74000 + if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
74001 + return -EFAULT;
74002 +
74003 + return 0;
74004 +}
74005 +
74006 +static size_t get_gr_arg_wrapper_size_normal(void)
74007 +{
74008 + return sizeof(struct gr_arg_wrapper);
74009 +}
74010 +
74011 +#ifdef CONFIG_COMPAT
74012 +extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
74013 +extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
74014 +extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
74015 +extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
74016 +extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
74017 +extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
74018 +extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
74019 +extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
74020 +extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
74021 +extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
74022 +extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
74023 +extern size_t get_gr_arg_wrapper_size_compat(void);
74024 +
74025 +int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
74026 +int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
74027 +int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
74028 +int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
74029 +int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
74030 +int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
74031 +int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
74032 +int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
74033 +int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
74034 +int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
74035 +int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
74036 +size_t (* get_gr_arg_wrapper_size)(void) __read_only;
74037 +
74038 +#else
74039 +#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
74040 +#define copy_gr_arg copy_gr_arg_normal
74041 +#define copy_gr_hash_struct copy_gr_hash_struct_normal
74042 +#define copy_acl_object_label copy_acl_object_label_normal
74043 +#define copy_acl_subject_label copy_acl_subject_label_normal
74044 +#define copy_acl_role_label copy_acl_role_label_normal
74045 +#define copy_acl_ip_label copy_acl_ip_label_normal
74046 +#define copy_pointer_from_array copy_pointer_from_array_normal
74047 +#define copy_sprole_pw copy_sprole_pw_normal
74048 +#define copy_role_transition copy_role_transition_normal
74049 +#define copy_role_allowed_ip copy_role_allowed_ip_normal
74050 +#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
74051 +#endif
74052 +
74053 +static struct acl_subject_label *
74054 +lookup_subject_map(const struct acl_subject_label *userp)
74055 +{
74056 + unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
74057 + struct subject_map *match;
74058 +
74059 + match = polstate->subj_map_set.s_hash[index];
74060 +
74061 + while (match && match->user != userp)
74062 + match = match->next;
74063 +
74064 + if (match != NULL)
74065 + return match->kernel;
74066 + else
74067 + return NULL;
74068 +}
74069 +
74070 +static void
74071 +insert_subj_map_entry(struct subject_map *subjmap)
74072 +{
74073 + unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
74074 + struct subject_map **curr;
74075 +
74076 + subjmap->prev = NULL;
74077 +
74078 + curr = &polstate->subj_map_set.s_hash[index];
74079 + if (*curr != NULL)
74080 + (*curr)->prev = subjmap;
74081 +
74082 + subjmap->next = *curr;
74083 + *curr = subjmap;
74084 +
74085 + return;
74086 +}
74087 +
74088 +static void
74089 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
74090 +{
74091 + unsigned int index =
74092 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
74093 + struct acl_role_label **curr;
74094 + struct acl_role_label *tmp, *tmp2;
74095 +
74096 + curr = &polstate->acl_role_set.r_hash[index];
74097 +
74098 + /* simple case, slot is empty, just set it to our role */
74099 + if (*curr == NULL) {
74100 + *curr = role;
74101 + } else {
74102 + /* example:
74103 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
74104 + 2 -> 3
74105 + */
74106 + /* first check to see if we can already be reached via this slot */
74107 + tmp = *curr;
74108 + while (tmp && tmp != role)
74109 + tmp = tmp->next;
74110 + if (tmp == role) {
74111 + /* we don't need to add ourselves to this slot's chain */
74112 + return;
74113 + }
74114 + /* we need to add ourselves to this chain, two cases */
74115 + if (role->next == NULL) {
74116 + /* simple case, append the current chain to our role */
74117 + role->next = *curr;
74118 + *curr = role;
74119 + } else {
74120 + /* 1 -> 2 -> 3 -> 4
74121 + 2 -> 3 -> 4
74122 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
74123 + */
74124 + /* trickier case: walk our role's chain until we find
74125 + the role for the start of the current slot's chain */
74126 + tmp = role;
74127 + tmp2 = *curr;
74128 + while (tmp->next && tmp->next != tmp2)
74129 + tmp = tmp->next;
74130 + if (tmp->next == tmp2) {
74131 + /* from example above, we found 3, so just
74132 + replace this slot's chain with ours */
74133 + *curr = role;
74134 + } else {
74135 + /* we didn't find a subset of our role's chain
74136 + in the current slot's chain, so append their
74137 + chain to ours, and set us as the first role in
74138 + the slot's chain
74139 +
74140 + we could fold this case with the case above,
74141 + but making it explicit for clarity
74142 + */
74143 + tmp->next = tmp2;
74144 + *curr = role;
74145 + }
74146 + }
74147 + }
74148 +
74149 + return;
74150 +}
74151 +
74152 +static void
74153 +insert_acl_role_label(struct acl_role_label *role)
74154 +{
74155 + int i;
74156 +
74157 + if (polstate->role_list == NULL) {
74158 + polstate->role_list = role;
74159 + role->prev = NULL;
74160 + } else {
74161 + role->prev = polstate->role_list;
74162 + polstate->role_list = role;
74163 + }
74164 +
74165 + /* used for hash chains */
74166 + role->next = NULL;
74167 +
74168 + if (role->roletype & GR_ROLE_DOMAIN) {
74169 + for (i = 0; i < role->domain_child_num; i++)
74170 + __insert_acl_role_label(role, role->domain_children[i]);
74171 + } else
74172 + __insert_acl_role_label(role, role->uidgid);
74173 +}
74174 +
74175 +static int
74176 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
74177 +{
74178 + struct name_entry **curr, *nentry;
74179 + struct inodev_entry *ientry;
74180 + unsigned int len = strlen(name);
74181 + unsigned int key = full_name_hash(name, len);
74182 + unsigned int index = key % polstate->name_set.n_size;
74183 +
74184 + curr = &polstate->name_set.n_hash[index];
74185 +
74186 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
74187 + curr = &((*curr)->next);
74188 +
74189 + if (*curr != NULL)
74190 + return 1;
74191 +
74192 + nentry = acl_alloc(sizeof (struct name_entry));
74193 + if (nentry == NULL)
74194 + return 0;
74195 + ientry = acl_alloc(sizeof (struct inodev_entry));
74196 + if (ientry == NULL)
74197 + return 0;
74198 + ientry->nentry = nentry;
74199 +
74200 + nentry->key = key;
74201 + nentry->name = name;
74202 + nentry->inode = inode;
74203 + nentry->device = device;
74204 + nentry->len = len;
74205 + nentry->deleted = deleted;
74206 +
74207 + nentry->prev = NULL;
74208 + curr = &polstate->name_set.n_hash[index];
74209 + if (*curr != NULL)
74210 + (*curr)->prev = nentry;
74211 + nentry->next = *curr;
74212 + *curr = nentry;
74213 +
74214 + /* insert us into the table searchable by inode/dev */
74215 + __insert_inodev_entry(polstate, ientry);
74216 +
74217 + return 1;
74218 +}
74219 +
74220 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
74221 +
74222 +static void *
74223 +create_table(__u32 * len, int elementsize)
74224 +{
74225 + unsigned int table_sizes[] = {
74226 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
74227 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
74228 + 4194301, 8388593, 16777213, 33554393, 67108859
74229 + };
74230 + void *newtable = NULL;
74231 + unsigned int pwr = 0;
74232 +
74233 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
74234 + table_sizes[pwr] <= *len)
74235 + pwr++;
74236 +
74237 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
74238 + return newtable;
74239 +
74240 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
74241 + newtable =
74242 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
74243 + else
74244 + newtable = vmalloc(table_sizes[pwr] * elementsize);
74245 +
74246 + *len = table_sizes[pwr];
74247 +
74248 + return newtable;
74249 +}
74250 +
74251 +static int
74252 +init_variables(const struct gr_arg *arg, bool reload)
74253 +{
74254 + struct task_struct *reaper = init_pid_ns.child_reaper;
74255 + unsigned int stacksize;
74256 +
74257 + polstate->subj_map_set.s_size = arg->role_db.num_subjects;
74258 + polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
74259 + polstate->name_set.n_size = arg->role_db.num_objects;
74260 + polstate->inodev_set.i_size = arg->role_db.num_objects;
74261 +
74262 + if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
74263 + !polstate->name_set.n_size || !polstate->inodev_set.i_size)
74264 + return 1;
74265 +
74266 + if (!reload) {
74267 + if (!gr_init_uidset())
74268 + return 1;
74269 + }
74270 +
74271 + /* set up the stack that holds allocation info */
74272 +
74273 + stacksize = arg->role_db.num_pointers + 5;
74274 +
74275 + if (!acl_alloc_stack_init(stacksize))
74276 + return 1;
74277 +
74278 + if (!reload) {
74279 + /* grab reference for the real root dentry and vfsmount */
74280 + get_fs_root(reaper->fs, &gr_real_root);
74281 +
74282 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
74283 + 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);
74284 +#endif
74285 +
74286 + fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
74287 + if (fakefs_obj_rw == NULL)
74288 + return 1;
74289 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
74290 +
74291 + fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
74292 + if (fakefs_obj_rwx == NULL)
74293 + return 1;
74294 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
74295 + }
74296 +
74297 + polstate->subj_map_set.s_hash =
74298 + (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
74299 + polstate->acl_role_set.r_hash =
74300 + (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
74301 + polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
74302 + polstate->inodev_set.i_hash =
74303 + (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
74304 +
74305 + if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
74306 + !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
74307 + return 1;
74308 +
74309 + memset(polstate->subj_map_set.s_hash, 0,
74310 + sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
74311 + memset(polstate->acl_role_set.r_hash, 0,
74312 + sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
74313 + memset(polstate->name_set.n_hash, 0,
74314 + sizeof (struct name_entry *) * polstate->name_set.n_size);
74315 + memset(polstate->inodev_set.i_hash, 0,
74316 + sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
74317 +
74318 + return 0;
74319 +}
74320 +
74321 +/* free information not needed after startup
74322 + currently contains user->kernel pointer mappings for subjects
74323 +*/
74324 +
74325 +static void
74326 +free_init_variables(void)
74327 +{
74328 + __u32 i;
74329 +
74330 + if (polstate->subj_map_set.s_hash) {
74331 + for (i = 0; i < polstate->subj_map_set.s_size; i++) {
74332 + if (polstate->subj_map_set.s_hash[i]) {
74333 + kfree(polstate->subj_map_set.s_hash[i]);
74334 + polstate->subj_map_set.s_hash[i] = NULL;
74335 + }
74336 + }
74337 +
74338 + if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
74339 + PAGE_SIZE)
74340 + kfree(polstate->subj_map_set.s_hash);
74341 + else
74342 + vfree(polstate->subj_map_set.s_hash);
74343 + }
74344 +
74345 + return;
74346 +}
74347 +
74348 +static void
74349 +free_variables(bool reload)
74350 +{
74351 + struct acl_subject_label *s;
74352 + struct acl_role_label *r;
74353 + struct task_struct *task, *task2;
74354 + unsigned int x;
74355 +
74356 + if (!reload) {
74357 + gr_clear_learn_entries();
74358 +
74359 + read_lock(&tasklist_lock);
74360 + do_each_thread(task2, task) {
74361 + task->acl_sp_role = 0;
74362 + task->acl_role_id = 0;
74363 + task->inherited = 0;
74364 + task->acl = NULL;
74365 + task->role = NULL;
74366 + } while_each_thread(task2, task);
74367 + read_unlock(&tasklist_lock);
74368 +
74369 + kfree(fakefs_obj_rw);
74370 + fakefs_obj_rw = NULL;
74371 + kfree(fakefs_obj_rwx);
74372 + fakefs_obj_rwx = NULL;
74373 +
74374 + /* release the reference to the real root dentry and vfsmount */
74375 + path_put(&gr_real_root);
74376 + memset(&gr_real_root, 0, sizeof(gr_real_root));
74377 + }
74378 +
74379 + /* free all object hash tables */
74380 +
74381 + FOR_EACH_ROLE_START(r)
74382 + if (r->subj_hash == NULL)
74383 + goto next_role;
74384 + FOR_EACH_SUBJECT_START(r, s, x)
74385 + if (s->obj_hash == NULL)
74386 + break;
74387 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
74388 + kfree(s->obj_hash);
74389 + else
74390 + vfree(s->obj_hash);
74391 + FOR_EACH_SUBJECT_END(s, x)
74392 + FOR_EACH_NESTED_SUBJECT_START(r, s)
74393 + if (s->obj_hash == NULL)
74394 + break;
74395 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
74396 + kfree(s->obj_hash);
74397 + else
74398 + vfree(s->obj_hash);
74399 + FOR_EACH_NESTED_SUBJECT_END(s)
74400 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
74401 + kfree(r->subj_hash);
74402 + else
74403 + vfree(r->subj_hash);
74404 + r->subj_hash = NULL;
74405 +next_role:
74406 + FOR_EACH_ROLE_END(r)
74407 +
74408 + acl_free_all();
74409 +
74410 + if (polstate->acl_role_set.r_hash) {
74411 + if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
74412 + PAGE_SIZE)
74413 + kfree(polstate->acl_role_set.r_hash);
74414 + else
74415 + vfree(polstate->acl_role_set.r_hash);
74416 + }
74417 + if (polstate->name_set.n_hash) {
74418 + if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
74419 + PAGE_SIZE)
74420 + kfree(polstate->name_set.n_hash);
74421 + else
74422 + vfree(polstate->name_set.n_hash);
74423 + }
74424 +
74425 + if (polstate->inodev_set.i_hash) {
74426 + if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
74427 + PAGE_SIZE)
74428 + kfree(polstate->inodev_set.i_hash);
74429 + else
74430 + vfree(polstate->inodev_set.i_hash);
74431 + }
74432 +
74433 + if (!reload)
74434 + gr_free_uidset();
74435 +
74436 + memset(&polstate->name_set, 0, sizeof (struct name_db));
74437 + memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
74438 + memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
74439 + memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
74440 +
74441 + polstate->default_role = NULL;
74442 + polstate->kernel_role = NULL;
74443 + polstate->role_list = NULL;
74444 +
74445 + return;
74446 +}
74447 +
74448 +static struct acl_subject_label *
74449 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
74450 +
74451 +static int alloc_and_copy_string(char **name, unsigned int maxlen)
74452 +{
74453 + unsigned int len = strnlen_user(*name, maxlen);
74454 + char *tmp;
74455 +
74456 + if (!len || len >= maxlen)
74457 + return -EINVAL;
74458 +
74459 + if ((tmp = (char *) acl_alloc(len)) == NULL)
74460 + return -ENOMEM;
74461 +
74462 + if (copy_from_user(tmp, *name, len))
74463 + return -EFAULT;
74464 +
74465 + tmp[len-1] = '\0';
74466 + *name = tmp;
74467 +
74468 + return 0;
74469 +}
74470 +
74471 +static int
74472 +copy_user_glob(struct acl_object_label *obj)
74473 +{
74474 + struct acl_object_label *g_tmp, **guser;
74475 + int error;
74476 +
74477 + if (obj->globbed == NULL)
74478 + return 0;
74479 +
74480 + guser = &obj->globbed;
74481 + while (*guser) {
74482 + g_tmp = (struct acl_object_label *)
74483 + acl_alloc(sizeof (struct acl_object_label));
74484 + if (g_tmp == NULL)
74485 + return -ENOMEM;
74486 +
74487 + if (copy_acl_object_label(g_tmp, *guser))
74488 + return -EFAULT;
74489 +
74490 + error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
74491 + if (error)
74492 + return error;
74493 +
74494 + *guser = g_tmp;
74495 + guser = &(g_tmp->next);
74496 + }
74497 +
74498 + return 0;
74499 +}
74500 +
74501 +static int
74502 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
74503 + struct acl_role_label *role)
74504 +{
74505 + struct acl_object_label *o_tmp;
74506 + int ret;
74507 +
74508 + while (userp) {
74509 + if ((o_tmp = (struct acl_object_label *)
74510 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
74511 + return -ENOMEM;
74512 +
74513 + if (copy_acl_object_label(o_tmp, userp))
74514 + return -EFAULT;
74515 +
74516 + userp = o_tmp->prev;
74517 +
74518 + ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
74519 + if (ret)
74520 + return ret;
74521 +
74522 + insert_acl_obj_label(o_tmp, subj);
74523 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
74524 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
74525 + return -ENOMEM;
74526 +
74527 + ret = copy_user_glob(o_tmp);
74528 + if (ret)
74529 + return ret;
74530 +
74531 + if (o_tmp->nested) {
74532 + int already_copied;
74533 +
74534 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
74535 + if (IS_ERR(o_tmp->nested))
74536 + return PTR_ERR(o_tmp->nested);
74537 +
74538 + /* insert into nested subject list if we haven't copied this one yet
74539 + to prevent duplicate entries */
74540 + if (!already_copied) {
74541 + o_tmp->nested->next = role->hash->first;
74542 + role->hash->first = o_tmp->nested;
74543 + }
74544 + }
74545 + }
74546 +
74547 + return 0;
74548 +}
74549 +
74550 +static __u32
74551 +count_user_subjs(struct acl_subject_label *userp)
74552 +{
74553 + struct acl_subject_label s_tmp;
74554 + __u32 num = 0;
74555 +
74556 + while (userp) {
74557 + if (copy_acl_subject_label(&s_tmp, userp))
74558 + break;
74559 +
74560 + userp = s_tmp.prev;
74561 + }
74562 +
74563 + return num;
74564 +}
74565 +
74566 +static int
74567 +copy_user_allowedips(struct acl_role_label *rolep)
74568 +{
74569 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
74570 +
74571 + ruserip = rolep->allowed_ips;
74572 +
74573 + while (ruserip) {
74574 + rlast = rtmp;
74575 +
74576 + if ((rtmp = (struct role_allowed_ip *)
74577 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
74578 + return -ENOMEM;
74579 +
74580 + if (copy_role_allowed_ip(rtmp, ruserip))
74581 + return -EFAULT;
74582 +
74583 + ruserip = rtmp->prev;
74584 +
74585 + if (!rlast) {
74586 + rtmp->prev = NULL;
74587 + rolep->allowed_ips = rtmp;
74588 + } else {
74589 + rlast->next = rtmp;
74590 + rtmp->prev = rlast;
74591 + }
74592 +
74593 + if (!ruserip)
74594 + rtmp->next = NULL;
74595 + }
74596 +
74597 + return 0;
74598 +}
74599 +
74600 +static int
74601 +copy_user_transitions(struct acl_role_label *rolep)
74602 +{
74603 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
74604 + int error;
74605 +
74606 + rusertp = rolep->transitions;
74607 +
74608 + while (rusertp) {
74609 + rlast = rtmp;
74610 +
74611 + if ((rtmp = (struct role_transition *)
74612 + acl_alloc(sizeof (struct role_transition))) == NULL)
74613 + return -ENOMEM;
74614 +
74615 + if (copy_role_transition(rtmp, rusertp))
74616 + return -EFAULT;
74617 +
74618 + rusertp = rtmp->prev;
74619 +
74620 + error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
74621 + if (error)
74622 + return error;
74623 +
74624 + if (!rlast) {
74625 + rtmp->prev = NULL;
74626 + rolep->transitions = rtmp;
74627 + } else {
74628 + rlast->next = rtmp;
74629 + rtmp->prev = rlast;
74630 + }
74631 +
74632 + if (!rusertp)
74633 + rtmp->next = NULL;
74634 + }
74635 +
74636 + return 0;
74637 +}
74638 +
74639 +static __u32 count_user_objs(const struct acl_object_label __user *userp)
74640 +{
74641 + struct acl_object_label o_tmp;
74642 + __u32 num = 0;
74643 +
74644 + while (userp) {
74645 + if (copy_acl_object_label(&o_tmp, userp))
74646 + break;
74647 +
74648 + userp = o_tmp.prev;
74649 + num++;
74650 + }
74651 +
74652 + return num;
74653 +}
74654 +
74655 +static struct acl_subject_label *
74656 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
74657 +{
74658 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
74659 + __u32 num_objs;
74660 + struct acl_ip_label **i_tmp, *i_utmp2;
74661 + struct gr_hash_struct ghash;
74662 + struct subject_map *subjmap;
74663 + unsigned int i_num;
74664 + int err;
74665 +
74666 + if (already_copied != NULL)
74667 + *already_copied = 0;
74668 +
74669 + s_tmp = lookup_subject_map(userp);
74670 +
74671 + /* we've already copied this subject into the kernel, just return
74672 + the reference to it, and don't copy it over again
74673 + */
74674 + if (s_tmp) {
74675 + if (already_copied != NULL)
74676 + *already_copied = 1;
74677 + return(s_tmp);
74678 + }
74679 +
74680 + if ((s_tmp = (struct acl_subject_label *)
74681 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
74682 + return ERR_PTR(-ENOMEM);
74683 +
74684 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
74685 + if (subjmap == NULL)
74686 + return ERR_PTR(-ENOMEM);
74687 +
74688 + subjmap->user = userp;
74689 + subjmap->kernel = s_tmp;
74690 + insert_subj_map_entry(subjmap);
74691 +
74692 + if (copy_acl_subject_label(s_tmp, userp))
74693 + return ERR_PTR(-EFAULT);
74694 +
74695 + err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
74696 + if (err)
74697 + return ERR_PTR(err);
74698 +
74699 + if (!strcmp(s_tmp->filename, "/"))
74700 + role->root_label = s_tmp;
74701 +
74702 + if (copy_gr_hash_struct(&ghash, s_tmp->hash))
74703 + return ERR_PTR(-EFAULT);
74704 +
74705 + /* copy user and group transition tables */
74706 +
74707 + if (s_tmp->user_trans_num) {
74708 + uid_t *uidlist;
74709 +
74710 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
74711 + if (uidlist == NULL)
74712 + return ERR_PTR(-ENOMEM);
74713 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
74714 + return ERR_PTR(-EFAULT);
74715 +
74716 + s_tmp->user_transitions = uidlist;
74717 + }
74718 +
74719 + if (s_tmp->group_trans_num) {
74720 + gid_t *gidlist;
74721 +
74722 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
74723 + if (gidlist == NULL)
74724 + return ERR_PTR(-ENOMEM);
74725 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
74726 + return ERR_PTR(-EFAULT);
74727 +
74728 + s_tmp->group_transitions = gidlist;
74729 + }
74730 +
74731 + /* set up object hash table */
74732 + num_objs = count_user_objs(ghash.first);
74733 +
74734 + s_tmp->obj_hash_size = num_objs;
74735 + s_tmp->obj_hash =
74736 + (struct acl_object_label **)
74737 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
74738 +
74739 + if (!s_tmp->obj_hash)
74740 + return ERR_PTR(-ENOMEM);
74741 +
74742 + memset(s_tmp->obj_hash, 0,
74743 + s_tmp->obj_hash_size *
74744 + sizeof (struct acl_object_label *));
74745 +
74746 + /* add in objects */
74747 + err = copy_user_objs(ghash.first, s_tmp, role);
74748 +
74749 + if (err)
74750 + return ERR_PTR(err);
74751 +
74752 + /* set pointer for parent subject */
74753 + if (s_tmp->parent_subject) {
74754 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
74755 +
74756 + if (IS_ERR(s_tmp2))
74757 + return s_tmp2;
74758 +
74759 + s_tmp->parent_subject = s_tmp2;
74760 + }
74761 +
74762 + /* add in ip acls */
74763 +
74764 + if (!s_tmp->ip_num) {
74765 + s_tmp->ips = NULL;
74766 + goto insert;
74767 + }
74768 +
74769 + i_tmp =
74770 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
74771 + sizeof (struct acl_ip_label *));
74772 +
74773 + if (!i_tmp)
74774 + return ERR_PTR(-ENOMEM);
74775 +
74776 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
74777 + *(i_tmp + i_num) =
74778 + (struct acl_ip_label *)
74779 + acl_alloc(sizeof (struct acl_ip_label));
74780 + if (!*(i_tmp + i_num))
74781 + return ERR_PTR(-ENOMEM);
74782 +
74783 + if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
74784 + return ERR_PTR(-EFAULT);
74785 +
74786 + if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
74787 + return ERR_PTR(-EFAULT);
74788 +
74789 + if ((*(i_tmp + i_num))->iface == NULL)
74790 + continue;
74791 +
74792 + err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
74793 + if (err)
74794 + return ERR_PTR(err);
74795 + }
74796 +
74797 + s_tmp->ips = i_tmp;
74798 +
74799 +insert:
74800 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
74801 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
74802 + return ERR_PTR(-ENOMEM);
74803 +
74804 + return s_tmp;
74805 +}
74806 +
74807 +static int
74808 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
74809 +{
74810 + struct acl_subject_label s_pre;
74811 + struct acl_subject_label * ret;
74812 + int err;
74813 +
74814 + while (userp) {
74815 + if (copy_acl_subject_label(&s_pre, userp))
74816 + return -EFAULT;
74817 +
74818 + ret = do_copy_user_subj(userp, role, NULL);
74819 +
74820 + err = PTR_ERR(ret);
74821 + if (IS_ERR(ret))
74822 + return err;
74823 +
74824 + insert_acl_subj_label(ret, role);
74825 +
74826 + userp = s_pre.prev;
74827 + }
74828 +
74829 + return 0;
74830 +}
74831 +
74832 +static int
74833 +copy_user_acl(struct gr_arg *arg)
74834 +{
74835 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
74836 + struct acl_subject_label *subj_list;
74837 + struct sprole_pw *sptmp;
74838 + struct gr_hash_struct *ghash;
74839 + uid_t *domainlist;
74840 + unsigned int r_num;
74841 + int err = 0;
74842 + __u16 i;
74843 + __u32 num_subjs;
74844 +
74845 + /* we need a default and kernel role */
74846 + if (arg->role_db.num_roles < 2)
74847 + return -EINVAL;
74848 +
74849 + /* copy special role authentication info from userspace */
74850 +
74851 + polstate->num_sprole_pws = arg->num_sprole_pws;
74852 + polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
74853 +
74854 + if (!polstate->acl_special_roles && polstate->num_sprole_pws)
74855 + return -ENOMEM;
74856 +
74857 + for (i = 0; i < polstate->num_sprole_pws; i++) {
74858 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
74859 + if (!sptmp)
74860 + return -ENOMEM;
74861 + if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
74862 + return -EFAULT;
74863 +
74864 + err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
74865 + if (err)
74866 + return err;
74867 +
74868 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
74869 + printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
74870 +#endif
74871 +
74872 + polstate->acl_special_roles[i] = sptmp;
74873 + }
74874 +
74875 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
74876 +
74877 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
74878 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
74879 +
74880 + if (!r_tmp)
74881 + return -ENOMEM;
74882 +
74883 + if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
74884 + return -EFAULT;
74885 +
74886 + if (copy_acl_role_label(r_tmp, r_utmp2))
74887 + return -EFAULT;
74888 +
74889 + err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
74890 + if (err)
74891 + return err;
74892 +
74893 + if (!strcmp(r_tmp->rolename, "default")
74894 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
74895 + polstate->default_role = r_tmp;
74896 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
74897 + polstate->kernel_role = r_tmp;
74898 + }
74899 +
74900 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
74901 + return -ENOMEM;
74902 +
74903 + if (copy_gr_hash_struct(ghash, r_tmp->hash))
74904 + return -EFAULT;
74905 +
74906 + r_tmp->hash = ghash;
74907 +
74908 + num_subjs = count_user_subjs(r_tmp->hash->first);
74909 +
74910 + r_tmp->subj_hash_size = num_subjs;
74911 + r_tmp->subj_hash =
74912 + (struct acl_subject_label **)
74913 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
74914 +
74915 + if (!r_tmp->subj_hash)
74916 + return -ENOMEM;
74917 +
74918 + err = copy_user_allowedips(r_tmp);
74919 + if (err)
74920 + return err;
74921 +
74922 + /* copy domain info */
74923 + if (r_tmp->domain_children != NULL) {
74924 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
74925 + if (domainlist == NULL)
74926 + return -ENOMEM;
74927 +
74928 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
74929 + return -EFAULT;
74930 +
74931 + r_tmp->domain_children = domainlist;
74932 + }
74933 +
74934 + err = copy_user_transitions(r_tmp);
74935 + if (err)
74936 + return err;
74937 +
74938 + memset(r_tmp->subj_hash, 0,
74939 + r_tmp->subj_hash_size *
74940 + sizeof (struct acl_subject_label *));
74941 +
74942 + /* acquire the list of subjects, then NULL out
74943 + the list prior to parsing the subjects for this role,
74944 + as during this parsing the list is replaced with a list
74945 + of *nested* subjects for the role
74946 + */
74947 + subj_list = r_tmp->hash->first;
74948 +
74949 + /* set nested subject list to null */
74950 + r_tmp->hash->first = NULL;
74951 +
74952 + err = copy_user_subjs(subj_list, r_tmp);
74953 +
74954 + if (err)
74955 + return err;
74956 +
74957 + insert_acl_role_label(r_tmp);
74958 + }
74959 +
74960 + if (polstate->default_role == NULL || polstate->kernel_role == NULL)
74961 + return -EINVAL;
74962 +
74963 + return err;
74964 +}
74965 +
74966 +static int gracl_reload_apply_policies(void *reload)
74967 +{
74968 + struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
74969 + struct task_struct *task, *task2;
74970 + struct acl_role_label *role, *rtmp;
74971 + struct acl_subject_label *subj;
74972 + const struct cred *cred;
74973 + int role_applied;
74974 + int ret = 0;
74975 +
74976 + memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
74977 + memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
74978 +
74979 + /* first make sure we'll be able to apply the new policy cleanly */
74980 + do_each_thread(task2, task) {
74981 + if (task->exec_file == NULL)
74982 + continue;
74983 + role_applied = 0;
74984 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
74985 + /* preserve special roles */
74986 + FOR_EACH_ROLE_START(role)
74987 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
74988 + rtmp = task->role;
74989 + task->role = role;
74990 + role_applied = 1;
74991 + break;
74992 + }
74993 + FOR_EACH_ROLE_END(role)
74994 + }
74995 + if (!role_applied) {
74996 + cred = __task_cred(task);
74997 + rtmp = task->role;
74998 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
74999 + }
75000 + /* this handles non-nested inherited subjects, nested subjects will still
75001 + be dropped currently */
75002 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
75003 + task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
75004 + /* change the role back so that we've made no modifications to the policy */
75005 + task->role = rtmp;
75006 +
75007 + if (subj == NULL || task->tmpacl == NULL) {
75008 + ret = -EINVAL;
75009 + goto out;
75010 + }
75011 + } while_each_thread(task2, task);
75012 +
75013 + /* now actually apply the policy */
75014 +
75015 + do_each_thread(task2, task) {
75016 + if (task->exec_file) {
75017 + role_applied = 0;
75018 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
75019 + /* preserve special roles */
75020 + FOR_EACH_ROLE_START(role)
75021 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
75022 + task->role = role;
75023 + role_applied = 1;
75024 + break;
75025 + }
75026 + FOR_EACH_ROLE_END(role)
75027 + }
75028 + if (!role_applied) {
75029 + cred = __task_cred(task);
75030 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
75031 + }
75032 + /* this handles non-nested inherited subjects, nested subjects will still
75033 + be dropped currently */
75034 + if (!reload_state->oldmode && task->inherited)
75035 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
75036 + else {
75037 + /* looked up and tagged to the task previously */
75038 + subj = task->tmpacl;
75039 + }
75040 + /* subj will be non-null */
75041 + __gr_apply_subject_to_task(polstate, task, subj);
75042 + if (reload_state->oldmode) {
75043 + task->acl_role_id = 0;
75044 + task->acl_sp_role = 0;
75045 + task->inherited = 0;
75046 + }
75047 + } else {
75048 + // it's a kernel process
75049 + task->role = polstate->kernel_role;
75050 + task->acl = polstate->kernel_role->root_label;
75051 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
75052 + task->acl->mode &= ~GR_PROCFIND;
75053 +#endif
75054 + }
75055 + } while_each_thread(task2, task);
75056 +
75057 + memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
75058 + memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
75059 +
75060 +out:
75061 +
75062 + return ret;
75063 +}
75064 +
75065 +static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
75066 +{
75067 + struct gr_reload_state new_reload_state = { };
75068 + int err;
75069 +
75070 + new_reload_state.oldpolicy_ptr = polstate;
75071 + new_reload_state.oldalloc_ptr = current_alloc_state;
75072 + new_reload_state.oldmode = oldmode;
75073 +
75074 + current_alloc_state = &new_reload_state.newalloc;
75075 + polstate = &new_reload_state.newpolicy;
75076 +
75077 + /* everything relevant is now saved off, copy in the new policy */
75078 + if (init_variables(args, true)) {
75079 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
75080 + err = -ENOMEM;
75081 + goto error;
75082 + }
75083 +
75084 + err = copy_user_acl(args);
75085 + free_init_variables();
75086 + if (err)
75087 + goto error;
75088 + /* the new policy is copied in, with the old policy available via saved_state
75089 + first go through applying roles, making sure to preserve special roles
75090 + then apply new subjects, making sure to preserve inherited and nested subjects,
75091 + though currently only inherited subjects will be preserved
75092 + */
75093 + err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
75094 + if (err)
75095 + goto error;
75096 +
75097 + /* we've now applied the new policy, so restore the old policy state to free it */
75098 + polstate = &new_reload_state.oldpolicy;
75099 + current_alloc_state = &new_reload_state.oldalloc;
75100 + free_variables(true);
75101 +
75102 + /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
75103 + to running_polstate/current_alloc_state inside stop_machine
75104 + */
75105 + err = 0;
75106 + goto out;
75107 +error:
75108 + /* on error of loading the new policy, we'll just keep the previous
75109 + policy set around
75110 + */
75111 + free_variables(true);
75112 +
75113 + /* doesn't affect runtime, but maintains consistent state */
75114 +out:
75115 + polstate = new_reload_state.oldpolicy_ptr;
75116 + current_alloc_state = new_reload_state.oldalloc_ptr;
75117 +
75118 + return err;
75119 +}
75120 +
75121 +static int
75122 +gracl_init(struct gr_arg *args)
75123 +{
75124 + int error = 0;
75125 +
75126 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
75127 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
75128 +
75129 + if (init_variables(args, false)) {
75130 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
75131 + error = -ENOMEM;
75132 + goto out;
75133 + }
75134 +
75135 + error = copy_user_acl(args);
75136 + free_init_variables();
75137 + if (error)
75138 + goto out;
75139 +
75140 + error = gr_set_acls(0);
75141 + if (error)
75142 + goto out;
75143 +
75144 + gr_enable_rbac_system();
75145 +
75146 + return 0;
75147 +
75148 +out:
75149 + free_variables(false);
75150 + return error;
75151 +}
75152 +
75153 +static int
75154 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
75155 + unsigned char **sum)
75156 +{
75157 + struct acl_role_label *r;
75158 + struct role_allowed_ip *ipp;
75159 + struct role_transition *trans;
75160 + unsigned int i;
75161 + int found = 0;
75162 + u32 curr_ip = current->signal->curr_ip;
75163 +
75164 + current->signal->saved_ip = curr_ip;
75165 +
75166 + /* check transition table */
75167 +
75168 + for (trans = current->role->transitions; trans; trans = trans->next) {
75169 + if (!strcmp(rolename, trans->rolename)) {
75170 + found = 1;
75171 + break;
75172 + }
75173 + }
75174 +
75175 + if (!found)
75176 + return 0;
75177 +
75178 + /* handle special roles that do not require authentication
75179 + and check ip */
75180 +
75181 + FOR_EACH_ROLE_START(r)
75182 + if (!strcmp(rolename, r->rolename) &&
75183 + (r->roletype & GR_ROLE_SPECIAL)) {
75184 + found = 0;
75185 + if (r->allowed_ips != NULL) {
75186 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
75187 + if ((ntohl(curr_ip) & ipp->netmask) ==
75188 + (ntohl(ipp->addr) & ipp->netmask))
75189 + found = 1;
75190 + }
75191 + } else
75192 + found = 2;
75193 + if (!found)
75194 + return 0;
75195 +
75196 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
75197 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
75198 + *salt = NULL;
75199 + *sum = NULL;
75200 + return 1;
75201 + }
75202 + }
75203 + FOR_EACH_ROLE_END(r)
75204 +
75205 + for (i = 0; i < polstate->num_sprole_pws; i++) {
75206 + if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
75207 + *salt = polstate->acl_special_roles[i]->salt;
75208 + *sum = polstate->acl_special_roles[i]->sum;
75209 + return 1;
75210 + }
75211 + }
75212 +
75213 + return 0;
75214 +}
75215 +
75216 +int gr_check_secure_terminal(struct task_struct *task)
75217 +{
75218 + struct task_struct *p, *p2, *p3;
75219 + struct files_struct *files;
75220 + struct fdtable *fdt;
75221 + struct file *our_file = NULL, *file;
75222 + int i;
75223 +
75224 + if (task->signal->tty == NULL)
75225 + return 1;
75226 +
75227 + files = get_files_struct(task);
75228 + if (files != NULL) {
75229 + rcu_read_lock();
75230 + fdt = files_fdtable(files);
75231 + for (i=0; i < fdt->max_fds; i++) {
75232 + file = fcheck_files(files, i);
75233 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
75234 + get_file(file);
75235 + our_file = file;
75236 + }
75237 + }
75238 + rcu_read_unlock();
75239 + put_files_struct(files);
75240 + }
75241 +
75242 + if (our_file == NULL)
75243 + return 1;
75244 +
75245 + read_lock(&tasklist_lock);
75246 + do_each_thread(p2, p) {
75247 + files = get_files_struct(p);
75248 + if (files == NULL ||
75249 + (p->signal && p->signal->tty == task->signal->tty)) {
75250 + if (files != NULL)
75251 + put_files_struct(files);
75252 + continue;
75253 + }
75254 + rcu_read_lock();
75255 + fdt = files_fdtable(files);
75256 + for (i=0; i < fdt->max_fds; i++) {
75257 + file = fcheck_files(files, i);
75258 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
75259 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
75260 + p3 = task;
75261 + while (task_pid_nr(p3) > 0) {
75262 + if (p3 == p)
75263 + break;
75264 + p3 = p3->real_parent;
75265 + }
75266 + if (p3 == p)
75267 + break;
75268 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
75269 + gr_handle_alertkill(p);
75270 + rcu_read_unlock();
75271 + put_files_struct(files);
75272 + read_unlock(&tasklist_lock);
75273 + fput(our_file);
75274 + return 0;
75275 + }
75276 + }
75277 + rcu_read_unlock();
75278 + put_files_struct(files);
75279 + } while_each_thread(p2, p);
75280 + read_unlock(&tasklist_lock);
75281 +
75282 + fput(our_file);
75283 + return 1;
75284 +}
75285 +
75286 +ssize_t
75287 +write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
75288 +{
75289 + struct gr_arg_wrapper uwrap;
75290 + unsigned char *sprole_salt = NULL;
75291 + unsigned char *sprole_sum = NULL;
75292 + int error = 0;
75293 + int error2 = 0;
75294 + size_t req_count = 0;
75295 + unsigned char oldmode = 0;
75296 +
75297 + mutex_lock(&gr_dev_mutex);
75298 +
75299 + if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
75300 + error = -EPERM;
75301 + goto out;
75302 + }
75303 +
75304 +#ifdef CONFIG_COMPAT
75305 + pax_open_kernel();
75306 + if (is_compat_task()) {
75307 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
75308 + copy_gr_arg = &copy_gr_arg_compat;
75309 + copy_acl_object_label = &copy_acl_object_label_compat;
75310 + copy_acl_subject_label = &copy_acl_subject_label_compat;
75311 + copy_acl_role_label = &copy_acl_role_label_compat;
75312 + copy_acl_ip_label = &copy_acl_ip_label_compat;
75313 + copy_role_allowed_ip = &copy_role_allowed_ip_compat;
75314 + copy_role_transition = &copy_role_transition_compat;
75315 + copy_sprole_pw = &copy_sprole_pw_compat;
75316 + copy_gr_hash_struct = &copy_gr_hash_struct_compat;
75317 + copy_pointer_from_array = &copy_pointer_from_array_compat;
75318 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
75319 + } else {
75320 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
75321 + copy_gr_arg = &copy_gr_arg_normal;
75322 + copy_acl_object_label = &copy_acl_object_label_normal;
75323 + copy_acl_subject_label = &copy_acl_subject_label_normal;
75324 + copy_acl_role_label = &copy_acl_role_label_normal;
75325 + copy_acl_ip_label = &copy_acl_ip_label_normal;
75326 + copy_role_allowed_ip = &copy_role_allowed_ip_normal;
75327 + copy_role_transition = &copy_role_transition_normal;
75328 + copy_sprole_pw = &copy_sprole_pw_normal;
75329 + copy_gr_hash_struct = &copy_gr_hash_struct_normal;
75330 + copy_pointer_from_array = &copy_pointer_from_array_normal;
75331 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
75332 + }
75333 + pax_close_kernel();
75334 +#endif
75335 +
75336 + req_count = get_gr_arg_wrapper_size();
75337 +
75338 + if (count != req_count) {
75339 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
75340 + error = -EINVAL;
75341 + goto out;
75342 + }
75343 +
75344 +
75345 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
75346 + gr_auth_expires = 0;
75347 + gr_auth_attempts = 0;
75348 + }
75349 +
75350 + error = copy_gr_arg_wrapper(buf, &uwrap);
75351 + if (error)
75352 + goto out;
75353 +
75354 + error = copy_gr_arg(uwrap.arg, gr_usermode);
75355 + if (error)
75356 + goto out;
75357 +
75358 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
75359 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
75360 + time_after(gr_auth_expires, get_seconds())) {
75361 + error = -EBUSY;
75362 + goto out;
75363 + }
75364 +
75365 + /* if non-root trying to do anything other than use a special role,
75366 + do not attempt authentication, do not count towards authentication
75367 + locking
75368 + */
75369 +
75370 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
75371 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
75372 + gr_is_global_nonroot(current_uid())) {
75373 + error = -EPERM;
75374 + goto out;
75375 + }
75376 +
75377 + /* ensure pw and special role name are null terminated */
75378 +
75379 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
75380 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
75381 +
75382 + /* Okay.
75383 + * We have our enough of the argument structure..(we have yet
75384 + * to copy_from_user the tables themselves) . Copy the tables
75385 + * only if we need them, i.e. for loading operations. */
75386 +
75387 + switch (gr_usermode->mode) {
75388 + case GR_STATUS:
75389 + if (gr_acl_is_enabled()) {
75390 + error = 1;
75391 + if (!gr_check_secure_terminal(current))
75392 + error = 3;
75393 + } else
75394 + error = 2;
75395 + goto out;
75396 + case GR_SHUTDOWN:
75397 + if (gr_acl_is_enabled() && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75398 + stop_machine(gr_rbac_disable, NULL, NULL);
75399 + free_variables(false);
75400 + memset(gr_usermode, 0, sizeof(struct gr_arg));
75401 + memset(gr_system_salt, 0, GR_SALT_LEN);
75402 + memset(gr_system_sum, 0, GR_SHA_LEN);
75403 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
75404 + } else if (gr_acl_is_enabled()) {
75405 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
75406 + error = -EPERM;
75407 + } else {
75408 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
75409 + error = -EAGAIN;
75410 + }
75411 + break;
75412 + case GR_ENABLE:
75413 + if (!gr_acl_is_enabled() && !(error2 = gracl_init(gr_usermode)))
75414 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
75415 + else {
75416 + if (gr_acl_is_enabled())
75417 + error = -EAGAIN;
75418 + else
75419 + error = error2;
75420 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
75421 + }
75422 + break;
75423 + case GR_OLDRELOAD:
75424 + oldmode = 1;
75425 + case GR_RELOAD:
75426 + if (!gr_acl_is_enabled()) {
75427 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
75428 + error = -EAGAIN;
75429 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75430 + error2 = gracl_reload(gr_usermode, oldmode);
75431 + if (!error2)
75432 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
75433 + else {
75434 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
75435 + error = error2;
75436 + }
75437 + } else {
75438 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
75439 + error = -EPERM;
75440 + }
75441 + break;
75442 + case GR_SEGVMOD:
75443 + if (unlikely(!gr_acl_is_enabled())) {
75444 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
75445 + error = -EAGAIN;
75446 + break;
75447 + }
75448 +
75449 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75450 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
75451 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
75452 + struct acl_subject_label *segvacl;
75453 + segvacl =
75454 + lookup_acl_subj_label(gr_usermode->segv_inode,
75455 + gr_usermode->segv_device,
75456 + current->role);
75457 + if (segvacl) {
75458 + segvacl->crashes = 0;
75459 + segvacl->expires = 0;
75460 + }
75461 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
75462 + gr_remove_uid(gr_usermode->segv_uid);
75463 + }
75464 + } else {
75465 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
75466 + error = -EPERM;
75467 + }
75468 + break;
75469 + case GR_SPROLE:
75470 + case GR_SPROLEPAM:
75471 + if (unlikely(!gr_acl_is_enabled())) {
75472 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
75473 + error = -EAGAIN;
75474 + break;
75475 + }
75476 +
75477 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
75478 + current->role->expires = 0;
75479 + current->role->auth_attempts = 0;
75480 + }
75481 +
75482 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
75483 + time_after(current->role->expires, get_seconds())) {
75484 + error = -EBUSY;
75485 + goto out;
75486 + }
75487 +
75488 + if (lookup_special_role_auth
75489 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
75490 + && ((!sprole_salt && !sprole_sum)
75491 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
75492 + char *p = "";
75493 + assign_special_role(gr_usermode->sp_role);
75494 + read_lock(&tasklist_lock);
75495 + if (current->real_parent)
75496 + p = current->real_parent->role->rolename;
75497 + read_unlock(&tasklist_lock);
75498 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
75499 + p, acl_sp_role_value);
75500 + } else {
75501 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
75502 + error = -EPERM;
75503 + if(!(current->role->auth_attempts++))
75504 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
75505 +
75506 + goto out;
75507 + }
75508 + break;
75509 + case GR_UNSPROLE:
75510 + if (unlikely(!gr_acl_is_enabled())) {
75511 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
75512 + error = -EAGAIN;
75513 + break;
75514 + }
75515 +
75516 + if (current->role->roletype & GR_ROLE_SPECIAL) {
75517 + char *p = "";
75518 + int i = 0;
75519 +
75520 + read_lock(&tasklist_lock);
75521 + if (current->real_parent) {
75522 + p = current->real_parent->role->rolename;
75523 + i = current->real_parent->acl_role_id;
75524 + }
75525 + read_unlock(&tasklist_lock);
75526 +
75527 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
75528 + gr_set_acls(1);
75529 + } else {
75530 + error = -EPERM;
75531 + goto out;
75532 + }
75533 + break;
75534 + default:
75535 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
75536 + error = -EINVAL;
75537 + break;
75538 + }
75539 +
75540 + if (error != -EPERM)
75541 + goto out;
75542 +
75543 + if(!(gr_auth_attempts++))
75544 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
75545 +
75546 + out:
75547 + mutex_unlock(&gr_dev_mutex);
75548 +
75549 + if (!error)
75550 + error = req_count;
75551 +
75552 + return error;
75553 +}
75554 +
75555 +int
75556 +gr_set_acls(const int type)
75557 +{
75558 + struct task_struct *task, *task2;
75559 + struct acl_role_label *role = current->role;
75560 + struct acl_subject_label *subj;
75561 + __u16 acl_role_id = current->acl_role_id;
75562 + const struct cred *cred;
75563 + int ret;
75564 +
75565 + rcu_read_lock();
75566 + read_lock(&tasklist_lock);
75567 + read_lock(&grsec_exec_file_lock);
75568 + do_each_thread(task2, task) {
75569 + /* check to see if we're called from the exit handler,
75570 + if so, only replace ACLs that have inherited the admin
75571 + ACL */
75572 +
75573 + if (type && (task->role != role ||
75574 + task->acl_role_id != acl_role_id))
75575 + continue;
75576 +
75577 + task->acl_role_id = 0;
75578 + task->acl_sp_role = 0;
75579 + task->inherited = 0;
75580 +
75581 + if (task->exec_file) {
75582 + cred = __task_cred(task);
75583 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
75584 + subj = __gr_get_subject_for_task(polstate, task, NULL);
75585 + if (subj == NULL) {
75586 + ret = -EINVAL;
75587 + read_unlock(&grsec_exec_file_lock);
75588 + read_unlock(&tasklist_lock);
75589 + rcu_read_unlock();
75590 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
75591 + return ret;
75592 + }
75593 + __gr_apply_subject_to_task(polstate, task, subj);
75594 + } else {
75595 + // it's a kernel process
75596 + task->role = polstate->kernel_role;
75597 + task->acl = polstate->kernel_role->root_label;
75598 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
75599 + task->acl->mode &= ~GR_PROCFIND;
75600 +#endif
75601 + }
75602 + } while_each_thread(task2, task);
75603 + read_unlock(&grsec_exec_file_lock);
75604 + read_unlock(&tasklist_lock);
75605 + rcu_read_unlock();
75606 +
75607 + return 0;
75608 +}
75609 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
75610 new file mode 100644
75611 index 0000000..39645c9
75612 --- /dev/null
75613 +++ b/grsecurity/gracl_res.c
75614 @@ -0,0 +1,68 @@
75615 +#include <linux/kernel.h>
75616 +#include <linux/sched.h>
75617 +#include <linux/gracl.h>
75618 +#include <linux/grinternal.h>
75619 +
75620 +static const char *restab_log[] = {
75621 + [RLIMIT_CPU] = "RLIMIT_CPU",
75622 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
75623 + [RLIMIT_DATA] = "RLIMIT_DATA",
75624 + [RLIMIT_STACK] = "RLIMIT_STACK",
75625 + [RLIMIT_CORE] = "RLIMIT_CORE",
75626 + [RLIMIT_RSS] = "RLIMIT_RSS",
75627 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
75628 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
75629 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
75630 + [RLIMIT_AS] = "RLIMIT_AS",
75631 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
75632 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
75633 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
75634 + [RLIMIT_NICE] = "RLIMIT_NICE",
75635 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
75636 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
75637 + [GR_CRASH_RES] = "RLIMIT_CRASH"
75638 +};
75639 +
75640 +void
75641 +gr_log_resource(const struct task_struct *task,
75642 + const int res, const unsigned long wanted, const int gt)
75643 +{
75644 + const struct cred *cred;
75645 + unsigned long rlim;
75646 +
75647 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
75648 + return;
75649 +
75650 + // not yet supported resource
75651 + if (unlikely(!restab_log[res]))
75652 + return;
75653 +
75654 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
75655 + rlim = task_rlimit_max(task, res);
75656 + else
75657 + rlim = task_rlimit(task, res);
75658 +
75659 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
75660 + return;
75661 +
75662 + rcu_read_lock();
75663 + cred = __task_cred(task);
75664 +
75665 + if (res == RLIMIT_NPROC &&
75666 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
75667 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
75668 + goto out_rcu_unlock;
75669 + else if (res == RLIMIT_MEMLOCK &&
75670 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
75671 + goto out_rcu_unlock;
75672 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
75673 + goto out_rcu_unlock;
75674 + rcu_read_unlock();
75675 +
75676 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
75677 +
75678 + return;
75679 +out_rcu_unlock:
75680 + rcu_read_unlock();
75681 + return;
75682 +}
75683 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
75684 new file mode 100644
75685 index 0000000..2040e61
75686 --- /dev/null
75687 +++ b/grsecurity/gracl_segv.c
75688 @@ -0,0 +1,313 @@
75689 +#include <linux/kernel.h>
75690 +#include <linux/mm.h>
75691 +#include <asm/uaccess.h>
75692 +#include <asm/errno.h>
75693 +#include <asm/mman.h>
75694 +#include <net/sock.h>
75695 +#include <linux/file.h>
75696 +#include <linux/fs.h>
75697 +#include <linux/net.h>
75698 +#include <linux/in.h>
75699 +#include <linux/slab.h>
75700 +#include <linux/types.h>
75701 +#include <linux/sched.h>
75702 +#include <linux/timer.h>
75703 +#include <linux/gracl.h>
75704 +#include <linux/grsecurity.h>
75705 +#include <linux/grinternal.h>
75706 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
75707 +#include <linux/magic.h>
75708 +#include <linux/pagemap.h>
75709 +#include "../fs/btrfs/async-thread.h"
75710 +#include "../fs/btrfs/ctree.h"
75711 +#include "../fs/btrfs/btrfs_inode.h"
75712 +#endif
75713 +
75714 +static struct crash_uid *uid_set;
75715 +static unsigned short uid_used;
75716 +static DEFINE_SPINLOCK(gr_uid_lock);
75717 +extern rwlock_t gr_inode_lock;
75718 +extern struct acl_subject_label *
75719 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
75720 + struct acl_role_label *role);
75721 +
75722 +static inline dev_t __get_dev(const struct dentry *dentry)
75723 +{
75724 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
75725 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
75726 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
75727 + else
75728 +#endif
75729 + return dentry->d_sb->s_dev;
75730 +}
75731 +
75732 +int
75733 +gr_init_uidset(void)
75734 +{
75735 + uid_set =
75736 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
75737 + uid_used = 0;
75738 +
75739 + return uid_set ? 1 : 0;
75740 +}
75741 +
75742 +void
75743 +gr_free_uidset(void)
75744 +{
75745 + if (uid_set) {
75746 + struct crash_uid *tmpset;
75747 + spin_lock(&gr_uid_lock);
75748 + tmpset = uid_set;
75749 + uid_set = NULL;
75750 + uid_used = 0;
75751 + spin_unlock(&gr_uid_lock);
75752 + if (tmpset)
75753 + kfree(tmpset);
75754 + }
75755 +
75756 + return;
75757 +}
75758 +
75759 +int
75760 +gr_find_uid(const uid_t uid)
75761 +{
75762 + struct crash_uid *tmp = uid_set;
75763 + uid_t buid;
75764 + int low = 0, high = uid_used - 1, mid;
75765 +
75766 + while (high >= low) {
75767 + mid = (low + high) >> 1;
75768 + buid = tmp[mid].uid;
75769 + if (buid == uid)
75770 + return mid;
75771 + if (buid > uid)
75772 + high = mid - 1;
75773 + if (buid < uid)
75774 + low = mid + 1;
75775 + }
75776 +
75777 + return -1;
75778 +}
75779 +
75780 +static __inline__ void
75781 +gr_insertsort(void)
75782 +{
75783 + unsigned short i, j;
75784 + struct crash_uid index;
75785 +
75786 + for (i = 1; i < uid_used; i++) {
75787 + index = uid_set[i];
75788 + j = i;
75789 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
75790 + uid_set[j] = uid_set[j - 1];
75791 + j--;
75792 + }
75793 + uid_set[j] = index;
75794 + }
75795 +
75796 + return;
75797 +}
75798 +
75799 +static __inline__ void
75800 +gr_insert_uid(const kuid_t kuid, const unsigned long expires)
75801 +{
75802 + int loc;
75803 + uid_t uid = GR_GLOBAL_UID(kuid);
75804 +
75805 + if (uid_used == GR_UIDTABLE_MAX)
75806 + return;
75807 +
75808 + loc = gr_find_uid(uid);
75809 +
75810 + if (loc >= 0) {
75811 + uid_set[loc].expires = expires;
75812 + return;
75813 + }
75814 +
75815 + uid_set[uid_used].uid = uid;
75816 + uid_set[uid_used].expires = expires;
75817 + uid_used++;
75818 +
75819 + gr_insertsort();
75820 +
75821 + return;
75822 +}
75823 +
75824 +void
75825 +gr_remove_uid(const unsigned short loc)
75826 +{
75827 + unsigned short i;
75828 +
75829 + for (i = loc + 1; i < uid_used; i++)
75830 + uid_set[i - 1] = uid_set[i];
75831 +
75832 + uid_used--;
75833 +
75834 + return;
75835 +}
75836 +
75837 +int
75838 +gr_check_crash_uid(const kuid_t kuid)
75839 +{
75840 + int loc;
75841 + int ret = 0;
75842 + uid_t uid;
75843 +
75844 + if (unlikely(!gr_acl_is_enabled()))
75845 + return 0;
75846 +
75847 + uid = GR_GLOBAL_UID(kuid);
75848 +
75849 + spin_lock(&gr_uid_lock);
75850 + loc = gr_find_uid(uid);
75851 +
75852 + if (loc < 0)
75853 + goto out_unlock;
75854 +
75855 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
75856 + gr_remove_uid(loc);
75857 + else
75858 + ret = 1;
75859 +
75860 +out_unlock:
75861 + spin_unlock(&gr_uid_lock);
75862 + return ret;
75863 +}
75864 +
75865 +static __inline__ int
75866 +proc_is_setxid(const struct cred *cred)
75867 +{
75868 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
75869 + !uid_eq(cred->uid, cred->fsuid))
75870 + return 1;
75871 + if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
75872 + !gid_eq(cred->gid, cred->fsgid))
75873 + return 1;
75874 +
75875 + return 0;
75876 +}
75877 +
75878 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
75879 +
75880 +void
75881 +gr_handle_crash(struct task_struct *task, const int sig)
75882 +{
75883 + struct acl_subject_label *curr;
75884 + struct task_struct *tsk, *tsk2;
75885 + const struct cred *cred;
75886 + const struct cred *cred2;
75887 +
75888 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
75889 + return;
75890 +
75891 + if (unlikely(!gr_acl_is_enabled()))
75892 + return;
75893 +
75894 + curr = task->acl;
75895 +
75896 + if (!(curr->resmask & (1U << GR_CRASH_RES)))
75897 + return;
75898 +
75899 + if (time_before_eq(curr->expires, get_seconds())) {
75900 + curr->expires = 0;
75901 + curr->crashes = 0;
75902 + }
75903 +
75904 + curr->crashes++;
75905 +
75906 + if (!curr->expires)
75907 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
75908 +
75909 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
75910 + time_after(curr->expires, get_seconds())) {
75911 + rcu_read_lock();
75912 + cred = __task_cred(task);
75913 + if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
75914 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
75915 + spin_lock(&gr_uid_lock);
75916 + gr_insert_uid(cred->uid, curr->expires);
75917 + spin_unlock(&gr_uid_lock);
75918 + curr->expires = 0;
75919 + curr->crashes = 0;
75920 + read_lock(&tasklist_lock);
75921 + do_each_thread(tsk2, tsk) {
75922 + cred2 = __task_cred(tsk);
75923 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
75924 + gr_fake_force_sig(SIGKILL, tsk);
75925 + } while_each_thread(tsk2, tsk);
75926 + read_unlock(&tasklist_lock);
75927 + } else {
75928 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
75929 + read_lock(&tasklist_lock);
75930 + read_lock(&grsec_exec_file_lock);
75931 + do_each_thread(tsk2, tsk) {
75932 + if (likely(tsk != task)) {
75933 + // if this thread has the same subject as the one that triggered
75934 + // RES_CRASH and it's the same binary, kill it
75935 + if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
75936 + gr_fake_force_sig(SIGKILL, tsk);
75937 + }
75938 + } while_each_thread(tsk2, tsk);
75939 + read_unlock(&grsec_exec_file_lock);
75940 + read_unlock(&tasklist_lock);
75941 + }
75942 + rcu_read_unlock();
75943 + }
75944 +
75945 + return;
75946 +}
75947 +
75948 +int
75949 +gr_check_crash_exec(const struct file *filp)
75950 +{
75951 + struct acl_subject_label *curr;
75952 +
75953 + if (unlikely(!gr_acl_is_enabled()))
75954 + return 0;
75955 +
75956 + read_lock(&gr_inode_lock);
75957 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
75958 + __get_dev(filp->f_path.dentry),
75959 + current->role);
75960 + read_unlock(&gr_inode_lock);
75961 +
75962 + if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
75963 + (!curr->crashes && !curr->expires))
75964 + return 0;
75965 +
75966 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
75967 + time_after(curr->expires, get_seconds()))
75968 + return 1;
75969 + else if (time_before_eq(curr->expires, get_seconds())) {
75970 + curr->crashes = 0;
75971 + curr->expires = 0;
75972 + }
75973 +
75974 + return 0;
75975 +}
75976 +
75977 +void
75978 +gr_handle_alertkill(struct task_struct *task)
75979 +{
75980 + struct acl_subject_label *curracl;
75981 + __u32 curr_ip;
75982 + struct task_struct *p, *p2;
75983 +
75984 + if (unlikely(!gr_acl_is_enabled()))
75985 + return;
75986 +
75987 + curracl = task->acl;
75988 + curr_ip = task->signal->curr_ip;
75989 +
75990 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
75991 + read_lock(&tasklist_lock);
75992 + do_each_thread(p2, p) {
75993 + if (p->signal->curr_ip == curr_ip)
75994 + gr_fake_force_sig(SIGKILL, p);
75995 + } while_each_thread(p2, p);
75996 + read_unlock(&tasklist_lock);
75997 + } else if (curracl->mode & GR_KILLPROC)
75998 + gr_fake_force_sig(SIGKILL, task);
75999 +
76000 + return;
76001 +}
76002 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
76003 new file mode 100644
76004 index 0000000..6b0c9cc
76005 --- /dev/null
76006 +++ b/grsecurity/gracl_shm.c
76007 @@ -0,0 +1,40 @@
76008 +#include <linux/kernel.h>
76009 +#include <linux/mm.h>
76010 +#include <linux/sched.h>
76011 +#include <linux/file.h>
76012 +#include <linux/ipc.h>
76013 +#include <linux/gracl.h>
76014 +#include <linux/grsecurity.h>
76015 +#include <linux/grinternal.h>
76016 +
76017 +int
76018 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
76019 + const u64 shm_createtime, const kuid_t cuid, const int shmid)
76020 +{
76021 + struct task_struct *task;
76022 +
76023 + if (!gr_acl_is_enabled())
76024 + return 1;
76025 +
76026 + rcu_read_lock();
76027 + read_lock(&tasklist_lock);
76028 +
76029 + task = find_task_by_vpid(shm_cprid);
76030 +
76031 + if (unlikely(!task))
76032 + task = find_task_by_vpid(shm_lapid);
76033 +
76034 + if (unlikely(task && (time_before_eq64(task->start_time, shm_createtime) ||
76035 + (task_pid_nr(task) == shm_lapid)) &&
76036 + (task->acl->mode & GR_PROTSHM) &&
76037 + (task->acl != current->acl))) {
76038 + read_unlock(&tasklist_lock);
76039 + rcu_read_unlock();
76040 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
76041 + return 0;
76042 + }
76043 + read_unlock(&tasklist_lock);
76044 + rcu_read_unlock();
76045 +
76046 + return 1;
76047 +}
76048 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
76049 new file mode 100644
76050 index 0000000..bc0be01
76051 --- /dev/null
76052 +++ b/grsecurity/grsec_chdir.c
76053 @@ -0,0 +1,19 @@
76054 +#include <linux/kernel.h>
76055 +#include <linux/sched.h>
76056 +#include <linux/fs.h>
76057 +#include <linux/file.h>
76058 +#include <linux/grsecurity.h>
76059 +#include <linux/grinternal.h>
76060 +
76061 +void
76062 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
76063 +{
76064 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
76065 + if ((grsec_enable_chdir && grsec_enable_group &&
76066 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
76067 + !grsec_enable_group)) {
76068 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
76069 + }
76070 +#endif
76071 + return;
76072 +}
76073 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
76074 new file mode 100644
76075 index 0000000..6d99cec
76076 --- /dev/null
76077 +++ b/grsecurity/grsec_chroot.c
76078 @@ -0,0 +1,385 @@
76079 +#include <linux/kernel.h>
76080 +#include <linux/module.h>
76081 +#include <linux/sched.h>
76082 +#include <linux/file.h>
76083 +#include <linux/fs.h>
76084 +#include <linux/mount.h>
76085 +#include <linux/types.h>
76086 +#include "../fs/mount.h"
76087 +#include <linux/grsecurity.h>
76088 +#include <linux/grinternal.h>
76089 +
76090 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76091 +int gr_init_ran;
76092 +#endif
76093 +
76094 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
76095 +{
76096 +#ifdef CONFIG_GRKERNSEC
76097 + if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
76098 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
76099 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76100 + && gr_init_ran
76101 +#endif
76102 + )
76103 + task->gr_is_chrooted = 1;
76104 + else {
76105 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76106 + if (task_pid_nr(task) == 1 && !gr_init_ran)
76107 + gr_init_ran = 1;
76108 +#endif
76109 + task->gr_is_chrooted = 0;
76110 + }
76111 +
76112 + task->gr_chroot_dentry = path->dentry;
76113 +#endif
76114 + return;
76115 +}
76116 +
76117 +void gr_clear_chroot_entries(struct task_struct *task)
76118 +{
76119 +#ifdef CONFIG_GRKERNSEC
76120 + task->gr_is_chrooted = 0;
76121 + task->gr_chroot_dentry = NULL;
76122 +#endif
76123 + return;
76124 +}
76125 +
76126 +int
76127 +gr_handle_chroot_unix(const pid_t pid)
76128 +{
76129 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
76130 + struct task_struct *p;
76131 +
76132 + if (unlikely(!grsec_enable_chroot_unix))
76133 + return 1;
76134 +
76135 + if (likely(!proc_is_chrooted(current)))
76136 + return 1;
76137 +
76138 + rcu_read_lock();
76139 + read_lock(&tasklist_lock);
76140 + p = find_task_by_vpid_unrestricted(pid);
76141 + if (unlikely(p && !have_same_root(current, p))) {
76142 + read_unlock(&tasklist_lock);
76143 + rcu_read_unlock();
76144 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
76145 + return 0;
76146 + }
76147 + read_unlock(&tasklist_lock);
76148 + rcu_read_unlock();
76149 +#endif
76150 + return 1;
76151 +}
76152 +
76153 +int
76154 +gr_handle_chroot_nice(void)
76155 +{
76156 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76157 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
76158 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
76159 + return -EPERM;
76160 + }
76161 +#endif
76162 + return 0;
76163 +}
76164 +
76165 +int
76166 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
76167 +{
76168 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76169 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
76170 + && proc_is_chrooted(current)) {
76171 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
76172 + return -EACCES;
76173 + }
76174 +#endif
76175 + return 0;
76176 +}
76177 +
76178 +int
76179 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
76180 +{
76181 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76182 + struct task_struct *p;
76183 + int ret = 0;
76184 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
76185 + return ret;
76186 +
76187 + read_lock(&tasklist_lock);
76188 + do_each_pid_task(pid, type, p) {
76189 + if (!have_same_root(current, p)) {
76190 + ret = 1;
76191 + goto out;
76192 + }
76193 + } while_each_pid_task(pid, type, p);
76194 +out:
76195 + read_unlock(&tasklist_lock);
76196 + return ret;
76197 +#endif
76198 + return 0;
76199 +}
76200 +
76201 +int
76202 +gr_pid_is_chrooted(struct task_struct *p)
76203 +{
76204 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76205 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
76206 + return 0;
76207 +
76208 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
76209 + !have_same_root(current, p)) {
76210 + return 1;
76211 + }
76212 +#endif
76213 + return 0;
76214 +}
76215 +
76216 +EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
76217 +
76218 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
76219 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
76220 +{
76221 + struct path path, currentroot;
76222 + int ret = 0;
76223 +
76224 + path.dentry = (struct dentry *)u_dentry;
76225 + path.mnt = (struct vfsmount *)u_mnt;
76226 + get_fs_root(current->fs, &currentroot);
76227 + if (path_is_under(&path, &currentroot))
76228 + ret = 1;
76229 + path_put(&currentroot);
76230 +
76231 + return ret;
76232 +}
76233 +#endif
76234 +
76235 +int
76236 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
76237 +{
76238 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76239 + if (!grsec_enable_chroot_fchdir)
76240 + return 1;
76241 +
76242 + if (!proc_is_chrooted(current))
76243 + return 1;
76244 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
76245 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
76246 + return 0;
76247 + }
76248 +#endif
76249 + return 1;
76250 +}
76251 +
76252 +int
76253 +gr_chroot_fhandle(void)
76254 +{
76255 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76256 + if (!grsec_enable_chroot_fchdir)
76257 + return 1;
76258 +
76259 + if (!proc_is_chrooted(current))
76260 + return 1;
76261 + else {
76262 + gr_log_noargs(GR_DONT_AUDIT, GR_CHROOT_FHANDLE_MSG);
76263 + return 0;
76264 + }
76265 +#endif
76266 + return 1;
76267 +}
76268 +
76269 +int
76270 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
76271 + const u64 shm_createtime)
76272 +{
76273 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
76274 + struct task_struct *p;
76275 +
76276 + if (unlikely(!grsec_enable_chroot_shmat))
76277 + return 1;
76278 +
76279 + if (likely(!proc_is_chrooted(current)))
76280 + return 1;
76281 +
76282 + rcu_read_lock();
76283 + read_lock(&tasklist_lock);
76284 +
76285 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
76286 + if (time_before_eq64(p->start_time, shm_createtime)) {
76287 + if (have_same_root(current, p)) {
76288 + goto allow;
76289 + } else {
76290 + read_unlock(&tasklist_lock);
76291 + rcu_read_unlock();
76292 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
76293 + return 0;
76294 + }
76295 + }
76296 + /* creator exited, pid reuse, fall through to next check */
76297 + }
76298 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
76299 + if (unlikely(!have_same_root(current, p))) {
76300 + read_unlock(&tasklist_lock);
76301 + rcu_read_unlock();
76302 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
76303 + return 0;
76304 + }
76305 + }
76306 +
76307 +allow:
76308 + read_unlock(&tasklist_lock);
76309 + rcu_read_unlock();
76310 +#endif
76311 + return 1;
76312 +}
76313 +
76314 +void
76315 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
76316 +{
76317 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
76318 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
76319 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
76320 +#endif
76321 + return;
76322 +}
76323 +
76324 +int
76325 +gr_handle_chroot_mknod(const struct dentry *dentry,
76326 + const struct vfsmount *mnt, const int mode)
76327 +{
76328 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
76329 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
76330 + proc_is_chrooted(current)) {
76331 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
76332 + return -EPERM;
76333 + }
76334 +#endif
76335 + return 0;
76336 +}
76337 +
76338 +int
76339 +gr_handle_chroot_mount(const struct dentry *dentry,
76340 + const struct vfsmount *mnt, const char *dev_name)
76341 +{
76342 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
76343 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
76344 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
76345 + return -EPERM;
76346 + }
76347 +#endif
76348 + return 0;
76349 +}
76350 +
76351 +int
76352 +gr_handle_chroot_pivot(void)
76353 +{
76354 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
76355 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
76356 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
76357 + return -EPERM;
76358 + }
76359 +#endif
76360 + return 0;
76361 +}
76362 +
76363 +int
76364 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
76365 +{
76366 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
76367 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
76368 + !gr_is_outside_chroot(dentry, mnt)) {
76369 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
76370 + return -EPERM;
76371 + }
76372 +#endif
76373 + return 0;
76374 +}
76375 +
76376 +extern const char *captab_log[];
76377 +extern int captab_log_entries;
76378 +
76379 +int
76380 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
76381 +{
76382 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76383 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
76384 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
76385 + if (cap_raised(chroot_caps, cap)) {
76386 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
76387 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
76388 + }
76389 + return 0;
76390 + }
76391 + }
76392 +#endif
76393 + return 1;
76394 +}
76395 +
76396 +int
76397 +gr_chroot_is_capable(const int cap)
76398 +{
76399 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76400 + return gr_task_chroot_is_capable(current, current_cred(), cap);
76401 +#endif
76402 + return 1;
76403 +}
76404 +
76405 +int
76406 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
76407 +{
76408 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76409 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
76410 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
76411 + if (cap_raised(chroot_caps, cap)) {
76412 + return 0;
76413 + }
76414 + }
76415 +#endif
76416 + return 1;
76417 +}
76418 +
76419 +int
76420 +gr_chroot_is_capable_nolog(const int cap)
76421 +{
76422 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76423 + return gr_task_chroot_is_capable_nolog(current, cap);
76424 +#endif
76425 + return 1;
76426 +}
76427 +
76428 +int
76429 +gr_handle_chroot_sysctl(const int op)
76430 +{
76431 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
76432 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
76433 + proc_is_chrooted(current))
76434 + return -EACCES;
76435 +#endif
76436 + return 0;
76437 +}
76438 +
76439 +void
76440 +gr_handle_chroot_chdir(const struct path *path)
76441 +{
76442 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
76443 + if (grsec_enable_chroot_chdir)
76444 + set_fs_pwd(current->fs, path);
76445 +#endif
76446 + return;
76447 +}
76448 +
76449 +int
76450 +gr_handle_chroot_chmod(const struct dentry *dentry,
76451 + const struct vfsmount *mnt, const int mode)
76452 +{
76453 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
76454 + /* allow chmod +s on directories, but not files */
76455 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
76456 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
76457 + proc_is_chrooted(current)) {
76458 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
76459 + return -EPERM;
76460 + }
76461 +#endif
76462 + return 0;
76463 +}
76464 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
76465 new file mode 100644
76466 index 0000000..0f9ac91
76467 --- /dev/null
76468 +++ b/grsecurity/grsec_disabled.c
76469 @@ -0,0 +1,440 @@
76470 +#include <linux/kernel.h>
76471 +#include <linux/module.h>
76472 +#include <linux/sched.h>
76473 +#include <linux/file.h>
76474 +#include <linux/fs.h>
76475 +#include <linux/kdev_t.h>
76476 +#include <linux/net.h>
76477 +#include <linux/in.h>
76478 +#include <linux/ip.h>
76479 +#include <linux/skbuff.h>
76480 +#include <linux/sysctl.h>
76481 +
76482 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
76483 +void
76484 +pax_set_initial_flags(struct linux_binprm *bprm)
76485 +{
76486 + return;
76487 +}
76488 +#endif
76489 +
76490 +#ifdef CONFIG_SYSCTL
76491 +__u32
76492 +gr_handle_sysctl(const struct ctl_table * table, const int op)
76493 +{
76494 + return 0;
76495 +}
76496 +#endif
76497 +
76498 +#ifdef CONFIG_TASKSTATS
76499 +int gr_is_taskstats_denied(int pid)
76500 +{
76501 + return 0;
76502 +}
76503 +#endif
76504 +
76505 +int
76506 +gr_acl_is_enabled(void)
76507 +{
76508 + return 0;
76509 +}
76510 +
76511 +int
76512 +gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
76513 +{
76514 + return 0;
76515 +}
76516 +
76517 +void
76518 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
76519 +{
76520 + return;
76521 +}
76522 +
76523 +int
76524 +gr_handle_rawio(const struct inode *inode)
76525 +{
76526 + return 0;
76527 +}
76528 +
76529 +void
76530 +gr_acl_handle_psacct(struct task_struct *task, const long code)
76531 +{
76532 + return;
76533 +}
76534 +
76535 +int
76536 +gr_handle_ptrace(struct task_struct *task, const long request)
76537 +{
76538 + return 0;
76539 +}
76540 +
76541 +int
76542 +gr_handle_proc_ptrace(struct task_struct *task)
76543 +{
76544 + return 0;
76545 +}
76546 +
76547 +int
76548 +gr_set_acls(const int type)
76549 +{
76550 + return 0;
76551 +}
76552 +
76553 +int
76554 +gr_check_hidden_task(const struct task_struct *tsk)
76555 +{
76556 + return 0;
76557 +}
76558 +
76559 +int
76560 +gr_check_protected_task(const struct task_struct *task)
76561 +{
76562 + return 0;
76563 +}
76564 +
76565 +int
76566 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
76567 +{
76568 + return 0;
76569 +}
76570 +
76571 +void
76572 +gr_copy_label(struct task_struct *tsk)
76573 +{
76574 + return;
76575 +}
76576 +
76577 +void
76578 +gr_set_pax_flags(struct task_struct *task)
76579 +{
76580 + return;
76581 +}
76582 +
76583 +int
76584 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
76585 + const int unsafe_share)
76586 +{
76587 + return 0;
76588 +}
76589 +
76590 +void
76591 +gr_handle_delete(const ino_t ino, const dev_t dev)
76592 +{
76593 + return;
76594 +}
76595 +
76596 +void
76597 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
76598 +{
76599 + return;
76600 +}
76601 +
76602 +void
76603 +gr_handle_crash(struct task_struct *task, const int sig)
76604 +{
76605 + return;
76606 +}
76607 +
76608 +int
76609 +gr_check_crash_exec(const struct file *filp)
76610 +{
76611 + return 0;
76612 +}
76613 +
76614 +int
76615 +gr_check_crash_uid(const kuid_t uid)
76616 +{
76617 + return 0;
76618 +}
76619 +
76620 +void
76621 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
76622 + struct dentry *old_dentry,
76623 + struct dentry *new_dentry,
76624 + struct vfsmount *mnt, const __u8 replace, unsigned int flags)
76625 +{
76626 + return;
76627 +}
76628 +
76629 +int
76630 +gr_search_socket(const int family, const int type, const int protocol)
76631 +{
76632 + return 1;
76633 +}
76634 +
76635 +int
76636 +gr_search_connectbind(const int mode, const struct socket *sock,
76637 + const struct sockaddr_in *addr)
76638 +{
76639 + return 0;
76640 +}
76641 +
76642 +void
76643 +gr_handle_alertkill(struct task_struct *task)
76644 +{
76645 + return;
76646 +}
76647 +
76648 +__u32
76649 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
76650 +{
76651 + return 1;
76652 +}
76653 +
76654 +__u32
76655 +gr_acl_handle_hidden_file(const struct dentry * dentry,
76656 + const struct vfsmount * mnt)
76657 +{
76658 + return 1;
76659 +}
76660 +
76661 +__u32
76662 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
76663 + int acc_mode)
76664 +{
76665 + return 1;
76666 +}
76667 +
76668 +__u32
76669 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
76670 +{
76671 + return 1;
76672 +}
76673 +
76674 +__u32
76675 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
76676 +{
76677 + return 1;
76678 +}
76679 +
76680 +int
76681 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
76682 + unsigned int *vm_flags)
76683 +{
76684 + return 1;
76685 +}
76686 +
76687 +__u32
76688 +gr_acl_handle_truncate(const struct dentry * dentry,
76689 + const struct vfsmount * mnt)
76690 +{
76691 + return 1;
76692 +}
76693 +
76694 +__u32
76695 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
76696 +{
76697 + return 1;
76698 +}
76699 +
76700 +__u32
76701 +gr_acl_handle_access(const struct dentry * dentry,
76702 + const struct vfsmount * mnt, const int fmode)
76703 +{
76704 + return 1;
76705 +}
76706 +
76707 +__u32
76708 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
76709 + umode_t *mode)
76710 +{
76711 + return 1;
76712 +}
76713 +
76714 +__u32
76715 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
76716 +{
76717 + return 1;
76718 +}
76719 +
76720 +__u32
76721 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
76722 +{
76723 + return 1;
76724 +}
76725 +
76726 +__u32
76727 +gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
76728 +{
76729 + return 1;
76730 +}
76731 +
76732 +void
76733 +grsecurity_init(void)
76734 +{
76735 + return;
76736 +}
76737 +
76738 +umode_t gr_acl_umask(void)
76739 +{
76740 + return 0;
76741 +}
76742 +
76743 +__u32
76744 +gr_acl_handle_mknod(const struct dentry * new_dentry,
76745 + const struct dentry * parent_dentry,
76746 + const struct vfsmount * parent_mnt,
76747 + const int mode)
76748 +{
76749 + return 1;
76750 +}
76751 +
76752 +__u32
76753 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
76754 + const struct dentry * parent_dentry,
76755 + const struct vfsmount * parent_mnt)
76756 +{
76757 + return 1;
76758 +}
76759 +
76760 +__u32
76761 +gr_acl_handle_symlink(const struct dentry * new_dentry,
76762 + const struct dentry * parent_dentry,
76763 + const struct vfsmount * parent_mnt, const struct filename *from)
76764 +{
76765 + return 1;
76766 +}
76767 +
76768 +__u32
76769 +gr_acl_handle_link(const struct dentry * new_dentry,
76770 + const struct dentry * parent_dentry,
76771 + const struct vfsmount * parent_mnt,
76772 + const struct dentry * old_dentry,
76773 + const struct vfsmount * old_mnt, const struct filename *to)
76774 +{
76775 + return 1;
76776 +}
76777 +
76778 +int
76779 +gr_acl_handle_rename(const struct dentry *new_dentry,
76780 + const struct dentry *parent_dentry,
76781 + const struct vfsmount *parent_mnt,
76782 + const struct dentry *old_dentry,
76783 + const struct inode *old_parent_inode,
76784 + const struct vfsmount *old_mnt, const struct filename *newname,
76785 + unsigned int flags)
76786 +{
76787 + return 0;
76788 +}
76789 +
76790 +int
76791 +gr_acl_handle_filldir(const struct file *file, const char *name,
76792 + const int namelen, const ino_t ino)
76793 +{
76794 + return 1;
76795 +}
76796 +
76797 +int
76798 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
76799 + const u64 shm_createtime, const kuid_t cuid, const int shmid)
76800 +{
76801 + return 1;
76802 +}
76803 +
76804 +int
76805 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
76806 +{
76807 + return 0;
76808 +}
76809 +
76810 +int
76811 +gr_search_accept(const struct socket *sock)
76812 +{
76813 + return 0;
76814 +}
76815 +
76816 +int
76817 +gr_search_listen(const struct socket *sock)
76818 +{
76819 + return 0;
76820 +}
76821 +
76822 +int
76823 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
76824 +{
76825 + return 0;
76826 +}
76827 +
76828 +__u32
76829 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
76830 +{
76831 + return 1;
76832 +}
76833 +
76834 +__u32
76835 +gr_acl_handle_creat(const struct dentry * dentry,
76836 + const struct dentry * p_dentry,
76837 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
76838 + const int imode)
76839 +{
76840 + return 1;
76841 +}
76842 +
76843 +void
76844 +gr_acl_handle_exit(void)
76845 +{
76846 + return;
76847 +}
76848 +
76849 +int
76850 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
76851 +{
76852 + return 1;
76853 +}
76854 +
76855 +void
76856 +gr_set_role_label(const kuid_t uid, const kgid_t gid)
76857 +{
76858 + return;
76859 +}
76860 +
76861 +int
76862 +gr_acl_handle_procpidmem(const struct task_struct *task)
76863 +{
76864 + return 0;
76865 +}
76866 +
76867 +int
76868 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
76869 +{
76870 + return 0;
76871 +}
76872 +
76873 +int
76874 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
76875 +{
76876 + return 0;
76877 +}
76878 +
76879 +int
76880 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
76881 +{
76882 + return 0;
76883 +}
76884 +
76885 +int
76886 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
76887 +{
76888 + return 0;
76889 +}
76890 +
76891 +int gr_acl_enable_at_secure(void)
76892 +{
76893 + return 0;
76894 +}
76895 +
76896 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
76897 +{
76898 + return dentry->d_sb->s_dev;
76899 +}
76900 +
76901 +void gr_put_exec_file(struct task_struct *task)
76902 +{
76903 + return;
76904 +}
76905 +
76906 +#ifdef CONFIG_SECURITY
76907 +EXPORT_SYMBOL_GPL(gr_check_user_change);
76908 +EXPORT_SYMBOL_GPL(gr_check_group_change);
76909 +#endif
76910 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
76911 new file mode 100644
76912 index 0000000..14638ff
76913 --- /dev/null
76914 +++ b/grsecurity/grsec_exec.c
76915 @@ -0,0 +1,188 @@
76916 +#include <linux/kernel.h>
76917 +#include <linux/sched.h>
76918 +#include <linux/file.h>
76919 +#include <linux/binfmts.h>
76920 +#include <linux/fs.h>
76921 +#include <linux/types.h>
76922 +#include <linux/grdefs.h>
76923 +#include <linux/grsecurity.h>
76924 +#include <linux/grinternal.h>
76925 +#include <linux/capability.h>
76926 +#include <linux/module.h>
76927 +#include <linux/compat.h>
76928 +
76929 +#include <asm/uaccess.h>
76930 +
76931 +#ifdef CONFIG_GRKERNSEC_EXECLOG
76932 +static char gr_exec_arg_buf[132];
76933 +static DEFINE_MUTEX(gr_exec_arg_mutex);
76934 +#endif
76935 +
76936 +struct user_arg_ptr {
76937 +#ifdef CONFIG_COMPAT
76938 + bool is_compat;
76939 +#endif
76940 + union {
76941 + const char __user *const __user *native;
76942 +#ifdef CONFIG_COMPAT
76943 + const compat_uptr_t __user *compat;
76944 +#endif
76945 + } ptr;
76946 +};
76947 +
76948 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
76949 +
76950 +void
76951 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
76952 +{
76953 +#ifdef CONFIG_GRKERNSEC_EXECLOG
76954 + char *grarg = gr_exec_arg_buf;
76955 + unsigned int i, x, execlen = 0;
76956 + char c;
76957 +
76958 + if (!((grsec_enable_execlog && grsec_enable_group &&
76959 + in_group_p(grsec_audit_gid))
76960 + || (grsec_enable_execlog && !grsec_enable_group)))
76961 + return;
76962 +
76963 + mutex_lock(&gr_exec_arg_mutex);
76964 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
76965 +
76966 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
76967 + const char __user *p;
76968 + unsigned int len;
76969 +
76970 + p = get_user_arg_ptr(argv, i);
76971 + if (IS_ERR(p))
76972 + goto log;
76973 +
76974 + len = strnlen_user(p, 128 - execlen);
76975 + if (len > 128 - execlen)
76976 + len = 128 - execlen;
76977 + else if (len > 0)
76978 + len--;
76979 + if (copy_from_user(grarg + execlen, p, len))
76980 + goto log;
76981 +
76982 + /* rewrite unprintable characters */
76983 + for (x = 0; x < len; x++) {
76984 + c = *(grarg + execlen + x);
76985 + if (c < 32 || c > 126)
76986 + *(grarg + execlen + x) = ' ';
76987 + }
76988 +
76989 + execlen += len;
76990 + *(grarg + execlen) = ' ';
76991 + *(grarg + execlen + 1) = '\0';
76992 + execlen++;
76993 + }
76994 +
76995 + log:
76996 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
76997 + bprm->file->f_path.mnt, grarg);
76998 + mutex_unlock(&gr_exec_arg_mutex);
76999 +#endif
77000 + return;
77001 +}
77002 +
77003 +#ifdef CONFIG_GRKERNSEC
77004 +extern int gr_acl_is_capable(const int cap);
77005 +extern int gr_acl_is_capable_nolog(const int cap);
77006 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
77007 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
77008 +extern int gr_chroot_is_capable(const int cap);
77009 +extern int gr_chroot_is_capable_nolog(const int cap);
77010 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
77011 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
77012 +#endif
77013 +
77014 +const char *captab_log[] = {
77015 + "CAP_CHOWN",
77016 + "CAP_DAC_OVERRIDE",
77017 + "CAP_DAC_READ_SEARCH",
77018 + "CAP_FOWNER",
77019 + "CAP_FSETID",
77020 + "CAP_KILL",
77021 + "CAP_SETGID",
77022 + "CAP_SETUID",
77023 + "CAP_SETPCAP",
77024 + "CAP_LINUX_IMMUTABLE",
77025 + "CAP_NET_BIND_SERVICE",
77026 + "CAP_NET_BROADCAST",
77027 + "CAP_NET_ADMIN",
77028 + "CAP_NET_RAW",
77029 + "CAP_IPC_LOCK",
77030 + "CAP_IPC_OWNER",
77031 + "CAP_SYS_MODULE",
77032 + "CAP_SYS_RAWIO",
77033 + "CAP_SYS_CHROOT",
77034 + "CAP_SYS_PTRACE",
77035 + "CAP_SYS_PACCT",
77036 + "CAP_SYS_ADMIN",
77037 + "CAP_SYS_BOOT",
77038 + "CAP_SYS_NICE",
77039 + "CAP_SYS_RESOURCE",
77040 + "CAP_SYS_TIME",
77041 + "CAP_SYS_TTY_CONFIG",
77042 + "CAP_MKNOD",
77043 + "CAP_LEASE",
77044 + "CAP_AUDIT_WRITE",
77045 + "CAP_AUDIT_CONTROL",
77046 + "CAP_SETFCAP",
77047 + "CAP_MAC_OVERRIDE",
77048 + "CAP_MAC_ADMIN",
77049 + "CAP_SYSLOG",
77050 + "CAP_WAKE_ALARM",
77051 + "CAP_BLOCK_SUSPEND"
77052 +};
77053 +
77054 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
77055 +
77056 +int gr_is_capable(const int cap)
77057 +{
77058 +#ifdef CONFIG_GRKERNSEC
77059 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
77060 + return 1;
77061 + return 0;
77062 +#else
77063 + return 1;
77064 +#endif
77065 +}
77066 +
77067 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
77068 +{
77069 +#ifdef CONFIG_GRKERNSEC
77070 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
77071 + return 1;
77072 + return 0;
77073 +#else
77074 + return 1;
77075 +#endif
77076 +}
77077 +
77078 +int gr_is_capable_nolog(const int cap)
77079 +{
77080 +#ifdef CONFIG_GRKERNSEC
77081 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
77082 + return 1;
77083 + return 0;
77084 +#else
77085 + return 1;
77086 +#endif
77087 +}
77088 +
77089 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
77090 +{
77091 +#ifdef CONFIG_GRKERNSEC
77092 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
77093 + return 1;
77094 + return 0;
77095 +#else
77096 + return 1;
77097 +#endif
77098 +}
77099 +
77100 +EXPORT_SYMBOL_GPL(gr_is_capable);
77101 +EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
77102 +EXPORT_SYMBOL_GPL(gr_task_is_capable);
77103 +EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
77104 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
77105 new file mode 100644
77106 index 0000000..06cc6ea
77107 --- /dev/null
77108 +++ b/grsecurity/grsec_fifo.c
77109 @@ -0,0 +1,24 @@
77110 +#include <linux/kernel.h>
77111 +#include <linux/sched.h>
77112 +#include <linux/fs.h>
77113 +#include <linux/file.h>
77114 +#include <linux/grinternal.h>
77115 +
77116 +int
77117 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
77118 + const struct dentry *dir, const int flag, const int acc_mode)
77119 +{
77120 +#ifdef CONFIG_GRKERNSEC_FIFO
77121 + const struct cred *cred = current_cred();
77122 +
77123 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
77124 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
77125 + !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
77126 + !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
77127 + if (!inode_permission(dentry->d_inode, acc_mode))
77128 + 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));
77129 + return -EACCES;
77130 + }
77131 +#endif
77132 + return 0;
77133 +}
77134 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
77135 new file mode 100644
77136 index 0000000..8ca18bf
77137 --- /dev/null
77138 +++ b/grsecurity/grsec_fork.c
77139 @@ -0,0 +1,23 @@
77140 +#include <linux/kernel.h>
77141 +#include <linux/sched.h>
77142 +#include <linux/grsecurity.h>
77143 +#include <linux/grinternal.h>
77144 +#include <linux/errno.h>
77145 +
77146 +void
77147 +gr_log_forkfail(const int retval)
77148 +{
77149 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
77150 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
77151 + switch (retval) {
77152 + case -EAGAIN:
77153 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
77154 + break;
77155 + case -ENOMEM:
77156 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
77157 + break;
77158 + }
77159 + }
77160 +#endif
77161 + return;
77162 +}
77163 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
77164 new file mode 100644
77165 index 0000000..b7cb191
77166 --- /dev/null
77167 +++ b/grsecurity/grsec_init.c
77168 @@ -0,0 +1,286 @@
77169 +#include <linux/kernel.h>
77170 +#include <linux/sched.h>
77171 +#include <linux/mm.h>
77172 +#include <linux/gracl.h>
77173 +#include <linux/slab.h>
77174 +#include <linux/vmalloc.h>
77175 +#include <linux/percpu.h>
77176 +#include <linux/module.h>
77177 +
77178 +int grsec_enable_ptrace_readexec;
77179 +int grsec_enable_setxid;
77180 +int grsec_enable_symlinkown;
77181 +kgid_t grsec_symlinkown_gid;
77182 +int grsec_enable_brute;
77183 +int grsec_enable_link;
77184 +int grsec_enable_dmesg;
77185 +int grsec_enable_harden_ptrace;
77186 +int grsec_enable_harden_ipc;
77187 +int grsec_enable_fifo;
77188 +int grsec_enable_execlog;
77189 +int grsec_enable_signal;
77190 +int grsec_enable_forkfail;
77191 +int grsec_enable_audit_ptrace;
77192 +int grsec_enable_time;
77193 +int grsec_enable_group;
77194 +kgid_t grsec_audit_gid;
77195 +int grsec_enable_chdir;
77196 +int grsec_enable_mount;
77197 +int grsec_enable_rofs;
77198 +int grsec_deny_new_usb;
77199 +int grsec_enable_chroot_findtask;
77200 +int grsec_enable_chroot_mount;
77201 +int grsec_enable_chroot_shmat;
77202 +int grsec_enable_chroot_fchdir;
77203 +int grsec_enable_chroot_double;
77204 +int grsec_enable_chroot_pivot;
77205 +int grsec_enable_chroot_chdir;
77206 +int grsec_enable_chroot_chmod;
77207 +int grsec_enable_chroot_mknod;
77208 +int grsec_enable_chroot_nice;
77209 +int grsec_enable_chroot_execlog;
77210 +int grsec_enable_chroot_caps;
77211 +int grsec_enable_chroot_sysctl;
77212 +int grsec_enable_chroot_unix;
77213 +int grsec_enable_tpe;
77214 +kgid_t grsec_tpe_gid;
77215 +int grsec_enable_blackhole;
77216 +#ifdef CONFIG_IPV6_MODULE
77217 +EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
77218 +#endif
77219 +int grsec_lastack_retries;
77220 +int grsec_enable_tpe_all;
77221 +int grsec_enable_tpe_invert;
77222 +int grsec_enable_socket_all;
77223 +kgid_t grsec_socket_all_gid;
77224 +int grsec_enable_socket_client;
77225 +kgid_t grsec_socket_client_gid;
77226 +int grsec_enable_socket_server;
77227 +kgid_t grsec_socket_server_gid;
77228 +int grsec_resource_logging;
77229 +int grsec_disable_privio;
77230 +int grsec_enable_log_rwxmaps;
77231 +int grsec_lock;
77232 +
77233 +DEFINE_SPINLOCK(grsec_alert_lock);
77234 +unsigned long grsec_alert_wtime = 0;
77235 +unsigned long grsec_alert_fyet = 0;
77236 +
77237 +DEFINE_SPINLOCK(grsec_audit_lock);
77238 +
77239 +DEFINE_RWLOCK(grsec_exec_file_lock);
77240 +
77241 +char *gr_shared_page[4];
77242 +
77243 +char *gr_alert_log_fmt;
77244 +char *gr_audit_log_fmt;
77245 +char *gr_alert_log_buf;
77246 +char *gr_audit_log_buf;
77247 +
77248 +extern struct gr_arg *gr_usermode;
77249 +extern unsigned char *gr_system_salt;
77250 +extern unsigned char *gr_system_sum;
77251 +
77252 +void __init
77253 +grsecurity_init(void)
77254 +{
77255 + int j;
77256 + /* create the per-cpu shared pages */
77257 +
77258 +#ifdef CONFIG_X86
77259 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
77260 +#endif
77261 +
77262 + for (j = 0; j < 4; j++) {
77263 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
77264 + if (gr_shared_page[j] == NULL) {
77265 + panic("Unable to allocate grsecurity shared page");
77266 + return;
77267 + }
77268 + }
77269 +
77270 + /* allocate log buffers */
77271 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
77272 + if (!gr_alert_log_fmt) {
77273 + panic("Unable to allocate grsecurity alert log format buffer");
77274 + return;
77275 + }
77276 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
77277 + if (!gr_audit_log_fmt) {
77278 + panic("Unable to allocate grsecurity audit log format buffer");
77279 + return;
77280 + }
77281 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
77282 + if (!gr_alert_log_buf) {
77283 + panic("Unable to allocate grsecurity alert log buffer");
77284 + return;
77285 + }
77286 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
77287 + if (!gr_audit_log_buf) {
77288 + panic("Unable to allocate grsecurity audit log buffer");
77289 + return;
77290 + }
77291 +
77292 + /* allocate memory for authentication structure */
77293 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
77294 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
77295 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
77296 +
77297 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
77298 + panic("Unable to allocate grsecurity authentication structure");
77299 + return;
77300 + }
77301 +
77302 +#ifdef CONFIG_GRKERNSEC_IO
77303 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
77304 + grsec_disable_privio = 1;
77305 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
77306 + grsec_disable_privio = 1;
77307 +#else
77308 + grsec_disable_privio = 0;
77309 +#endif
77310 +#endif
77311 +
77312 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
77313 + /* for backward compatibility, tpe_invert always defaults to on if
77314 + enabled in the kernel
77315 + */
77316 + grsec_enable_tpe_invert = 1;
77317 +#endif
77318 +
77319 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
77320 +#ifndef CONFIG_GRKERNSEC_SYSCTL
77321 + grsec_lock = 1;
77322 +#endif
77323 +
77324 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
77325 + grsec_enable_log_rwxmaps = 1;
77326 +#endif
77327 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
77328 + grsec_enable_group = 1;
77329 + grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
77330 +#endif
77331 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
77332 + grsec_enable_ptrace_readexec = 1;
77333 +#endif
77334 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
77335 + grsec_enable_chdir = 1;
77336 +#endif
77337 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
77338 + grsec_enable_harden_ptrace = 1;
77339 +#endif
77340 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
77341 + grsec_enable_harden_ipc = 1;
77342 +#endif
77343 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
77344 + grsec_enable_mount = 1;
77345 +#endif
77346 +#ifdef CONFIG_GRKERNSEC_LINK
77347 + grsec_enable_link = 1;
77348 +#endif
77349 +#ifdef CONFIG_GRKERNSEC_BRUTE
77350 + grsec_enable_brute = 1;
77351 +#endif
77352 +#ifdef CONFIG_GRKERNSEC_DMESG
77353 + grsec_enable_dmesg = 1;
77354 +#endif
77355 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77356 + grsec_enable_blackhole = 1;
77357 + grsec_lastack_retries = 4;
77358 +#endif
77359 +#ifdef CONFIG_GRKERNSEC_FIFO
77360 + grsec_enable_fifo = 1;
77361 +#endif
77362 +#ifdef CONFIG_GRKERNSEC_EXECLOG
77363 + grsec_enable_execlog = 1;
77364 +#endif
77365 +#ifdef CONFIG_GRKERNSEC_SETXID
77366 + grsec_enable_setxid = 1;
77367 +#endif
77368 +#ifdef CONFIG_GRKERNSEC_SIGNAL
77369 + grsec_enable_signal = 1;
77370 +#endif
77371 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
77372 + grsec_enable_forkfail = 1;
77373 +#endif
77374 +#ifdef CONFIG_GRKERNSEC_TIME
77375 + grsec_enable_time = 1;
77376 +#endif
77377 +#ifdef CONFIG_GRKERNSEC_RESLOG
77378 + grsec_resource_logging = 1;
77379 +#endif
77380 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
77381 + grsec_enable_chroot_findtask = 1;
77382 +#endif
77383 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
77384 + grsec_enable_chroot_unix = 1;
77385 +#endif
77386 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
77387 + grsec_enable_chroot_mount = 1;
77388 +#endif
77389 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
77390 + grsec_enable_chroot_fchdir = 1;
77391 +#endif
77392 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
77393 + grsec_enable_chroot_shmat = 1;
77394 +#endif
77395 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
77396 + grsec_enable_audit_ptrace = 1;
77397 +#endif
77398 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
77399 + grsec_enable_chroot_double = 1;
77400 +#endif
77401 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
77402 + grsec_enable_chroot_pivot = 1;
77403 +#endif
77404 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
77405 + grsec_enable_chroot_chdir = 1;
77406 +#endif
77407 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
77408 + grsec_enable_chroot_chmod = 1;
77409 +#endif
77410 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
77411 + grsec_enable_chroot_mknod = 1;
77412 +#endif
77413 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
77414 + grsec_enable_chroot_nice = 1;
77415 +#endif
77416 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
77417 + grsec_enable_chroot_execlog = 1;
77418 +#endif
77419 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
77420 + grsec_enable_chroot_caps = 1;
77421 +#endif
77422 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
77423 + grsec_enable_chroot_sysctl = 1;
77424 +#endif
77425 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
77426 + grsec_enable_symlinkown = 1;
77427 + grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
77428 +#endif
77429 +#ifdef CONFIG_GRKERNSEC_TPE
77430 + grsec_enable_tpe = 1;
77431 + grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
77432 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
77433 + grsec_enable_tpe_all = 1;
77434 +#endif
77435 +#endif
77436 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
77437 + grsec_enable_socket_all = 1;
77438 + grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
77439 +#endif
77440 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
77441 + grsec_enable_socket_client = 1;
77442 + grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
77443 +#endif
77444 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
77445 + grsec_enable_socket_server = 1;
77446 + grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
77447 +#endif
77448 +#endif
77449 +#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
77450 + grsec_deny_new_usb = 1;
77451 +#endif
77452 +
77453 + return;
77454 +}
77455 diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
77456 new file mode 100644
77457 index 0000000..1773300
77458 --- /dev/null
77459 +++ b/grsecurity/grsec_ipc.c
77460 @@ -0,0 +1,48 @@
77461 +#include <linux/kernel.h>
77462 +#include <linux/mm.h>
77463 +#include <linux/sched.h>
77464 +#include <linux/file.h>
77465 +#include <linux/ipc.h>
77466 +#include <linux/ipc_namespace.h>
77467 +#include <linux/grsecurity.h>
77468 +#include <linux/grinternal.h>
77469 +
77470 +int
77471 +gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
77472 +{
77473 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
77474 + int write;
77475 + int orig_granted_mode;
77476 + kuid_t euid;
77477 + kgid_t egid;
77478 +
77479 + if (!grsec_enable_harden_ipc)
77480 + return 1;
77481 +
77482 + euid = current_euid();
77483 + egid = current_egid();
77484 +
77485 + write = requested_mode & 00002;
77486 + orig_granted_mode = ipcp->mode;
77487 +
77488 + if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
77489 + orig_granted_mode >>= 6;
77490 + else {
77491 + /* if likely wrong permissions, lock to user */
77492 + if (orig_granted_mode & 0007)
77493 + orig_granted_mode = 0;
77494 + /* otherwise do a egid-only check */
77495 + else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
77496 + orig_granted_mode >>= 3;
77497 + /* otherwise, no access */
77498 + else
77499 + orig_granted_mode = 0;
77500 + }
77501 + if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
77502 + !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
77503 + gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
77504 + return 0;
77505 + }
77506 +#endif
77507 + return 1;
77508 +}
77509 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
77510 new file mode 100644
77511 index 0000000..5e05e20
77512 --- /dev/null
77513 +++ b/grsecurity/grsec_link.c
77514 @@ -0,0 +1,58 @@
77515 +#include <linux/kernel.h>
77516 +#include <linux/sched.h>
77517 +#include <linux/fs.h>
77518 +#include <linux/file.h>
77519 +#include <linux/grinternal.h>
77520 +
77521 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
77522 +{
77523 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
77524 + const struct inode *link_inode = link->dentry->d_inode;
77525 +
77526 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
77527 + /* ignore root-owned links, e.g. /proc/self */
77528 + gr_is_global_nonroot(link_inode->i_uid) && target &&
77529 + !uid_eq(link_inode->i_uid, target->i_uid)) {
77530 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
77531 + return 1;
77532 + }
77533 +#endif
77534 + return 0;
77535 +}
77536 +
77537 +int
77538 +gr_handle_follow_link(const struct inode *parent,
77539 + const struct inode *inode,
77540 + const struct dentry *dentry, const struct vfsmount *mnt)
77541 +{
77542 +#ifdef CONFIG_GRKERNSEC_LINK
77543 + const struct cred *cred = current_cred();
77544 +
77545 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
77546 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
77547 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
77548 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
77549 + return -EACCES;
77550 + }
77551 +#endif
77552 + return 0;
77553 +}
77554 +
77555 +int
77556 +gr_handle_hardlink(const struct dentry *dentry,
77557 + const struct vfsmount *mnt,
77558 + struct inode *inode, const int mode, const struct filename *to)
77559 +{
77560 +#ifdef CONFIG_GRKERNSEC_LINK
77561 + const struct cred *cred = current_cred();
77562 +
77563 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
77564 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
77565 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
77566 + !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
77567 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
77568 + return -EPERM;
77569 + }
77570 +#endif
77571 + return 0;
77572 +}
77573 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
77574 new file mode 100644
77575 index 0000000..dbe0a6b
77576 --- /dev/null
77577 +++ b/grsecurity/grsec_log.c
77578 @@ -0,0 +1,341 @@
77579 +#include <linux/kernel.h>
77580 +#include <linux/sched.h>
77581 +#include <linux/file.h>
77582 +#include <linux/tty.h>
77583 +#include <linux/fs.h>
77584 +#include <linux/mm.h>
77585 +#include <linux/grinternal.h>
77586 +
77587 +#ifdef CONFIG_TREE_PREEMPT_RCU
77588 +#define DISABLE_PREEMPT() preempt_disable()
77589 +#define ENABLE_PREEMPT() preempt_enable()
77590 +#else
77591 +#define DISABLE_PREEMPT()
77592 +#define ENABLE_PREEMPT()
77593 +#endif
77594 +
77595 +#define BEGIN_LOCKS(x) \
77596 + DISABLE_PREEMPT(); \
77597 + rcu_read_lock(); \
77598 + read_lock(&tasklist_lock); \
77599 + read_lock(&grsec_exec_file_lock); \
77600 + if (x != GR_DO_AUDIT) \
77601 + spin_lock(&grsec_alert_lock); \
77602 + else \
77603 + spin_lock(&grsec_audit_lock)
77604 +
77605 +#define END_LOCKS(x) \
77606 + if (x != GR_DO_AUDIT) \
77607 + spin_unlock(&grsec_alert_lock); \
77608 + else \
77609 + spin_unlock(&grsec_audit_lock); \
77610 + read_unlock(&grsec_exec_file_lock); \
77611 + read_unlock(&tasklist_lock); \
77612 + rcu_read_unlock(); \
77613 + ENABLE_PREEMPT(); \
77614 + if (x == GR_DONT_AUDIT) \
77615 + gr_handle_alertkill(current)
77616 +
77617 +enum {
77618 + FLOODING,
77619 + NO_FLOODING
77620 +};
77621 +
77622 +extern char *gr_alert_log_fmt;
77623 +extern char *gr_audit_log_fmt;
77624 +extern char *gr_alert_log_buf;
77625 +extern char *gr_audit_log_buf;
77626 +
77627 +static int gr_log_start(int audit)
77628 +{
77629 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
77630 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
77631 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77632 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
77633 + unsigned long curr_secs = get_seconds();
77634 +
77635 + if (audit == GR_DO_AUDIT)
77636 + goto set_fmt;
77637 +
77638 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
77639 + grsec_alert_wtime = curr_secs;
77640 + grsec_alert_fyet = 0;
77641 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
77642 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
77643 + grsec_alert_fyet++;
77644 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
77645 + grsec_alert_wtime = curr_secs;
77646 + grsec_alert_fyet++;
77647 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
77648 + return FLOODING;
77649 + }
77650 + else return FLOODING;
77651 +
77652 +set_fmt:
77653 +#endif
77654 + memset(buf, 0, PAGE_SIZE);
77655 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
77656 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
77657 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
77658 + } else if (current->signal->curr_ip) {
77659 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
77660 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
77661 + } else if (gr_acl_is_enabled()) {
77662 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
77663 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
77664 + } else {
77665 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
77666 + strcpy(buf, fmt);
77667 + }
77668 +
77669 + return NO_FLOODING;
77670 +}
77671 +
77672 +static void gr_log_middle(int audit, const char *msg, va_list ap)
77673 + __attribute__ ((format (printf, 2, 0)));
77674 +
77675 +static void gr_log_middle(int audit, const char *msg, va_list ap)
77676 +{
77677 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77678 + unsigned int len = strlen(buf);
77679 +
77680 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
77681 +
77682 + return;
77683 +}
77684 +
77685 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
77686 + __attribute__ ((format (printf, 2, 3)));
77687 +
77688 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
77689 +{
77690 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77691 + unsigned int len = strlen(buf);
77692 + va_list ap;
77693 +
77694 + va_start(ap, msg);
77695 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
77696 + va_end(ap);
77697 +
77698 + return;
77699 +}
77700 +
77701 +static void gr_log_end(int audit, int append_default)
77702 +{
77703 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77704 + if (append_default) {
77705 + struct task_struct *task = current;
77706 + struct task_struct *parent = task->real_parent;
77707 + const struct cred *cred = __task_cred(task);
77708 + const struct cred *pcred = __task_cred(parent);
77709 + unsigned int len = strlen(buf);
77710 +
77711 + 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));
77712 + }
77713 +
77714 + printk("%s\n", buf);
77715 +
77716 + return;
77717 +}
77718 +
77719 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
77720 +{
77721 + int logtype;
77722 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
77723 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
77724 + void *voidptr = NULL;
77725 + int num1 = 0, num2 = 0;
77726 + unsigned long ulong1 = 0, ulong2 = 0;
77727 + struct dentry *dentry = NULL;
77728 + struct vfsmount *mnt = NULL;
77729 + struct file *file = NULL;
77730 + struct task_struct *task = NULL;
77731 + struct vm_area_struct *vma = NULL;
77732 + const struct cred *cred, *pcred;
77733 + va_list ap;
77734 +
77735 + BEGIN_LOCKS(audit);
77736 + logtype = gr_log_start(audit);
77737 + if (logtype == FLOODING) {
77738 + END_LOCKS(audit);
77739 + return;
77740 + }
77741 + va_start(ap, argtypes);
77742 + switch (argtypes) {
77743 + case GR_TTYSNIFF:
77744 + task = va_arg(ap, struct task_struct *);
77745 + 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));
77746 + break;
77747 + case GR_SYSCTL_HIDDEN:
77748 + str1 = va_arg(ap, char *);
77749 + gr_log_middle_varargs(audit, msg, result, str1);
77750 + break;
77751 + case GR_RBAC:
77752 + dentry = va_arg(ap, struct dentry *);
77753 + mnt = va_arg(ap, struct vfsmount *);
77754 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
77755 + break;
77756 + case GR_RBAC_STR:
77757 + dentry = va_arg(ap, struct dentry *);
77758 + mnt = va_arg(ap, struct vfsmount *);
77759 + str1 = va_arg(ap, char *);
77760 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
77761 + break;
77762 + case GR_STR_RBAC:
77763 + str1 = va_arg(ap, char *);
77764 + dentry = va_arg(ap, struct dentry *);
77765 + mnt = va_arg(ap, struct vfsmount *);
77766 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
77767 + break;
77768 + case GR_RBAC_MODE2:
77769 + dentry = va_arg(ap, struct dentry *);
77770 + mnt = va_arg(ap, struct vfsmount *);
77771 + str1 = va_arg(ap, char *);
77772 + str2 = va_arg(ap, char *);
77773 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
77774 + break;
77775 + case GR_RBAC_MODE3:
77776 + dentry = va_arg(ap, struct dentry *);
77777 + mnt = va_arg(ap, struct vfsmount *);
77778 + str1 = va_arg(ap, char *);
77779 + str2 = va_arg(ap, char *);
77780 + str3 = va_arg(ap, char *);
77781 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
77782 + break;
77783 + case GR_FILENAME:
77784 + dentry = va_arg(ap, struct dentry *);
77785 + mnt = va_arg(ap, struct vfsmount *);
77786 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
77787 + break;
77788 + case GR_STR_FILENAME:
77789 + str1 = va_arg(ap, char *);
77790 + dentry = va_arg(ap, struct dentry *);
77791 + mnt = va_arg(ap, struct vfsmount *);
77792 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
77793 + break;
77794 + case GR_FILENAME_STR:
77795 + dentry = va_arg(ap, struct dentry *);
77796 + mnt = va_arg(ap, struct vfsmount *);
77797 + str1 = va_arg(ap, char *);
77798 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
77799 + break;
77800 + case GR_FILENAME_TWO_INT:
77801 + dentry = va_arg(ap, struct dentry *);
77802 + mnt = va_arg(ap, struct vfsmount *);
77803 + num1 = va_arg(ap, int);
77804 + num2 = va_arg(ap, int);
77805 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
77806 + break;
77807 + case GR_FILENAME_TWO_INT_STR:
77808 + dentry = va_arg(ap, struct dentry *);
77809 + mnt = va_arg(ap, struct vfsmount *);
77810 + num1 = va_arg(ap, int);
77811 + num2 = va_arg(ap, int);
77812 + str1 = va_arg(ap, char *);
77813 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
77814 + break;
77815 + case GR_TEXTREL:
77816 + file = va_arg(ap, struct file *);
77817 + ulong1 = va_arg(ap, unsigned long);
77818 + ulong2 = va_arg(ap, unsigned long);
77819 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
77820 + break;
77821 + case GR_PTRACE:
77822 + task = va_arg(ap, struct task_struct *);
77823 + 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));
77824 + break;
77825 + case GR_RESOURCE:
77826 + task = va_arg(ap, struct task_struct *);
77827 + cred = __task_cred(task);
77828 + pcred = __task_cred(task->real_parent);
77829 + ulong1 = va_arg(ap, unsigned long);
77830 + str1 = va_arg(ap, char *);
77831 + ulong2 = va_arg(ap, unsigned long);
77832 + 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));
77833 + break;
77834 + case GR_CAP:
77835 + task = va_arg(ap, struct task_struct *);
77836 + cred = __task_cred(task);
77837 + pcred = __task_cred(task->real_parent);
77838 + str1 = va_arg(ap, char *);
77839 + 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));
77840 + break;
77841 + case GR_SIG:
77842 + str1 = va_arg(ap, char *);
77843 + voidptr = va_arg(ap, void *);
77844 + gr_log_middle_varargs(audit, msg, str1, voidptr);
77845 + break;
77846 + case GR_SIG2:
77847 + task = va_arg(ap, struct task_struct *);
77848 + cred = __task_cred(task);
77849 + pcred = __task_cred(task->real_parent);
77850 + num1 = va_arg(ap, int);
77851 + 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));
77852 + break;
77853 + case GR_CRASH1:
77854 + task = va_arg(ap, struct task_struct *);
77855 + cred = __task_cred(task);
77856 + pcred = __task_cred(task->real_parent);
77857 + ulong1 = va_arg(ap, unsigned long);
77858 + 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);
77859 + break;
77860 + case GR_CRASH2:
77861 + task = va_arg(ap, struct task_struct *);
77862 + cred = __task_cred(task);
77863 + pcred = __task_cred(task->real_parent);
77864 + ulong1 = va_arg(ap, unsigned long);
77865 + 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);
77866 + break;
77867 + case GR_RWXMAP:
77868 + file = va_arg(ap, struct file *);
77869 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
77870 + break;
77871 + case GR_RWXMAPVMA:
77872 + vma = va_arg(ap, struct vm_area_struct *);
77873 + if (vma->vm_file)
77874 + str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
77875 + else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
77876 + str1 = "<stack>";
77877 + else if (vma->vm_start <= current->mm->brk &&
77878 + vma->vm_end >= current->mm->start_brk)
77879 + str1 = "<heap>";
77880 + else
77881 + str1 = "<anonymous mapping>";
77882 + gr_log_middle_varargs(audit, msg, str1);
77883 + break;
77884 + case GR_PSACCT:
77885 + {
77886 + unsigned int wday, cday;
77887 + __u8 whr, chr;
77888 + __u8 wmin, cmin;
77889 + __u8 wsec, csec;
77890 + char cur_tty[64] = { 0 };
77891 + char parent_tty[64] = { 0 };
77892 +
77893 + task = va_arg(ap, struct task_struct *);
77894 + wday = va_arg(ap, unsigned int);
77895 + cday = va_arg(ap, unsigned int);
77896 + whr = va_arg(ap, int);
77897 + chr = va_arg(ap, int);
77898 + wmin = va_arg(ap, int);
77899 + cmin = va_arg(ap, int);
77900 + wsec = va_arg(ap, int);
77901 + csec = va_arg(ap, int);
77902 + ulong1 = va_arg(ap, unsigned long);
77903 + cred = __task_cred(task);
77904 + pcred = __task_cred(task->real_parent);
77905 +
77906 + 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));
77907 + }
77908 + break;
77909 + default:
77910 + gr_log_middle(audit, msg, ap);
77911 + }
77912 + va_end(ap);
77913 + // these don't need DEFAULTSECARGS printed on the end
77914 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
77915 + gr_log_end(audit, 0);
77916 + else
77917 + gr_log_end(audit, 1);
77918 + END_LOCKS(audit);
77919 +}
77920 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
77921 new file mode 100644
77922 index 0000000..0e39d8c
77923 --- /dev/null
77924 +++ b/grsecurity/grsec_mem.c
77925 @@ -0,0 +1,48 @@
77926 +#include <linux/kernel.h>
77927 +#include <linux/sched.h>
77928 +#include <linux/mm.h>
77929 +#include <linux/mman.h>
77930 +#include <linux/module.h>
77931 +#include <linux/grinternal.h>
77932 +
77933 +void gr_handle_msr_write(void)
77934 +{
77935 + gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
77936 + return;
77937 +}
77938 +EXPORT_SYMBOL_GPL(gr_handle_msr_write);
77939 +
77940 +void
77941 +gr_handle_ioperm(void)
77942 +{
77943 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
77944 + return;
77945 +}
77946 +
77947 +void
77948 +gr_handle_iopl(void)
77949 +{
77950 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
77951 + return;
77952 +}
77953 +
77954 +void
77955 +gr_handle_mem_readwrite(u64 from, u64 to)
77956 +{
77957 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
77958 + return;
77959 +}
77960 +
77961 +void
77962 +gr_handle_vm86(void)
77963 +{
77964 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
77965 + return;
77966 +}
77967 +
77968 +void
77969 +gr_log_badprocpid(const char *entry)
77970 +{
77971 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
77972 + return;
77973 +}
77974 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
77975 new file mode 100644
77976 index 0000000..cd9e124
77977 --- /dev/null
77978 +++ b/grsecurity/grsec_mount.c
77979 @@ -0,0 +1,65 @@
77980 +#include <linux/kernel.h>
77981 +#include <linux/sched.h>
77982 +#include <linux/mount.h>
77983 +#include <linux/major.h>
77984 +#include <linux/grsecurity.h>
77985 +#include <linux/grinternal.h>
77986 +
77987 +void
77988 +gr_log_remount(const char *devname, const int retval)
77989 +{
77990 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
77991 + if (grsec_enable_mount && (retval >= 0))
77992 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
77993 +#endif
77994 + return;
77995 +}
77996 +
77997 +void
77998 +gr_log_unmount(const char *devname, const int retval)
77999 +{
78000 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78001 + if (grsec_enable_mount && (retval >= 0))
78002 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
78003 +#endif
78004 + return;
78005 +}
78006 +
78007 +void
78008 +gr_log_mount(const char *from, const char *to, const int retval)
78009 +{
78010 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78011 + if (grsec_enable_mount && (retval >= 0))
78012 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
78013 +#endif
78014 + return;
78015 +}
78016 +
78017 +int
78018 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
78019 +{
78020 +#ifdef CONFIG_GRKERNSEC_ROFS
78021 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
78022 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
78023 + return -EPERM;
78024 + } else
78025 + return 0;
78026 +#endif
78027 + return 0;
78028 +}
78029 +
78030 +int
78031 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
78032 +{
78033 +#ifdef CONFIG_GRKERNSEC_ROFS
78034 + struct inode *inode = dentry->d_inode;
78035 +
78036 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
78037 + inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
78038 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
78039 + return -EPERM;
78040 + } else
78041 + return 0;
78042 +#endif
78043 + return 0;
78044 +}
78045 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
78046 new file mode 100644
78047 index 0000000..6ee9d50
78048 --- /dev/null
78049 +++ b/grsecurity/grsec_pax.c
78050 @@ -0,0 +1,45 @@
78051 +#include <linux/kernel.h>
78052 +#include <linux/sched.h>
78053 +#include <linux/mm.h>
78054 +#include <linux/file.h>
78055 +#include <linux/grinternal.h>
78056 +#include <linux/grsecurity.h>
78057 +
78058 +void
78059 +gr_log_textrel(struct vm_area_struct * vma)
78060 +{
78061 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78062 + if (grsec_enable_log_rwxmaps)
78063 + gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
78064 +#endif
78065 + return;
78066 +}
78067 +
78068 +void gr_log_ptgnustack(struct file *file)
78069 +{
78070 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78071 + if (grsec_enable_log_rwxmaps)
78072 + gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
78073 +#endif
78074 + return;
78075 +}
78076 +
78077 +void
78078 +gr_log_rwxmmap(struct file *file)
78079 +{
78080 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78081 + if (grsec_enable_log_rwxmaps)
78082 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
78083 +#endif
78084 + return;
78085 +}
78086 +
78087 +void
78088 +gr_log_rwxmprotect(struct vm_area_struct *vma)
78089 +{
78090 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78091 + if (grsec_enable_log_rwxmaps)
78092 + gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
78093 +#endif
78094 + return;
78095 +}
78096 diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
78097 new file mode 100644
78098 index 0000000..2005a3a
78099 --- /dev/null
78100 +++ b/grsecurity/grsec_proc.c
78101 @@ -0,0 +1,20 @@
78102 +#include <linux/kernel.h>
78103 +#include <linux/sched.h>
78104 +#include <linux/grsecurity.h>
78105 +#include <linux/grinternal.h>
78106 +
78107 +int gr_proc_is_restricted(void)
78108 +{
78109 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78110 + const struct cred *cred = current_cred();
78111 +#endif
78112 +
78113 +#ifdef CONFIG_GRKERNSEC_PROC_USER
78114 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
78115 + return -EACCES;
78116 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78117 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
78118 + return -EACCES;
78119 +#endif
78120 + return 0;
78121 +}
78122 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
78123 new file mode 100644
78124 index 0000000..f7f29aa
78125 --- /dev/null
78126 +++ b/grsecurity/grsec_ptrace.c
78127 @@ -0,0 +1,30 @@
78128 +#include <linux/kernel.h>
78129 +#include <linux/sched.h>
78130 +#include <linux/grinternal.h>
78131 +#include <linux/security.h>
78132 +
78133 +void
78134 +gr_audit_ptrace(struct task_struct *task)
78135 +{
78136 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
78137 + if (grsec_enable_audit_ptrace)
78138 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
78139 +#endif
78140 + return;
78141 +}
78142 +
78143 +int
78144 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
78145 +{
78146 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
78147 + const struct dentry *dentry = file->f_path.dentry;
78148 + const struct vfsmount *mnt = file->f_path.mnt;
78149 +
78150 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
78151 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
78152 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
78153 + return -EACCES;
78154 + }
78155 +#endif
78156 + return 0;
78157 +}
78158 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
78159 new file mode 100644
78160 index 0000000..3860c7e
78161 --- /dev/null
78162 +++ b/grsecurity/grsec_sig.c
78163 @@ -0,0 +1,236 @@
78164 +#include <linux/kernel.h>
78165 +#include <linux/sched.h>
78166 +#include <linux/fs.h>
78167 +#include <linux/delay.h>
78168 +#include <linux/grsecurity.h>
78169 +#include <linux/grinternal.h>
78170 +#include <linux/hardirq.h>
78171 +
78172 +char *signames[] = {
78173 + [SIGSEGV] = "Segmentation fault",
78174 + [SIGILL] = "Illegal instruction",
78175 + [SIGABRT] = "Abort",
78176 + [SIGBUS] = "Invalid alignment/Bus error"
78177 +};
78178 +
78179 +void
78180 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
78181 +{
78182 +#ifdef CONFIG_GRKERNSEC_SIGNAL
78183 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
78184 + (sig == SIGABRT) || (sig == SIGBUS))) {
78185 + if (task_pid_nr(t) == task_pid_nr(current)) {
78186 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
78187 + } else {
78188 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
78189 + }
78190 + }
78191 +#endif
78192 + return;
78193 +}
78194 +
78195 +int
78196 +gr_handle_signal(const struct task_struct *p, const int sig)
78197 +{
78198 +#ifdef CONFIG_GRKERNSEC
78199 + /* ignore the 0 signal for protected task checks */
78200 + if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
78201 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
78202 + return -EPERM;
78203 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
78204 + return -EPERM;
78205 + }
78206 +#endif
78207 + return 0;
78208 +}
78209 +
78210 +#ifdef CONFIG_GRKERNSEC
78211 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
78212 +
78213 +int gr_fake_force_sig(int sig, struct task_struct *t)
78214 +{
78215 + unsigned long int flags;
78216 + int ret, blocked, ignored;
78217 + struct k_sigaction *action;
78218 +
78219 + spin_lock_irqsave(&t->sighand->siglock, flags);
78220 + action = &t->sighand->action[sig-1];
78221 + ignored = action->sa.sa_handler == SIG_IGN;
78222 + blocked = sigismember(&t->blocked, sig);
78223 + if (blocked || ignored) {
78224 + action->sa.sa_handler = SIG_DFL;
78225 + if (blocked) {
78226 + sigdelset(&t->blocked, sig);
78227 + recalc_sigpending_and_wake(t);
78228 + }
78229 + }
78230 + if (action->sa.sa_handler == SIG_DFL)
78231 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
78232 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
78233 +
78234 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
78235 +
78236 + return ret;
78237 +}
78238 +#endif
78239 +
78240 +#define GR_USER_BAN_TIME (15 * 60)
78241 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
78242 +
78243 +void gr_handle_brute_attach(int dumpable)
78244 +{
78245 +#ifdef CONFIG_GRKERNSEC_BRUTE
78246 + struct task_struct *p = current;
78247 + kuid_t uid = GLOBAL_ROOT_UID;
78248 + int daemon = 0;
78249 +
78250 + if (!grsec_enable_brute)
78251 + return;
78252 +
78253 + rcu_read_lock();
78254 + read_lock(&tasklist_lock);
78255 + read_lock(&grsec_exec_file_lock);
78256 + if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
78257 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
78258 + p->real_parent->brute = 1;
78259 + daemon = 1;
78260 + } else {
78261 + const struct cred *cred = __task_cred(p), *cred2;
78262 + struct task_struct *tsk, *tsk2;
78263 +
78264 + if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
78265 + struct user_struct *user;
78266 +
78267 + uid = cred->uid;
78268 +
78269 + /* this is put upon execution past expiration */
78270 + user = find_user(uid);
78271 + if (user == NULL)
78272 + goto unlock;
78273 + user->suid_banned = 1;
78274 + user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
78275 + if (user->suid_ban_expires == ~0UL)
78276 + user->suid_ban_expires--;
78277 +
78278 + /* only kill other threads of the same binary, from the same user */
78279 + do_each_thread(tsk2, tsk) {
78280 + cred2 = __task_cred(tsk);
78281 + if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
78282 + gr_fake_force_sig(SIGKILL, tsk);
78283 + } while_each_thread(tsk2, tsk);
78284 + }
78285 + }
78286 +unlock:
78287 + read_unlock(&grsec_exec_file_lock);
78288 + read_unlock(&tasklist_lock);
78289 + rcu_read_unlock();
78290 +
78291 + if (gr_is_global_nonroot(uid))
78292 + 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);
78293 + else if (daemon)
78294 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
78295 +
78296 +#endif
78297 + return;
78298 +}
78299 +
78300 +void gr_handle_brute_check(void)
78301 +{
78302 +#ifdef CONFIG_GRKERNSEC_BRUTE
78303 + struct task_struct *p = current;
78304 +
78305 + if (unlikely(p->brute)) {
78306 + if (!grsec_enable_brute)
78307 + p->brute = 0;
78308 + else if (time_before(get_seconds(), p->brute_expires))
78309 + msleep(30 * 1000);
78310 + }
78311 +#endif
78312 + return;
78313 +}
78314 +
78315 +void gr_handle_kernel_exploit(void)
78316 +{
78317 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78318 + const struct cred *cred;
78319 + struct task_struct *tsk, *tsk2;
78320 + struct user_struct *user;
78321 + kuid_t uid;
78322 +
78323 + if (in_irq() || in_serving_softirq() || in_nmi())
78324 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
78325 +
78326 + uid = current_uid();
78327 +
78328 + if (gr_is_global_root(uid))
78329 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
78330 + else {
78331 + /* kill all the processes of this user, hold a reference
78332 + to their creds struct, and prevent them from creating
78333 + another process until system reset
78334 + */
78335 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
78336 + GR_GLOBAL_UID(uid));
78337 + /* we intentionally leak this ref */
78338 + user = get_uid(current->cred->user);
78339 + if (user)
78340 + user->kernel_banned = 1;
78341 +
78342 + /* kill all processes of this user */
78343 + read_lock(&tasklist_lock);
78344 + do_each_thread(tsk2, tsk) {
78345 + cred = __task_cred(tsk);
78346 + if (uid_eq(cred->uid, uid))
78347 + gr_fake_force_sig(SIGKILL, tsk);
78348 + } while_each_thread(tsk2, tsk);
78349 + read_unlock(&tasklist_lock);
78350 + }
78351 +#endif
78352 +}
78353 +
78354 +#ifdef CONFIG_GRKERNSEC_BRUTE
78355 +static bool suid_ban_expired(struct user_struct *user)
78356 +{
78357 + if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
78358 + user->suid_banned = 0;
78359 + user->suid_ban_expires = 0;
78360 + free_uid(user);
78361 + return true;
78362 + }
78363 +
78364 + return false;
78365 +}
78366 +#endif
78367 +
78368 +int gr_process_kernel_exec_ban(void)
78369 +{
78370 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78371 + if (unlikely(current->cred->user->kernel_banned))
78372 + return -EPERM;
78373 +#endif
78374 + return 0;
78375 +}
78376 +
78377 +int gr_process_kernel_setuid_ban(struct user_struct *user)
78378 +{
78379 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78380 + if (unlikely(user->kernel_banned))
78381 + gr_fake_force_sig(SIGKILL, current);
78382 +#endif
78383 + return 0;
78384 +}
78385 +
78386 +int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
78387 +{
78388 +#ifdef CONFIG_GRKERNSEC_BRUTE
78389 + struct user_struct *user = current->cred->user;
78390 + if (unlikely(user->suid_banned)) {
78391 + if (suid_ban_expired(user))
78392 + return 0;
78393 + /* disallow execution of suid binaries only */
78394 + else if (!uid_eq(bprm->cred->euid, current->cred->uid))
78395 + return -EPERM;
78396 + }
78397 +#endif
78398 + return 0;
78399 +}
78400 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
78401 new file mode 100644
78402 index 0000000..e3650b6
78403 --- /dev/null
78404 +++ b/grsecurity/grsec_sock.c
78405 @@ -0,0 +1,244 @@
78406 +#include <linux/kernel.h>
78407 +#include <linux/module.h>
78408 +#include <linux/sched.h>
78409 +#include <linux/file.h>
78410 +#include <linux/net.h>
78411 +#include <linux/in.h>
78412 +#include <linux/ip.h>
78413 +#include <net/sock.h>
78414 +#include <net/inet_sock.h>
78415 +#include <linux/grsecurity.h>
78416 +#include <linux/grinternal.h>
78417 +#include <linux/gracl.h>
78418 +
78419 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
78420 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
78421 +
78422 +EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
78423 +EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
78424 +
78425 +#ifdef CONFIG_UNIX_MODULE
78426 +EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
78427 +EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
78428 +EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
78429 +EXPORT_SYMBOL_GPL(gr_handle_create);
78430 +#endif
78431 +
78432 +#ifdef CONFIG_GRKERNSEC
78433 +#define gr_conn_table_size 32749
78434 +struct conn_table_entry {
78435 + struct conn_table_entry *next;
78436 + struct signal_struct *sig;
78437 +};
78438 +
78439 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
78440 +DEFINE_SPINLOCK(gr_conn_table_lock);
78441 +
78442 +extern const char * gr_socktype_to_name(unsigned char type);
78443 +extern const char * gr_proto_to_name(unsigned char proto);
78444 +extern const char * gr_sockfamily_to_name(unsigned char family);
78445 +
78446 +static __inline__ int
78447 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
78448 +{
78449 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
78450 +}
78451 +
78452 +static __inline__ int
78453 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
78454 + __u16 sport, __u16 dport)
78455 +{
78456 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
78457 + sig->gr_sport == sport && sig->gr_dport == dport))
78458 + return 1;
78459 + else
78460 + return 0;
78461 +}
78462 +
78463 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
78464 +{
78465 + struct conn_table_entry **match;
78466 + unsigned int index;
78467 +
78468 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
78469 + sig->gr_sport, sig->gr_dport,
78470 + gr_conn_table_size);
78471 +
78472 + newent->sig = sig;
78473 +
78474 + match = &gr_conn_table[index];
78475 + newent->next = *match;
78476 + *match = newent;
78477 +
78478 + return;
78479 +}
78480 +
78481 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
78482 +{
78483 + struct conn_table_entry *match, *last = NULL;
78484 + unsigned int index;
78485 +
78486 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
78487 + sig->gr_sport, sig->gr_dport,
78488 + gr_conn_table_size);
78489 +
78490 + match = gr_conn_table[index];
78491 + while (match && !conn_match(match->sig,
78492 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
78493 + sig->gr_dport)) {
78494 + last = match;
78495 + match = match->next;
78496 + }
78497 +
78498 + if (match) {
78499 + if (last)
78500 + last->next = match->next;
78501 + else
78502 + gr_conn_table[index] = NULL;
78503 + kfree(match);
78504 + }
78505 +
78506 + return;
78507 +}
78508 +
78509 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
78510 + __u16 sport, __u16 dport)
78511 +{
78512 + struct conn_table_entry *match;
78513 + unsigned int index;
78514 +
78515 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
78516 +
78517 + match = gr_conn_table[index];
78518 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
78519 + match = match->next;
78520 +
78521 + if (match)
78522 + return match->sig;
78523 + else
78524 + return NULL;
78525 +}
78526 +
78527 +#endif
78528 +
78529 +void gr_update_task_in_ip_table(const struct inet_sock *inet)
78530 +{
78531 +#ifdef CONFIG_GRKERNSEC
78532 + struct signal_struct *sig = current->signal;
78533 + struct conn_table_entry *newent;
78534 +
78535 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
78536 + if (newent == NULL)
78537 + return;
78538 + /* no bh lock needed since we are called with bh disabled */
78539 + spin_lock(&gr_conn_table_lock);
78540 + gr_del_task_from_ip_table_nolock(sig);
78541 + sig->gr_saddr = inet->inet_rcv_saddr;
78542 + sig->gr_daddr = inet->inet_daddr;
78543 + sig->gr_sport = inet->inet_sport;
78544 + sig->gr_dport = inet->inet_dport;
78545 + gr_add_to_task_ip_table_nolock(sig, newent);
78546 + spin_unlock(&gr_conn_table_lock);
78547 +#endif
78548 + return;
78549 +}
78550 +
78551 +void gr_del_task_from_ip_table(struct task_struct *task)
78552 +{
78553 +#ifdef CONFIG_GRKERNSEC
78554 + spin_lock_bh(&gr_conn_table_lock);
78555 + gr_del_task_from_ip_table_nolock(task->signal);
78556 + spin_unlock_bh(&gr_conn_table_lock);
78557 +#endif
78558 + return;
78559 +}
78560 +
78561 +void
78562 +gr_attach_curr_ip(const struct sock *sk)
78563 +{
78564 +#ifdef CONFIG_GRKERNSEC
78565 + struct signal_struct *p, *set;
78566 + const struct inet_sock *inet = inet_sk(sk);
78567 +
78568 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
78569 + return;
78570 +
78571 + set = current->signal;
78572 +
78573 + spin_lock_bh(&gr_conn_table_lock);
78574 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
78575 + inet->inet_dport, inet->inet_sport);
78576 + if (unlikely(p != NULL)) {
78577 + set->curr_ip = p->curr_ip;
78578 + set->used_accept = 1;
78579 + gr_del_task_from_ip_table_nolock(p);
78580 + spin_unlock_bh(&gr_conn_table_lock);
78581 + return;
78582 + }
78583 + spin_unlock_bh(&gr_conn_table_lock);
78584 +
78585 + set->curr_ip = inet->inet_daddr;
78586 + set->used_accept = 1;
78587 +#endif
78588 + return;
78589 +}
78590 +
78591 +int
78592 +gr_handle_sock_all(const int family, const int type, const int protocol)
78593 +{
78594 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
78595 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
78596 + (family != AF_UNIX)) {
78597 + if (family == AF_INET)
78598 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
78599 + else
78600 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
78601 + return -EACCES;
78602 + }
78603 +#endif
78604 + return 0;
78605 +}
78606 +
78607 +int
78608 +gr_handle_sock_server(const struct sockaddr *sck)
78609 +{
78610 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
78611 + if (grsec_enable_socket_server &&
78612 + in_group_p(grsec_socket_server_gid) &&
78613 + sck && (sck->sa_family != AF_UNIX) &&
78614 + (sck->sa_family != AF_LOCAL)) {
78615 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
78616 + return -EACCES;
78617 + }
78618 +#endif
78619 + return 0;
78620 +}
78621 +
78622 +int
78623 +gr_handle_sock_server_other(const struct sock *sck)
78624 +{
78625 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
78626 + if (grsec_enable_socket_server &&
78627 + in_group_p(grsec_socket_server_gid) &&
78628 + sck && (sck->sk_family != AF_UNIX) &&
78629 + (sck->sk_family != AF_LOCAL)) {
78630 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
78631 + return -EACCES;
78632 + }
78633 +#endif
78634 + return 0;
78635 +}
78636 +
78637 +int
78638 +gr_handle_sock_client(const struct sockaddr *sck)
78639 +{
78640 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
78641 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
78642 + sck && (sck->sa_family != AF_UNIX) &&
78643 + (sck->sa_family != AF_LOCAL)) {
78644 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
78645 + return -EACCES;
78646 + }
78647 +#endif
78648 + return 0;
78649 +}
78650 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
78651 new file mode 100644
78652 index 0000000..8159888
78653 --- /dev/null
78654 +++ b/grsecurity/grsec_sysctl.c
78655 @@ -0,0 +1,479 @@
78656 +#include <linux/kernel.h>
78657 +#include <linux/sched.h>
78658 +#include <linux/sysctl.h>
78659 +#include <linux/grsecurity.h>
78660 +#include <linux/grinternal.h>
78661 +
78662 +int
78663 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
78664 +{
78665 +#ifdef CONFIG_GRKERNSEC_SYSCTL
78666 + if (dirname == NULL || name == NULL)
78667 + return 0;
78668 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
78669 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
78670 + return -EACCES;
78671 + }
78672 +#endif
78673 + return 0;
78674 +}
78675 +
78676 +#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
78677 +static int __maybe_unused __read_only one = 1;
78678 +#endif
78679 +
78680 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
78681 + defined(CONFIG_GRKERNSEC_DENYUSB)
78682 +struct ctl_table grsecurity_table[] = {
78683 +#ifdef CONFIG_GRKERNSEC_SYSCTL
78684 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
78685 +#ifdef CONFIG_GRKERNSEC_IO
78686 + {
78687 + .procname = "disable_priv_io",
78688 + .data = &grsec_disable_privio,
78689 + .maxlen = sizeof(int),
78690 + .mode = 0600,
78691 + .proc_handler = &proc_dointvec,
78692 + },
78693 +#endif
78694 +#endif
78695 +#ifdef CONFIG_GRKERNSEC_LINK
78696 + {
78697 + .procname = "linking_restrictions",
78698 + .data = &grsec_enable_link,
78699 + .maxlen = sizeof(int),
78700 + .mode = 0600,
78701 + .proc_handler = &proc_dointvec,
78702 + },
78703 +#endif
78704 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
78705 + {
78706 + .procname = "enforce_symlinksifowner",
78707 + .data = &grsec_enable_symlinkown,
78708 + .maxlen = sizeof(int),
78709 + .mode = 0600,
78710 + .proc_handler = &proc_dointvec,
78711 + },
78712 + {
78713 + .procname = "symlinkown_gid",
78714 + .data = &grsec_symlinkown_gid,
78715 + .maxlen = sizeof(int),
78716 + .mode = 0600,
78717 + .proc_handler = &proc_dointvec,
78718 + },
78719 +#endif
78720 +#ifdef CONFIG_GRKERNSEC_BRUTE
78721 + {
78722 + .procname = "deter_bruteforce",
78723 + .data = &grsec_enable_brute,
78724 + .maxlen = sizeof(int),
78725 + .mode = 0600,
78726 + .proc_handler = &proc_dointvec,
78727 + },
78728 +#endif
78729 +#ifdef CONFIG_GRKERNSEC_FIFO
78730 + {
78731 + .procname = "fifo_restrictions",
78732 + .data = &grsec_enable_fifo,
78733 + .maxlen = sizeof(int),
78734 + .mode = 0600,
78735 + .proc_handler = &proc_dointvec,
78736 + },
78737 +#endif
78738 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
78739 + {
78740 + .procname = "ptrace_readexec",
78741 + .data = &grsec_enable_ptrace_readexec,
78742 + .maxlen = sizeof(int),
78743 + .mode = 0600,
78744 + .proc_handler = &proc_dointvec,
78745 + },
78746 +#endif
78747 +#ifdef CONFIG_GRKERNSEC_SETXID
78748 + {
78749 + .procname = "consistent_setxid",
78750 + .data = &grsec_enable_setxid,
78751 + .maxlen = sizeof(int),
78752 + .mode = 0600,
78753 + .proc_handler = &proc_dointvec,
78754 + },
78755 +#endif
78756 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78757 + {
78758 + .procname = "ip_blackhole",
78759 + .data = &grsec_enable_blackhole,
78760 + .maxlen = sizeof(int),
78761 + .mode = 0600,
78762 + .proc_handler = &proc_dointvec,
78763 + },
78764 + {
78765 + .procname = "lastack_retries",
78766 + .data = &grsec_lastack_retries,
78767 + .maxlen = sizeof(int),
78768 + .mode = 0600,
78769 + .proc_handler = &proc_dointvec,
78770 + },
78771 +#endif
78772 +#ifdef CONFIG_GRKERNSEC_EXECLOG
78773 + {
78774 + .procname = "exec_logging",
78775 + .data = &grsec_enable_execlog,
78776 + .maxlen = sizeof(int),
78777 + .mode = 0600,
78778 + .proc_handler = &proc_dointvec,
78779 + },
78780 +#endif
78781 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78782 + {
78783 + .procname = "rwxmap_logging",
78784 + .data = &grsec_enable_log_rwxmaps,
78785 + .maxlen = sizeof(int),
78786 + .mode = 0600,
78787 + .proc_handler = &proc_dointvec,
78788 + },
78789 +#endif
78790 +#ifdef CONFIG_GRKERNSEC_SIGNAL
78791 + {
78792 + .procname = "signal_logging",
78793 + .data = &grsec_enable_signal,
78794 + .maxlen = sizeof(int),
78795 + .mode = 0600,
78796 + .proc_handler = &proc_dointvec,
78797 + },
78798 +#endif
78799 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
78800 + {
78801 + .procname = "forkfail_logging",
78802 + .data = &grsec_enable_forkfail,
78803 + .maxlen = sizeof(int),
78804 + .mode = 0600,
78805 + .proc_handler = &proc_dointvec,
78806 + },
78807 +#endif
78808 +#ifdef CONFIG_GRKERNSEC_TIME
78809 + {
78810 + .procname = "timechange_logging",
78811 + .data = &grsec_enable_time,
78812 + .maxlen = sizeof(int),
78813 + .mode = 0600,
78814 + .proc_handler = &proc_dointvec,
78815 + },
78816 +#endif
78817 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
78818 + {
78819 + .procname = "chroot_deny_shmat",
78820 + .data = &grsec_enable_chroot_shmat,
78821 + .maxlen = sizeof(int),
78822 + .mode = 0600,
78823 + .proc_handler = &proc_dointvec,
78824 + },
78825 +#endif
78826 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
78827 + {
78828 + .procname = "chroot_deny_unix",
78829 + .data = &grsec_enable_chroot_unix,
78830 + .maxlen = sizeof(int),
78831 + .mode = 0600,
78832 + .proc_handler = &proc_dointvec,
78833 + },
78834 +#endif
78835 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
78836 + {
78837 + .procname = "chroot_deny_mount",
78838 + .data = &grsec_enable_chroot_mount,
78839 + .maxlen = sizeof(int),
78840 + .mode = 0600,
78841 + .proc_handler = &proc_dointvec,
78842 + },
78843 +#endif
78844 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
78845 + {
78846 + .procname = "chroot_deny_fchdir",
78847 + .data = &grsec_enable_chroot_fchdir,
78848 + .maxlen = sizeof(int),
78849 + .mode = 0600,
78850 + .proc_handler = &proc_dointvec,
78851 + },
78852 +#endif
78853 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
78854 + {
78855 + .procname = "chroot_deny_chroot",
78856 + .data = &grsec_enable_chroot_double,
78857 + .maxlen = sizeof(int),
78858 + .mode = 0600,
78859 + .proc_handler = &proc_dointvec,
78860 + },
78861 +#endif
78862 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
78863 + {
78864 + .procname = "chroot_deny_pivot",
78865 + .data = &grsec_enable_chroot_pivot,
78866 + .maxlen = sizeof(int),
78867 + .mode = 0600,
78868 + .proc_handler = &proc_dointvec,
78869 + },
78870 +#endif
78871 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
78872 + {
78873 + .procname = "chroot_enforce_chdir",
78874 + .data = &grsec_enable_chroot_chdir,
78875 + .maxlen = sizeof(int),
78876 + .mode = 0600,
78877 + .proc_handler = &proc_dointvec,
78878 + },
78879 +#endif
78880 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
78881 + {
78882 + .procname = "chroot_deny_chmod",
78883 + .data = &grsec_enable_chroot_chmod,
78884 + .maxlen = sizeof(int),
78885 + .mode = 0600,
78886 + .proc_handler = &proc_dointvec,
78887 + },
78888 +#endif
78889 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
78890 + {
78891 + .procname = "chroot_deny_mknod",
78892 + .data = &grsec_enable_chroot_mknod,
78893 + .maxlen = sizeof(int),
78894 + .mode = 0600,
78895 + .proc_handler = &proc_dointvec,
78896 + },
78897 +#endif
78898 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
78899 + {
78900 + .procname = "chroot_restrict_nice",
78901 + .data = &grsec_enable_chroot_nice,
78902 + .maxlen = sizeof(int),
78903 + .mode = 0600,
78904 + .proc_handler = &proc_dointvec,
78905 + },
78906 +#endif
78907 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
78908 + {
78909 + .procname = "chroot_execlog",
78910 + .data = &grsec_enable_chroot_execlog,
78911 + .maxlen = sizeof(int),
78912 + .mode = 0600,
78913 + .proc_handler = &proc_dointvec,
78914 + },
78915 +#endif
78916 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
78917 + {
78918 + .procname = "chroot_caps",
78919 + .data = &grsec_enable_chroot_caps,
78920 + .maxlen = sizeof(int),
78921 + .mode = 0600,
78922 + .proc_handler = &proc_dointvec,
78923 + },
78924 +#endif
78925 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
78926 + {
78927 + .procname = "chroot_deny_sysctl",
78928 + .data = &grsec_enable_chroot_sysctl,
78929 + .maxlen = sizeof(int),
78930 + .mode = 0600,
78931 + .proc_handler = &proc_dointvec,
78932 + },
78933 +#endif
78934 +#ifdef CONFIG_GRKERNSEC_TPE
78935 + {
78936 + .procname = "tpe",
78937 + .data = &grsec_enable_tpe,
78938 + .maxlen = sizeof(int),
78939 + .mode = 0600,
78940 + .proc_handler = &proc_dointvec,
78941 + },
78942 + {
78943 + .procname = "tpe_gid",
78944 + .data = &grsec_tpe_gid,
78945 + .maxlen = sizeof(int),
78946 + .mode = 0600,
78947 + .proc_handler = &proc_dointvec,
78948 + },
78949 +#endif
78950 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
78951 + {
78952 + .procname = "tpe_invert",
78953 + .data = &grsec_enable_tpe_invert,
78954 + .maxlen = sizeof(int),
78955 + .mode = 0600,
78956 + .proc_handler = &proc_dointvec,
78957 + },
78958 +#endif
78959 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
78960 + {
78961 + .procname = "tpe_restrict_all",
78962 + .data = &grsec_enable_tpe_all,
78963 + .maxlen = sizeof(int),
78964 + .mode = 0600,
78965 + .proc_handler = &proc_dointvec,
78966 + },
78967 +#endif
78968 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
78969 + {
78970 + .procname = "socket_all",
78971 + .data = &grsec_enable_socket_all,
78972 + .maxlen = sizeof(int),
78973 + .mode = 0600,
78974 + .proc_handler = &proc_dointvec,
78975 + },
78976 + {
78977 + .procname = "socket_all_gid",
78978 + .data = &grsec_socket_all_gid,
78979 + .maxlen = sizeof(int),
78980 + .mode = 0600,
78981 + .proc_handler = &proc_dointvec,
78982 + },
78983 +#endif
78984 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
78985 + {
78986 + .procname = "socket_client",
78987 + .data = &grsec_enable_socket_client,
78988 + .maxlen = sizeof(int),
78989 + .mode = 0600,
78990 + .proc_handler = &proc_dointvec,
78991 + },
78992 + {
78993 + .procname = "socket_client_gid",
78994 + .data = &grsec_socket_client_gid,
78995 + .maxlen = sizeof(int),
78996 + .mode = 0600,
78997 + .proc_handler = &proc_dointvec,
78998 + },
78999 +#endif
79000 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
79001 + {
79002 + .procname = "socket_server",
79003 + .data = &grsec_enable_socket_server,
79004 + .maxlen = sizeof(int),
79005 + .mode = 0600,
79006 + .proc_handler = &proc_dointvec,
79007 + },
79008 + {
79009 + .procname = "socket_server_gid",
79010 + .data = &grsec_socket_server_gid,
79011 + .maxlen = sizeof(int),
79012 + .mode = 0600,
79013 + .proc_handler = &proc_dointvec,
79014 + },
79015 +#endif
79016 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
79017 + {
79018 + .procname = "audit_group",
79019 + .data = &grsec_enable_group,
79020 + .maxlen = sizeof(int),
79021 + .mode = 0600,
79022 + .proc_handler = &proc_dointvec,
79023 + },
79024 + {
79025 + .procname = "audit_gid",
79026 + .data = &grsec_audit_gid,
79027 + .maxlen = sizeof(int),
79028 + .mode = 0600,
79029 + .proc_handler = &proc_dointvec,
79030 + },
79031 +#endif
79032 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
79033 + {
79034 + .procname = "audit_chdir",
79035 + .data = &grsec_enable_chdir,
79036 + .maxlen = sizeof(int),
79037 + .mode = 0600,
79038 + .proc_handler = &proc_dointvec,
79039 + },
79040 +#endif
79041 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
79042 + {
79043 + .procname = "audit_mount",
79044 + .data = &grsec_enable_mount,
79045 + .maxlen = sizeof(int),
79046 + .mode = 0600,
79047 + .proc_handler = &proc_dointvec,
79048 + },
79049 +#endif
79050 +#ifdef CONFIG_GRKERNSEC_DMESG
79051 + {
79052 + .procname = "dmesg",
79053 + .data = &grsec_enable_dmesg,
79054 + .maxlen = sizeof(int),
79055 + .mode = 0600,
79056 + .proc_handler = &proc_dointvec,
79057 + },
79058 +#endif
79059 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
79060 + {
79061 + .procname = "chroot_findtask",
79062 + .data = &grsec_enable_chroot_findtask,
79063 + .maxlen = sizeof(int),
79064 + .mode = 0600,
79065 + .proc_handler = &proc_dointvec,
79066 + },
79067 +#endif
79068 +#ifdef CONFIG_GRKERNSEC_RESLOG
79069 + {
79070 + .procname = "resource_logging",
79071 + .data = &grsec_resource_logging,
79072 + .maxlen = sizeof(int),
79073 + .mode = 0600,
79074 + .proc_handler = &proc_dointvec,
79075 + },
79076 +#endif
79077 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
79078 + {
79079 + .procname = "audit_ptrace",
79080 + .data = &grsec_enable_audit_ptrace,
79081 + .maxlen = sizeof(int),
79082 + .mode = 0600,
79083 + .proc_handler = &proc_dointvec,
79084 + },
79085 +#endif
79086 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
79087 + {
79088 + .procname = "harden_ptrace",
79089 + .data = &grsec_enable_harden_ptrace,
79090 + .maxlen = sizeof(int),
79091 + .mode = 0600,
79092 + .proc_handler = &proc_dointvec,
79093 + },
79094 +#endif
79095 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
79096 + {
79097 + .procname = "harden_ipc",
79098 + .data = &grsec_enable_harden_ipc,
79099 + .maxlen = sizeof(int),
79100 + .mode = 0600,
79101 + .proc_handler = &proc_dointvec,
79102 + },
79103 +#endif
79104 + {
79105 + .procname = "grsec_lock",
79106 + .data = &grsec_lock,
79107 + .maxlen = sizeof(int),
79108 + .mode = 0600,
79109 + .proc_handler = &proc_dointvec,
79110 + },
79111 +#endif
79112 +#ifdef CONFIG_GRKERNSEC_ROFS
79113 + {
79114 + .procname = "romount_protect",
79115 + .data = &grsec_enable_rofs,
79116 + .maxlen = sizeof(int),
79117 + .mode = 0600,
79118 + .proc_handler = &proc_dointvec_minmax,
79119 + .extra1 = &one,
79120 + .extra2 = &one,
79121 + },
79122 +#endif
79123 +#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
79124 + {
79125 + .procname = "deny_new_usb",
79126 + .data = &grsec_deny_new_usb,
79127 + .maxlen = sizeof(int),
79128 + .mode = 0600,
79129 + .proc_handler = &proc_dointvec,
79130 + },
79131 +#endif
79132 + { }
79133 +};
79134 +#endif
79135 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
79136 new file mode 100644
79137 index 0000000..61b514e
79138 --- /dev/null
79139 +++ b/grsecurity/grsec_time.c
79140 @@ -0,0 +1,16 @@
79141 +#include <linux/kernel.h>
79142 +#include <linux/sched.h>
79143 +#include <linux/grinternal.h>
79144 +#include <linux/module.h>
79145 +
79146 +void
79147 +gr_log_timechange(void)
79148 +{
79149 +#ifdef CONFIG_GRKERNSEC_TIME
79150 + if (grsec_enable_time)
79151 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
79152 +#endif
79153 + return;
79154 +}
79155 +
79156 +EXPORT_SYMBOL_GPL(gr_log_timechange);
79157 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
79158 new file mode 100644
79159 index 0000000..d1953de
79160 --- /dev/null
79161 +++ b/grsecurity/grsec_tpe.c
79162 @@ -0,0 +1,78 @@
79163 +#include <linux/kernel.h>
79164 +#include <linux/sched.h>
79165 +#include <linux/file.h>
79166 +#include <linux/fs.h>
79167 +#include <linux/grinternal.h>
79168 +
79169 +extern int gr_acl_tpe_check(void);
79170 +
79171 +int
79172 +gr_tpe_allow(const struct file *file)
79173 +{
79174 +#ifdef CONFIG_GRKERNSEC
79175 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
79176 + struct inode *file_inode = file->f_path.dentry->d_inode;
79177 + const struct cred *cred = current_cred();
79178 + char *msg = NULL;
79179 + char *msg2 = NULL;
79180 +
79181 + // never restrict root
79182 + if (gr_is_global_root(cred->uid))
79183 + return 1;
79184 +
79185 + if (grsec_enable_tpe) {
79186 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
79187 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
79188 + msg = "not being in trusted group";
79189 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
79190 + msg = "being in untrusted group";
79191 +#else
79192 + if (in_group_p(grsec_tpe_gid))
79193 + msg = "being in untrusted group";
79194 +#endif
79195 + }
79196 + if (!msg && gr_acl_tpe_check())
79197 + msg = "being in untrusted role";
79198 +
79199 + // not in any affected group/role
79200 + if (!msg)
79201 + goto next_check;
79202 +
79203 + if (gr_is_global_nonroot(inode->i_uid))
79204 + msg2 = "file in non-root-owned directory";
79205 + else if (inode->i_mode & S_IWOTH)
79206 + msg2 = "file in world-writable directory";
79207 + else if (inode->i_mode & S_IWGRP)
79208 + msg2 = "file in group-writable directory";
79209 + else if (file_inode->i_mode & S_IWOTH)
79210 + msg2 = "file is world-writable";
79211 +
79212 + if (msg && msg2) {
79213 + char fullmsg[70] = {0};
79214 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
79215 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
79216 + return 0;
79217 + }
79218 + msg = NULL;
79219 +next_check:
79220 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
79221 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
79222 + return 1;
79223 +
79224 + if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
79225 + msg = "directory not owned by user";
79226 + else if (inode->i_mode & S_IWOTH)
79227 + msg = "file in world-writable directory";
79228 + else if (inode->i_mode & S_IWGRP)
79229 + msg = "file in group-writable directory";
79230 + else if (file_inode->i_mode & S_IWOTH)
79231 + msg = "file is world-writable";
79232 +
79233 + if (msg) {
79234 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
79235 + return 0;
79236 + }
79237 +#endif
79238 +#endif
79239 + return 1;
79240 +}
79241 diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
79242 new file mode 100644
79243 index 0000000..ae02d8e
79244 --- /dev/null
79245 +++ b/grsecurity/grsec_usb.c
79246 @@ -0,0 +1,15 @@
79247 +#include <linux/kernel.h>
79248 +#include <linux/grinternal.h>
79249 +#include <linux/module.h>
79250 +
79251 +int gr_handle_new_usb(void)
79252 +{
79253 +#ifdef CONFIG_GRKERNSEC_DENYUSB
79254 + if (grsec_deny_new_usb) {
79255 + printk(KERN_ALERT "grsec: denied insert of new USB device\n");
79256 + return 1;
79257 + }
79258 +#endif
79259 + return 0;
79260 +}
79261 +EXPORT_SYMBOL_GPL(gr_handle_new_usb);
79262 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
79263 new file mode 100644
79264 index 0000000..158b330
79265 --- /dev/null
79266 +++ b/grsecurity/grsum.c
79267 @@ -0,0 +1,64 @@
79268 +#include <linux/err.h>
79269 +#include <linux/kernel.h>
79270 +#include <linux/sched.h>
79271 +#include <linux/mm.h>
79272 +#include <linux/scatterlist.h>
79273 +#include <linux/crypto.h>
79274 +#include <linux/gracl.h>
79275 +
79276 +
79277 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
79278 +#error "crypto and sha256 must be built into the kernel"
79279 +#endif
79280 +
79281 +int
79282 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
79283 +{
79284 + struct crypto_hash *tfm;
79285 + struct hash_desc desc;
79286 + struct scatterlist sg[2];
79287 + unsigned char temp_sum[GR_SHA_LEN] __attribute__((aligned(__alignof__(unsigned long))));
79288 + unsigned long *tmpsumptr = (unsigned long *)temp_sum;
79289 + unsigned long *sumptr = (unsigned long *)sum;
79290 + int cryptres;
79291 + int retval = 1;
79292 + volatile int mismatched = 0;
79293 + volatile int dummy = 0;
79294 + unsigned int i;
79295 +
79296 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
79297 + if (IS_ERR(tfm)) {
79298 + /* should never happen, since sha256 should be built in */
79299 + memset(entry->pw, 0, GR_PW_LEN);
79300 + return 1;
79301 + }
79302 +
79303 + sg_init_table(sg, 2);
79304 + sg_set_buf(&sg[0], salt, GR_SALT_LEN);
79305 + sg_set_buf(&sg[1], entry->pw, strlen(entry->pw));
79306 +
79307 + desc.tfm = tfm;
79308 + desc.flags = 0;
79309 +
79310 + cryptres = crypto_hash_digest(&desc, sg, GR_SALT_LEN + strlen(entry->pw),
79311 + temp_sum);
79312 +
79313 + memset(entry->pw, 0, GR_PW_LEN);
79314 +
79315 + if (cryptres)
79316 + goto out;
79317 +
79318 + for (i = 0; i < GR_SHA_LEN/sizeof(tmpsumptr[0]); i++)
79319 + if (sumptr[i] != tmpsumptr[i])
79320 + mismatched = 1;
79321 + else
79322 + dummy = 1; // waste a cycle
79323 +
79324 + if (!mismatched)
79325 + retval = dummy - 1;
79326 +
79327 +out:
79328 + crypto_free_hash(tfm);
79329 +
79330 + return retval;
79331 +}
79332 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
79333 index 77ff547..181834f 100644
79334 --- a/include/asm-generic/4level-fixup.h
79335 +++ b/include/asm-generic/4level-fixup.h
79336 @@ -13,8 +13,10 @@
79337 #define pmd_alloc(mm, pud, address) \
79338 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
79339 NULL: pmd_offset(pud, address))
79340 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
79341
79342 #define pud_alloc(mm, pgd, address) (pgd)
79343 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
79344 #define pud_offset(pgd, start) (pgd)
79345 #define pud_none(pud) 0
79346 #define pud_bad(pud) 0
79347 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
79348 index b7babf0..97f4c4f 100644
79349 --- a/include/asm-generic/atomic-long.h
79350 +++ b/include/asm-generic/atomic-long.h
79351 @@ -22,6 +22,12 @@
79352
79353 typedef atomic64_t atomic_long_t;
79354
79355 +#ifdef CONFIG_PAX_REFCOUNT
79356 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
79357 +#else
79358 +typedef atomic64_t atomic_long_unchecked_t;
79359 +#endif
79360 +
79361 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
79362
79363 static inline long atomic_long_read(atomic_long_t *l)
79364 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
79365 return (long)atomic64_read(v);
79366 }
79367
79368 +#ifdef CONFIG_PAX_REFCOUNT
79369 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
79370 +{
79371 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79372 +
79373 + return (long)atomic64_read_unchecked(v);
79374 +}
79375 +#endif
79376 +
79377 static inline void atomic_long_set(atomic_long_t *l, long i)
79378 {
79379 atomic64_t *v = (atomic64_t *)l;
79380 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
79381 atomic64_set(v, i);
79382 }
79383
79384 +#ifdef CONFIG_PAX_REFCOUNT
79385 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
79386 +{
79387 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79388 +
79389 + atomic64_set_unchecked(v, i);
79390 +}
79391 +#endif
79392 +
79393 static inline void atomic_long_inc(atomic_long_t *l)
79394 {
79395 atomic64_t *v = (atomic64_t *)l;
79396 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
79397 atomic64_inc(v);
79398 }
79399
79400 +#ifdef CONFIG_PAX_REFCOUNT
79401 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
79402 +{
79403 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79404 +
79405 + atomic64_inc_unchecked(v);
79406 +}
79407 +#endif
79408 +
79409 static inline void atomic_long_dec(atomic_long_t *l)
79410 {
79411 atomic64_t *v = (atomic64_t *)l;
79412 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
79413 atomic64_dec(v);
79414 }
79415
79416 +#ifdef CONFIG_PAX_REFCOUNT
79417 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
79418 +{
79419 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79420 +
79421 + atomic64_dec_unchecked(v);
79422 +}
79423 +#endif
79424 +
79425 static inline void atomic_long_add(long i, atomic_long_t *l)
79426 {
79427 atomic64_t *v = (atomic64_t *)l;
79428 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
79429 atomic64_add(i, v);
79430 }
79431
79432 +#ifdef CONFIG_PAX_REFCOUNT
79433 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
79434 +{
79435 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79436 +
79437 + atomic64_add_unchecked(i, v);
79438 +}
79439 +#endif
79440 +
79441 static inline void atomic_long_sub(long i, atomic_long_t *l)
79442 {
79443 atomic64_t *v = (atomic64_t *)l;
79444 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
79445 atomic64_sub(i, v);
79446 }
79447
79448 +#ifdef CONFIG_PAX_REFCOUNT
79449 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
79450 +{
79451 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79452 +
79453 + atomic64_sub_unchecked(i, v);
79454 +}
79455 +#endif
79456 +
79457 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
79458 {
79459 atomic64_t *v = (atomic64_t *)l;
79460 @@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
79461 return atomic64_add_negative(i, v);
79462 }
79463
79464 -static inline long atomic_long_add_return(long i, atomic_long_t *l)
79465 +static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
79466 {
79467 atomic64_t *v = (atomic64_t *)l;
79468
79469 return (long)atomic64_add_return(i, v);
79470 }
79471
79472 +#ifdef CONFIG_PAX_REFCOUNT
79473 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
79474 +{
79475 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79476 +
79477 + return (long)atomic64_add_return_unchecked(i, v);
79478 +}
79479 +#endif
79480 +
79481 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
79482 {
79483 atomic64_t *v = (atomic64_t *)l;
79484 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
79485 return (long)atomic64_inc_return(v);
79486 }
79487
79488 +#ifdef CONFIG_PAX_REFCOUNT
79489 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
79490 +{
79491 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79492 +
79493 + return (long)atomic64_inc_return_unchecked(v);
79494 +}
79495 +#endif
79496 +
79497 static inline long atomic_long_dec_return(atomic_long_t *l)
79498 {
79499 atomic64_t *v = (atomic64_t *)l;
79500 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
79501
79502 typedef atomic_t atomic_long_t;
79503
79504 +#ifdef CONFIG_PAX_REFCOUNT
79505 +typedef atomic_unchecked_t atomic_long_unchecked_t;
79506 +#else
79507 +typedef atomic_t atomic_long_unchecked_t;
79508 +#endif
79509 +
79510 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
79511 static inline long atomic_long_read(atomic_long_t *l)
79512 {
79513 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
79514 return (long)atomic_read(v);
79515 }
79516
79517 +#ifdef CONFIG_PAX_REFCOUNT
79518 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
79519 +{
79520 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79521 +
79522 + return (long)atomic_read_unchecked(v);
79523 +}
79524 +#endif
79525 +
79526 static inline void atomic_long_set(atomic_long_t *l, long i)
79527 {
79528 atomic_t *v = (atomic_t *)l;
79529 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
79530 atomic_set(v, i);
79531 }
79532
79533 +#ifdef CONFIG_PAX_REFCOUNT
79534 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
79535 +{
79536 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79537 +
79538 + atomic_set_unchecked(v, i);
79539 +}
79540 +#endif
79541 +
79542 static inline void atomic_long_inc(atomic_long_t *l)
79543 {
79544 atomic_t *v = (atomic_t *)l;
79545 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
79546 atomic_inc(v);
79547 }
79548
79549 +#ifdef CONFIG_PAX_REFCOUNT
79550 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
79551 +{
79552 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79553 +
79554 + atomic_inc_unchecked(v);
79555 +}
79556 +#endif
79557 +
79558 static inline void atomic_long_dec(atomic_long_t *l)
79559 {
79560 atomic_t *v = (atomic_t *)l;
79561 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
79562 atomic_dec(v);
79563 }
79564
79565 +#ifdef CONFIG_PAX_REFCOUNT
79566 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
79567 +{
79568 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79569 +
79570 + atomic_dec_unchecked(v);
79571 +}
79572 +#endif
79573 +
79574 static inline void atomic_long_add(long i, atomic_long_t *l)
79575 {
79576 atomic_t *v = (atomic_t *)l;
79577 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
79578 atomic_add(i, v);
79579 }
79580
79581 +#ifdef CONFIG_PAX_REFCOUNT
79582 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
79583 +{
79584 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79585 +
79586 + atomic_add_unchecked(i, v);
79587 +}
79588 +#endif
79589 +
79590 static inline void atomic_long_sub(long i, atomic_long_t *l)
79591 {
79592 atomic_t *v = (atomic_t *)l;
79593 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
79594 atomic_sub(i, v);
79595 }
79596
79597 +#ifdef CONFIG_PAX_REFCOUNT
79598 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
79599 +{
79600 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79601 +
79602 + atomic_sub_unchecked(i, v);
79603 +}
79604 +#endif
79605 +
79606 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
79607 {
79608 atomic_t *v = (atomic_t *)l;
79609 @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
79610 return (long)atomic_add_return(i, v);
79611 }
79612
79613 +#ifdef CONFIG_PAX_REFCOUNT
79614 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
79615 +{
79616 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79617 +
79618 + return (long)atomic_add_return_unchecked(i, v);
79619 +}
79620 +
79621 +#endif
79622 +
79623 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
79624 {
79625 atomic_t *v = (atomic_t *)l;
79626 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
79627 return (long)atomic_inc_return(v);
79628 }
79629
79630 +#ifdef CONFIG_PAX_REFCOUNT
79631 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
79632 +{
79633 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79634 +
79635 + return (long)atomic_inc_return_unchecked(v);
79636 +}
79637 +#endif
79638 +
79639 static inline long atomic_long_dec_return(atomic_long_t *l)
79640 {
79641 atomic_t *v = (atomic_t *)l;
79642 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
79643
79644 #endif /* BITS_PER_LONG == 64 */
79645
79646 +#ifdef CONFIG_PAX_REFCOUNT
79647 +static inline void pax_refcount_needs_these_functions(void)
79648 +{
79649 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
79650 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
79651 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
79652 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
79653 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
79654 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
79655 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
79656 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
79657 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
79658 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
79659 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
79660 +#ifdef CONFIG_X86
79661 + atomic_clear_mask_unchecked(0, NULL);
79662 + atomic_set_mask_unchecked(0, NULL);
79663 +#endif
79664 +
79665 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
79666 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
79667 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
79668 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
79669 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
79670 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
79671 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
79672 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
79673 +}
79674 +#else
79675 +#define atomic_read_unchecked(v) atomic_read(v)
79676 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
79677 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
79678 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
79679 +#define atomic_inc_unchecked(v) atomic_inc(v)
79680 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
79681 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
79682 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
79683 +#define atomic_dec_unchecked(v) atomic_dec(v)
79684 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
79685 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
79686 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
79687 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
79688 +
79689 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
79690 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
79691 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
79692 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
79693 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
79694 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
79695 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
79696 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
79697 +#endif
79698 +
79699 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
79700 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
79701 index 9c79e76..9f7827d 100644
79702 --- a/include/asm-generic/atomic.h
79703 +++ b/include/asm-generic/atomic.h
79704 @@ -154,7 +154,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
79705 * Atomically clears the bits set in @mask from @v
79706 */
79707 #ifndef atomic_clear_mask
79708 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
79709 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
79710 {
79711 unsigned long flags;
79712
79713 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
79714 index b18ce4f..2ee2843 100644
79715 --- a/include/asm-generic/atomic64.h
79716 +++ b/include/asm-generic/atomic64.h
79717 @@ -16,6 +16,8 @@ typedef struct {
79718 long long counter;
79719 } atomic64_t;
79720
79721 +typedef atomic64_t atomic64_unchecked_t;
79722 +
79723 #define ATOMIC64_INIT(i) { (i) }
79724
79725 extern long long atomic64_read(const atomic64_t *v);
79726 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
79727 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
79728 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
79729
79730 +#define atomic64_read_unchecked(v) atomic64_read(v)
79731 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
79732 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
79733 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
79734 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
79735 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
79736 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
79737 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
79738 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
79739 +
79740 #endif /* _ASM_GENERIC_ATOMIC64_H */
79741 diff --git a/include/asm-generic/barrier.h b/include/asm-generic/barrier.h
79742 index 1402fa8..025a736 100644
79743 --- a/include/asm-generic/barrier.h
79744 +++ b/include/asm-generic/barrier.h
79745 @@ -74,7 +74,7 @@
79746 do { \
79747 compiletime_assert_atomic_type(*p); \
79748 smp_mb(); \
79749 - ACCESS_ONCE(*p) = (v); \
79750 + ACCESS_ONCE_RW(*p) = (v); \
79751 } while (0)
79752
79753 #define smp_load_acquire(p) \
79754 diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
79755 index a60a7cc..0fe12f2 100644
79756 --- a/include/asm-generic/bitops/__fls.h
79757 +++ b/include/asm-generic/bitops/__fls.h
79758 @@ -9,7 +9,7 @@
79759 *
79760 * Undefined if no set bit exists, so code should check against 0 first.
79761 */
79762 -static __always_inline unsigned long __fls(unsigned long word)
79763 +static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
79764 {
79765 int num = BITS_PER_LONG - 1;
79766
79767 diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
79768 index 0576d1f..dad6c71 100644
79769 --- a/include/asm-generic/bitops/fls.h
79770 +++ b/include/asm-generic/bitops/fls.h
79771 @@ -9,7 +9,7 @@
79772 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
79773 */
79774
79775 -static __always_inline int fls(int x)
79776 +static __always_inline int __intentional_overflow(-1) fls(int x)
79777 {
79778 int r = 32;
79779
79780 diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
79781 index b097cf8..3d40e14 100644
79782 --- a/include/asm-generic/bitops/fls64.h
79783 +++ b/include/asm-generic/bitops/fls64.h
79784 @@ -15,7 +15,7 @@
79785 * at position 64.
79786 */
79787 #if BITS_PER_LONG == 32
79788 -static __always_inline int fls64(__u64 x)
79789 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
79790 {
79791 __u32 h = x >> 32;
79792 if (h)
79793 @@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
79794 return fls(x);
79795 }
79796 #elif BITS_PER_LONG == 64
79797 -static __always_inline int fls64(__u64 x)
79798 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
79799 {
79800 if (x == 0)
79801 return 0;
79802 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
79803 index 1bfcfe5..e04c5c9 100644
79804 --- a/include/asm-generic/cache.h
79805 +++ b/include/asm-generic/cache.h
79806 @@ -6,7 +6,7 @@
79807 * cache lines need to provide their own cache.h.
79808 */
79809
79810 -#define L1_CACHE_SHIFT 5
79811 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
79812 +#define L1_CACHE_SHIFT 5UL
79813 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
79814
79815 #endif /* __ASM_GENERIC_CACHE_H */
79816 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
79817 index 0d68a1e..b74a761 100644
79818 --- a/include/asm-generic/emergency-restart.h
79819 +++ b/include/asm-generic/emergency-restart.h
79820 @@ -1,7 +1,7 @@
79821 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
79822 #define _ASM_GENERIC_EMERGENCY_RESTART_H
79823
79824 -static inline void machine_emergency_restart(void)
79825 +static inline __noreturn void machine_emergency_restart(void)
79826 {
79827 machine_restart(NULL);
79828 }
79829 diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
79830 index 975e1cc..0b8a083 100644
79831 --- a/include/asm-generic/io.h
79832 +++ b/include/asm-generic/io.h
79833 @@ -289,7 +289,7 @@ static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
79834 * These are pretty trivial
79835 */
79836 #ifndef virt_to_phys
79837 -static inline unsigned long virt_to_phys(volatile void *address)
79838 +static inline unsigned long __intentional_overflow(-1) virt_to_phys(volatile void *address)
79839 {
79840 return __pa((unsigned long)address);
79841 }
79842 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
79843 index 90f99c7..00ce236 100644
79844 --- a/include/asm-generic/kmap_types.h
79845 +++ b/include/asm-generic/kmap_types.h
79846 @@ -2,9 +2,9 @@
79847 #define _ASM_GENERIC_KMAP_TYPES_H
79848
79849 #ifdef __WITH_KM_FENCE
79850 -# define KM_TYPE_NR 41
79851 +# define KM_TYPE_NR 42
79852 #else
79853 -# define KM_TYPE_NR 20
79854 +# define KM_TYPE_NR 21
79855 #endif
79856
79857 #endif
79858 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
79859 index 9ceb03b..62b0b8f 100644
79860 --- a/include/asm-generic/local.h
79861 +++ b/include/asm-generic/local.h
79862 @@ -23,24 +23,37 @@ typedef struct
79863 atomic_long_t a;
79864 } local_t;
79865
79866 +typedef struct {
79867 + atomic_long_unchecked_t a;
79868 +} local_unchecked_t;
79869 +
79870 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
79871
79872 #define local_read(l) atomic_long_read(&(l)->a)
79873 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
79874 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
79875 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
79876 #define local_inc(l) atomic_long_inc(&(l)->a)
79877 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
79878 #define local_dec(l) atomic_long_dec(&(l)->a)
79879 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
79880 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
79881 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
79882 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
79883 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
79884
79885 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
79886 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
79887 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
79888 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
79889 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
79890 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
79891 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
79892 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
79893 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
79894
79895 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
79896 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
79897 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
79898 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
79899 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
79900 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
79901 index 725612b..9cc513a 100644
79902 --- a/include/asm-generic/pgtable-nopmd.h
79903 +++ b/include/asm-generic/pgtable-nopmd.h
79904 @@ -1,14 +1,19 @@
79905 #ifndef _PGTABLE_NOPMD_H
79906 #define _PGTABLE_NOPMD_H
79907
79908 -#ifndef __ASSEMBLY__
79909 -
79910 #include <asm-generic/pgtable-nopud.h>
79911
79912 -struct mm_struct;
79913 -
79914 #define __PAGETABLE_PMD_FOLDED
79915
79916 +#define PMD_SHIFT PUD_SHIFT
79917 +#define PTRS_PER_PMD 1
79918 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
79919 +#define PMD_MASK (~(PMD_SIZE-1))
79920 +
79921 +#ifndef __ASSEMBLY__
79922 +
79923 +struct mm_struct;
79924 +
79925 /*
79926 * Having the pmd type consist of a pud gets the size right, and allows
79927 * us to conceptually access the pud entry that this pmd is folded into
79928 @@ -16,11 +21,6 @@ struct mm_struct;
79929 */
79930 typedef struct { pud_t pud; } pmd_t;
79931
79932 -#define PMD_SHIFT PUD_SHIFT
79933 -#define PTRS_PER_PMD 1
79934 -#define PMD_SIZE (1UL << PMD_SHIFT)
79935 -#define PMD_MASK (~(PMD_SIZE-1))
79936 -
79937 /*
79938 * The "pud_xxx()" functions here are trivial for a folded two-level
79939 * setup: the pmd is never bad, and a pmd always exists (as it's folded
79940 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
79941 index 810431d..0ec4804f 100644
79942 --- a/include/asm-generic/pgtable-nopud.h
79943 +++ b/include/asm-generic/pgtable-nopud.h
79944 @@ -1,10 +1,15 @@
79945 #ifndef _PGTABLE_NOPUD_H
79946 #define _PGTABLE_NOPUD_H
79947
79948 -#ifndef __ASSEMBLY__
79949 -
79950 #define __PAGETABLE_PUD_FOLDED
79951
79952 +#define PUD_SHIFT PGDIR_SHIFT
79953 +#define PTRS_PER_PUD 1
79954 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
79955 +#define PUD_MASK (~(PUD_SIZE-1))
79956 +
79957 +#ifndef __ASSEMBLY__
79958 +
79959 /*
79960 * Having the pud type consist of a pgd gets the size right, and allows
79961 * us to conceptually access the pgd entry that this pud is folded into
79962 @@ -12,11 +17,6 @@
79963 */
79964 typedef struct { pgd_t pgd; } pud_t;
79965
79966 -#define PUD_SHIFT PGDIR_SHIFT
79967 -#define PTRS_PER_PUD 1
79968 -#define PUD_SIZE (1UL << PUD_SHIFT)
79969 -#define PUD_MASK (~(PUD_SIZE-1))
79970 -
79971 /*
79972 * The "pgd_xxx()" functions here are trivial for a folded two-level
79973 * setup: the pud is never bad, and a pud always exists (as it's folded
79974 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
79975 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
79976
79977 #define pgd_populate(mm, pgd, pud) do { } while (0)
79978 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
79979 /*
79980 * (puds are folded into pgds so this doesn't get actually called,
79981 * but the define is needed for a generic inline function.)
79982 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
79983 index 53b2acc..f4568e7 100644
79984 --- a/include/asm-generic/pgtable.h
79985 +++ b/include/asm-generic/pgtable.h
79986 @@ -819,6 +819,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
79987 }
79988 #endif /* CONFIG_NUMA_BALANCING */
79989
79990 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
79991 +#ifdef CONFIG_PAX_KERNEXEC
79992 +#error KERNEXEC requires pax_open_kernel
79993 +#else
79994 +static inline unsigned long pax_open_kernel(void) { return 0; }
79995 +#endif
79996 +#endif
79997 +
79998 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
79999 +#ifdef CONFIG_PAX_KERNEXEC
80000 +#error KERNEXEC requires pax_close_kernel
80001 +#else
80002 +static inline unsigned long pax_close_kernel(void) { return 0; }
80003 +#endif
80004 +#endif
80005 +
80006 #endif /* CONFIG_MMU */
80007
80008 #endif /* !__ASSEMBLY__ */
80009 diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
80010 index 72d8803..cb9749c 100644
80011 --- a/include/asm-generic/uaccess.h
80012 +++ b/include/asm-generic/uaccess.h
80013 @@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
80014 return __clear_user(to, n);
80015 }
80016
80017 +#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
80018 +#ifdef CONFIG_PAX_MEMORY_UDEREF
80019 +#error UDEREF requires pax_open_userland
80020 +#else
80021 +static inline unsigned long pax_open_userland(void) { return 0; }
80022 +#endif
80023 +#endif
80024 +
80025 +#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
80026 +#ifdef CONFIG_PAX_MEMORY_UDEREF
80027 +#error UDEREF requires pax_close_userland
80028 +#else
80029 +static inline unsigned long pax_close_userland(void) { return 0; }
80030 +#endif
80031 +#endif
80032 +
80033 #endif /* __ASM_GENERIC_UACCESS_H */
80034 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
80035 index 5ba0360..e85c934 100644
80036 --- a/include/asm-generic/vmlinux.lds.h
80037 +++ b/include/asm-generic/vmlinux.lds.h
80038 @@ -231,6 +231,7 @@
80039 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
80040 VMLINUX_SYMBOL(__start_rodata) = .; \
80041 *(.rodata) *(.rodata.*) \
80042 + *(.data..read_only) \
80043 *(__vermagic) /* Kernel version magic */ \
80044 . = ALIGN(8); \
80045 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
80046 @@ -722,17 +723,18 @@
80047 * section in the linker script will go there too. @phdr should have
80048 * a leading colon.
80049 *
80050 - * Note that this macros defines __per_cpu_load as an absolute symbol.
80051 + * Note that this macros defines per_cpu_load as an absolute symbol.
80052 * If there is no need to put the percpu section at a predetermined
80053 * address, use PERCPU_SECTION.
80054 */
80055 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
80056 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
80057 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
80058 + per_cpu_load = .; \
80059 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
80060 - LOAD_OFFSET) { \
80061 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
80062 PERCPU_INPUT(cacheline) \
80063 } phdr \
80064 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
80065 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
80066
80067 /**
80068 * PERCPU_SECTION - define output section for percpu area, simple version
80069 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
80070 index 623a59c..1e79ab9 100644
80071 --- a/include/crypto/algapi.h
80072 +++ b/include/crypto/algapi.h
80073 @@ -34,7 +34,7 @@ struct crypto_type {
80074 unsigned int maskclear;
80075 unsigned int maskset;
80076 unsigned int tfmsize;
80077 -};
80078 +} __do_const;
80079
80080 struct crypto_instance {
80081 struct crypto_alg alg;
80082 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
80083 index 1968907..7d9ed9f 100644
80084 --- a/include/drm/drmP.h
80085 +++ b/include/drm/drmP.h
80086 @@ -68,6 +68,7 @@
80087 #include <linux/workqueue.h>
80088 #include <linux/poll.h>
80089 #include <asm/pgalloc.h>
80090 +#include <asm/local.h>
80091 #include <drm/drm.h>
80092 #include <drm/drm_sarea.h>
80093 #include <drm/drm_vma_manager.h>
80094 @@ -260,10 +261,12 @@ do { \
80095 * \param cmd command.
80096 * \param arg argument.
80097 */
80098 -typedef int drm_ioctl_t(struct drm_device *dev, void *data,
80099 +typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
80100 + struct drm_file *file_priv);
80101 +typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
80102 struct drm_file *file_priv);
80103
80104 -typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
80105 +typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
80106 unsigned long arg);
80107
80108 #define DRM_IOCTL_NR(n) _IOC_NR(n)
80109 @@ -279,10 +282,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
80110 struct drm_ioctl_desc {
80111 unsigned int cmd;
80112 int flags;
80113 - drm_ioctl_t *func;
80114 + drm_ioctl_t func;
80115 unsigned int cmd_drv;
80116 const char *name;
80117 -};
80118 +} __do_const;
80119
80120 /**
80121 * Creates a driver or general drm_ioctl_desc array entry for the given
80122 @@ -946,7 +949,8 @@ struct drm_info_list {
80123 int (*show)(struct seq_file*, void*); /** show callback */
80124 u32 driver_features; /**< Required driver features for this entry */
80125 void *data;
80126 -};
80127 +} __do_const;
80128 +typedef struct drm_info_list __no_const drm_info_list_no_const;
80129
80130 /**
80131 * debugfs node structure. This structure represents a debugfs file.
80132 @@ -1030,7 +1034,7 @@ struct drm_device {
80133
80134 /** \name Usage Counters */
80135 /*@{ */
80136 - int open_count; /**< Outstanding files open, protected by drm_global_mutex. */
80137 + local_t open_count; /**< Outstanding files open, protected by drm_global_mutex. */
80138 spinlock_t buf_lock; /**< For drm_device::buf_use and a few other things. */
80139 int buf_use; /**< Buffers in use -- cannot alloc */
80140 atomic_t buf_alloc; /**< Buffer allocation in progress */
80141 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
80142 index a3d75fe..6802f9c 100644
80143 --- a/include/drm/drm_crtc_helper.h
80144 +++ b/include/drm/drm_crtc_helper.h
80145 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
80146 struct drm_connector *connector);
80147 /* disable encoder when not in use - more explicit than dpms off */
80148 void (*disable)(struct drm_encoder *encoder);
80149 -};
80150 +} __no_const;
80151
80152 /**
80153 * drm_connector_helper_funcs - helper operations for connectors
80154 diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
80155 index a70d456..6ea07cd 100644
80156 --- a/include/drm/i915_pciids.h
80157 +++ b/include/drm/i915_pciids.h
80158 @@ -37,7 +37,7 @@
80159 */
80160 #define INTEL_VGA_DEVICE(id, info) { \
80161 0x8086, id, \
80162 - ~0, ~0, \
80163 + PCI_ANY_ID, PCI_ANY_ID, \
80164 0x030000, 0xff0000, \
80165 (unsigned long) info }
80166
80167 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
80168 index 72dcbe8..8db58d7 100644
80169 --- a/include/drm/ttm/ttm_memory.h
80170 +++ b/include/drm/ttm/ttm_memory.h
80171 @@ -48,7 +48,7 @@
80172
80173 struct ttm_mem_shrink {
80174 int (*do_shrink) (struct ttm_mem_shrink *);
80175 -};
80176 +} __no_const;
80177
80178 /**
80179 * struct ttm_mem_global - Global memory accounting structure.
80180 diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
80181 index 49a8284..9643967 100644
80182 --- a/include/drm/ttm/ttm_page_alloc.h
80183 +++ b/include/drm/ttm/ttm_page_alloc.h
80184 @@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
80185 */
80186 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
80187
80188 +struct device;
80189 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
80190 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
80191
80192 diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
80193 index 4b840e8..155d235 100644
80194 --- a/include/keys/asymmetric-subtype.h
80195 +++ b/include/keys/asymmetric-subtype.h
80196 @@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
80197 /* Verify the signature on a key of this subtype (optional) */
80198 int (*verify_signature)(const struct key *key,
80199 const struct public_key_signature *sig);
80200 -};
80201 +} __do_const;
80202
80203 /**
80204 * asymmetric_key_subtype - Get the subtype from an asymmetric key
80205 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
80206 index c1da539..1dcec55 100644
80207 --- a/include/linux/atmdev.h
80208 +++ b/include/linux/atmdev.h
80209 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
80210 #endif
80211
80212 struct k_atm_aal_stats {
80213 -#define __HANDLE_ITEM(i) atomic_t i
80214 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
80215 __AAL_STAT_ITEMS
80216 #undef __HANDLE_ITEM
80217 };
80218 @@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
80219 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
80220 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
80221 struct module *owner;
80222 -};
80223 +} __do_const ;
80224
80225 struct atmphy_ops {
80226 int (*start)(struct atm_dev *dev);
80227 diff --git a/include/linux/audit.h b/include/linux/audit.h
80228 index 22cfddb..1514eef 100644
80229 --- a/include/linux/audit.h
80230 +++ b/include/linux/audit.h
80231 @@ -86,7 +86,7 @@ extern unsigned compat_dir_class[];
80232 extern unsigned compat_chattr_class[];
80233 extern unsigned compat_signal_class[];
80234
80235 -extern int __weak audit_classify_compat_syscall(int abi, unsigned syscall);
80236 +extern int audit_classify_compat_syscall(int abi, unsigned syscall);
80237
80238 /* audit_names->type values */
80239 #define AUDIT_TYPE_UNKNOWN 0 /* we don't know yet */
80240 @@ -210,7 +210,7 @@ static inline void audit_ptrace(struct task_struct *t)
80241 extern unsigned int audit_serial(void);
80242 extern int auditsc_get_stamp(struct audit_context *ctx,
80243 struct timespec *t, unsigned int *serial);
80244 -extern int audit_set_loginuid(kuid_t loginuid);
80245 +extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
80246
80247 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
80248 {
80249 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
80250 index 61f29e5..e67c658 100644
80251 --- a/include/linux/binfmts.h
80252 +++ b/include/linux/binfmts.h
80253 @@ -44,7 +44,7 @@ struct linux_binprm {
80254 unsigned interp_flags;
80255 unsigned interp_data;
80256 unsigned long loader, exec;
80257 -};
80258 +} __randomize_layout;
80259
80260 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
80261 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
80262 @@ -73,8 +73,10 @@ struct linux_binfmt {
80263 int (*load_binary)(struct linux_binprm *);
80264 int (*load_shlib)(struct file *);
80265 int (*core_dump)(struct coredump_params *cprm);
80266 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
80267 + void (*handle_mmap)(struct file *);
80268 unsigned long min_coredump; /* minimal dump size */
80269 -};
80270 +} __do_const __randomize_layout;
80271
80272 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
80273
80274 diff --git a/include/linux/bitops.h b/include/linux/bitops.h
80275 index cbc5833..8123ebc 100644
80276 --- a/include/linux/bitops.h
80277 +++ b/include/linux/bitops.h
80278 @@ -122,7 +122,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
80279 * @word: value to rotate
80280 * @shift: bits to roll
80281 */
80282 -static inline __u32 rol32(__u32 word, unsigned int shift)
80283 +static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
80284 {
80285 return (word << shift) | (word >> (32 - shift));
80286 }
80287 @@ -132,7 +132,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
80288 * @word: value to rotate
80289 * @shift: bits to roll
80290 */
80291 -static inline __u32 ror32(__u32 word, unsigned int shift)
80292 +static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
80293 {
80294 return (word >> shift) | (word << (32 - shift));
80295 }
80296 @@ -188,7 +188,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
80297 return (__s32)(value << shift) >> shift;
80298 }
80299
80300 -static inline unsigned fls_long(unsigned long l)
80301 +static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
80302 {
80303 if (sizeof(l) == 4)
80304 return fls(l);
80305 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
80306 index f2057ff8..59dfa2d 100644
80307 --- a/include/linux/blkdev.h
80308 +++ b/include/linux/blkdev.h
80309 @@ -1625,7 +1625,7 @@ struct block_device_operations {
80310 /* this callback is with swap_lock and sometimes page table lock held */
80311 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
80312 struct module *owner;
80313 -};
80314 +} __do_const;
80315
80316 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
80317 unsigned long);
80318 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
80319 index afc1343..9735539 100644
80320 --- a/include/linux/blktrace_api.h
80321 +++ b/include/linux/blktrace_api.h
80322 @@ -25,7 +25,7 @@ struct blk_trace {
80323 struct dentry *dropped_file;
80324 struct dentry *msg_file;
80325 struct list_head running_list;
80326 - atomic_t dropped;
80327 + atomic_unchecked_t dropped;
80328 };
80329
80330 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
80331 diff --git a/include/linux/cache.h b/include/linux/cache.h
80332 index 17e7e82..1d7da26 100644
80333 --- a/include/linux/cache.h
80334 +++ b/include/linux/cache.h
80335 @@ -16,6 +16,14 @@
80336 #define __read_mostly
80337 #endif
80338
80339 +#ifndef __read_only
80340 +#ifdef CONFIG_PAX_KERNEXEC
80341 +#error KERNEXEC requires __read_only
80342 +#else
80343 +#define __read_only __read_mostly
80344 +#endif
80345 +#endif
80346 +
80347 #ifndef ____cacheline_aligned
80348 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
80349 #endif
80350 diff --git a/include/linux/capability.h b/include/linux/capability.h
80351 index aa93e5e..985a1b0 100644
80352 --- a/include/linux/capability.h
80353 +++ b/include/linux/capability.h
80354 @@ -214,9 +214,14 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
80355 extern bool capable(int cap);
80356 extern bool ns_capable(struct user_namespace *ns, int cap);
80357 extern bool capable_wrt_inode_uidgid(const struct inode *inode, int cap);
80358 +extern bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap);
80359 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
80360 +extern bool capable_nolog(int cap);
80361 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
80362
80363 /* audit system wants to get cap info from files as well */
80364 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
80365
80366 +extern int is_privileged_binary(const struct dentry *dentry);
80367 +
80368 #endif /* !_LINUX_CAPABILITY_H */
80369 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
80370 index 8609d57..86e4d79 100644
80371 --- a/include/linux/cdrom.h
80372 +++ b/include/linux/cdrom.h
80373 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
80374
80375 /* driver specifications */
80376 const int capability; /* capability flags */
80377 - int n_minors; /* number of active minor devices */
80378 /* handle uniform packets for scsi type devices (scsi,atapi) */
80379 int (*generic_packet) (struct cdrom_device_info *,
80380 struct packet_command *);
80381 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
80382 index 4ce9056..86caac6 100644
80383 --- a/include/linux/cleancache.h
80384 +++ b/include/linux/cleancache.h
80385 @@ -31,7 +31,7 @@ struct cleancache_ops {
80386 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
80387 void (*invalidate_inode)(int, struct cleancache_filekey);
80388 void (*invalidate_fs)(int);
80389 -};
80390 +} __no_const;
80391
80392 extern struct cleancache_ops *
80393 cleancache_register_ops(struct cleancache_ops *ops);
80394 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
80395 index 411dd7e..ee38878 100644
80396 --- a/include/linux/clk-provider.h
80397 +++ b/include/linux/clk-provider.h
80398 @@ -180,6 +180,7 @@ struct clk_ops {
80399 void (*init)(struct clk_hw *hw);
80400 int (*debug_init)(struct clk_hw *hw, struct dentry *dentry);
80401 };
80402 +typedef struct clk_ops __no_const clk_ops_no_const;
80403
80404 /**
80405 * struct clk_init_data - holds init data that's common to all clocks and is
80406 diff --git a/include/linux/compat.h b/include/linux/compat.h
80407 index e649426..a74047b 100644
80408 --- a/include/linux/compat.h
80409 +++ b/include/linux/compat.h
80410 @@ -316,7 +316,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
80411 compat_size_t __user *len_ptr);
80412
80413 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
80414 -asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
80415 +asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
80416 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
80417 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
80418 compat_ssize_t msgsz, int msgflg);
80419 @@ -436,7 +436,7 @@ extern int compat_ptrace_request(struct task_struct *child,
80420 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
80421 compat_ulong_t addr, compat_ulong_t data);
80422 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
80423 - compat_long_t addr, compat_long_t data);
80424 + compat_ulong_t addr, compat_ulong_t data);
80425
80426 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
80427 /*
80428 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
80429 index 2507fd2..55203f8 100644
80430 --- a/include/linux/compiler-gcc4.h
80431 +++ b/include/linux/compiler-gcc4.h
80432 @@ -39,9 +39,34 @@
80433 # define __compiletime_warning(message) __attribute__((warning(message)))
80434 # define __compiletime_error(message) __attribute__((error(message)))
80435 #endif /* __CHECKER__ */
80436 +
80437 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
80438 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
80439 +#define __bos0(ptr) __bos((ptr), 0)
80440 +#define __bos1(ptr) __bos((ptr), 1)
80441 #endif /* GCC_VERSION >= 40300 */
80442
80443 #if GCC_VERSION >= 40500
80444 +
80445 +#ifdef RANDSTRUCT_PLUGIN
80446 +#define __randomize_layout __attribute__((randomize_layout))
80447 +#define __no_randomize_layout __attribute__((no_randomize_layout))
80448 +#endif
80449 +
80450 +#ifdef CONSTIFY_PLUGIN
80451 +#define __no_const __attribute__((no_const))
80452 +#define __do_const __attribute__((do_const))
80453 +#endif
80454 +
80455 +#ifdef SIZE_OVERFLOW_PLUGIN
80456 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
80457 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
80458 +#endif
80459 +
80460 +#ifdef LATENT_ENTROPY_PLUGIN
80461 +#define __latent_entropy __attribute__((latent_entropy))
80462 +#endif
80463 +
80464 /*
80465 * Mark a position in code as unreachable. This can be used to
80466 * suppress control flow warnings after asm blocks that transfer
80467 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
80468 index d5ad7b1..3b74638 100644
80469 --- a/include/linux/compiler.h
80470 +++ b/include/linux/compiler.h
80471 @@ -5,11 +5,14 @@
80472
80473 #ifdef __CHECKER__
80474 # define __user __attribute__((noderef, address_space(1)))
80475 +# define __force_user __force __user
80476 # define __kernel __attribute__((address_space(0)))
80477 +# define __force_kernel __force __kernel
80478 # define __safe __attribute__((safe))
80479 # define __force __attribute__((force))
80480 # define __nocast __attribute__((nocast))
80481 # define __iomem __attribute__((noderef, address_space(2)))
80482 +# define __force_iomem __force __iomem
80483 # define __must_hold(x) __attribute__((context(x,1,1)))
80484 # define __acquires(x) __attribute__((context(x,0,1)))
80485 # define __releases(x) __attribute__((context(x,1,0)))
80486 @@ -17,20 +20,37 @@
80487 # define __release(x) __context__(x,-1)
80488 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
80489 # define __percpu __attribute__((noderef, address_space(3)))
80490 +# define __force_percpu __force __percpu
80491 #ifdef CONFIG_SPARSE_RCU_POINTER
80492 # define __rcu __attribute__((noderef, address_space(4)))
80493 +# define __force_rcu __force __rcu
80494 #else
80495 # define __rcu
80496 +# define __force_rcu
80497 #endif
80498 extern void __chk_user_ptr(const volatile void __user *);
80499 extern void __chk_io_ptr(const volatile void __iomem *);
80500 #else
80501 -# define __user
80502 -# define __kernel
80503 +# ifdef CHECKER_PLUGIN
80504 +//# define __user
80505 +//# define __force_user
80506 +//# define __kernel
80507 +//# define __force_kernel
80508 +# else
80509 +# ifdef STRUCTLEAK_PLUGIN
80510 +# define __user __attribute__((user))
80511 +# else
80512 +# define __user
80513 +# endif
80514 +# define __force_user
80515 +# define __kernel
80516 +# define __force_kernel
80517 +# endif
80518 # define __safe
80519 # define __force
80520 # define __nocast
80521 # define __iomem
80522 +# define __force_iomem
80523 # define __chk_user_ptr(x) (void)0
80524 # define __chk_io_ptr(x) (void)0
80525 # define __builtin_warning(x, y...) (1)
80526 @@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
80527 # define __release(x) (void)0
80528 # define __cond_lock(x,c) (c)
80529 # define __percpu
80530 +# define __force_percpu
80531 # define __rcu
80532 +# define __force_rcu
80533 #endif
80534
80535 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
80536 @@ -286,6 +308,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80537 # define __attribute_const__ /* unimplemented */
80538 #endif
80539
80540 +#ifndef __randomize_layout
80541 +# define __randomize_layout
80542 +#endif
80543 +
80544 +#ifndef __no_randomize_layout
80545 +# define __no_randomize_layout
80546 +#endif
80547 +
80548 +#ifndef __no_const
80549 +# define __no_const
80550 +#endif
80551 +
80552 +#ifndef __do_const
80553 +# define __do_const
80554 +#endif
80555 +
80556 +#ifndef __size_overflow
80557 +# define __size_overflow(...)
80558 +#endif
80559 +
80560 +#ifndef __intentional_overflow
80561 +# define __intentional_overflow(...)
80562 +#endif
80563 +
80564 +#ifndef __latent_entropy
80565 +# define __latent_entropy
80566 +#endif
80567 +
80568 /*
80569 * Tell gcc if a function is cold. The compiler will assume any path
80570 * directly leading to the call is unlikely.
80571 @@ -295,6 +345,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80572 #define __cold
80573 #endif
80574
80575 +#ifndef __alloc_size
80576 +#define __alloc_size(...)
80577 +#endif
80578 +
80579 +#ifndef __bos
80580 +#define __bos(ptr, arg)
80581 +#endif
80582 +
80583 +#ifndef __bos0
80584 +#define __bos0(ptr)
80585 +#endif
80586 +
80587 +#ifndef __bos1
80588 +#define __bos1(ptr)
80589 +#endif
80590 +
80591 /* Simple shorthand for a section definition */
80592 #ifndef __section
80593 # define __section(S) __attribute__ ((__section__(#S)))
80594 @@ -378,7 +444,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80595 * use is to mediate communication between process-level code and irq/NMI
80596 * handlers, all running on the same CPU.
80597 */
80598 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
80599 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
80600 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
80601
80602 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
80603 #ifdef CONFIG_KPROBES
80604 diff --git a/include/linux/completion.h b/include/linux/completion.h
80605 index 5d5aaae..0ea9b84 100644
80606 --- a/include/linux/completion.h
80607 +++ b/include/linux/completion.h
80608 @@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
80609
80610 extern void wait_for_completion(struct completion *);
80611 extern void wait_for_completion_io(struct completion *);
80612 -extern int wait_for_completion_interruptible(struct completion *x);
80613 -extern int wait_for_completion_killable(struct completion *x);
80614 +extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
80615 +extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
80616 extern unsigned long wait_for_completion_timeout(struct completion *x,
80617 - unsigned long timeout);
80618 + unsigned long timeout) __intentional_overflow(-1);
80619 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
80620 - unsigned long timeout);
80621 + unsigned long timeout) __intentional_overflow(-1);
80622 extern long wait_for_completion_interruptible_timeout(
80623 - struct completion *x, unsigned long timeout);
80624 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
80625 extern long wait_for_completion_killable_timeout(
80626 - struct completion *x, unsigned long timeout);
80627 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
80628 extern bool try_wait_for_completion(struct completion *x);
80629 extern bool completion_done(struct completion *x);
80630
80631 diff --git a/include/linux/configfs.h b/include/linux/configfs.h
80632 index 34025df..d94bbbc 100644
80633 --- a/include/linux/configfs.h
80634 +++ b/include/linux/configfs.h
80635 @@ -125,7 +125,7 @@ struct configfs_attribute {
80636 const char *ca_name;
80637 struct module *ca_owner;
80638 umode_t ca_mode;
80639 -};
80640 +} __do_const;
80641
80642 /*
80643 * Users often need to create attribute structures for their configurable
80644 diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
80645 index 7d1955a..d86a3ca 100644
80646 --- a/include/linux/cpufreq.h
80647 +++ b/include/linux/cpufreq.h
80648 @@ -203,6 +203,7 @@ struct global_attr {
80649 ssize_t (*store)(struct kobject *a, struct attribute *b,
80650 const char *c, size_t count);
80651 };
80652 +typedef struct global_attr __no_const global_attr_no_const;
80653
80654 #define define_one_global_ro(_name) \
80655 static struct global_attr _name = \
80656 @@ -269,7 +270,7 @@ struct cpufreq_driver {
80657 bool boost_supported;
80658 bool boost_enabled;
80659 int (*set_boost) (int state);
80660 -};
80661 +} __do_const;
80662
80663 /* flags */
80664 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
80665 diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
80666 index 25e0df6..952dffd 100644
80667 --- a/include/linux/cpuidle.h
80668 +++ b/include/linux/cpuidle.h
80669 @@ -50,7 +50,8 @@ struct cpuidle_state {
80670 int index);
80671
80672 int (*enter_dead) (struct cpuidle_device *dev, int index);
80673 -};
80674 +} __do_const;
80675 +typedef struct cpuidle_state __no_const cpuidle_state_no_const;
80676
80677 /* Idle State Flags */
80678 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
80679 @@ -209,7 +210,7 @@ struct cpuidle_governor {
80680 void (*reflect) (struct cpuidle_device *dev, int index);
80681
80682 struct module *owner;
80683 -};
80684 +} __do_const;
80685
80686 #ifdef CONFIG_CPU_IDLE
80687 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
80688 diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
80689 index 2997af6..424ddc1 100644
80690 --- a/include/linux/cpumask.h
80691 +++ b/include/linux/cpumask.h
80692 @@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
80693 }
80694
80695 /* Valid inputs for n are -1 and 0. */
80696 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
80697 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
80698 {
80699 return n+1;
80700 }
80701
80702 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
80703 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
80704 {
80705 return n+1;
80706 }
80707
80708 -static inline unsigned int cpumask_next_and(int n,
80709 +static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
80710 const struct cpumask *srcp,
80711 const struct cpumask *andp)
80712 {
80713 @@ -174,7 +174,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
80714 *
80715 * Returns >= nr_cpu_ids if no further cpus set.
80716 */
80717 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
80718 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
80719 {
80720 /* -1 is a legal arg here. */
80721 if (n != -1)
80722 @@ -189,7 +189,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
80723 *
80724 * Returns >= nr_cpu_ids if no further cpus unset.
80725 */
80726 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
80727 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
80728 {
80729 /* -1 is a legal arg here. */
80730 if (n != -1)
80731 @@ -197,7 +197,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
80732 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
80733 }
80734
80735 -int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
80736 +int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
80737 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
80738 int cpumask_set_cpu_local_first(int i, int numa_node, cpumask_t *dstp);
80739
80740 diff --git a/include/linux/cred.h b/include/linux/cred.h
80741 index b2d0820..2ecafd3 100644
80742 --- a/include/linux/cred.h
80743 +++ b/include/linux/cred.h
80744 @@ -35,7 +35,7 @@ struct group_info {
80745 int nblocks;
80746 kgid_t small_block[NGROUPS_SMALL];
80747 kgid_t *blocks[0];
80748 -};
80749 +} __randomize_layout;
80750
80751 /**
80752 * get_group_info - Get a reference to a group info structure
80753 @@ -136,7 +136,7 @@ struct cred {
80754 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
80755 struct group_info *group_info; /* supplementary groups for euid/fsgid */
80756 struct rcu_head rcu; /* RCU deletion hook */
80757 -};
80758 +} __randomize_layout;
80759
80760 extern void __put_cred(struct cred *);
80761 extern void exit_creds(struct task_struct *);
80762 @@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
80763 static inline void validate_process_creds(void)
80764 {
80765 }
80766 +static inline void validate_task_creds(struct task_struct *task)
80767 +{
80768 +}
80769 #endif
80770
80771 /**
80772 @@ -331,6 +334,7 @@ static inline void put_cred(const struct cred *_cred)
80773
80774 #define task_uid(task) (task_cred_xxx((task), uid))
80775 #define task_euid(task) (task_cred_xxx((task), euid))
80776 +#define task_securebits(task) (task_cred_xxx((task), securebits))
80777
80778 #define current_cred_xxx(xxx) \
80779 ({ \
80780 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
80781 index d45e949..51cf5ea 100644
80782 --- a/include/linux/crypto.h
80783 +++ b/include/linux/crypto.h
80784 @@ -373,7 +373,7 @@ struct cipher_tfm {
80785 const u8 *key, unsigned int keylen);
80786 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
80787 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
80788 -};
80789 +} __no_const;
80790
80791 struct hash_tfm {
80792 int (*init)(struct hash_desc *desc);
80793 @@ -394,13 +394,13 @@ struct compress_tfm {
80794 int (*cot_decompress)(struct crypto_tfm *tfm,
80795 const u8 *src, unsigned int slen,
80796 u8 *dst, unsigned int *dlen);
80797 -};
80798 +} __no_const;
80799
80800 struct rng_tfm {
80801 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
80802 unsigned int dlen);
80803 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
80804 -};
80805 +} __no_const;
80806
80807 #define crt_ablkcipher crt_u.ablkcipher
80808 #define crt_aead crt_u.aead
80809 diff --git a/include/linux/ctype.h b/include/linux/ctype.h
80810 index 653589e..4ef254a 100644
80811 --- a/include/linux/ctype.h
80812 +++ b/include/linux/ctype.h
80813 @@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
80814 * Fast implementation of tolower() for internal usage. Do not use in your
80815 * code.
80816 */
80817 -static inline char _tolower(const char c)
80818 +static inline unsigned char _tolower(const unsigned char c)
80819 {
80820 return c | 0x20;
80821 }
80822 diff --git a/include/linux/dcache.h b/include/linux/dcache.h
80823 index 75a227c..1456987 100644
80824 --- a/include/linux/dcache.h
80825 +++ b/include/linux/dcache.h
80826 @@ -134,7 +134,7 @@ struct dentry {
80827 } d_u;
80828 struct list_head d_subdirs; /* our children */
80829 struct hlist_node d_alias; /* inode alias list */
80830 -};
80831 +} __randomize_layout;
80832
80833 /*
80834 * dentry->d_lock spinlock nesting subclasses:
80835 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
80836 index 7925bf0..d5143d2 100644
80837 --- a/include/linux/decompress/mm.h
80838 +++ b/include/linux/decompress/mm.h
80839 @@ -77,7 +77,7 @@ static void free(void *where)
80840 * warnings when not needed (indeed large_malloc / large_free are not
80841 * needed by inflate */
80842
80843 -#define malloc(a) kmalloc(a, GFP_KERNEL)
80844 +#define malloc(a) kmalloc((a), GFP_KERNEL)
80845 #define free(a) kfree(a)
80846
80847 #define large_malloc(a) vmalloc(a)
80848 diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
80849 index f1863dc..5c26074 100644
80850 --- a/include/linux/devfreq.h
80851 +++ b/include/linux/devfreq.h
80852 @@ -114,7 +114,7 @@ struct devfreq_governor {
80853 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
80854 int (*event_handler)(struct devfreq *devfreq,
80855 unsigned int event, void *data);
80856 -};
80857 +} __do_const;
80858
80859 /**
80860 * struct devfreq - Device devfreq structure
80861 diff --git a/include/linux/device.h b/include/linux/device.h
80862 index 43d183a..03b6ba2 100644
80863 --- a/include/linux/device.h
80864 +++ b/include/linux/device.h
80865 @@ -310,7 +310,7 @@ struct subsys_interface {
80866 struct list_head node;
80867 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
80868 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
80869 -};
80870 +} __do_const;
80871
80872 int subsys_interface_register(struct subsys_interface *sif);
80873 void subsys_interface_unregister(struct subsys_interface *sif);
80874 @@ -506,7 +506,7 @@ struct device_type {
80875 void (*release)(struct device *dev);
80876
80877 const struct dev_pm_ops *pm;
80878 -};
80879 +} __do_const;
80880
80881 /* interface for exporting device attributes */
80882 struct device_attribute {
80883 @@ -516,11 +516,12 @@ struct device_attribute {
80884 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
80885 const char *buf, size_t count);
80886 };
80887 +typedef struct device_attribute __no_const device_attribute_no_const;
80888
80889 struct dev_ext_attribute {
80890 struct device_attribute attr;
80891 void *var;
80892 -};
80893 +} __do_const;
80894
80895 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
80896 char *buf);
80897 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
80898 index 931b709..89b2d89 100644
80899 --- a/include/linux/dma-mapping.h
80900 +++ b/include/linux/dma-mapping.h
80901 @@ -60,7 +60,7 @@ struct dma_map_ops {
80902 u64 (*get_required_mask)(struct device *dev);
80903 #endif
80904 int is_phys;
80905 -};
80906 +} __do_const;
80907
80908 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
80909
80910 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
80911 index 1f9e642..39e4263 100644
80912 --- a/include/linux/dmaengine.h
80913 +++ b/include/linux/dmaengine.h
80914 @@ -1147,9 +1147,9 @@ struct dma_pinned_list {
80915 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
80916 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
80917
80918 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
80919 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
80920 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
80921 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
80922 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
80923 struct dma_pinned_list *pinned_list, struct page *page,
80924 unsigned int offset, size_t len);
80925
80926 diff --git a/include/linux/efi.h b/include/linux/efi.h
80927 index 45cb4ff..c9b4912 100644
80928 --- a/include/linux/efi.h
80929 +++ b/include/linux/efi.h
80930 @@ -1036,6 +1036,7 @@ struct efivar_operations {
80931 efi_set_variable_t *set_variable;
80932 efi_query_variable_store_t *query_variable_store;
80933 };
80934 +typedef struct efivar_operations __no_const efivar_operations_no_const;
80935
80936 struct efivars {
80937 /*
80938 diff --git a/include/linux/elf.h b/include/linux/elf.h
80939 index 67a5fa7..b817372 100644
80940 --- a/include/linux/elf.h
80941 +++ b/include/linux/elf.h
80942 @@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
80943 #define elf_note elf32_note
80944 #define elf_addr_t Elf32_Off
80945 #define Elf_Half Elf32_Half
80946 +#define elf_dyn Elf32_Dyn
80947
80948 #else
80949
80950 @@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
80951 #define elf_note elf64_note
80952 #define elf_addr_t Elf64_Off
80953 #define Elf_Half Elf64_Half
80954 +#define elf_dyn Elf64_Dyn
80955
80956 #endif
80957
80958 diff --git a/include/linux/err.h b/include/linux/err.h
80959 index a729120..6ede2c9 100644
80960 --- a/include/linux/err.h
80961 +++ b/include/linux/err.h
80962 @@ -20,12 +20,12 @@
80963
80964 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
80965
80966 -static inline void * __must_check ERR_PTR(long error)
80967 +static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
80968 {
80969 return (void *) error;
80970 }
80971
80972 -static inline long __must_check PTR_ERR(__force const void *ptr)
80973 +static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
80974 {
80975 return (long) ptr;
80976 }
80977 diff --git a/include/linux/extcon.h b/include/linux/extcon.h
80978 index 36f49c4..a2a1f4c 100644
80979 --- a/include/linux/extcon.h
80980 +++ b/include/linux/extcon.h
80981 @@ -135,7 +135,7 @@ struct extcon_dev {
80982 /* /sys/class/extcon/.../mutually_exclusive/... */
80983 struct attribute_group attr_g_muex;
80984 struct attribute **attrs_muex;
80985 - struct device_attribute *d_attrs_muex;
80986 + device_attribute_no_const *d_attrs_muex;
80987 };
80988
80989 /**
80990 diff --git a/include/linux/fb.h b/include/linux/fb.h
80991 index 09bb7a1..d98870a 100644
80992 --- a/include/linux/fb.h
80993 +++ b/include/linux/fb.h
80994 @@ -305,7 +305,7 @@ struct fb_ops {
80995 /* called at KDB enter and leave time to prepare the console */
80996 int (*fb_debug_enter)(struct fb_info *info);
80997 int (*fb_debug_leave)(struct fb_info *info);
80998 -};
80999 +} __do_const;
81000
81001 #ifdef CONFIG_FB_TILEBLITTING
81002 #define FB_TILE_CURSOR_NONE 0
81003 diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
81004 index 230f87b..1fd0485 100644
81005 --- a/include/linux/fdtable.h
81006 +++ b/include/linux/fdtable.h
81007 @@ -100,7 +100,7 @@ struct files_struct *get_files_struct(struct task_struct *);
81008 void put_files_struct(struct files_struct *fs);
81009 void reset_files_struct(struct files_struct *);
81010 int unshare_files(struct files_struct **);
81011 -struct files_struct *dup_fd(struct files_struct *, int *);
81012 +struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
81013 void do_close_on_exec(struct files_struct *);
81014 int iterate_fd(struct files_struct *, unsigned,
81015 int (*)(const void *, struct file *, unsigned),
81016 diff --git a/include/linux/filter.h b/include/linux/filter.h
81017 index a5227ab..c789945 100644
81018 --- a/include/linux/filter.h
81019 +++ b/include/linux/filter.h
81020 @@ -9,6 +9,11 @@
81021 #include <linux/skbuff.h>
81022 #include <linux/workqueue.h>
81023 #include <uapi/linux/filter.h>
81024 +#include <asm/cacheflush.h>
81025 +
81026 +struct sk_buff;
81027 +struct sock;
81028 +struct seccomp_data;
81029
81030 /* Internally used and optimized filter representation with extended
81031 * instruction set based on top of classic BPF.
81032 @@ -320,20 +325,23 @@ struct sock_fprog_kern {
81033 struct sock_filter *filter;
81034 };
81035
81036 -struct sk_buff;
81037 -struct sock;
81038 -struct seccomp_data;
81039 +struct bpf_work_struct {
81040 + struct bpf_prog *prog;
81041 + struct work_struct work;
81042 +};
81043
81044 struct bpf_prog {
81045 + u32 pages; /* Number of allocated pages */
81046 u32 jited:1, /* Is our filter JIT'ed? */
81047 len:31; /* Number of filter blocks */
81048 struct sock_fprog_kern *orig_prog; /* Original BPF program */
81049 + struct bpf_work_struct *work; /* Deferred free work struct */
81050 unsigned int (*bpf_func)(const struct sk_buff *skb,
81051 const struct bpf_insn *filter);
81052 + /* Instructions for interpreter */
81053 union {
81054 struct sock_filter insns[0];
81055 struct bpf_insn insnsi[0];
81056 - struct work_struct work;
81057 };
81058 };
81059
81060 @@ -353,6 +361,26 @@ static inline unsigned int bpf_prog_size(unsigned int proglen)
81061
81062 #define bpf_classic_proglen(fprog) (fprog->len * sizeof(fprog->filter[0]))
81063
81064 +#ifdef CONFIG_DEBUG_SET_MODULE_RONX
81065 +static inline void bpf_prog_lock_ro(struct bpf_prog *fp)
81066 +{
81067 + set_memory_ro((unsigned long)fp, fp->pages);
81068 +}
81069 +
81070 +static inline void bpf_prog_unlock_ro(struct bpf_prog *fp)
81071 +{
81072 + set_memory_rw((unsigned long)fp, fp->pages);
81073 +}
81074 +#else
81075 +static inline void bpf_prog_lock_ro(struct bpf_prog *fp)
81076 +{
81077 +}
81078 +
81079 +static inline void bpf_prog_unlock_ro(struct bpf_prog *fp)
81080 +{
81081 +}
81082 +#endif /* CONFIG_DEBUG_SET_MODULE_RONX */
81083 +
81084 int sk_filter(struct sock *sk, struct sk_buff *skb);
81085
81086 void bpf_prog_select_runtime(struct bpf_prog *fp);
81087 @@ -361,6 +389,17 @@ void bpf_prog_free(struct bpf_prog *fp);
81088 int bpf_convert_filter(struct sock_filter *prog, int len,
81089 struct bpf_insn *new_prog, int *new_len);
81090
81091 +struct bpf_prog *bpf_prog_alloc(unsigned int size, gfp_t gfp_extra_flags);
81092 +struct bpf_prog *bpf_prog_realloc(struct bpf_prog *fp_old, unsigned int size,
81093 + gfp_t gfp_extra_flags);
81094 +void __bpf_prog_free(struct bpf_prog *fp);
81095 +
81096 +static inline void bpf_prog_unlock_free(struct bpf_prog *fp)
81097 +{
81098 + bpf_prog_unlock_ro(fp);
81099 + __bpf_prog_free(fp);
81100 +}
81101 +
81102 int bpf_prog_create(struct bpf_prog **pfp, struct sock_fprog_kern *fprog);
81103 void bpf_prog_destroy(struct bpf_prog *fp);
81104
81105 @@ -450,7 +489,7 @@ static inline void bpf_jit_compile(struct bpf_prog *fp)
81106
81107 static inline void bpf_jit_free(struct bpf_prog *fp)
81108 {
81109 - kfree(fp);
81110 + bpf_prog_unlock_free(fp);
81111 }
81112 #endif /* CONFIG_BPF_JIT */
81113
81114 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
81115 index 8293262..2b3b8bd 100644
81116 --- a/include/linux/frontswap.h
81117 +++ b/include/linux/frontswap.h
81118 @@ -11,7 +11,7 @@ struct frontswap_ops {
81119 int (*load)(unsigned, pgoff_t, struct page *);
81120 void (*invalidate_page)(unsigned, pgoff_t);
81121 void (*invalidate_area)(unsigned);
81122 -};
81123 +} __no_const;
81124
81125 extern bool frontswap_enabled;
81126 extern struct frontswap_ops *
81127 diff --git a/include/linux/fs.h b/include/linux/fs.h
81128 index 9418772..0155807 100644
81129 --- a/include/linux/fs.h
81130 +++ b/include/linux/fs.h
81131 @@ -401,7 +401,7 @@ struct address_space {
81132 spinlock_t private_lock; /* for use by the address_space */
81133 struct list_head private_list; /* ditto */
81134 void *private_data; /* ditto */
81135 -} __attribute__((aligned(sizeof(long))));
81136 +} __attribute__((aligned(sizeof(long)))) __randomize_layout;
81137 /*
81138 * On most architectures that alignment is already the case; but
81139 * must be enforced here for CRIS, to let the least significant bit
81140 @@ -444,7 +444,7 @@ struct block_device {
81141 int bd_fsfreeze_count;
81142 /* Mutex for freeze */
81143 struct mutex bd_fsfreeze_mutex;
81144 -};
81145 +} __randomize_layout;
81146
81147 /*
81148 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
81149 @@ -613,7 +613,7 @@ struct inode {
81150 #endif
81151
81152 void *i_private; /* fs or device private pointer */
81153 -};
81154 +} __randomize_layout;
81155
81156 static inline int inode_unhashed(struct inode *inode)
81157 {
81158 @@ -806,7 +806,7 @@ struct file {
81159 struct list_head f_tfile_llink;
81160 #endif /* #ifdef CONFIG_EPOLL */
81161 struct address_space *f_mapping;
81162 -} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
81163 +} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
81164
81165 struct file_handle {
81166 __u32 handle_bytes;
81167 @@ -934,7 +934,7 @@ struct file_lock {
81168 int state; /* state of grant or error if -ve */
81169 } afs;
81170 } fl_u;
81171 -};
81172 +} __randomize_layout;
81173
81174 /* The following constant reflects the upper bound of the file/locking space */
81175 #ifndef OFFSET_MAX
81176 @@ -1284,7 +1284,7 @@ struct super_block {
81177 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
81178 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
81179 struct rcu_head rcu;
81180 -};
81181 +} __randomize_layout;
81182
81183 extern struct timespec current_fs_time(struct super_block *sb);
81184
81185 @@ -1510,7 +1510,8 @@ struct file_operations {
81186 long (*fallocate)(struct file *file, int mode, loff_t offset,
81187 loff_t len);
81188 int (*show_fdinfo)(struct seq_file *m, struct file *f);
81189 -};
81190 +} __do_const __randomize_layout;
81191 +typedef struct file_operations __no_const file_operations_no_const;
81192
81193 struct inode_operations {
81194 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
81195 @@ -2796,4 +2797,14 @@ static inline bool dir_relax(struct inode *inode)
81196 return !IS_DEADDIR(inode);
81197 }
81198
81199 +static inline bool is_sidechannel_device(const struct inode *inode)
81200 +{
81201 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
81202 + umode_t mode = inode->i_mode;
81203 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
81204 +#else
81205 + return false;
81206 +#endif
81207 +}
81208 +
81209 #endif /* _LINUX_FS_H */
81210 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
81211 index 0efc3e6..fd23610 100644
81212 --- a/include/linux/fs_struct.h
81213 +++ b/include/linux/fs_struct.h
81214 @@ -6,13 +6,13 @@
81215 #include <linux/seqlock.h>
81216
81217 struct fs_struct {
81218 - int users;
81219 + atomic_t users;
81220 spinlock_t lock;
81221 seqcount_t seq;
81222 int umask;
81223 int in_exec;
81224 struct path root, pwd;
81225 -};
81226 +} __randomize_layout;
81227
81228 extern struct kmem_cache *fs_cachep;
81229
81230 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
81231 index 7714849..a4a5c7a 100644
81232 --- a/include/linux/fscache-cache.h
81233 +++ b/include/linux/fscache-cache.h
81234 @@ -113,7 +113,7 @@ struct fscache_operation {
81235 fscache_operation_release_t release;
81236 };
81237
81238 -extern atomic_t fscache_op_debug_id;
81239 +extern atomic_unchecked_t fscache_op_debug_id;
81240 extern void fscache_op_work_func(struct work_struct *work);
81241
81242 extern void fscache_enqueue_operation(struct fscache_operation *);
81243 @@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
81244 INIT_WORK(&op->work, fscache_op_work_func);
81245 atomic_set(&op->usage, 1);
81246 op->state = FSCACHE_OP_ST_INITIALISED;
81247 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
81248 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
81249 op->processor = processor;
81250 op->release = release;
81251 INIT_LIST_HEAD(&op->pend_link);
81252 diff --git a/include/linux/fscache.h b/include/linux/fscache.h
81253 index 115bb81..e7b812b 100644
81254 --- a/include/linux/fscache.h
81255 +++ b/include/linux/fscache.h
81256 @@ -152,7 +152,7 @@ struct fscache_cookie_def {
81257 * - this is mandatory for any object that may have data
81258 */
81259 void (*now_uncached)(void *cookie_netfs_data);
81260 -};
81261 +} __do_const;
81262
81263 /*
81264 * fscache cached network filesystem type
81265 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
81266 index 1c804b0..1432c2b 100644
81267 --- a/include/linux/fsnotify.h
81268 +++ b/include/linux/fsnotify.h
81269 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
81270 struct inode *inode = file_inode(file);
81271 __u32 mask = FS_ACCESS;
81272
81273 + if (is_sidechannel_device(inode))
81274 + return;
81275 +
81276 if (S_ISDIR(inode->i_mode))
81277 mask |= FS_ISDIR;
81278
81279 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
81280 struct inode *inode = file_inode(file);
81281 __u32 mask = FS_MODIFY;
81282
81283 + if (is_sidechannel_device(inode))
81284 + return;
81285 +
81286 if (S_ISDIR(inode->i_mode))
81287 mask |= FS_ISDIR;
81288
81289 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
81290 */
81291 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
81292 {
81293 - return kstrdup(name, GFP_KERNEL);
81294 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
81295 }
81296
81297 /*
81298 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
81299 index ec274e0..e678159 100644
81300 --- a/include/linux/genhd.h
81301 +++ b/include/linux/genhd.h
81302 @@ -194,7 +194,7 @@ struct gendisk {
81303 struct kobject *slave_dir;
81304
81305 struct timer_rand_state *random;
81306 - atomic_t sync_io; /* RAID */
81307 + atomic_unchecked_t sync_io; /* RAID */
81308 struct disk_events *ev;
81309 #ifdef CONFIG_BLK_DEV_INTEGRITY
81310 struct blk_integrity *integrity;
81311 @@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
81312 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
81313
81314 /* drivers/char/random.c */
81315 -extern void add_disk_randomness(struct gendisk *disk);
81316 +extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
81317 extern void rand_initialize_disk(struct gendisk *disk);
81318
81319 static inline sector_t get_start_sect(struct block_device *bdev)
81320 diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
81321 index c0894dd..2fbf10c 100644
81322 --- a/include/linux/genl_magic_func.h
81323 +++ b/include/linux/genl_magic_func.h
81324 @@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
81325 },
81326
81327 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
81328 -static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
81329 +static struct genl_ops ZZZ_genl_ops[] = {
81330 #include GENL_MAGIC_INCLUDE_FILE
81331 };
81332
81333 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
81334 index 5e7219d..b1ed627 100644
81335 --- a/include/linux/gfp.h
81336 +++ b/include/linux/gfp.h
81337 @@ -34,6 +34,13 @@ struct vm_area_struct;
81338 #define ___GFP_NO_KSWAPD 0x400000u
81339 #define ___GFP_OTHER_NODE 0x800000u
81340 #define ___GFP_WRITE 0x1000000u
81341 +
81342 +#ifdef CONFIG_PAX_USERCOPY_SLABS
81343 +#define ___GFP_USERCOPY 0x2000000u
81344 +#else
81345 +#define ___GFP_USERCOPY 0
81346 +#endif
81347 +
81348 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
81349
81350 /*
81351 @@ -90,6 +97,7 @@ struct vm_area_struct;
81352 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
81353 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
81354 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
81355 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
81356
81357 /*
81358 * This may seem redundant, but it's a way of annotating false positives vs.
81359 @@ -97,7 +105,7 @@ struct vm_area_struct;
81360 */
81361 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
81362
81363 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
81364 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
81365 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
81366
81367 /* This equals 0, but use constants in case they ever change */
81368 @@ -155,6 +163,8 @@ struct vm_area_struct;
81369 /* 4GB DMA on some platforms */
81370 #define GFP_DMA32 __GFP_DMA32
81371
81372 +#define GFP_USERCOPY __GFP_USERCOPY
81373 +
81374 /* Convert GFP flags to their corresponding migrate type */
81375 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
81376 {
81377 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
81378 new file mode 100644
81379 index 0000000..edb2cb6
81380 --- /dev/null
81381 +++ b/include/linux/gracl.h
81382 @@ -0,0 +1,340 @@
81383 +#ifndef GR_ACL_H
81384 +#define GR_ACL_H
81385 +
81386 +#include <linux/grdefs.h>
81387 +#include <linux/resource.h>
81388 +#include <linux/capability.h>
81389 +#include <linux/dcache.h>
81390 +#include <asm/resource.h>
81391 +
81392 +/* Major status information */
81393 +
81394 +#define GR_VERSION "grsecurity 3.0"
81395 +#define GRSECURITY_VERSION 0x3000
81396 +
81397 +enum {
81398 + GR_SHUTDOWN = 0,
81399 + GR_ENABLE = 1,
81400 + GR_SPROLE = 2,
81401 + GR_OLDRELOAD = 3,
81402 + GR_SEGVMOD = 4,
81403 + GR_STATUS = 5,
81404 + GR_UNSPROLE = 6,
81405 + GR_PASSSET = 7,
81406 + GR_SPROLEPAM = 8,
81407 + GR_RELOAD = 9,
81408 +};
81409 +
81410 +/* Password setup definitions
81411 + * kernel/grhash.c */
81412 +enum {
81413 + GR_PW_LEN = 128,
81414 + GR_SALT_LEN = 16,
81415 + GR_SHA_LEN = 32,
81416 +};
81417 +
81418 +enum {
81419 + GR_SPROLE_LEN = 64,
81420 +};
81421 +
81422 +enum {
81423 + GR_NO_GLOB = 0,
81424 + GR_REG_GLOB,
81425 + GR_CREATE_GLOB
81426 +};
81427 +
81428 +#define GR_NLIMITS 32
81429 +
81430 +/* Begin Data Structures */
81431 +
81432 +struct sprole_pw {
81433 + unsigned char *rolename;
81434 + unsigned char salt[GR_SALT_LEN];
81435 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
81436 +};
81437 +
81438 +struct name_entry {
81439 + __u32 key;
81440 + ino_t inode;
81441 + dev_t device;
81442 + char *name;
81443 + __u16 len;
81444 + __u8 deleted;
81445 + struct name_entry *prev;
81446 + struct name_entry *next;
81447 +};
81448 +
81449 +struct inodev_entry {
81450 + struct name_entry *nentry;
81451 + struct inodev_entry *prev;
81452 + struct inodev_entry *next;
81453 +};
81454 +
81455 +struct acl_role_db {
81456 + struct acl_role_label **r_hash;
81457 + __u32 r_size;
81458 +};
81459 +
81460 +struct inodev_db {
81461 + struct inodev_entry **i_hash;
81462 + __u32 i_size;
81463 +};
81464 +
81465 +struct name_db {
81466 + struct name_entry **n_hash;
81467 + __u32 n_size;
81468 +};
81469 +
81470 +struct crash_uid {
81471 + uid_t uid;
81472 + unsigned long expires;
81473 +};
81474 +
81475 +struct gr_hash_struct {
81476 + void **table;
81477 + void **nametable;
81478 + void *first;
81479 + __u32 table_size;
81480 + __u32 used_size;
81481 + int type;
81482 +};
81483 +
81484 +/* Userspace Grsecurity ACL data structures */
81485 +
81486 +struct acl_subject_label {
81487 + char *filename;
81488 + ino_t inode;
81489 + dev_t device;
81490 + __u32 mode;
81491 + kernel_cap_t cap_mask;
81492 + kernel_cap_t cap_lower;
81493 + kernel_cap_t cap_invert_audit;
81494 +
81495 + struct rlimit res[GR_NLIMITS];
81496 + __u32 resmask;
81497 +
81498 + __u8 user_trans_type;
81499 + __u8 group_trans_type;
81500 + uid_t *user_transitions;
81501 + gid_t *group_transitions;
81502 + __u16 user_trans_num;
81503 + __u16 group_trans_num;
81504 +
81505 + __u32 sock_families[2];
81506 + __u32 ip_proto[8];
81507 + __u32 ip_type;
81508 + struct acl_ip_label **ips;
81509 + __u32 ip_num;
81510 + __u32 inaddr_any_override;
81511 +
81512 + __u32 crashes;
81513 + unsigned long expires;
81514 +
81515 + struct acl_subject_label *parent_subject;
81516 + struct gr_hash_struct *hash;
81517 + struct acl_subject_label *prev;
81518 + struct acl_subject_label *next;
81519 +
81520 + struct acl_object_label **obj_hash;
81521 + __u32 obj_hash_size;
81522 + __u16 pax_flags;
81523 +};
81524 +
81525 +struct role_allowed_ip {
81526 + __u32 addr;
81527 + __u32 netmask;
81528 +
81529 + struct role_allowed_ip *prev;
81530 + struct role_allowed_ip *next;
81531 +};
81532 +
81533 +struct role_transition {
81534 + char *rolename;
81535 +
81536 + struct role_transition *prev;
81537 + struct role_transition *next;
81538 +};
81539 +
81540 +struct acl_role_label {
81541 + char *rolename;
81542 + uid_t uidgid;
81543 + __u16 roletype;
81544 +
81545 + __u16 auth_attempts;
81546 + unsigned long expires;
81547 +
81548 + struct acl_subject_label *root_label;
81549 + struct gr_hash_struct *hash;
81550 +
81551 + struct acl_role_label *prev;
81552 + struct acl_role_label *next;
81553 +
81554 + struct role_transition *transitions;
81555 + struct role_allowed_ip *allowed_ips;
81556 + uid_t *domain_children;
81557 + __u16 domain_child_num;
81558 +
81559 + umode_t umask;
81560 +
81561 + struct acl_subject_label **subj_hash;
81562 + __u32 subj_hash_size;
81563 +};
81564 +
81565 +struct user_acl_role_db {
81566 + struct acl_role_label **r_table;
81567 + __u32 num_pointers; /* Number of allocations to track */
81568 + __u32 num_roles; /* Number of roles */
81569 + __u32 num_domain_children; /* Number of domain children */
81570 + __u32 num_subjects; /* Number of subjects */
81571 + __u32 num_objects; /* Number of objects */
81572 +};
81573 +
81574 +struct acl_object_label {
81575 + char *filename;
81576 + ino_t inode;
81577 + dev_t device;
81578 + __u32 mode;
81579 +
81580 + struct acl_subject_label *nested;
81581 + struct acl_object_label *globbed;
81582 +
81583 + /* next two structures not used */
81584 +
81585 + struct acl_object_label *prev;
81586 + struct acl_object_label *next;
81587 +};
81588 +
81589 +struct acl_ip_label {
81590 + char *iface;
81591 + __u32 addr;
81592 + __u32 netmask;
81593 + __u16 low, high;
81594 + __u8 mode;
81595 + __u32 type;
81596 + __u32 proto[8];
81597 +
81598 + /* next two structures not used */
81599 +
81600 + struct acl_ip_label *prev;
81601 + struct acl_ip_label *next;
81602 +};
81603 +
81604 +struct gr_arg {
81605 + struct user_acl_role_db role_db;
81606 + unsigned char pw[GR_PW_LEN];
81607 + unsigned char salt[GR_SALT_LEN];
81608 + unsigned char sum[GR_SHA_LEN];
81609 + unsigned char sp_role[GR_SPROLE_LEN];
81610 + struct sprole_pw *sprole_pws;
81611 + dev_t segv_device;
81612 + ino_t segv_inode;
81613 + uid_t segv_uid;
81614 + __u16 num_sprole_pws;
81615 + __u16 mode;
81616 +};
81617 +
81618 +struct gr_arg_wrapper {
81619 + struct gr_arg *arg;
81620 + __u32 version;
81621 + __u32 size;
81622 +};
81623 +
81624 +struct subject_map {
81625 + struct acl_subject_label *user;
81626 + struct acl_subject_label *kernel;
81627 + struct subject_map *prev;
81628 + struct subject_map *next;
81629 +};
81630 +
81631 +struct acl_subj_map_db {
81632 + struct subject_map **s_hash;
81633 + __u32 s_size;
81634 +};
81635 +
81636 +struct gr_policy_state {
81637 + struct sprole_pw **acl_special_roles;
81638 + __u16 num_sprole_pws;
81639 + struct acl_role_label *kernel_role;
81640 + struct acl_role_label *role_list;
81641 + struct acl_role_label *default_role;
81642 + struct acl_role_db acl_role_set;
81643 + struct acl_subj_map_db subj_map_set;
81644 + struct name_db name_set;
81645 + struct inodev_db inodev_set;
81646 +};
81647 +
81648 +struct gr_alloc_state {
81649 + unsigned long alloc_stack_next;
81650 + unsigned long alloc_stack_size;
81651 + void **alloc_stack;
81652 +};
81653 +
81654 +struct gr_reload_state {
81655 + struct gr_policy_state oldpolicy;
81656 + struct gr_alloc_state oldalloc;
81657 + struct gr_policy_state newpolicy;
81658 + struct gr_alloc_state newalloc;
81659 + struct gr_policy_state *oldpolicy_ptr;
81660 + struct gr_alloc_state *oldalloc_ptr;
81661 + unsigned char oldmode;
81662 +};
81663 +
81664 +/* End Data Structures Section */
81665 +
81666 +/* Hash functions generated by empirical testing by Brad Spengler
81667 + Makes good use of the low bits of the inode. Generally 0-1 times
81668 + in loop for successful match. 0-3 for unsuccessful match.
81669 + Shift/add algorithm with modulus of table size and an XOR*/
81670 +
81671 +static __inline__ unsigned int
81672 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
81673 +{
81674 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
81675 +}
81676 +
81677 + static __inline__ unsigned int
81678 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
81679 +{
81680 + return ((const unsigned long)userp % sz);
81681 +}
81682 +
81683 +static __inline__ unsigned int
81684 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
81685 +{
81686 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
81687 +}
81688 +
81689 +static __inline__ unsigned int
81690 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
81691 +{
81692 + return full_name_hash((const unsigned char *)name, len) % sz;
81693 +}
81694 +
81695 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
81696 + subj = NULL; \
81697 + iter = 0; \
81698 + while (iter < role->subj_hash_size) { \
81699 + if (subj == NULL) \
81700 + subj = role->subj_hash[iter]; \
81701 + if (subj == NULL) { \
81702 + iter++; \
81703 + continue; \
81704 + }
81705 +
81706 +#define FOR_EACH_SUBJECT_END(subj,iter) \
81707 + subj = subj->next; \
81708 + if (subj == NULL) \
81709 + iter++; \
81710 + }
81711 +
81712 +
81713 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
81714 + subj = role->hash->first; \
81715 + while (subj != NULL) {
81716 +
81717 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
81718 + subj = subj->next; \
81719 + }
81720 +
81721 +#endif
81722 +
81723 diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
81724 new file mode 100644
81725 index 0000000..33ebd1f
81726 --- /dev/null
81727 +++ b/include/linux/gracl_compat.h
81728 @@ -0,0 +1,156 @@
81729 +#ifndef GR_ACL_COMPAT_H
81730 +#define GR_ACL_COMPAT_H
81731 +
81732 +#include <linux/resource.h>
81733 +#include <asm/resource.h>
81734 +
81735 +struct sprole_pw_compat {
81736 + compat_uptr_t rolename;
81737 + unsigned char salt[GR_SALT_LEN];
81738 + unsigned char sum[GR_SHA_LEN];
81739 +};
81740 +
81741 +struct gr_hash_struct_compat {
81742 + compat_uptr_t table;
81743 + compat_uptr_t nametable;
81744 + compat_uptr_t first;
81745 + __u32 table_size;
81746 + __u32 used_size;
81747 + int type;
81748 +};
81749 +
81750 +struct acl_subject_label_compat {
81751 + compat_uptr_t filename;
81752 + compat_ino_t inode;
81753 + __u32 device;
81754 + __u32 mode;
81755 + kernel_cap_t cap_mask;
81756 + kernel_cap_t cap_lower;
81757 + kernel_cap_t cap_invert_audit;
81758 +
81759 + struct compat_rlimit res[GR_NLIMITS];
81760 + __u32 resmask;
81761 +
81762 + __u8 user_trans_type;
81763 + __u8 group_trans_type;
81764 + compat_uptr_t user_transitions;
81765 + compat_uptr_t group_transitions;
81766 + __u16 user_trans_num;
81767 + __u16 group_trans_num;
81768 +
81769 + __u32 sock_families[2];
81770 + __u32 ip_proto[8];
81771 + __u32 ip_type;
81772 + compat_uptr_t ips;
81773 + __u32 ip_num;
81774 + __u32 inaddr_any_override;
81775 +
81776 + __u32 crashes;
81777 + compat_ulong_t expires;
81778 +
81779 + compat_uptr_t parent_subject;
81780 + compat_uptr_t hash;
81781 + compat_uptr_t prev;
81782 + compat_uptr_t next;
81783 +
81784 + compat_uptr_t obj_hash;
81785 + __u32 obj_hash_size;
81786 + __u16 pax_flags;
81787 +};
81788 +
81789 +struct role_allowed_ip_compat {
81790 + __u32 addr;
81791 + __u32 netmask;
81792 +
81793 + compat_uptr_t prev;
81794 + compat_uptr_t next;
81795 +};
81796 +
81797 +struct role_transition_compat {
81798 + compat_uptr_t rolename;
81799 +
81800 + compat_uptr_t prev;
81801 + compat_uptr_t next;
81802 +};
81803 +
81804 +struct acl_role_label_compat {
81805 + compat_uptr_t rolename;
81806 + uid_t uidgid;
81807 + __u16 roletype;
81808 +
81809 + __u16 auth_attempts;
81810 + compat_ulong_t expires;
81811 +
81812 + compat_uptr_t root_label;
81813 + compat_uptr_t hash;
81814 +
81815 + compat_uptr_t prev;
81816 + compat_uptr_t next;
81817 +
81818 + compat_uptr_t transitions;
81819 + compat_uptr_t allowed_ips;
81820 + compat_uptr_t domain_children;
81821 + __u16 domain_child_num;
81822 +
81823 + umode_t umask;
81824 +
81825 + compat_uptr_t subj_hash;
81826 + __u32 subj_hash_size;
81827 +};
81828 +
81829 +struct user_acl_role_db_compat {
81830 + compat_uptr_t r_table;
81831 + __u32 num_pointers;
81832 + __u32 num_roles;
81833 + __u32 num_domain_children;
81834 + __u32 num_subjects;
81835 + __u32 num_objects;
81836 +};
81837 +
81838 +struct acl_object_label_compat {
81839 + compat_uptr_t filename;
81840 + compat_ino_t inode;
81841 + __u32 device;
81842 + __u32 mode;
81843 +
81844 + compat_uptr_t nested;
81845 + compat_uptr_t globbed;
81846 +
81847 + compat_uptr_t prev;
81848 + compat_uptr_t next;
81849 +};
81850 +
81851 +struct acl_ip_label_compat {
81852 + compat_uptr_t iface;
81853 + __u32 addr;
81854 + __u32 netmask;
81855 + __u16 low, high;
81856 + __u8 mode;
81857 + __u32 type;
81858 + __u32 proto[8];
81859 +
81860 + compat_uptr_t prev;
81861 + compat_uptr_t next;
81862 +};
81863 +
81864 +struct gr_arg_compat {
81865 + struct user_acl_role_db_compat role_db;
81866 + unsigned char pw[GR_PW_LEN];
81867 + unsigned char salt[GR_SALT_LEN];
81868 + unsigned char sum[GR_SHA_LEN];
81869 + unsigned char sp_role[GR_SPROLE_LEN];
81870 + compat_uptr_t sprole_pws;
81871 + __u32 segv_device;
81872 + compat_ino_t segv_inode;
81873 + uid_t segv_uid;
81874 + __u16 num_sprole_pws;
81875 + __u16 mode;
81876 +};
81877 +
81878 +struct gr_arg_wrapper_compat {
81879 + compat_uptr_t arg;
81880 + __u32 version;
81881 + __u32 size;
81882 +};
81883 +
81884 +#endif
81885 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
81886 new file mode 100644
81887 index 0000000..323ecf2
81888 --- /dev/null
81889 +++ b/include/linux/gralloc.h
81890 @@ -0,0 +1,9 @@
81891 +#ifndef __GRALLOC_H
81892 +#define __GRALLOC_H
81893 +
81894 +void acl_free_all(void);
81895 +int acl_alloc_stack_init(unsigned long size);
81896 +void *acl_alloc(unsigned long len);
81897 +void *acl_alloc_num(unsigned long num, unsigned long len);
81898 +
81899 +#endif
81900 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
81901 new file mode 100644
81902 index 0000000..be66033
81903 --- /dev/null
81904 +++ b/include/linux/grdefs.h
81905 @@ -0,0 +1,140 @@
81906 +#ifndef GRDEFS_H
81907 +#define GRDEFS_H
81908 +
81909 +/* Begin grsecurity status declarations */
81910 +
81911 +enum {
81912 + GR_READY = 0x01,
81913 + GR_STATUS_INIT = 0x00 // disabled state
81914 +};
81915 +
81916 +/* Begin ACL declarations */
81917 +
81918 +/* Role flags */
81919 +
81920 +enum {
81921 + GR_ROLE_USER = 0x0001,
81922 + GR_ROLE_GROUP = 0x0002,
81923 + GR_ROLE_DEFAULT = 0x0004,
81924 + GR_ROLE_SPECIAL = 0x0008,
81925 + GR_ROLE_AUTH = 0x0010,
81926 + GR_ROLE_NOPW = 0x0020,
81927 + GR_ROLE_GOD = 0x0040,
81928 + GR_ROLE_LEARN = 0x0080,
81929 + GR_ROLE_TPE = 0x0100,
81930 + GR_ROLE_DOMAIN = 0x0200,
81931 + GR_ROLE_PAM = 0x0400,
81932 + GR_ROLE_PERSIST = 0x0800
81933 +};
81934 +
81935 +/* ACL Subject and Object mode flags */
81936 +enum {
81937 + GR_DELETED = 0x80000000
81938 +};
81939 +
81940 +/* ACL Object-only mode flags */
81941 +enum {
81942 + GR_READ = 0x00000001,
81943 + GR_APPEND = 0x00000002,
81944 + GR_WRITE = 0x00000004,
81945 + GR_EXEC = 0x00000008,
81946 + GR_FIND = 0x00000010,
81947 + GR_INHERIT = 0x00000020,
81948 + GR_SETID = 0x00000040,
81949 + GR_CREATE = 0x00000080,
81950 + GR_DELETE = 0x00000100,
81951 + GR_LINK = 0x00000200,
81952 + GR_AUDIT_READ = 0x00000400,
81953 + GR_AUDIT_APPEND = 0x00000800,
81954 + GR_AUDIT_WRITE = 0x00001000,
81955 + GR_AUDIT_EXEC = 0x00002000,
81956 + GR_AUDIT_FIND = 0x00004000,
81957 + GR_AUDIT_INHERIT= 0x00008000,
81958 + GR_AUDIT_SETID = 0x00010000,
81959 + GR_AUDIT_CREATE = 0x00020000,
81960 + GR_AUDIT_DELETE = 0x00040000,
81961 + GR_AUDIT_LINK = 0x00080000,
81962 + GR_PTRACERD = 0x00100000,
81963 + GR_NOPTRACE = 0x00200000,
81964 + GR_SUPPRESS = 0x00400000,
81965 + GR_NOLEARN = 0x00800000,
81966 + GR_INIT_TRANSFER= 0x01000000
81967 +};
81968 +
81969 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
81970 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
81971 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
81972 +
81973 +/* ACL subject-only mode flags */
81974 +enum {
81975 + GR_KILL = 0x00000001,
81976 + GR_VIEW = 0x00000002,
81977 + GR_PROTECTED = 0x00000004,
81978 + GR_LEARN = 0x00000008,
81979 + GR_OVERRIDE = 0x00000010,
81980 + /* just a placeholder, this mode is only used in userspace */
81981 + GR_DUMMY = 0x00000020,
81982 + GR_PROTSHM = 0x00000040,
81983 + GR_KILLPROC = 0x00000080,
81984 + GR_KILLIPPROC = 0x00000100,
81985 + /* just a placeholder, this mode is only used in userspace */
81986 + GR_NOTROJAN = 0x00000200,
81987 + GR_PROTPROCFD = 0x00000400,
81988 + GR_PROCACCT = 0x00000800,
81989 + GR_RELAXPTRACE = 0x00001000,
81990 + //GR_NESTED = 0x00002000,
81991 + GR_INHERITLEARN = 0x00004000,
81992 + GR_PROCFIND = 0x00008000,
81993 + GR_POVERRIDE = 0x00010000,
81994 + GR_KERNELAUTH = 0x00020000,
81995 + GR_ATSECURE = 0x00040000,
81996 + GR_SHMEXEC = 0x00080000
81997 +};
81998 +
81999 +enum {
82000 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
82001 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
82002 + GR_PAX_ENABLE_MPROTECT = 0x0004,
82003 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
82004 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
82005 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
82006 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
82007 + GR_PAX_DISABLE_MPROTECT = 0x0400,
82008 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
82009 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
82010 +};
82011 +
82012 +enum {
82013 + GR_ID_USER = 0x01,
82014 + GR_ID_GROUP = 0x02,
82015 +};
82016 +
82017 +enum {
82018 + GR_ID_ALLOW = 0x01,
82019 + GR_ID_DENY = 0x02,
82020 +};
82021 +
82022 +#define GR_CRASH_RES 31
82023 +#define GR_UIDTABLE_MAX 500
82024 +
82025 +/* begin resource learning section */
82026 +enum {
82027 + GR_RLIM_CPU_BUMP = 60,
82028 + GR_RLIM_FSIZE_BUMP = 50000,
82029 + GR_RLIM_DATA_BUMP = 10000,
82030 + GR_RLIM_STACK_BUMP = 1000,
82031 + GR_RLIM_CORE_BUMP = 10000,
82032 + GR_RLIM_RSS_BUMP = 500000,
82033 + GR_RLIM_NPROC_BUMP = 1,
82034 + GR_RLIM_NOFILE_BUMP = 5,
82035 + GR_RLIM_MEMLOCK_BUMP = 50000,
82036 + GR_RLIM_AS_BUMP = 500000,
82037 + GR_RLIM_LOCKS_BUMP = 2,
82038 + GR_RLIM_SIGPENDING_BUMP = 5,
82039 + GR_RLIM_MSGQUEUE_BUMP = 10000,
82040 + GR_RLIM_NICE_BUMP = 1,
82041 + GR_RLIM_RTPRIO_BUMP = 1,
82042 + GR_RLIM_RTTIME_BUMP = 1000000
82043 +};
82044 +
82045 +#endif
82046 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
82047 new file mode 100644
82048 index 0000000..d25522e
82049 --- /dev/null
82050 +++ b/include/linux/grinternal.h
82051 @@ -0,0 +1,229 @@
82052 +#ifndef __GRINTERNAL_H
82053 +#define __GRINTERNAL_H
82054 +
82055 +#ifdef CONFIG_GRKERNSEC
82056 +
82057 +#include <linux/fs.h>
82058 +#include <linux/mnt_namespace.h>
82059 +#include <linux/nsproxy.h>
82060 +#include <linux/gracl.h>
82061 +#include <linux/grdefs.h>
82062 +#include <linux/grmsg.h>
82063 +
82064 +void gr_add_learn_entry(const char *fmt, ...)
82065 + __attribute__ ((format (printf, 1, 2)));
82066 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
82067 + const struct vfsmount *mnt);
82068 +__u32 gr_check_create(const struct dentry *new_dentry,
82069 + const struct dentry *parent,
82070 + const struct vfsmount *mnt, const __u32 mode);
82071 +int gr_check_protected_task(const struct task_struct *task);
82072 +__u32 to_gr_audit(const __u32 reqmode);
82073 +int gr_set_acls(const int type);
82074 +int gr_acl_is_enabled(void);
82075 +char gr_roletype_to_char(void);
82076 +
82077 +void gr_handle_alertkill(struct task_struct *task);
82078 +char *gr_to_filename(const struct dentry *dentry,
82079 + const struct vfsmount *mnt);
82080 +char *gr_to_filename1(const struct dentry *dentry,
82081 + const struct vfsmount *mnt);
82082 +char *gr_to_filename2(const struct dentry *dentry,
82083 + const struct vfsmount *mnt);
82084 +char *gr_to_filename3(const struct dentry *dentry,
82085 + const struct vfsmount *mnt);
82086 +
82087 +extern int grsec_enable_ptrace_readexec;
82088 +extern int grsec_enable_harden_ptrace;
82089 +extern int grsec_enable_link;
82090 +extern int grsec_enable_fifo;
82091 +extern int grsec_enable_execve;
82092 +extern int grsec_enable_shm;
82093 +extern int grsec_enable_execlog;
82094 +extern int grsec_enable_signal;
82095 +extern int grsec_enable_audit_ptrace;
82096 +extern int grsec_enable_forkfail;
82097 +extern int grsec_enable_time;
82098 +extern int grsec_enable_rofs;
82099 +extern int grsec_deny_new_usb;
82100 +extern int grsec_enable_chroot_shmat;
82101 +extern int grsec_enable_chroot_mount;
82102 +extern int grsec_enable_chroot_double;
82103 +extern int grsec_enable_chroot_pivot;
82104 +extern int grsec_enable_chroot_chdir;
82105 +extern int grsec_enable_chroot_chmod;
82106 +extern int grsec_enable_chroot_mknod;
82107 +extern int grsec_enable_chroot_fchdir;
82108 +extern int grsec_enable_chroot_nice;
82109 +extern int grsec_enable_chroot_execlog;
82110 +extern int grsec_enable_chroot_caps;
82111 +extern int grsec_enable_chroot_sysctl;
82112 +extern int grsec_enable_chroot_unix;
82113 +extern int grsec_enable_symlinkown;
82114 +extern kgid_t grsec_symlinkown_gid;
82115 +extern int grsec_enable_tpe;
82116 +extern kgid_t grsec_tpe_gid;
82117 +extern int grsec_enable_tpe_all;
82118 +extern int grsec_enable_tpe_invert;
82119 +extern int grsec_enable_socket_all;
82120 +extern kgid_t grsec_socket_all_gid;
82121 +extern int grsec_enable_socket_client;
82122 +extern kgid_t grsec_socket_client_gid;
82123 +extern int grsec_enable_socket_server;
82124 +extern kgid_t grsec_socket_server_gid;
82125 +extern kgid_t grsec_audit_gid;
82126 +extern int grsec_enable_group;
82127 +extern int grsec_enable_log_rwxmaps;
82128 +extern int grsec_enable_mount;
82129 +extern int grsec_enable_chdir;
82130 +extern int grsec_resource_logging;
82131 +extern int grsec_enable_blackhole;
82132 +extern int grsec_lastack_retries;
82133 +extern int grsec_enable_brute;
82134 +extern int grsec_enable_harden_ipc;
82135 +extern int grsec_lock;
82136 +
82137 +extern spinlock_t grsec_alert_lock;
82138 +extern unsigned long grsec_alert_wtime;
82139 +extern unsigned long grsec_alert_fyet;
82140 +
82141 +extern spinlock_t grsec_audit_lock;
82142 +
82143 +extern rwlock_t grsec_exec_file_lock;
82144 +
82145 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
82146 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
82147 + (tsk)->exec_file->f_path.mnt) : "/")
82148 +
82149 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
82150 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
82151 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
82152 +
82153 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
82154 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
82155 + (tsk)->exec_file->f_path.mnt) : "/")
82156 +
82157 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
82158 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
82159 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
82160 +
82161 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
82162 +
82163 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
82164 +
82165 +static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
82166 +{
82167 + if (file1 && file2) {
82168 + const struct inode *inode1 = file1->f_path.dentry->d_inode;
82169 + const struct inode *inode2 = file2->f_path.dentry->d_inode;
82170 + if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
82171 + return true;
82172 + }
82173 +
82174 + return false;
82175 +}
82176 +
82177 +#define GR_CHROOT_CAPS {{ \
82178 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
82179 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
82180 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
82181 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
82182 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
82183 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
82184 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
82185 +
82186 +#define security_learn(normal_msg,args...) \
82187 +({ \
82188 + read_lock(&grsec_exec_file_lock); \
82189 + gr_add_learn_entry(normal_msg "\n", ## args); \
82190 + read_unlock(&grsec_exec_file_lock); \
82191 +})
82192 +
82193 +enum {
82194 + GR_DO_AUDIT,
82195 + GR_DONT_AUDIT,
82196 + /* used for non-audit messages that we shouldn't kill the task on */
82197 + GR_DONT_AUDIT_GOOD
82198 +};
82199 +
82200 +enum {
82201 + GR_TTYSNIFF,
82202 + GR_RBAC,
82203 + GR_RBAC_STR,
82204 + GR_STR_RBAC,
82205 + GR_RBAC_MODE2,
82206 + GR_RBAC_MODE3,
82207 + GR_FILENAME,
82208 + GR_SYSCTL_HIDDEN,
82209 + GR_NOARGS,
82210 + GR_ONE_INT,
82211 + GR_ONE_INT_TWO_STR,
82212 + GR_ONE_STR,
82213 + GR_STR_INT,
82214 + GR_TWO_STR_INT,
82215 + GR_TWO_INT,
82216 + GR_TWO_U64,
82217 + GR_THREE_INT,
82218 + GR_FIVE_INT_TWO_STR,
82219 + GR_TWO_STR,
82220 + GR_THREE_STR,
82221 + GR_FOUR_STR,
82222 + GR_STR_FILENAME,
82223 + GR_FILENAME_STR,
82224 + GR_FILENAME_TWO_INT,
82225 + GR_FILENAME_TWO_INT_STR,
82226 + GR_TEXTREL,
82227 + GR_PTRACE,
82228 + GR_RESOURCE,
82229 + GR_CAP,
82230 + GR_SIG,
82231 + GR_SIG2,
82232 + GR_CRASH1,
82233 + GR_CRASH2,
82234 + GR_PSACCT,
82235 + GR_RWXMAP,
82236 + GR_RWXMAPVMA
82237 +};
82238 +
82239 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
82240 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
82241 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
82242 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
82243 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
82244 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
82245 +#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)
82246 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
82247 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
82248 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
82249 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
82250 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
82251 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
82252 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
82253 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
82254 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
82255 +#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)
82256 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
82257 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
82258 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
82259 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
82260 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
82261 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
82262 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
82263 +#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)
82264 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
82265 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
82266 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
82267 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
82268 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
82269 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
82270 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
82271 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
82272 +#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)
82273 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
82274 +#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
82275 +
82276 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
82277 +
82278 +#endif
82279 +
82280 +#endif
82281 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
82282 new file mode 100644
82283 index 0000000..b02ba9d
82284 --- /dev/null
82285 +++ b/include/linux/grmsg.h
82286 @@ -0,0 +1,117 @@
82287 +#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"
82288 +#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"
82289 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
82290 +#define GR_STOPMOD_MSG "denied modification of module state by "
82291 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
82292 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
82293 +#define GR_IOPERM_MSG "denied use of ioperm() by "
82294 +#define GR_IOPL_MSG "denied use of iopl() by "
82295 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
82296 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
82297 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
82298 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
82299 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
82300 +#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"
82301 +#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"
82302 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
82303 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
82304 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
82305 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
82306 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
82307 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
82308 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
82309 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
82310 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
82311 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
82312 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
82313 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
82314 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
82315 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
82316 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
82317 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
82318 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
82319 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
82320 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
82321 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
82322 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
82323 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
82324 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
82325 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
82326 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
82327 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
82328 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
82329 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
82330 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
82331 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
82332 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
82333 +#define GR_CHROOT_FHANDLE_MSG "denied use of file handles inside chroot by "
82334 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
82335 +#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
82336 +#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
82337 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
82338 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
82339 +#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"
82340 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
82341 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
82342 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
82343 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
82344 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
82345 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
82346 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
82347 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
82348 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
82349 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
82350 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
82351 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
82352 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
82353 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
82354 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
82355 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
82356 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
82357 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
82358 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
82359 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
82360 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
82361 +#define GR_NICE_CHROOT_MSG "denied priority change by "
82362 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
82363 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
82364 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
82365 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
82366 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
82367 +#define GR_TIME_MSG "time set by "
82368 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
82369 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
82370 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
82371 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
82372 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
82373 +#define GR_BIND_MSG "denied bind() by "
82374 +#define GR_CONNECT_MSG "denied connect() by "
82375 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
82376 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
82377 +#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"
82378 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
82379 +#define GR_CAP_ACL_MSG "use of %s denied for "
82380 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
82381 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
82382 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
82383 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
82384 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
82385 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
82386 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
82387 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
82388 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
82389 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
82390 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
82391 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
82392 +#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
82393 +#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
82394 +#define GR_VM86_MSG "denied use of vm86 by "
82395 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
82396 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
82397 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
82398 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
82399 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
82400 +#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 "
82401 +#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 "
82402 +#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
82403 +#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
82404 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
82405 new file mode 100644
82406 index 0000000..10b9635
82407 --- /dev/null
82408 +++ b/include/linux/grsecurity.h
82409 @@ -0,0 +1,254 @@
82410 +#ifndef GR_SECURITY_H
82411 +#define GR_SECURITY_H
82412 +#include <linux/fs.h>
82413 +#include <linux/fs_struct.h>
82414 +#include <linux/binfmts.h>
82415 +#include <linux/gracl.h>
82416 +
82417 +/* notify of brain-dead configs */
82418 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
82419 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
82420 +#endif
82421 +#if defined(CONFIG_GRKERNSEC_PROC) && !defined(CONFIG_GRKERNSEC_PROC_USER) && !defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
82422 +#error "CONFIG_GRKERNSEC_PROC enabled, but neither CONFIG_GRKERNSEC_PROC_USER nor CONFIG_GRKERNSEC_PROC_USERGROUP enabled"
82423 +#endif
82424 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
82425 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
82426 +#endif
82427 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
82428 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
82429 +#endif
82430 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
82431 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
82432 +#endif
82433 +
82434 +int gr_handle_new_usb(void);
82435 +
82436 +void gr_handle_brute_attach(int dumpable);
82437 +void gr_handle_brute_check(void);
82438 +void gr_handle_kernel_exploit(void);
82439 +
82440 +char gr_roletype_to_char(void);
82441 +
82442 +int gr_proc_is_restricted(void);
82443 +
82444 +int gr_acl_enable_at_secure(void);
82445 +
82446 +int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
82447 +int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
82448 +
82449 +int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap);
82450 +
82451 +void gr_del_task_from_ip_table(struct task_struct *p);
82452 +
82453 +int gr_pid_is_chrooted(struct task_struct *p);
82454 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
82455 +int gr_handle_chroot_nice(void);
82456 +int gr_handle_chroot_sysctl(const int op);
82457 +int gr_handle_chroot_setpriority(struct task_struct *p,
82458 + const int niceval);
82459 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
82460 +int gr_chroot_fhandle(void);
82461 +int gr_handle_chroot_chroot(const struct dentry *dentry,
82462 + const struct vfsmount *mnt);
82463 +void gr_handle_chroot_chdir(const struct path *path);
82464 +int gr_handle_chroot_chmod(const struct dentry *dentry,
82465 + const struct vfsmount *mnt, const int mode);
82466 +int gr_handle_chroot_mknod(const struct dentry *dentry,
82467 + const struct vfsmount *mnt, const int mode);
82468 +int gr_handle_chroot_mount(const struct dentry *dentry,
82469 + const struct vfsmount *mnt,
82470 + const char *dev_name);
82471 +int gr_handle_chroot_pivot(void);
82472 +int gr_handle_chroot_unix(const pid_t pid);
82473 +
82474 +int gr_handle_rawio(const struct inode *inode);
82475 +
82476 +void gr_handle_ioperm(void);
82477 +void gr_handle_iopl(void);
82478 +void gr_handle_msr_write(void);
82479 +
82480 +umode_t gr_acl_umask(void);
82481 +
82482 +int gr_tpe_allow(const struct file *file);
82483 +
82484 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
82485 +void gr_clear_chroot_entries(struct task_struct *task);
82486 +
82487 +void gr_log_forkfail(const int retval);
82488 +void gr_log_timechange(void);
82489 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
82490 +void gr_log_chdir(const struct dentry *dentry,
82491 + const struct vfsmount *mnt);
82492 +void gr_log_chroot_exec(const struct dentry *dentry,
82493 + const struct vfsmount *mnt);
82494 +void gr_log_remount(const char *devname, const int retval);
82495 +void gr_log_unmount(const char *devname, const int retval);
82496 +void gr_log_mount(const char *from, const char *to, const int retval);
82497 +void gr_log_textrel(struct vm_area_struct *vma);
82498 +void gr_log_ptgnustack(struct file *file);
82499 +void gr_log_rwxmmap(struct file *file);
82500 +void gr_log_rwxmprotect(struct vm_area_struct *vma);
82501 +
82502 +int gr_handle_follow_link(const struct inode *parent,
82503 + const struct inode *inode,
82504 + const struct dentry *dentry,
82505 + const struct vfsmount *mnt);
82506 +int gr_handle_fifo(const struct dentry *dentry,
82507 + const struct vfsmount *mnt,
82508 + const struct dentry *dir, const int flag,
82509 + const int acc_mode);
82510 +int gr_handle_hardlink(const struct dentry *dentry,
82511 + const struct vfsmount *mnt,
82512 + struct inode *inode,
82513 + const int mode, const struct filename *to);
82514 +
82515 +int gr_is_capable(const int cap);
82516 +int gr_is_capable_nolog(const int cap);
82517 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
82518 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
82519 +
82520 +void gr_copy_label(struct task_struct *tsk);
82521 +void gr_handle_crash(struct task_struct *task, const int sig);
82522 +int gr_handle_signal(const struct task_struct *p, const int sig);
82523 +int gr_check_crash_uid(const kuid_t uid);
82524 +int gr_check_protected_task(const struct task_struct *task);
82525 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
82526 +int gr_acl_handle_mmap(const struct file *file,
82527 + const unsigned long prot);
82528 +int gr_acl_handle_mprotect(const struct file *file,
82529 + const unsigned long prot);
82530 +int gr_check_hidden_task(const struct task_struct *tsk);
82531 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
82532 + const struct vfsmount *mnt);
82533 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
82534 + const struct vfsmount *mnt);
82535 +__u32 gr_acl_handle_access(const struct dentry *dentry,
82536 + const struct vfsmount *mnt, const int fmode);
82537 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
82538 + const struct vfsmount *mnt, umode_t *mode);
82539 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
82540 + const struct vfsmount *mnt);
82541 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
82542 + const struct vfsmount *mnt);
82543 +__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
82544 + const struct vfsmount *mnt);
82545 +int gr_handle_ptrace(struct task_struct *task, const long request);
82546 +int gr_handle_proc_ptrace(struct task_struct *task);
82547 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
82548 + const struct vfsmount *mnt);
82549 +int gr_check_crash_exec(const struct file *filp);
82550 +int gr_acl_is_enabled(void);
82551 +void gr_set_role_label(struct task_struct *task, const kuid_t uid,
82552 + const kgid_t gid);
82553 +int gr_set_proc_label(const struct dentry *dentry,
82554 + const struct vfsmount *mnt,
82555 + const int unsafe_flags);
82556 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
82557 + const struct vfsmount *mnt);
82558 +__u32 gr_acl_handle_open(const struct dentry *dentry,
82559 + const struct vfsmount *mnt, int acc_mode);
82560 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
82561 + const struct dentry *p_dentry,
82562 + const struct vfsmount *p_mnt,
82563 + int open_flags, int acc_mode, const int imode);
82564 +void gr_handle_create(const struct dentry *dentry,
82565 + const struct vfsmount *mnt);
82566 +void gr_handle_proc_create(const struct dentry *dentry,
82567 + const struct inode *inode);
82568 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
82569 + const struct dentry *parent_dentry,
82570 + const struct vfsmount *parent_mnt,
82571 + const int mode);
82572 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
82573 + const struct dentry *parent_dentry,
82574 + const struct vfsmount *parent_mnt);
82575 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
82576 + const struct vfsmount *mnt);
82577 +void gr_handle_delete(const ino_t ino, const dev_t dev);
82578 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
82579 + const struct vfsmount *mnt);
82580 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
82581 + const struct dentry *parent_dentry,
82582 + const struct vfsmount *parent_mnt,
82583 + const struct filename *from);
82584 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
82585 + const struct dentry *parent_dentry,
82586 + const struct vfsmount *parent_mnt,
82587 + const struct dentry *old_dentry,
82588 + const struct vfsmount *old_mnt, const struct filename *to);
82589 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
82590 +int gr_acl_handle_rename(struct dentry *new_dentry,
82591 + struct dentry *parent_dentry,
82592 + const struct vfsmount *parent_mnt,
82593 + struct dentry *old_dentry,
82594 + struct inode *old_parent_inode,
82595 + struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags);
82596 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
82597 + struct dentry *old_dentry,
82598 + struct dentry *new_dentry,
82599 + struct vfsmount *mnt, const __u8 replace, unsigned int flags);
82600 +__u32 gr_check_link(const struct dentry *new_dentry,
82601 + const struct dentry *parent_dentry,
82602 + const struct vfsmount *parent_mnt,
82603 + const struct dentry *old_dentry,
82604 + const struct vfsmount *old_mnt);
82605 +int gr_acl_handle_filldir(const struct file *file, const char *name,
82606 + const unsigned int namelen, const ino_t ino);
82607 +
82608 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
82609 + const struct vfsmount *mnt);
82610 +void gr_acl_handle_exit(void);
82611 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
82612 +int gr_acl_handle_procpidmem(const struct task_struct *task);
82613 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
82614 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
82615 +void gr_audit_ptrace(struct task_struct *task);
82616 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
82617 +void gr_put_exec_file(struct task_struct *task);
82618 +
82619 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
82620 +
82621 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
82622 +extern void gr_learn_resource(const struct task_struct *task, const int res,
82623 + const unsigned long wanted, const int gt);
82624 +#else
82625 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
82626 + const unsigned long wanted, const int gt)
82627 +{
82628 +}
82629 +#endif
82630 +
82631 +#ifdef CONFIG_GRKERNSEC_RESLOG
82632 +extern void gr_log_resource(const struct task_struct *task, const int res,
82633 + const unsigned long wanted, const int gt);
82634 +#else
82635 +static inline void gr_log_resource(const struct task_struct *task, const int res,
82636 + const unsigned long wanted, const int gt)
82637 +{
82638 +}
82639 +#endif
82640 +
82641 +#ifdef CONFIG_GRKERNSEC
82642 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
82643 +void gr_handle_vm86(void);
82644 +void gr_handle_mem_readwrite(u64 from, u64 to);
82645 +
82646 +void gr_log_badprocpid(const char *entry);
82647 +
82648 +extern int grsec_enable_dmesg;
82649 +extern int grsec_disable_privio;
82650 +
82651 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
82652 +extern kgid_t grsec_proc_gid;
82653 +#endif
82654 +
82655 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
82656 +extern int grsec_enable_chroot_findtask;
82657 +#endif
82658 +#ifdef CONFIG_GRKERNSEC_SETXID
82659 +extern int grsec_enable_setxid;
82660 +#endif
82661 +#endif
82662 +
82663 +#endif
82664 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
82665 new file mode 100644
82666 index 0000000..e7ffaaf
82667 --- /dev/null
82668 +++ b/include/linux/grsock.h
82669 @@ -0,0 +1,19 @@
82670 +#ifndef __GRSOCK_H
82671 +#define __GRSOCK_H
82672 +
82673 +extern void gr_attach_curr_ip(const struct sock *sk);
82674 +extern int gr_handle_sock_all(const int family, const int type,
82675 + const int protocol);
82676 +extern int gr_handle_sock_server(const struct sockaddr *sck);
82677 +extern int gr_handle_sock_server_other(const struct sock *sck);
82678 +extern int gr_handle_sock_client(const struct sockaddr *sck);
82679 +extern int gr_search_connect(struct socket * sock,
82680 + struct sockaddr_in * addr);
82681 +extern int gr_search_bind(struct socket * sock,
82682 + struct sockaddr_in * addr);
82683 +extern int gr_search_listen(struct socket * sock);
82684 +extern int gr_search_accept(struct socket * sock);
82685 +extern int gr_search_socket(const int domain, const int type,
82686 + const int protocol);
82687 +
82688 +#endif
82689 diff --git a/include/linux/hash.h b/include/linux/hash.h
82690 index d0494c3..69b7715 100644
82691 --- a/include/linux/hash.h
82692 +++ b/include/linux/hash.h
82693 @@ -87,7 +87,7 @@ static inline u32 hash32_ptr(const void *ptr)
82694 struct fast_hash_ops {
82695 u32 (*hash)(const void *data, u32 len, u32 seed);
82696 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
82697 -};
82698 +} __no_const;
82699
82700 /**
82701 * arch_fast_hash - Caclulates a hash over a given buffer that can have
82702 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
82703 index 9286a46..373f27f 100644
82704 --- a/include/linux/highmem.h
82705 +++ b/include/linux/highmem.h
82706 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
82707 kunmap_atomic(kaddr);
82708 }
82709
82710 +static inline void sanitize_highpage(struct page *page)
82711 +{
82712 + void *kaddr;
82713 + unsigned long flags;
82714 +
82715 + local_irq_save(flags);
82716 + kaddr = kmap_atomic(page);
82717 + clear_page(kaddr);
82718 + kunmap_atomic(kaddr);
82719 + local_irq_restore(flags);
82720 +}
82721 +
82722 static inline void zero_user_segments(struct page *page,
82723 unsigned start1, unsigned end1,
82724 unsigned start2, unsigned end2)
82725 diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
82726 index 1c7b89a..7dda400 100644
82727 --- a/include/linux/hwmon-sysfs.h
82728 +++ b/include/linux/hwmon-sysfs.h
82729 @@ -25,7 +25,8 @@
82730 struct sensor_device_attribute{
82731 struct device_attribute dev_attr;
82732 int index;
82733 -};
82734 +} __do_const;
82735 +typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
82736 #define to_sensor_dev_attr(_dev_attr) \
82737 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
82738
82739 @@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
82740 struct device_attribute dev_attr;
82741 u8 index;
82742 u8 nr;
82743 -};
82744 +} __do_const;
82745 +typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
82746 #define to_sensor_dev_attr_2(_dev_attr) \
82747 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
82748
82749 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
82750 index b556e0a..c10a515 100644
82751 --- a/include/linux/i2c.h
82752 +++ b/include/linux/i2c.h
82753 @@ -378,6 +378,7 @@ struct i2c_algorithm {
82754 /* To determine what the adapter supports */
82755 u32 (*functionality) (struct i2c_adapter *);
82756 };
82757 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
82758
82759 /**
82760 * struct i2c_bus_recovery_info - I2C bus recovery information
82761 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
82762 index d23c3c2..eb63c81 100644
82763 --- a/include/linux/i2o.h
82764 +++ b/include/linux/i2o.h
82765 @@ -565,7 +565,7 @@ struct i2o_controller {
82766 struct i2o_device *exec; /* Executive */
82767 #if BITS_PER_LONG == 64
82768 spinlock_t context_list_lock; /* lock for context_list */
82769 - atomic_t context_list_counter; /* needed for unique contexts */
82770 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
82771 struct list_head context_list; /* list of context id's
82772 and pointers */
82773 #endif
82774 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
82775 index aff7ad8..3942bbd 100644
82776 --- a/include/linux/if_pppox.h
82777 +++ b/include/linux/if_pppox.h
82778 @@ -76,7 +76,7 @@ struct pppox_proto {
82779 int (*ioctl)(struct socket *sock, unsigned int cmd,
82780 unsigned long arg);
82781 struct module *owner;
82782 -};
82783 +} __do_const;
82784
82785 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
82786 extern void unregister_pppox_proto(int proto_num);
82787 diff --git a/include/linux/init.h b/include/linux/init.h
82788 index 2df8e8d..3e1280d 100644
82789 --- a/include/linux/init.h
82790 +++ b/include/linux/init.h
82791 @@ -37,9 +37,17 @@
82792 * section.
82793 */
82794
82795 +#define add_init_latent_entropy __latent_entropy
82796 +
82797 +#ifdef CONFIG_MEMORY_HOTPLUG
82798 +#define add_meminit_latent_entropy
82799 +#else
82800 +#define add_meminit_latent_entropy __latent_entropy
82801 +#endif
82802 +
82803 /* These are for everybody (although not all archs will actually
82804 discard it in modules) */
82805 -#define __init __section(.init.text) __cold notrace
82806 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
82807 #define __initdata __section(.init.data)
82808 #define __initconst __constsection(.init.rodata)
82809 #define __exitdata __section(.exit.data)
82810 @@ -100,7 +108,7 @@
82811 #define __cpuexitconst
82812
82813 /* Used for MEMORY_HOTPLUG */
82814 -#define __meminit __section(.meminit.text) __cold notrace
82815 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
82816 #define __meminitdata __section(.meminit.data)
82817 #define __meminitconst __constsection(.meminit.rodata)
82818 #define __memexit __section(.memexit.text) __exitused __cold notrace
82819 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
82820 index 2bb4c4f3..e0fac69 100644
82821 --- a/include/linux/init_task.h
82822 +++ b/include/linux/init_task.h
82823 @@ -149,6 +149,12 @@ extern struct task_group root_task_group;
82824
82825 #define INIT_TASK_COMM "swapper"
82826
82827 +#ifdef CONFIG_X86
82828 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
82829 +#else
82830 +#define INIT_TASK_THREAD_INFO
82831 +#endif
82832 +
82833 #ifdef CONFIG_RT_MUTEXES
82834 # define INIT_RT_MUTEXES(tsk) \
82835 .pi_waiters = RB_ROOT, \
82836 @@ -196,6 +202,7 @@ extern struct task_group root_task_group;
82837 RCU_POINTER_INITIALIZER(cred, &init_cred), \
82838 .comm = INIT_TASK_COMM, \
82839 .thread = INIT_THREAD, \
82840 + INIT_TASK_THREAD_INFO \
82841 .fs = &init_fs, \
82842 .files = &init_files, \
82843 .signal = &init_signals, \
82844 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
82845 index 698ad05..8601bb7 100644
82846 --- a/include/linux/interrupt.h
82847 +++ b/include/linux/interrupt.h
82848 @@ -418,8 +418,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
82849
82850 struct softirq_action
82851 {
82852 - void (*action)(struct softirq_action *);
82853 -};
82854 + void (*action)(void);
82855 +} __no_const;
82856
82857 asmlinkage void do_softirq(void);
82858 asmlinkage void __do_softirq(void);
82859 @@ -433,7 +433,7 @@ static inline void do_softirq_own_stack(void)
82860 }
82861 #endif
82862
82863 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
82864 +extern void open_softirq(int nr, void (*action)(void));
82865 extern void softirq_init(void);
82866 extern void __raise_softirq_irqoff(unsigned int nr);
82867
82868 diff --git a/include/linux/iommu.h b/include/linux/iommu.h
82869 index 20f9a52..63ee2e3 100644
82870 --- a/include/linux/iommu.h
82871 +++ b/include/linux/iommu.h
82872 @@ -131,7 +131,7 @@ struct iommu_ops {
82873 u32 (*domain_get_windows)(struct iommu_domain *domain);
82874
82875 unsigned long pgsize_bitmap;
82876 -};
82877 +} __do_const;
82878
82879 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
82880 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
82881 diff --git a/include/linux/ioport.h b/include/linux/ioport.h
82882 index 142ec54..873e033 100644
82883 --- a/include/linux/ioport.h
82884 +++ b/include/linux/ioport.h
82885 @@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
82886 int adjust_resource(struct resource *res, resource_size_t start,
82887 resource_size_t size);
82888 resource_size_t resource_alignment(struct resource *res);
82889 -static inline resource_size_t resource_size(const struct resource *res)
82890 +static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
82891 {
82892 return res->end - res->start + 1;
82893 }
82894 diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
82895 index 35e7eca..6afb7ad 100644
82896 --- a/include/linux/ipc_namespace.h
82897 +++ b/include/linux/ipc_namespace.h
82898 @@ -69,7 +69,7 @@ struct ipc_namespace {
82899 struct user_namespace *user_ns;
82900
82901 unsigned int proc_inum;
82902 -};
82903 +} __randomize_layout;
82904
82905 extern struct ipc_namespace init_ipc_ns;
82906 extern atomic_t nr_ipc_ns;
82907 diff --git a/include/linux/irq.h b/include/linux/irq.h
82908 index 62af592..cc3b0d0 100644
82909 --- a/include/linux/irq.h
82910 +++ b/include/linux/irq.h
82911 @@ -344,7 +344,8 @@ struct irq_chip {
82912 void (*irq_release_resources)(struct irq_data *data);
82913
82914 unsigned long flags;
82915 -};
82916 +} __do_const;
82917 +typedef struct irq_chip __no_const irq_chip_no_const;
82918
82919 /*
82920 * irq_chip specific flags
82921 diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
82922 index 45e2d8c..26d85da 100644
82923 --- a/include/linux/irqchip/arm-gic.h
82924 +++ b/include/linux/irqchip/arm-gic.h
82925 @@ -75,9 +75,11 @@
82926
82927 #ifndef __ASSEMBLY__
82928
82929 +#include <linux/irq.h>
82930 +
82931 struct device_node;
82932
82933 -extern struct irq_chip gic_arch_extn;
82934 +extern irq_chip_no_const gic_arch_extn;
82935
82936 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
82937 u32 offset, struct device_node *);
82938 diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
82939 index c367cbd..c9b79e6 100644
82940 --- a/include/linux/jiffies.h
82941 +++ b/include/linux/jiffies.h
82942 @@ -280,20 +280,20 @@ extern unsigned long preset_lpj;
82943 /*
82944 * Convert various time units to each other:
82945 */
82946 -extern unsigned int jiffies_to_msecs(const unsigned long j);
82947 -extern unsigned int jiffies_to_usecs(const unsigned long j);
82948 +extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
82949 +extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
82950
82951 -static inline u64 jiffies_to_nsecs(const unsigned long j)
82952 +static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
82953 {
82954 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
82955 }
82956
82957 -extern unsigned long msecs_to_jiffies(const unsigned int m);
82958 -extern unsigned long usecs_to_jiffies(const unsigned int u);
82959 +extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
82960 +extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
82961 extern unsigned long timespec_to_jiffies(const struct timespec *value);
82962 extern void jiffies_to_timespec(const unsigned long jiffies,
82963 - struct timespec *value);
82964 -extern unsigned long timeval_to_jiffies(const struct timeval *value);
82965 + struct timespec *value) __intentional_overflow(-1);
82966 +extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
82967 extern void jiffies_to_timeval(const unsigned long jiffies,
82968 struct timeval *value);
82969
82970 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
82971 index 6883e19..e854fcb 100644
82972 --- a/include/linux/kallsyms.h
82973 +++ b/include/linux/kallsyms.h
82974 @@ -15,7 +15,8 @@
82975
82976 struct module;
82977
82978 -#ifdef CONFIG_KALLSYMS
82979 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
82980 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
82981 /* Lookup the address for a symbol. Returns 0 if not found. */
82982 unsigned long kallsyms_lookup_name(const char *name);
82983
82984 @@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
82985 /* Stupid that this does nothing, but I didn't create this mess. */
82986 #define __print_symbol(fmt, addr)
82987 #endif /*CONFIG_KALLSYMS*/
82988 +#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
82989 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
82990 +extern unsigned long kallsyms_lookup_name(const char *name);
82991 +extern void __print_symbol(const char *fmt, unsigned long address);
82992 +extern int sprint_backtrace(char *buffer, unsigned long address);
82993 +extern int sprint_symbol(char *buffer, unsigned long address);
82994 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
82995 +const char *kallsyms_lookup(unsigned long addr,
82996 + unsigned long *symbolsize,
82997 + unsigned long *offset,
82998 + char **modname, char *namebuf);
82999 +extern int kallsyms_lookup_size_offset(unsigned long addr,
83000 + unsigned long *symbolsize,
83001 + unsigned long *offset);
83002 +#endif
83003
83004 /* This macro allows us to keep printk typechecking */
83005 static __printf(1, 2)
83006 diff --git a/include/linux/key-type.h b/include/linux/key-type.h
83007 index 44792ee..6172f2a 100644
83008 --- a/include/linux/key-type.h
83009 +++ b/include/linux/key-type.h
83010 @@ -132,7 +132,7 @@ struct key_type {
83011 /* internal fields */
83012 struct list_head link; /* link in types list */
83013 struct lock_class_key lock_class; /* key->sem lock class */
83014 -};
83015 +} __do_const;
83016
83017 extern struct key_type key_type_keyring;
83018
83019 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
83020 index e465bb1..19f605f 100644
83021 --- a/include/linux/kgdb.h
83022 +++ b/include/linux/kgdb.h
83023 @@ -52,7 +52,7 @@ extern int kgdb_connected;
83024 extern int kgdb_io_module_registered;
83025
83026 extern atomic_t kgdb_setting_breakpoint;
83027 -extern atomic_t kgdb_cpu_doing_single_step;
83028 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
83029
83030 extern struct task_struct *kgdb_usethread;
83031 extern struct task_struct *kgdb_contthread;
83032 @@ -254,7 +254,7 @@ struct kgdb_arch {
83033 void (*correct_hw_break)(void);
83034
83035 void (*enable_nmi)(bool on);
83036 -};
83037 +} __do_const;
83038
83039 /**
83040 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
83041 @@ -279,7 +279,7 @@ struct kgdb_io {
83042 void (*pre_exception) (void);
83043 void (*post_exception) (void);
83044 int is_console;
83045 -};
83046 +} __do_const;
83047
83048 extern struct kgdb_arch arch_kgdb_ops;
83049
83050 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
83051 index 0555cc6..40116ce 100644
83052 --- a/include/linux/kmod.h
83053 +++ b/include/linux/kmod.h
83054 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
83055 * usually useless though. */
83056 extern __printf(2, 3)
83057 int __request_module(bool wait, const char *name, ...);
83058 +extern __printf(3, 4)
83059 +int ___request_module(bool wait, char *param_name, const char *name, ...);
83060 #define request_module(mod...) __request_module(true, mod)
83061 #define request_module_nowait(mod...) __request_module(false, mod)
83062 #define try_then_request_module(x, mod...) \
83063 @@ -57,6 +59,9 @@ struct subprocess_info {
83064 struct work_struct work;
83065 struct completion *complete;
83066 char *path;
83067 +#ifdef CONFIG_GRKERNSEC
83068 + char *origpath;
83069 +#endif
83070 char **argv;
83071 char **envp;
83072 int wait;
83073 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
83074 index 2d61b90..a1d0a13 100644
83075 --- a/include/linux/kobject.h
83076 +++ b/include/linux/kobject.h
83077 @@ -118,7 +118,7 @@ struct kobj_type {
83078 struct attribute **default_attrs;
83079 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
83080 const void *(*namespace)(struct kobject *kobj);
83081 -};
83082 +} __do_const;
83083
83084 struct kobj_uevent_env {
83085 char *argv[3];
83086 @@ -142,6 +142,7 @@ struct kobj_attribute {
83087 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
83088 const char *buf, size_t count);
83089 };
83090 +typedef struct kobj_attribute __no_const kobj_attribute_no_const;
83091
83092 extern const struct sysfs_ops kobj_sysfs_ops;
83093
83094 @@ -169,7 +170,7 @@ struct kset {
83095 spinlock_t list_lock;
83096 struct kobject kobj;
83097 const struct kset_uevent_ops *uevent_ops;
83098 -};
83099 +} __randomize_layout;
83100
83101 extern void kset_init(struct kset *kset);
83102 extern int __must_check kset_register(struct kset *kset);
83103 diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
83104 index df32d25..fb52e27 100644
83105 --- a/include/linux/kobject_ns.h
83106 +++ b/include/linux/kobject_ns.h
83107 @@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
83108 const void *(*netlink_ns)(struct sock *sk);
83109 const void *(*initial_ns)(void);
83110 void (*drop_ns)(void *);
83111 -};
83112 +} __do_const;
83113
83114 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
83115 int kobj_ns_type_registered(enum kobj_ns_type type);
83116 diff --git a/include/linux/kref.h b/include/linux/kref.h
83117 index 484604d..0f6c5b6 100644
83118 --- a/include/linux/kref.h
83119 +++ b/include/linux/kref.h
83120 @@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
83121 static inline int kref_sub(struct kref *kref, unsigned int count,
83122 void (*release)(struct kref *kref))
83123 {
83124 - WARN_ON(release == NULL);
83125 + BUG_ON(release == NULL);
83126
83127 if (atomic_sub_and_test((int) count, &kref->refcount)) {
83128 release(kref);
83129 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
83130 index a4c33b3..e854710 100644
83131 --- a/include/linux/kvm_host.h
83132 +++ b/include/linux/kvm_host.h
83133 @@ -452,7 +452,7 @@ static inline void kvm_irqfd_exit(void)
83134 {
83135 }
83136 #endif
83137 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
83138 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
83139 struct module *module);
83140 void kvm_exit(void);
83141
83142 @@ -618,7 +618,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
83143 struct kvm_guest_debug *dbg);
83144 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
83145
83146 -int kvm_arch_init(void *opaque);
83147 +int kvm_arch_init(const void *opaque);
83148 void kvm_arch_exit(void);
83149
83150 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
83151 diff --git a/include/linux/libata.h b/include/linux/libata.h
83152 index 92abb49..e7fff2a 100644
83153 --- a/include/linux/libata.h
83154 +++ b/include/linux/libata.h
83155 @@ -976,7 +976,7 @@ struct ata_port_operations {
83156 * fields must be pointers.
83157 */
83158 const struct ata_port_operations *inherits;
83159 -};
83160 +} __do_const;
83161
83162 struct ata_port_info {
83163 unsigned long flags;
83164 diff --git a/include/linux/linkage.h b/include/linux/linkage.h
83165 index a6a42dd..6c5ebce 100644
83166 --- a/include/linux/linkage.h
83167 +++ b/include/linux/linkage.h
83168 @@ -36,6 +36,7 @@
83169 #endif
83170
83171 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
83172 +#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
83173 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
83174
83175 /*
83176 diff --git a/include/linux/list.h b/include/linux/list.h
83177 index cbbb96f..602d023 100644
83178 --- a/include/linux/list.h
83179 +++ b/include/linux/list.h
83180 @@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
83181 extern void list_del(struct list_head *entry);
83182 #endif
83183
83184 +extern void __pax_list_add(struct list_head *new,
83185 + struct list_head *prev,
83186 + struct list_head *next);
83187 +static inline void pax_list_add(struct list_head *new, struct list_head *head)
83188 +{
83189 + __pax_list_add(new, head, head->next);
83190 +}
83191 +static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
83192 +{
83193 + __pax_list_add(new, head->prev, head);
83194 +}
83195 +extern void pax_list_del(struct list_head *entry);
83196 +
83197 /**
83198 * list_replace - replace old entry by new one
83199 * @old : the element to be replaced
83200 @@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
83201 INIT_LIST_HEAD(entry);
83202 }
83203
83204 +extern void pax_list_del_init(struct list_head *entry);
83205 +
83206 /**
83207 * list_move - delete from one list and add as another's head
83208 * @list: the entry to move
83209 diff --git a/include/linux/lockref.h b/include/linux/lockref.h
83210 index 4bfde0e..d6e2e09 100644
83211 --- a/include/linux/lockref.h
83212 +++ b/include/linux/lockref.h
83213 @@ -47,4 +47,36 @@ static inline int __lockref_is_dead(const struct lockref *l)
83214 return ((int)l->count < 0);
83215 }
83216
83217 +static inline unsigned int __lockref_read(struct lockref *lockref)
83218 +{
83219 + return lockref->count;
83220 +}
83221 +
83222 +static inline void __lockref_set(struct lockref *lockref, unsigned int count)
83223 +{
83224 + lockref->count = count;
83225 +}
83226 +
83227 +static inline void __lockref_inc(struct lockref *lockref)
83228 +{
83229 +
83230 +#ifdef CONFIG_PAX_REFCOUNT
83231 + atomic_inc((atomic_t *)&lockref->count);
83232 +#else
83233 + lockref->count++;
83234 +#endif
83235 +
83236 +}
83237 +
83238 +static inline void __lockref_dec(struct lockref *lockref)
83239 +{
83240 +
83241 +#ifdef CONFIG_PAX_REFCOUNT
83242 + atomic_dec((atomic_t *)&lockref->count);
83243 +#else
83244 + lockref->count--;
83245 +#endif
83246 +
83247 +}
83248 +
83249 #endif /* __LINUX_LOCKREF_H */
83250 diff --git a/include/linux/math64.h b/include/linux/math64.h
83251 index c45c089..298841c 100644
83252 --- a/include/linux/math64.h
83253 +++ b/include/linux/math64.h
83254 @@ -15,7 +15,7 @@
83255 * This is commonly provided by 32bit archs to provide an optimized 64bit
83256 * divide.
83257 */
83258 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83259 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83260 {
83261 *remainder = dividend % divisor;
83262 return dividend / divisor;
83263 @@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
83264 /**
83265 * div64_u64 - unsigned 64bit divide with 64bit divisor
83266 */
83267 -static inline u64 div64_u64(u64 dividend, u64 divisor)
83268 +static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
83269 {
83270 return dividend / divisor;
83271 }
83272 @@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
83273 #define div64_ul(x, y) div_u64((x), (y))
83274
83275 #ifndef div_u64_rem
83276 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83277 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83278 {
83279 *remainder = do_div(dividend, divisor);
83280 return dividend;
83281 @@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
83282 #endif
83283
83284 #ifndef div64_u64
83285 -extern u64 div64_u64(u64 dividend, u64 divisor);
83286 +extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
83287 #endif
83288
83289 #ifndef div64_s64
83290 @@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
83291 * divide.
83292 */
83293 #ifndef div_u64
83294 -static inline u64 div_u64(u64 dividend, u32 divisor)
83295 +static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
83296 {
83297 u32 remainder;
83298 return div_u64_rem(dividend, divisor, &remainder);
83299 diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
83300 index f230a97..714c006 100644
83301 --- a/include/linux/mempolicy.h
83302 +++ b/include/linux/mempolicy.h
83303 @@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
83304 }
83305
83306 #define vma_policy(vma) ((vma)->vm_policy)
83307 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
83308 +{
83309 + vma->vm_policy = pol;
83310 +}
83311
83312 static inline void mpol_get(struct mempolicy *pol)
83313 {
83314 @@ -228,6 +232,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
83315 }
83316
83317 #define vma_policy(vma) NULL
83318 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
83319 +{
83320 +}
83321
83322 static inline int
83323 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
83324 diff --git a/include/linux/mm.h b/include/linux/mm.h
83325 index f952cc8..b9f6135 100644
83326 --- a/include/linux/mm.h
83327 +++ b/include/linux/mm.h
83328 @@ -127,6 +127,11 @@ extern unsigned int kobjsize(const void *objp);
83329 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
83330 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
83331 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
83332 +
83333 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
83334 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
83335 +#endif
83336 +
83337 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
83338
83339 #ifdef CONFIG_MEM_SOFT_DIRTY
83340 @@ -237,8 +242,8 @@ struct vm_operations_struct {
83341 /* called by access_process_vm when get_user_pages() fails, typically
83342 * for use by special VMAs that can switch between memory and hardware
83343 */
83344 - int (*access)(struct vm_area_struct *vma, unsigned long addr,
83345 - void *buf, int len, int write);
83346 + ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
83347 + void *buf, size_t len, int write);
83348
83349 /* Called by the /proc/PID/maps code to ask the vma whether it
83350 * has a special name. Returning non-NULL will also cause this
83351 @@ -274,6 +279,7 @@ struct vm_operations_struct {
83352 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
83353 unsigned long size, pgoff_t pgoff);
83354 };
83355 +typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
83356
83357 struct mmu_gather;
83358 struct inode;
83359 @@ -1163,8 +1169,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
83360 unsigned long *pfn);
83361 int follow_phys(struct vm_area_struct *vma, unsigned long address,
83362 unsigned int flags, unsigned long *prot, resource_size_t *phys);
83363 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
83364 - void *buf, int len, int write);
83365 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
83366 + void *buf, size_t len, int write);
83367
83368 static inline void unmap_shared_mapping_range(struct address_space *mapping,
83369 loff_t const holebegin, loff_t const holelen)
83370 @@ -1204,9 +1210,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
83371 }
83372 #endif
83373
83374 -extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
83375 -extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
83376 - void *buf, int len, int write);
83377 +extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
83378 +extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
83379 + void *buf, size_t len, int write);
83380
83381 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
83382 unsigned long start, unsigned long nr_pages,
83383 @@ -1238,34 +1244,6 @@ int set_page_dirty_lock(struct page *page);
83384 int clear_page_dirty_for_io(struct page *page);
83385 int get_cmdline(struct task_struct *task, char *buffer, int buflen);
83386
83387 -/* Is the vma a continuation of the stack vma above it? */
83388 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
83389 -{
83390 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
83391 -}
83392 -
83393 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
83394 - unsigned long addr)
83395 -{
83396 - return (vma->vm_flags & VM_GROWSDOWN) &&
83397 - (vma->vm_start == addr) &&
83398 - !vma_growsdown(vma->vm_prev, addr);
83399 -}
83400 -
83401 -/* Is the vma a continuation of the stack vma below it? */
83402 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
83403 -{
83404 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
83405 -}
83406 -
83407 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
83408 - unsigned long addr)
83409 -{
83410 - return (vma->vm_flags & VM_GROWSUP) &&
83411 - (vma->vm_end == addr) &&
83412 - !vma_growsup(vma->vm_next, addr);
83413 -}
83414 -
83415 extern pid_t
83416 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
83417
83418 @@ -1365,6 +1343,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
83419 }
83420 #endif
83421
83422 +#ifdef CONFIG_MMU
83423 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
83424 +#else
83425 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
83426 +{
83427 + return __pgprot(0);
83428 +}
83429 +#endif
83430 +
83431 int vma_wants_writenotify(struct vm_area_struct *vma);
83432
83433 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
83434 @@ -1383,8 +1370,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
83435 {
83436 return 0;
83437 }
83438 +
83439 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
83440 + unsigned long address)
83441 +{
83442 + return 0;
83443 +}
83444 #else
83445 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
83446 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
83447 #endif
83448
83449 #ifdef __PAGETABLE_PMD_FOLDED
83450 @@ -1393,8 +1387,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
83451 {
83452 return 0;
83453 }
83454 +
83455 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
83456 + unsigned long address)
83457 +{
83458 + return 0;
83459 +}
83460 #else
83461 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
83462 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
83463 #endif
83464
83465 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
83466 @@ -1412,11 +1413,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
83467 NULL: pud_offset(pgd, address);
83468 }
83469
83470 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
83471 +{
83472 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
83473 + NULL: pud_offset(pgd, address);
83474 +}
83475 +
83476 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
83477 {
83478 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
83479 NULL: pmd_offset(pud, address);
83480 }
83481 +
83482 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
83483 +{
83484 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
83485 + NULL: pmd_offset(pud, address);
83486 +}
83487 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
83488
83489 #if USE_SPLIT_PTE_PTLOCKS
83490 @@ -1815,7 +1828,7 @@ extern int install_special_mapping(struct mm_struct *mm,
83491 unsigned long addr, unsigned long len,
83492 unsigned long flags, struct page **pages);
83493
83494 -extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
83495 +extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
83496
83497 extern unsigned long mmap_region(struct file *file, unsigned long addr,
83498 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
83499 @@ -1823,6 +1836,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
83500 unsigned long len, unsigned long prot, unsigned long flags,
83501 unsigned long pgoff, unsigned long *populate);
83502 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
83503 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
83504
83505 #ifdef CONFIG_MMU
83506 extern int __mm_populate(unsigned long addr, unsigned long len,
83507 @@ -1851,10 +1865,11 @@ struct vm_unmapped_area_info {
83508 unsigned long high_limit;
83509 unsigned long align_mask;
83510 unsigned long align_offset;
83511 + unsigned long threadstack_offset;
83512 };
83513
83514 -extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
83515 -extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
83516 +extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
83517 +extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
83518
83519 /*
83520 * Search for an unmapped address range.
83521 @@ -1866,7 +1881,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
83522 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
83523 */
83524 static inline unsigned long
83525 -vm_unmapped_area(struct vm_unmapped_area_info *info)
83526 +vm_unmapped_area(const struct vm_unmapped_area_info *info)
83527 {
83528 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
83529 return unmapped_area(info);
83530 @@ -1928,6 +1943,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
83531 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
83532 struct vm_area_struct **pprev);
83533
83534 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
83535 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
83536 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
83537 +
83538 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
83539 NULL if none. Assume start_addr < end_addr. */
83540 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
83541 @@ -1956,15 +1975,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
83542 return vma;
83543 }
83544
83545 -#ifdef CONFIG_MMU
83546 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
83547 -#else
83548 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
83549 -{
83550 - return __pgprot(0);
83551 -}
83552 -#endif
83553 -
83554 #ifdef CONFIG_NUMA_BALANCING
83555 unsigned long change_prot_numa(struct vm_area_struct *vma,
83556 unsigned long start, unsigned long end);
83557 @@ -2016,6 +2026,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
83558 static inline void vm_stat_account(struct mm_struct *mm,
83559 unsigned long flags, struct file *file, long pages)
83560 {
83561 +
83562 +#ifdef CONFIG_PAX_RANDMMAP
83563 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
83564 +#endif
83565 +
83566 mm->total_vm += pages;
83567 }
83568 #endif /* CONFIG_PROC_FS */
83569 @@ -2104,7 +2119,7 @@ extern int unpoison_memory(unsigned long pfn);
83570 extern int sysctl_memory_failure_early_kill;
83571 extern int sysctl_memory_failure_recovery;
83572 extern void shake_page(struct page *p, int access);
83573 -extern atomic_long_t num_poisoned_pages;
83574 +extern atomic_long_unchecked_t num_poisoned_pages;
83575 extern int soft_offline_page(struct page *page, int flags);
83576
83577 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
83578 @@ -2139,5 +2154,11 @@ void __init setup_nr_node_ids(void);
83579 static inline void setup_nr_node_ids(void) {}
83580 #endif
83581
83582 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
83583 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
83584 +#else
83585 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
83586 +#endif
83587 +
83588 #endif /* __KERNEL__ */
83589 #endif /* _LINUX_MM_H */
83590 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
83591 index 6e0b286..90d9c0d 100644
83592 --- a/include/linux/mm_types.h
83593 +++ b/include/linux/mm_types.h
83594 @@ -308,7 +308,9 @@ struct vm_area_struct {
83595 #ifdef CONFIG_NUMA
83596 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
83597 #endif
83598 -};
83599 +
83600 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
83601 +} __randomize_layout;
83602
83603 struct core_thread {
83604 struct task_struct *task;
83605 @@ -454,7 +456,25 @@ struct mm_struct {
83606 bool tlb_flush_pending;
83607 #endif
83608 struct uprobes_state uprobes_state;
83609 -};
83610 +
83611 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
83612 + unsigned long pax_flags;
83613 +#endif
83614 +
83615 +#ifdef CONFIG_PAX_DLRESOLVE
83616 + unsigned long call_dl_resolve;
83617 +#endif
83618 +
83619 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
83620 + unsigned long call_syscall;
83621 +#endif
83622 +
83623 +#ifdef CONFIG_PAX_ASLR
83624 + unsigned long delta_mmap; /* randomized offset */
83625 + unsigned long delta_stack; /* randomized offset */
83626 +#endif
83627 +
83628 +} __randomize_layout;
83629
83630 static inline void mm_init_cpumask(struct mm_struct *mm)
83631 {
83632 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
83633 index c5d5278..f0b68c8 100644
83634 --- a/include/linux/mmiotrace.h
83635 +++ b/include/linux/mmiotrace.h
83636 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
83637 /* Called from ioremap.c */
83638 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
83639 void __iomem *addr);
83640 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
83641 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
83642
83643 /* For anyone to insert markers. Remember trailing newline. */
83644 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
83645 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
83646 {
83647 }
83648
83649 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
83650 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
83651 {
83652 }
83653
83654 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
83655 index b21bac4..94142ca 100644
83656 --- a/include/linux/mmzone.h
83657 +++ b/include/linux/mmzone.h
83658 @@ -527,7 +527,7 @@ struct zone {
83659
83660 ZONE_PADDING(_pad3_)
83661 /* Zone statistics */
83662 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83663 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83664 } ____cacheline_internodealigned_in_smp;
83665
83666 typedef enum {
83667 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
83668 index 44eeef0..a92d3f9 100644
83669 --- a/include/linux/mod_devicetable.h
83670 +++ b/include/linux/mod_devicetable.h
83671 @@ -139,7 +139,7 @@ struct usb_device_id {
83672 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
83673 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
83674
83675 -#define HID_ANY_ID (~0)
83676 +#define HID_ANY_ID (~0U)
83677 #define HID_BUS_ANY 0xffff
83678 #define HID_GROUP_ANY 0x0000
83679
83680 @@ -475,7 +475,7 @@ struct dmi_system_id {
83681 const char *ident;
83682 struct dmi_strmatch matches[4];
83683 void *driver_data;
83684 -};
83685 +} __do_const;
83686 /*
83687 * struct dmi_device_id appears during expansion of
83688 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
83689 diff --git a/include/linux/module.h b/include/linux/module.h
83690 index 71f282a..b2387e2 100644
83691 --- a/include/linux/module.h
83692 +++ b/include/linux/module.h
83693 @@ -17,9 +17,11 @@
83694 #include <linux/moduleparam.h>
83695 #include <linux/jump_label.h>
83696 #include <linux/export.h>
83697 +#include <linux/fs.h>
83698
83699 #include <linux/percpu.h>
83700 #include <asm/module.h>
83701 +#include <asm/pgtable.h>
83702
83703 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
83704 #define MODULE_SIG_STRING "~Module signature appended~\n"
83705 @@ -42,7 +44,7 @@ struct module_kobject {
83706 struct kobject *drivers_dir;
83707 struct module_param_attrs *mp;
83708 struct completion *kobj_completion;
83709 -};
83710 +} __randomize_layout;
83711
83712 struct module_attribute {
83713 struct attribute attr;
83714 @@ -54,12 +56,13 @@ struct module_attribute {
83715 int (*test)(struct module *);
83716 void (*free)(struct module *);
83717 };
83718 +typedef struct module_attribute __no_const module_attribute_no_const;
83719
83720 struct module_version_attribute {
83721 struct module_attribute mattr;
83722 const char *module_name;
83723 const char *version;
83724 -} __attribute__ ((__aligned__(sizeof(void *))));
83725 +} __do_const __attribute__ ((__aligned__(sizeof(void *))));
83726
83727 extern ssize_t __modver_version_show(struct module_attribute *,
83728 struct module_kobject *, char *);
83729 @@ -235,7 +238,7 @@ struct module {
83730
83731 /* Sysfs stuff. */
83732 struct module_kobject mkobj;
83733 - struct module_attribute *modinfo_attrs;
83734 + module_attribute_no_const *modinfo_attrs;
83735 const char *version;
83736 const char *srcversion;
83737 struct kobject *holders_dir;
83738 @@ -284,19 +287,16 @@ struct module {
83739 int (*init)(void);
83740
83741 /* If this is non-NULL, vfree after init() returns */
83742 - void *module_init;
83743 + void *module_init_rx, *module_init_rw;
83744
83745 /* Here is the actual code + data, vfree'd on unload. */
83746 - void *module_core;
83747 + void *module_core_rx, *module_core_rw;
83748
83749 /* Here are the sizes of the init and core sections */
83750 - unsigned int init_size, core_size;
83751 + unsigned int init_size_rw, core_size_rw;
83752
83753 /* The size of the executable code in each section. */
83754 - unsigned int init_text_size, core_text_size;
83755 -
83756 - /* Size of RO sections of the module (text+rodata) */
83757 - unsigned int init_ro_size, core_ro_size;
83758 + unsigned int init_size_rx, core_size_rx;
83759
83760 /* Arch-specific module values */
83761 struct mod_arch_specific arch;
83762 @@ -352,6 +352,10 @@ struct module {
83763 #ifdef CONFIG_EVENT_TRACING
83764 struct ftrace_event_call **trace_events;
83765 unsigned int num_trace_events;
83766 + struct file_operations trace_id;
83767 + struct file_operations trace_enable;
83768 + struct file_operations trace_format;
83769 + struct file_operations trace_filter;
83770 #endif
83771 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
83772 unsigned int num_ftrace_callsites;
83773 @@ -375,7 +379,7 @@ struct module {
83774 ctor_fn_t *ctors;
83775 unsigned int num_ctors;
83776 #endif
83777 -};
83778 +} __randomize_layout;
83779 #ifndef MODULE_ARCH_INIT
83780 #define MODULE_ARCH_INIT {}
83781 #endif
83782 @@ -396,18 +400,48 @@ bool is_module_address(unsigned long addr);
83783 bool is_module_percpu_address(unsigned long addr);
83784 bool is_module_text_address(unsigned long addr);
83785
83786 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
83787 +{
83788 +
83789 +#ifdef CONFIG_PAX_KERNEXEC
83790 + if (ktla_ktva(addr) >= (unsigned long)start &&
83791 + ktla_ktva(addr) < (unsigned long)start + size)
83792 + return 1;
83793 +#endif
83794 +
83795 + return ((void *)addr >= start && (void *)addr < start + size);
83796 +}
83797 +
83798 +static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
83799 +{
83800 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
83801 +}
83802 +
83803 +static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
83804 +{
83805 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
83806 +}
83807 +
83808 +static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
83809 +{
83810 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
83811 +}
83812 +
83813 +static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
83814 +{
83815 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
83816 +}
83817 +
83818 static inline bool within_module_core(unsigned long addr,
83819 const struct module *mod)
83820 {
83821 - return (unsigned long)mod->module_core <= addr &&
83822 - addr < (unsigned long)mod->module_core + mod->core_size;
83823 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
83824 }
83825
83826 static inline bool within_module_init(unsigned long addr,
83827 const struct module *mod)
83828 {
83829 - return (unsigned long)mod->module_init <= addr &&
83830 - addr < (unsigned long)mod->module_init + mod->init_size;
83831 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
83832 }
83833
83834 static inline bool within_module(unsigned long addr, const struct module *mod)
83835 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
83836 index 7eeb9bb..68f37e0 100644
83837 --- a/include/linux/moduleloader.h
83838 +++ b/include/linux/moduleloader.h
83839 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
83840 sections. Returns NULL on failure. */
83841 void *module_alloc(unsigned long size);
83842
83843 +#ifdef CONFIG_PAX_KERNEXEC
83844 +void *module_alloc_exec(unsigned long size);
83845 +#else
83846 +#define module_alloc_exec(x) module_alloc(x)
83847 +#endif
83848 +
83849 /* Free memory returned from module_alloc. */
83850 void module_free(struct module *mod, void *module_region);
83851
83852 +#ifdef CONFIG_PAX_KERNEXEC
83853 +void module_free_exec(struct module *mod, void *module_region);
83854 +#else
83855 +#define module_free_exec(x, y) module_free((x), (y))
83856 +#endif
83857 +
83858 /*
83859 * Apply the given relocation to the (simplified) ELF. Return -error
83860 * or 0.
83861 @@ -45,8 +57,10 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
83862 unsigned int relsec,
83863 struct module *me)
83864 {
83865 +#ifdef CONFIG_MODULES
83866 printk(KERN_ERR "module %s: REL relocation unsupported\n",
83867 module_name(me));
83868 +#endif
83869 return -ENOEXEC;
83870 }
83871 #endif
83872 @@ -68,8 +82,10 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
83873 unsigned int relsec,
83874 struct module *me)
83875 {
83876 +#ifdef CONFIG_MODULES
83877 printk(KERN_ERR "module %s: REL relocation unsupported\n",
83878 module_name(me));
83879 +#endif
83880 return -ENOEXEC;
83881 }
83882 #endif
83883 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
83884 index 494f99e..5059f63 100644
83885 --- a/include/linux/moduleparam.h
83886 +++ b/include/linux/moduleparam.h
83887 @@ -293,7 +293,7 @@ static inline void __kernel_param_unlock(void)
83888 * @len is usually just sizeof(string).
83889 */
83890 #define module_param_string(name, string, len, perm) \
83891 - static const struct kparam_string __param_string_##name \
83892 + static const struct kparam_string __param_string_##name __used \
83893 = { len, string }; \
83894 __module_param_call(MODULE_PARAM_PREFIX, name, \
83895 &param_ops_string, \
83896 @@ -437,7 +437,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
83897 */
83898 #define module_param_array_named(name, array, type, nump, perm) \
83899 param_check_##type(name, &(array)[0]); \
83900 - static const struct kparam_array __param_arr_##name \
83901 + static const struct kparam_array __param_arr_##name __used \
83902 = { .max = ARRAY_SIZE(array), .num = nump, \
83903 .ops = &param_ops_##type, \
83904 .elemsize = sizeof(array[0]), .elem = array }; \
83905 diff --git a/include/linux/mount.h b/include/linux/mount.h
83906 index 9262e4b..0a45f98 100644
83907 --- a/include/linux/mount.h
83908 +++ b/include/linux/mount.h
83909 @@ -66,7 +66,7 @@ struct vfsmount {
83910 struct dentry *mnt_root; /* root of the mounted tree */
83911 struct super_block *mnt_sb; /* pointer to superblock */
83912 int mnt_flags;
83913 -};
83914 +} __randomize_layout;
83915
83916 struct file; /* forward dec */
83917 struct path;
83918 diff --git a/include/linux/namei.h b/include/linux/namei.h
83919 index 492de72..1bddcd4 100644
83920 --- a/include/linux/namei.h
83921 +++ b/include/linux/namei.h
83922 @@ -19,7 +19,7 @@ struct nameidata {
83923 unsigned seq, m_seq;
83924 int last_type;
83925 unsigned depth;
83926 - char *saved_names[MAX_NESTED_LINKS + 1];
83927 + const char *saved_names[MAX_NESTED_LINKS + 1];
83928 };
83929
83930 /*
83931 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
83932
83933 extern void nd_jump_link(struct nameidata *nd, struct path *path);
83934
83935 -static inline void nd_set_link(struct nameidata *nd, char *path)
83936 +static inline void nd_set_link(struct nameidata *nd, const char *path)
83937 {
83938 nd->saved_names[nd->depth] = path;
83939 }
83940
83941 -static inline char *nd_get_link(struct nameidata *nd)
83942 +static inline const char *nd_get_link(const struct nameidata *nd)
83943 {
83944 return nd->saved_names[nd->depth];
83945 }
83946 diff --git a/include/linux/net.h b/include/linux/net.h
83947 index 17d8339..81656c0 100644
83948 --- a/include/linux/net.h
83949 +++ b/include/linux/net.h
83950 @@ -192,7 +192,7 @@ struct net_proto_family {
83951 int (*create)(struct net *net, struct socket *sock,
83952 int protocol, int kern);
83953 struct module *owner;
83954 -};
83955 +} __do_const;
83956
83957 struct iovec;
83958 struct kvec;
83959 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
83960 index c8e388e..5d8cd9b 100644
83961 --- a/include/linux/netdevice.h
83962 +++ b/include/linux/netdevice.h
83963 @@ -1147,6 +1147,7 @@ struct net_device_ops {
83964 void *priv);
83965 int (*ndo_get_lock_subclass)(struct net_device *dev);
83966 };
83967 +typedef struct net_device_ops __no_const net_device_ops_no_const;
83968
83969 /**
83970 * enum net_device_priv_flags - &struct net_device priv_flags
83971 @@ -1485,10 +1486,10 @@ struct net_device {
83972
83973 struct net_device_stats stats;
83974
83975 - atomic_long_t rx_dropped;
83976 - atomic_long_t tx_dropped;
83977 + atomic_long_unchecked_t rx_dropped;
83978 + atomic_long_unchecked_t tx_dropped;
83979
83980 - atomic_t carrier_changes;
83981 + atomic_unchecked_t carrier_changes;
83982
83983 #ifdef CONFIG_WIRELESS_EXT
83984 const struct iw_handler_def * wireless_handlers;
83985 diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
83986 index 2517ece..0bbfcfb 100644
83987 --- a/include/linux/netfilter.h
83988 +++ b/include/linux/netfilter.h
83989 @@ -85,7 +85,7 @@ struct nf_sockopt_ops {
83990 #endif
83991 /* Use the module struct to lock set/get code in place */
83992 struct module *owner;
83993 -};
83994 +} __do_const;
83995
83996 /* Function to register/unregister hook points. */
83997 int nf_register_hook(struct nf_hook_ops *reg);
83998 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
83999 index e955d47..04a5338 100644
84000 --- a/include/linux/netfilter/nfnetlink.h
84001 +++ b/include/linux/netfilter/nfnetlink.h
84002 @@ -19,7 +19,7 @@ struct nfnl_callback {
84003 const struct nlattr * const cda[]);
84004 const struct nla_policy *policy; /* netlink attribute policy */
84005 const u_int16_t attr_count; /* number of nlattr's */
84006 -};
84007 +} __do_const;
84008
84009 struct nfnetlink_subsystem {
84010 const char *name;
84011 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
84012 new file mode 100644
84013 index 0000000..33f4af8
84014 --- /dev/null
84015 +++ b/include/linux/netfilter/xt_gradm.h
84016 @@ -0,0 +1,9 @@
84017 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
84018 +#define _LINUX_NETFILTER_XT_GRADM_H 1
84019 +
84020 +struct xt_gradm_mtinfo {
84021 + __u16 flags;
84022 + __u16 invflags;
84023 +};
84024 +
84025 +#endif
84026 diff --git a/include/linux/nls.h b/include/linux/nls.h
84027 index 520681b..2b7fabb 100644
84028 --- a/include/linux/nls.h
84029 +++ b/include/linux/nls.h
84030 @@ -31,7 +31,7 @@ struct nls_table {
84031 const unsigned char *charset2upper;
84032 struct module *owner;
84033 struct nls_table *next;
84034 -};
84035 +} __do_const;
84036
84037 /* this value hold the maximum octet of charset */
84038 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
84039 @@ -46,7 +46,7 @@ enum utf16_endian {
84040 /* nls_base.c */
84041 extern int __register_nls(struct nls_table *, struct module *);
84042 extern int unregister_nls(struct nls_table *);
84043 -extern struct nls_table *load_nls(char *);
84044 +extern struct nls_table *load_nls(const char *);
84045 extern void unload_nls(struct nls_table *);
84046 extern struct nls_table *load_nls_default(void);
84047 #define register_nls(nls) __register_nls((nls), THIS_MODULE)
84048 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
84049 index d14a4c3..a078786 100644
84050 --- a/include/linux/notifier.h
84051 +++ b/include/linux/notifier.h
84052 @@ -54,7 +54,8 @@ struct notifier_block {
84053 notifier_fn_t notifier_call;
84054 struct notifier_block __rcu *next;
84055 int priority;
84056 -};
84057 +} __do_const;
84058 +typedef struct notifier_block __no_const notifier_block_no_const;
84059
84060 struct atomic_notifier_head {
84061 spinlock_t lock;
84062 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
84063 index b2a0f15..4d7da32 100644
84064 --- a/include/linux/oprofile.h
84065 +++ b/include/linux/oprofile.h
84066 @@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
84067 int oprofilefs_create_ro_ulong(struct dentry * root,
84068 char const * name, ulong * val);
84069
84070 -/** Create a file for read-only access to an atomic_t. */
84071 +/** Create a file for read-only access to an atomic_unchecked_t. */
84072 int oprofilefs_create_ro_atomic(struct dentry * root,
84073 - char const * name, atomic_t * val);
84074 + char const * name, atomic_unchecked_t * val);
84075
84076 /** create a directory */
84077 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
84078 diff --git a/include/linux/padata.h b/include/linux/padata.h
84079 index 4386946..f50c615 100644
84080 --- a/include/linux/padata.h
84081 +++ b/include/linux/padata.h
84082 @@ -129,7 +129,7 @@ struct parallel_data {
84083 struct padata_serial_queue __percpu *squeue;
84084 atomic_t reorder_objects;
84085 atomic_t refcnt;
84086 - atomic_t seq_nr;
84087 + atomic_unchecked_t seq_nr;
84088 struct padata_cpumask cpumask;
84089 spinlock_t lock ____cacheline_aligned;
84090 unsigned int processed;
84091 diff --git a/include/linux/path.h b/include/linux/path.h
84092 index d137218..be0c176 100644
84093 --- a/include/linux/path.h
84094 +++ b/include/linux/path.h
84095 @@ -1,13 +1,15 @@
84096 #ifndef _LINUX_PATH_H
84097 #define _LINUX_PATH_H
84098
84099 +#include <linux/compiler.h>
84100 +
84101 struct dentry;
84102 struct vfsmount;
84103
84104 struct path {
84105 struct vfsmount *mnt;
84106 struct dentry *dentry;
84107 -};
84108 +} __randomize_layout;
84109
84110 extern void path_get(const struct path *);
84111 extern void path_put(const struct path *);
84112 diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
84113 index 5f2e559..7d59314 100644
84114 --- a/include/linux/pci_hotplug.h
84115 +++ b/include/linux/pci_hotplug.h
84116 @@ -71,7 +71,8 @@ struct hotplug_slot_ops {
84117 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
84118 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
84119 int (*reset_slot) (struct hotplug_slot *slot, int probe);
84120 -};
84121 +} __do_const;
84122 +typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
84123
84124 /**
84125 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
84126 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
84127 index 707617a..28a2e7e 100644
84128 --- a/include/linux/perf_event.h
84129 +++ b/include/linux/perf_event.h
84130 @@ -339,8 +339,8 @@ struct perf_event {
84131
84132 enum perf_event_active_state state;
84133 unsigned int attach_state;
84134 - local64_t count;
84135 - atomic64_t child_count;
84136 + local64_t count; /* PaX: fix it one day */
84137 + atomic64_unchecked_t child_count;
84138
84139 /*
84140 * These are the total time in nanoseconds that the event
84141 @@ -391,8 +391,8 @@ struct perf_event {
84142 * These accumulate total time (in nanoseconds) that children
84143 * events have been enabled and running, respectively.
84144 */
84145 - atomic64_t child_total_time_enabled;
84146 - atomic64_t child_total_time_running;
84147 + atomic64_unchecked_t child_total_time_enabled;
84148 + atomic64_unchecked_t child_total_time_running;
84149
84150 /*
84151 * Protect attach/detach and child_list:
84152 @@ -722,7 +722,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
84153 entry->ip[entry->nr++] = ip;
84154 }
84155
84156 -extern int sysctl_perf_event_paranoid;
84157 +extern int sysctl_perf_event_legitimately_concerned;
84158 extern int sysctl_perf_event_mlock;
84159 extern int sysctl_perf_event_sample_rate;
84160 extern int sysctl_perf_cpu_time_max_percent;
84161 @@ -737,19 +737,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
84162 loff_t *ppos);
84163
84164
84165 +static inline bool perf_paranoid_any(void)
84166 +{
84167 + return sysctl_perf_event_legitimately_concerned > 2;
84168 +}
84169 +
84170 static inline bool perf_paranoid_tracepoint_raw(void)
84171 {
84172 - return sysctl_perf_event_paranoid > -1;
84173 + return sysctl_perf_event_legitimately_concerned > -1;
84174 }
84175
84176 static inline bool perf_paranoid_cpu(void)
84177 {
84178 - return sysctl_perf_event_paranoid > 0;
84179 + return sysctl_perf_event_legitimately_concerned > 0;
84180 }
84181
84182 static inline bool perf_paranoid_kernel(void)
84183 {
84184 - return sysctl_perf_event_paranoid > 1;
84185 + return sysctl_perf_event_legitimately_concerned > 1;
84186 }
84187
84188 extern void perf_event_init(void);
84189 @@ -880,7 +885,7 @@ struct perf_pmu_events_attr {
84190 struct device_attribute attr;
84191 u64 id;
84192 const char *event_str;
84193 -};
84194 +} __do_const;
84195
84196 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
84197 static struct perf_pmu_events_attr _var = { \
84198 diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
84199 index 1997ffc..4f1f44d 100644
84200 --- a/include/linux/pid_namespace.h
84201 +++ b/include/linux/pid_namespace.h
84202 @@ -44,7 +44,7 @@ struct pid_namespace {
84203 int hide_pid;
84204 int reboot; /* group exit code if this pidns was rebooted */
84205 unsigned int proc_inum;
84206 -};
84207 +} __randomize_layout;
84208
84209 extern struct pid_namespace init_pid_ns;
84210
84211 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
84212 index eb8b8ac..62649e1 100644
84213 --- a/include/linux/pipe_fs_i.h
84214 +++ b/include/linux/pipe_fs_i.h
84215 @@ -47,10 +47,10 @@ struct pipe_inode_info {
84216 struct mutex mutex;
84217 wait_queue_head_t wait;
84218 unsigned int nrbufs, curbuf, buffers;
84219 - unsigned int readers;
84220 - unsigned int writers;
84221 - unsigned int files;
84222 - unsigned int waiting_writers;
84223 + atomic_t readers;
84224 + atomic_t writers;
84225 + atomic_t files;
84226 + atomic_t waiting_writers;
84227 unsigned int r_counter;
84228 unsigned int w_counter;
84229 struct page *tmp_page;
84230 diff --git a/include/linux/pm.h b/include/linux/pm.h
84231 index 72c0fe0..26918ed 100644
84232 --- a/include/linux/pm.h
84233 +++ b/include/linux/pm.h
84234 @@ -620,6 +620,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
84235 struct dev_pm_domain {
84236 struct dev_pm_ops ops;
84237 };
84238 +typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
84239
84240 /*
84241 * The PM_EVENT_ messages are also used by drivers implementing the legacy
84242 diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
84243 index ebc4c76..7fab7b0 100644
84244 --- a/include/linux/pm_domain.h
84245 +++ b/include/linux/pm_domain.h
84246 @@ -44,11 +44,11 @@ struct gpd_dev_ops {
84247 int (*thaw_early)(struct device *dev);
84248 int (*thaw)(struct device *dev);
84249 bool (*active_wakeup)(struct device *dev);
84250 -};
84251 +} __no_const;
84252
84253 struct gpd_cpu_data {
84254 unsigned int saved_exit_latency;
84255 - struct cpuidle_state *idle_state;
84256 + cpuidle_state_no_const *idle_state;
84257 };
84258
84259 struct generic_pm_domain {
84260 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
84261 index 367f49b..d2f5a14 100644
84262 --- a/include/linux/pm_runtime.h
84263 +++ b/include/linux/pm_runtime.h
84264 @@ -125,7 +125,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
84265
84266 static inline void pm_runtime_mark_last_busy(struct device *dev)
84267 {
84268 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
84269 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
84270 }
84271
84272 #else /* !CONFIG_PM_RUNTIME */
84273 diff --git a/include/linux/pnp.h b/include/linux/pnp.h
84274 index 195aafc..49a7bc2 100644
84275 --- a/include/linux/pnp.h
84276 +++ b/include/linux/pnp.h
84277 @@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
84278 struct pnp_fixup {
84279 char id[7];
84280 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
84281 -};
84282 +} __do_const;
84283
84284 /* config parameters */
84285 #define PNP_CONFIG_NORMAL 0x0001
84286 diff --git a/include/linux/poison.h b/include/linux/poison.h
84287 index 2110a81..13a11bb 100644
84288 --- a/include/linux/poison.h
84289 +++ b/include/linux/poison.h
84290 @@ -19,8 +19,8 @@
84291 * under normal circumstances, used to verify that nobody uses
84292 * non-initialized list entries.
84293 */
84294 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
84295 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
84296 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
84297 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
84298
84299 /********** include/linux/timer.h **********/
84300 /*
84301 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
84302 index d8b187c3..9a9257a 100644
84303 --- a/include/linux/power/smartreflex.h
84304 +++ b/include/linux/power/smartreflex.h
84305 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
84306 int (*notify)(struct omap_sr *sr, u32 status);
84307 u8 notify_flags;
84308 u8 class_type;
84309 -};
84310 +} __do_const;
84311
84312 /**
84313 * struct omap_sr_nvalue_table - Smartreflex n-target value info
84314 diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
84315 index 4ea1d37..80f4b33 100644
84316 --- a/include/linux/ppp-comp.h
84317 +++ b/include/linux/ppp-comp.h
84318 @@ -84,7 +84,7 @@ struct compressor {
84319 struct module *owner;
84320 /* Extra skb space needed by the compressor algorithm */
84321 unsigned int comp_extra;
84322 -};
84323 +} __do_const;
84324
84325 /*
84326 * The return value from decompress routine is the length of the
84327 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
84328 index de83b4e..c4b997d 100644
84329 --- a/include/linux/preempt.h
84330 +++ b/include/linux/preempt.h
84331 @@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
84332 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
84333 #endif
84334
84335 +#define raw_preempt_count_add(val) __preempt_count_add(val)
84336 +#define raw_preempt_count_sub(val) __preempt_count_sub(val)
84337 +
84338 #define __preempt_count_inc() __preempt_count_add(1)
84339 #define __preempt_count_dec() __preempt_count_sub(1)
84340
84341 #define preempt_count_inc() preempt_count_add(1)
84342 +#define raw_preempt_count_inc() raw_preempt_count_add(1)
84343 #define preempt_count_dec() preempt_count_sub(1)
84344 +#define raw_preempt_count_dec() raw_preempt_count_sub(1)
84345
84346 #ifdef CONFIG_PREEMPT_COUNT
84347
84348 @@ -41,6 +46,12 @@ do { \
84349 barrier(); \
84350 } while (0)
84351
84352 +#define raw_preempt_disable() \
84353 +do { \
84354 + raw_preempt_count_inc(); \
84355 + barrier(); \
84356 +} while (0)
84357 +
84358 #define sched_preempt_enable_no_resched() \
84359 do { \
84360 barrier(); \
84361 @@ -49,6 +60,12 @@ do { \
84362
84363 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
84364
84365 +#define raw_preempt_enable_no_resched() \
84366 +do { \
84367 + barrier(); \
84368 + raw_preempt_count_dec(); \
84369 +} while (0)
84370 +
84371 #ifdef CONFIG_PREEMPT
84372 #define preempt_enable() \
84373 do { \
84374 @@ -113,8 +130,10 @@ do { \
84375 * region.
84376 */
84377 #define preempt_disable() barrier()
84378 +#define raw_preempt_disable() barrier()
84379 #define sched_preempt_enable_no_resched() barrier()
84380 #define preempt_enable_no_resched() barrier()
84381 +#define raw_preempt_enable_no_resched() barrier()
84382 #define preempt_enable() barrier()
84383 #define preempt_check_resched() do { } while (0)
84384
84385 @@ -128,11 +147,13 @@ do { \
84386 /*
84387 * Modules have no business playing preemption tricks.
84388 */
84389 +#ifndef CONFIG_PAX_KERNEXEC
84390 #undef sched_preempt_enable_no_resched
84391 #undef preempt_enable_no_resched
84392 #undef preempt_enable_no_resched_notrace
84393 #undef preempt_check_resched
84394 #endif
84395 +#endif
84396
84397 #define preempt_set_need_resched() \
84398 do { \
84399 diff --git a/include/linux/printk.h b/include/linux/printk.h
84400 index d78125f..7f36596 100644
84401 --- a/include/linux/printk.h
84402 +++ b/include/linux/printk.h
84403 @@ -124,6 +124,8 @@ static inline __printf(1, 2) __cold
84404 void early_printk(const char *s, ...) { }
84405 #endif
84406
84407 +extern int kptr_restrict;
84408 +
84409 #ifdef CONFIG_PRINTK
84410 asmlinkage __printf(5, 0)
84411 int vprintk_emit(int facility, int level,
84412 @@ -158,7 +160,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
84413
84414 extern int printk_delay_msec;
84415 extern int dmesg_restrict;
84416 -extern int kptr_restrict;
84417
84418 extern void wake_up_klogd(void);
84419
84420 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
84421 index 9d117f6..d832b31 100644
84422 --- a/include/linux/proc_fs.h
84423 +++ b/include/linux/proc_fs.h
84424 @@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
84425 extern struct proc_dir_entry *proc_symlink(const char *,
84426 struct proc_dir_entry *, const char *);
84427 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
84428 +extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
84429 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
84430 struct proc_dir_entry *, void *);
84431 +extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
84432 + struct proc_dir_entry *, void *);
84433 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
84434 struct proc_dir_entry *);
84435
84436 @@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
84437 return proc_create_data(name, mode, parent, proc_fops, NULL);
84438 }
84439
84440 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
84441 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
84442 +{
84443 +#ifdef CONFIG_GRKERNSEC_PROC_USER
84444 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
84445 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
84446 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
84447 +#else
84448 + return proc_create_data(name, mode, parent, proc_fops, NULL);
84449 +#endif
84450 +}
84451 +
84452 +
84453 extern void proc_set_size(struct proc_dir_entry *, loff_t);
84454 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
84455 extern void *PDE_DATA(const struct inode *);
84456 @@ -56,8 +72,12 @@ static inline struct proc_dir_entry *proc_symlink(const char *name,
84457 struct proc_dir_entry *parent,const char *dest) { return NULL;}
84458 static inline struct proc_dir_entry *proc_mkdir(const char *name,
84459 struct proc_dir_entry *parent) {return NULL;}
84460 +static inline struct proc_dir_entry *proc_mkdir_restrict(const char *name,
84461 + struct proc_dir_entry *parent) { return NULL; }
84462 static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
84463 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
84464 +static inline struct proc_dir_entry *proc_mkdir_data_restrict(const char *name,
84465 + umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
84466 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
84467 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
84468 #define proc_create(name, mode, parent, proc_fops) ({NULL;})
84469 @@ -77,7 +97,7 @@ static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *p
84470 static inline struct proc_dir_entry *proc_net_mkdir(
84471 struct net *net, const char *name, struct proc_dir_entry *parent)
84472 {
84473 - return proc_mkdir_data(name, 0, parent, net);
84474 + return proc_mkdir_data_restrict(name, 0, parent, net);
84475 }
84476
84477 #endif /* _LINUX_PROC_FS_H */
84478 diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
84479 index 34a1e10..70f6bde 100644
84480 --- a/include/linux/proc_ns.h
84481 +++ b/include/linux/proc_ns.h
84482 @@ -14,7 +14,7 @@ struct proc_ns_operations {
84483 void (*put)(void *ns);
84484 int (*install)(struct nsproxy *nsproxy, void *ns);
84485 unsigned int (*inum)(void *ns);
84486 -};
84487 +} __do_const __randomize_layout;
84488
84489 struct proc_ns {
84490 void *ns;
84491 diff --git a/include/linux/quota.h b/include/linux/quota.h
84492 index 80d345a..9e89a9a 100644
84493 --- a/include/linux/quota.h
84494 +++ b/include/linux/quota.h
84495 @@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
84496
84497 extern bool qid_eq(struct kqid left, struct kqid right);
84498 extern bool qid_lt(struct kqid left, struct kqid right);
84499 -extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
84500 +extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
84501 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
84502 extern bool qid_valid(struct kqid qid);
84503
84504 diff --git a/include/linux/random.h b/include/linux/random.h
84505 index 57fbbff..2170304 100644
84506 --- a/include/linux/random.h
84507 +++ b/include/linux/random.h
84508 @@ -9,9 +9,19 @@
84509 #include <uapi/linux/random.h>
84510
84511 extern void add_device_randomness(const void *, unsigned int);
84512 +
84513 +static inline void add_latent_entropy(void)
84514 +{
84515 +
84516 +#ifdef LATENT_ENTROPY_PLUGIN
84517 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
84518 +#endif
84519 +
84520 +}
84521 +
84522 extern void add_input_randomness(unsigned int type, unsigned int code,
84523 - unsigned int value);
84524 -extern void add_interrupt_randomness(int irq, int irq_flags);
84525 + unsigned int value) __latent_entropy;
84526 +extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
84527
84528 extern void get_random_bytes(void *buf, int nbytes);
84529 extern void get_random_bytes_arch(void *buf, int nbytes);
84530 @@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
84531 extern const struct file_operations random_fops, urandom_fops;
84532 #endif
84533
84534 -unsigned int get_random_int(void);
84535 +unsigned int __intentional_overflow(-1) get_random_int(void);
84536 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
84537
84538 -u32 prandom_u32(void);
84539 +u32 prandom_u32(void) __intentional_overflow(-1);
84540 void prandom_bytes(void *buf, int nbytes);
84541 void prandom_seed(u32 seed);
84542 void prandom_reseed_late(void);
84543 @@ -37,6 +47,11 @@ struct rnd_state {
84544 u32 prandom_u32_state(struct rnd_state *state);
84545 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
84546
84547 +static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
84548 +{
84549 + return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
84550 +}
84551 +
84552 /**
84553 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
84554 * @ep_ro: right open interval endpoint
84555 @@ -49,7 +64,7 @@ void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
84556 *
84557 * Returns: pseudo-random number in interval [0, ep_ro)
84558 */
84559 -static inline u32 prandom_u32_max(u32 ep_ro)
84560 +static inline u32 __intentional_overflow(-1) prandom_u32_max(u32 ep_ro)
84561 {
84562 return (u32)(((u64) prandom_u32() * ep_ro) >> 32);
84563 }
84564 diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
84565 index fea49b5..2ac22bb 100644
84566 --- a/include/linux/rbtree_augmented.h
84567 +++ b/include/linux/rbtree_augmented.h
84568 @@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
84569 old->rbaugmented = rbcompute(old); \
84570 } \
84571 rbstatic const struct rb_augment_callbacks rbname = { \
84572 - rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
84573 + .propagate = rbname ## _propagate, \
84574 + .copy = rbname ## _copy, \
84575 + .rotate = rbname ## _rotate \
84576 };
84577
84578
84579 diff --git a/include/linux/rculist.h b/include/linux/rculist.h
84580 index 372ad5e..d4373f8 100644
84581 --- a/include/linux/rculist.h
84582 +++ b/include/linux/rculist.h
84583 @@ -29,8 +29,8 @@
84584 */
84585 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
84586 {
84587 - ACCESS_ONCE(list->next) = list;
84588 - ACCESS_ONCE(list->prev) = list;
84589 + ACCESS_ONCE_RW(list->next) = list;
84590 + ACCESS_ONCE_RW(list->prev) = list;
84591 }
84592
84593 /*
84594 @@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
84595 struct list_head *prev, struct list_head *next);
84596 #endif
84597
84598 +void __pax_list_add_rcu(struct list_head *new,
84599 + struct list_head *prev, struct list_head *next);
84600 +
84601 /**
84602 * list_add_rcu - add a new entry to rcu-protected list
84603 * @new: new entry to be added
84604 @@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
84605 __list_add_rcu(new, head, head->next);
84606 }
84607
84608 +static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
84609 +{
84610 + __pax_list_add_rcu(new, head, head->next);
84611 +}
84612 +
84613 /**
84614 * list_add_tail_rcu - add a new entry to rcu-protected list
84615 * @new: new entry to be added
84616 @@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
84617 __list_add_rcu(new, head->prev, head);
84618 }
84619
84620 +static inline void pax_list_add_tail_rcu(struct list_head *new,
84621 + struct list_head *head)
84622 +{
84623 + __pax_list_add_rcu(new, head->prev, head);
84624 +}
84625 +
84626 /**
84627 * list_del_rcu - deletes entry from list without re-initialization
84628 * @entry: the element to delete from the list.
84629 @@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
84630 entry->prev = LIST_POISON2;
84631 }
84632
84633 +extern void pax_list_del_rcu(struct list_head *entry);
84634 +
84635 /**
84636 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
84637 * @n: the element to delete from the hash list.
84638 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
84639 index 48bf152..d38b785 100644
84640 --- a/include/linux/reboot.h
84641 +++ b/include/linux/reboot.h
84642 @@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
84643 */
84644
84645 extern void migrate_to_reboot_cpu(void);
84646 -extern void machine_restart(char *cmd);
84647 -extern void machine_halt(void);
84648 -extern void machine_power_off(void);
84649 +extern void machine_restart(char *cmd) __noreturn;
84650 +extern void machine_halt(void) __noreturn;
84651 +extern void machine_power_off(void) __noreturn;
84652
84653 extern void machine_shutdown(void);
84654 struct pt_regs;
84655 @@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
84656 */
84657
84658 extern void kernel_restart_prepare(char *cmd);
84659 -extern void kernel_restart(char *cmd);
84660 -extern void kernel_halt(void);
84661 -extern void kernel_power_off(void);
84662 +extern void kernel_restart(char *cmd) __noreturn;
84663 +extern void kernel_halt(void) __noreturn;
84664 +extern void kernel_power_off(void) __noreturn;
84665
84666 extern int C_A_D; /* for sysctl */
84667 void ctrl_alt_del(void);
84668 @@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
84669 * Emergency restart, callable from an interrupt handler.
84670 */
84671
84672 -extern void emergency_restart(void);
84673 +extern void emergency_restart(void) __noreturn;
84674 #include <asm/emergency-restart.h>
84675
84676 #endif /* _LINUX_REBOOT_H */
84677 diff --git a/include/linux/regset.h b/include/linux/regset.h
84678 index 8e0c9fe..ac4d221 100644
84679 --- a/include/linux/regset.h
84680 +++ b/include/linux/regset.h
84681 @@ -161,7 +161,8 @@ struct user_regset {
84682 unsigned int align;
84683 unsigned int bias;
84684 unsigned int core_note_type;
84685 -};
84686 +} __do_const;
84687 +typedef struct user_regset __no_const user_regset_no_const;
84688
84689 /**
84690 * struct user_regset_view - available regsets
84691 diff --git a/include/linux/relay.h b/include/linux/relay.h
84692 index d7c8359..818daf5 100644
84693 --- a/include/linux/relay.h
84694 +++ b/include/linux/relay.h
84695 @@ -157,7 +157,7 @@ struct rchan_callbacks
84696 * The callback should return 0 if successful, negative if not.
84697 */
84698 int (*remove_buf_file)(struct dentry *dentry);
84699 -};
84700 +} __no_const;
84701
84702 /*
84703 * CONFIG_RELAY kernel API, kernel/relay.c
84704 diff --git a/include/linux/rio.h b/include/linux/rio.h
84705 index 6bda06f..bf39a9b 100644
84706 --- a/include/linux/rio.h
84707 +++ b/include/linux/rio.h
84708 @@ -358,7 +358,7 @@ struct rio_ops {
84709 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
84710 u64 rstart, u32 size, u32 flags);
84711 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
84712 -};
84713 +} __no_const;
84714
84715 #define RIO_RESOURCE_MEM 0x00000100
84716 #define RIO_RESOURCE_DOORBELL 0x00000200
84717 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
84718 index be57450..31cf65e 100644
84719 --- a/include/linux/rmap.h
84720 +++ b/include/linux/rmap.h
84721 @@ -144,8 +144,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
84722 void anon_vma_init(void); /* create anon_vma_cachep */
84723 int anon_vma_prepare(struct vm_area_struct *);
84724 void unlink_anon_vmas(struct vm_area_struct *);
84725 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
84726 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
84727 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
84728 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
84729
84730 static inline void anon_vma_merge(struct vm_area_struct *vma,
84731 struct vm_area_struct *next)
84732 diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
84733 index ed8f9e7..999bc96 100644
84734 --- a/include/linux/scatterlist.h
84735 +++ b/include/linux/scatterlist.h
84736 @@ -1,6 +1,7 @@
84737 #ifndef _LINUX_SCATTERLIST_H
84738 #define _LINUX_SCATTERLIST_H
84739
84740 +#include <linux/sched.h>
84741 #include <linux/string.h>
84742 #include <linux/bug.h>
84743 #include <linux/mm.h>
84744 @@ -114,6 +115,12 @@ static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
84745 #ifdef CONFIG_DEBUG_SG
84746 BUG_ON(!virt_addr_valid(buf));
84747 #endif
84748 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
84749 + if (object_starts_on_stack(buf)) {
84750 + void *adjbuf = buf - current->stack + current->lowmem_stack;
84751 + sg_set_page(sg, virt_to_page(adjbuf), buflen, offset_in_page(adjbuf));
84752 + } else
84753 +#endif
84754 sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
84755 }
84756
84757 diff --git a/include/linux/sched.h b/include/linux/sched.h
84758 index 2b1d9e9..10ba706 100644
84759 --- a/include/linux/sched.h
84760 +++ b/include/linux/sched.h
84761 @@ -132,6 +132,7 @@ struct fs_struct;
84762 struct perf_event_context;
84763 struct blk_plug;
84764 struct filename;
84765 +struct linux_binprm;
84766
84767 #define VMACACHE_BITS 2
84768 #define VMACACHE_SIZE (1U << VMACACHE_BITS)
84769 @@ -374,7 +375,7 @@ extern char __sched_text_start[], __sched_text_end[];
84770 extern int in_sched_functions(unsigned long addr);
84771
84772 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
84773 -extern signed long schedule_timeout(signed long timeout);
84774 +extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
84775 extern signed long schedule_timeout_interruptible(signed long timeout);
84776 extern signed long schedule_timeout_killable(signed long timeout);
84777 extern signed long schedule_timeout_uninterruptible(signed long timeout);
84778 @@ -385,6 +386,19 @@ struct nsproxy;
84779 struct user_namespace;
84780
84781 #ifdef CONFIG_MMU
84782 +
84783 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
84784 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
84785 +#else
84786 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
84787 +{
84788 + return 0;
84789 +}
84790 +#endif
84791 +
84792 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
84793 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
84794 +
84795 extern void arch_pick_mmap_layout(struct mm_struct *mm);
84796 extern unsigned long
84797 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
84798 @@ -682,6 +696,17 @@ struct signal_struct {
84799 #ifdef CONFIG_TASKSTATS
84800 struct taskstats *stats;
84801 #endif
84802 +
84803 +#ifdef CONFIG_GRKERNSEC
84804 + u32 curr_ip;
84805 + u32 saved_ip;
84806 + u32 gr_saddr;
84807 + u32 gr_daddr;
84808 + u16 gr_sport;
84809 + u16 gr_dport;
84810 + u8 used_accept:1;
84811 +#endif
84812 +
84813 #ifdef CONFIG_AUDIT
84814 unsigned audit_tty;
84815 unsigned audit_tty_log_passwd;
84816 @@ -708,7 +733,7 @@ struct signal_struct {
84817 struct mutex cred_guard_mutex; /* guard against foreign influences on
84818 * credential calculations
84819 * (notably. ptrace) */
84820 -};
84821 +} __randomize_layout;
84822
84823 /*
84824 * Bits in flags field of signal_struct.
84825 @@ -761,6 +786,14 @@ struct user_struct {
84826 struct key *session_keyring; /* UID's default session keyring */
84827 #endif
84828
84829 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
84830 + unsigned char kernel_banned;
84831 +#endif
84832 +#ifdef CONFIG_GRKERNSEC_BRUTE
84833 + unsigned char suid_banned;
84834 + unsigned long suid_ban_expires;
84835 +#endif
84836 +
84837 /* Hash table maintenance information */
84838 struct hlist_node uidhash_node;
84839 kuid_t uid;
84840 @@ -768,7 +801,7 @@ struct user_struct {
84841 #ifdef CONFIG_PERF_EVENTS
84842 atomic_long_t locked_vm;
84843 #endif
84844 -};
84845 +} __randomize_layout;
84846
84847 extern int uids_sysfs_init(void);
84848
84849 @@ -1224,6 +1257,9 @@ enum perf_event_task_context {
84850 struct task_struct {
84851 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
84852 void *stack;
84853 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
84854 + void *lowmem_stack;
84855 +#endif
84856 atomic_t usage;
84857 unsigned int flags; /* per process flags, defined below */
84858 unsigned int ptrace;
84859 @@ -1345,8 +1381,8 @@ struct task_struct {
84860 struct list_head thread_node;
84861
84862 struct completion *vfork_done; /* for vfork() */
84863 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
84864 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
84865 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
84866 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
84867
84868 cputime_t utime, stime, utimescaled, stimescaled;
84869 cputime_t gtime;
84870 @@ -1371,11 +1407,6 @@ struct task_struct {
84871 struct task_cputime cputime_expires;
84872 struct list_head cpu_timers[3];
84873
84874 -/* process credentials */
84875 - const struct cred __rcu *real_cred; /* objective and real subjective task
84876 - * credentials (COW) */
84877 - const struct cred __rcu *cred; /* effective (overridable) subjective task
84878 - * credentials (COW) */
84879 char comm[TASK_COMM_LEN]; /* executable name excluding path
84880 - access with [gs]et_task_comm (which lock
84881 it with task_lock())
84882 @@ -1393,6 +1424,10 @@ struct task_struct {
84883 #endif
84884 /* CPU-specific state of this task */
84885 struct thread_struct thread;
84886 +/* thread_info moved to task_struct */
84887 +#ifdef CONFIG_X86
84888 + struct thread_info tinfo;
84889 +#endif
84890 /* filesystem information */
84891 struct fs_struct *fs;
84892 /* open file information */
84893 @@ -1467,6 +1502,10 @@ struct task_struct {
84894 gfp_t lockdep_reclaim_gfp;
84895 #endif
84896
84897 +/* process credentials */
84898 + const struct cred __rcu *real_cred; /* objective and real subjective task
84899 + * credentials (COW) */
84900 +
84901 /* journalling filesystem info */
84902 void *journal_info;
84903
84904 @@ -1505,6 +1544,10 @@ struct task_struct {
84905 /* cg_list protected by css_set_lock and tsk->alloc_lock */
84906 struct list_head cg_list;
84907 #endif
84908 +
84909 + const struct cred __rcu *cred; /* effective (overridable) subjective task
84910 + * credentials (COW) */
84911 +
84912 #ifdef CONFIG_FUTEX
84913 struct robust_list_head __user *robust_list;
84914 #ifdef CONFIG_COMPAT
84915 @@ -1644,7 +1687,78 @@ struct task_struct {
84916 unsigned int sequential_io;
84917 unsigned int sequential_io_avg;
84918 #endif
84919 -};
84920 +
84921 +#ifdef CONFIG_GRKERNSEC
84922 + /* grsecurity */
84923 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
84924 + u64 exec_id;
84925 +#endif
84926 +#ifdef CONFIG_GRKERNSEC_SETXID
84927 + const struct cred *delayed_cred;
84928 +#endif
84929 + struct dentry *gr_chroot_dentry;
84930 + struct acl_subject_label *acl;
84931 + struct acl_subject_label *tmpacl;
84932 + struct acl_role_label *role;
84933 + struct file *exec_file;
84934 + unsigned long brute_expires;
84935 + u16 acl_role_id;
84936 + u8 inherited;
84937 + /* is this the task that authenticated to the special role */
84938 + u8 acl_sp_role;
84939 + u8 is_writable;
84940 + u8 brute;
84941 + u8 gr_is_chrooted;
84942 +#endif
84943 +
84944 +} __randomize_layout;
84945 +
84946 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
84947 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
84948 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
84949 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
84950 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
84951 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
84952 +
84953 +#ifdef CONFIG_PAX_SOFTMODE
84954 +extern int pax_softmode;
84955 +#endif
84956 +
84957 +extern int pax_check_flags(unsigned long *);
84958 +#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
84959 +
84960 +/* if tsk != current then task_lock must be held on it */
84961 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
84962 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
84963 +{
84964 + if (likely(tsk->mm))
84965 + return tsk->mm->pax_flags;
84966 + else
84967 + return 0UL;
84968 +}
84969 +
84970 +/* if tsk != current then task_lock must be held on it */
84971 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
84972 +{
84973 + if (likely(tsk->mm)) {
84974 + tsk->mm->pax_flags = flags;
84975 + return 0;
84976 + }
84977 + return -EINVAL;
84978 +}
84979 +#endif
84980 +
84981 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
84982 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
84983 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
84984 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
84985 +#endif
84986 +
84987 +struct path;
84988 +extern char *pax_get_path(const struct path *path, char *buf, int buflen);
84989 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
84990 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
84991 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
84992
84993 /* Future-safe accessor for struct task_struct's cpus_allowed. */
84994 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
84995 @@ -1726,7 +1840,7 @@ struct pid_namespace;
84996 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
84997 struct pid_namespace *ns);
84998
84999 -static inline pid_t task_pid_nr(struct task_struct *tsk)
85000 +static inline pid_t task_pid_nr(const struct task_struct *tsk)
85001 {
85002 return tsk->pid;
85003 }
85004 @@ -2097,6 +2211,25 @@ extern u64 sched_clock_cpu(int cpu);
85005
85006 extern void sched_clock_init(void);
85007
85008 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
85009 +static inline void populate_stack(void)
85010 +{
85011 + struct task_struct *curtask = current;
85012 + int c;
85013 + int *ptr = curtask->stack;
85014 + int *end = curtask->stack + THREAD_SIZE;
85015 +
85016 + while (ptr < end) {
85017 + c = *(volatile int *)ptr;
85018 + ptr += PAGE_SIZE/sizeof(int);
85019 + }
85020 +}
85021 +#else
85022 +static inline void populate_stack(void)
85023 +{
85024 +}
85025 +#endif
85026 +
85027 #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
85028 static inline void sched_clock_tick(void)
85029 {
85030 @@ -2230,7 +2363,9 @@ void yield(void);
85031 extern struct exec_domain default_exec_domain;
85032
85033 union thread_union {
85034 +#ifndef CONFIG_X86
85035 struct thread_info thread_info;
85036 +#endif
85037 unsigned long stack[THREAD_SIZE/sizeof(long)];
85038 };
85039
85040 @@ -2263,6 +2398,7 @@ extern struct pid_namespace init_pid_ns;
85041 */
85042
85043 extern struct task_struct *find_task_by_vpid(pid_t nr);
85044 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
85045 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
85046 struct pid_namespace *ns);
85047
85048 @@ -2427,7 +2563,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
85049 extern void exit_itimers(struct signal_struct *);
85050 extern void flush_itimer_signals(void);
85051
85052 -extern void do_group_exit(int);
85053 +extern __noreturn void do_group_exit(int);
85054
85055 extern int do_execve(struct filename *,
85056 const char __user * const __user *,
85057 @@ -2642,9 +2778,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
85058
85059 #endif
85060
85061 -static inline int object_is_on_stack(void *obj)
85062 +static inline int object_starts_on_stack(const void *obj)
85063 {
85064 - void *stack = task_stack_page(current);
85065 + const void *stack = task_stack_page(current);
85066
85067 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
85068 }
85069 diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
85070 index 596a0e0..bea77ec 100644
85071 --- a/include/linux/sched/sysctl.h
85072 +++ b/include/linux/sched/sysctl.h
85073 @@ -34,6 +34,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
85074 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
85075
85076 extern int sysctl_max_map_count;
85077 +extern unsigned long sysctl_heap_stack_gap;
85078
85079 extern unsigned int sysctl_sched_latency;
85080 extern unsigned int sysctl_sched_min_granularity;
85081 diff --git a/include/linux/security.h b/include/linux/security.h
85082 index 623f90e..90b39da 100644
85083 --- a/include/linux/security.h
85084 +++ b/include/linux/security.h
85085 @@ -27,6 +27,7 @@
85086 #include <linux/slab.h>
85087 #include <linux/err.h>
85088 #include <linux/string.h>
85089 +#include <linux/grsecurity.h>
85090
85091 struct linux_binprm;
85092 struct cred;
85093 @@ -116,8 +117,6 @@ struct seq_file;
85094
85095 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
85096
85097 -void reset_security_ops(void);
85098 -
85099 #ifdef CONFIG_MMU
85100 extern unsigned long mmap_min_addr;
85101 extern unsigned long dac_mmap_min_addr;
85102 @@ -1729,7 +1728,7 @@ struct security_operations {
85103 struct audit_context *actx);
85104 void (*audit_rule_free) (void *lsmrule);
85105 #endif /* CONFIG_AUDIT */
85106 -};
85107 +} __randomize_layout;
85108
85109 /* prototypes */
85110 extern int security_init(void);
85111 diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
85112 index dc368b8..e895209 100644
85113 --- a/include/linux/semaphore.h
85114 +++ b/include/linux/semaphore.h
85115 @@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
85116 }
85117
85118 extern void down(struct semaphore *sem);
85119 -extern int __must_check down_interruptible(struct semaphore *sem);
85120 +extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
85121 extern int __must_check down_killable(struct semaphore *sem);
85122 extern int __must_check down_trylock(struct semaphore *sem);
85123 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
85124 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
85125 index 52e0097..383f21d 100644
85126 --- a/include/linux/seq_file.h
85127 +++ b/include/linux/seq_file.h
85128 @@ -27,6 +27,9 @@ struct seq_file {
85129 struct mutex lock;
85130 const struct seq_operations *op;
85131 int poll_event;
85132 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
85133 + u64 exec_id;
85134 +#endif
85135 #ifdef CONFIG_USER_NS
85136 struct user_namespace *user_ns;
85137 #endif
85138 @@ -39,6 +42,7 @@ struct seq_operations {
85139 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
85140 int (*show) (struct seq_file *m, void *v);
85141 };
85142 +typedef struct seq_operations __no_const seq_operations_no_const;
85143
85144 #define SEQ_SKIP 1
85145
85146 @@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
85147
85148 char *mangle_path(char *s, const char *p, const char *esc);
85149 int seq_open(struct file *, const struct seq_operations *);
85150 +int seq_open_restrict(struct file *, const struct seq_operations *);
85151 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
85152 loff_t seq_lseek(struct file *, loff_t, int);
85153 int seq_release(struct inode *, struct file *);
85154 @@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
85155 }
85156
85157 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
85158 +int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
85159 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
85160 int single_release(struct inode *, struct file *);
85161 void *__seq_open_private(struct file *, const struct seq_operations *, int);
85162 diff --git a/include/linux/shm.h b/include/linux/shm.h
85163 index 6fb8016..ab4465e 100644
85164 --- a/include/linux/shm.h
85165 +++ b/include/linux/shm.h
85166 @@ -22,6 +22,10 @@ struct shmid_kernel /* private to the kernel */
85167 /* The task created the shm object. NULL if the task is dead. */
85168 struct task_struct *shm_creator;
85169 struct list_head shm_clist; /* list by creator */
85170 +#ifdef CONFIG_GRKERNSEC
85171 + u64 shm_createtime;
85172 + pid_t shm_lapid;
85173 +#endif
85174 };
85175
85176 /* shm_mode upper byte flags */
85177 diff --git a/include/linux/signal.h b/include/linux/signal.h
85178 index 750196f..ae7a3a4 100644
85179 --- a/include/linux/signal.h
85180 +++ b/include/linux/signal.h
85181 @@ -292,7 +292,7 @@ static inline void allow_signal(int sig)
85182 * know it'll be handled, so that they don't get converted to
85183 * SIGKILL or just silently dropped.
85184 */
85185 - kernel_sigaction(sig, (__force __sighandler_t)2);
85186 + kernel_sigaction(sig, (__force_user __sighandler_t)2);
85187 }
85188
85189 static inline void disallow_signal(int sig)
85190 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
85191 index abde271..bc9ece1 100644
85192 --- a/include/linux/skbuff.h
85193 +++ b/include/linux/skbuff.h
85194 @@ -728,7 +728,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
85195 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
85196 int node);
85197 struct sk_buff *build_skb(void *data, unsigned int frag_size);
85198 -static inline struct sk_buff *alloc_skb(unsigned int size,
85199 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
85200 gfp_t priority)
85201 {
85202 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
85203 @@ -1845,7 +1845,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
85204 return skb->inner_transport_header - skb->inner_network_header;
85205 }
85206
85207 -static inline int skb_network_offset(const struct sk_buff *skb)
85208 +static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
85209 {
85210 return skb_network_header(skb) - skb->data;
85211 }
85212 @@ -1917,7 +1917,7 @@ static inline void skb_pop_rcv_encapsulation(struct sk_buff *skb)
85213 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
85214 */
85215 #ifndef NET_SKB_PAD
85216 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
85217 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
85218 #endif
85219
85220 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
85221 @@ -2524,7 +2524,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
85222 int *err);
85223 unsigned int datagram_poll(struct file *file, struct socket *sock,
85224 struct poll_table_struct *wait);
85225 -int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
85226 +int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
85227 struct iovec *to, int size);
85228 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
85229 struct iovec *iov);
85230 @@ -2918,6 +2918,9 @@ static inline void nf_reset(struct sk_buff *skb)
85231 nf_bridge_put(skb->nf_bridge);
85232 skb->nf_bridge = NULL;
85233 #endif
85234 +#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
85235 + skb->nf_trace = 0;
85236 +#endif
85237 }
85238
85239 static inline void nf_reset_trace(struct sk_buff *skb)
85240 diff --git a/include/linux/slab.h b/include/linux/slab.h
85241 index 1d9abb7..b1e8b10 100644
85242 --- a/include/linux/slab.h
85243 +++ b/include/linux/slab.h
85244 @@ -14,15 +14,29 @@
85245 #include <linux/gfp.h>
85246 #include <linux/types.h>
85247 #include <linux/workqueue.h>
85248 -
85249 +#include <linux/err.h>
85250
85251 /*
85252 * Flags to pass to kmem_cache_create().
85253 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
85254 */
85255 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
85256 +
85257 +#ifdef CONFIG_PAX_USERCOPY_SLABS
85258 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
85259 +#else
85260 +#define SLAB_USERCOPY 0x00000000UL
85261 +#endif
85262 +
85263 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
85264 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
85265 +
85266 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
85267 +#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
85268 +#else
85269 +#define SLAB_NO_SANITIZE 0x00000000UL
85270 +#endif
85271 +
85272 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
85273 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
85274 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
85275 @@ -98,10 +112,13 @@
85276 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
85277 * Both make kfree a no-op.
85278 */
85279 -#define ZERO_SIZE_PTR ((void *)16)
85280 +#define ZERO_SIZE_PTR \
85281 +({ \
85282 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
85283 + (void *)(-MAX_ERRNO-1L); \
85284 +})
85285
85286 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
85287 - (unsigned long)ZERO_SIZE_PTR)
85288 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
85289
85290 #include <linux/kmemleak.h>
85291
85292 @@ -144,6 +161,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
85293 void kfree(const void *);
85294 void kzfree(const void *);
85295 size_t ksize(const void *);
85296 +const char *check_heap_object(const void *ptr, unsigned long n);
85297 +bool is_usercopy_object(const void *ptr);
85298
85299 /*
85300 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
85301 @@ -176,7 +195,7 @@ struct kmem_cache {
85302 unsigned int align; /* Alignment as calculated */
85303 unsigned long flags; /* Active flags on the slab */
85304 const char *name; /* Slab name for sysfs */
85305 - int refcount; /* Use counter */
85306 + atomic_t refcount; /* Use counter */
85307 void (*ctor)(void *); /* Called on object slot creation */
85308 struct list_head list; /* List of all slab caches on the system */
85309 };
85310 @@ -261,6 +280,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
85311 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
85312 #endif
85313
85314 +#ifdef CONFIG_PAX_USERCOPY_SLABS
85315 +extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
85316 +#endif
85317 +
85318 /*
85319 * Figure out which kmalloc slab an allocation of a certain size
85320 * belongs to.
85321 @@ -269,7 +292,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
85322 * 2 = 120 .. 192 bytes
85323 * n = 2^(n-1) .. 2^n -1
85324 */
85325 -static __always_inline int kmalloc_index(size_t size)
85326 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
85327 {
85328 if (!size)
85329 return 0;
85330 @@ -312,11 +335,11 @@ static __always_inline int kmalloc_index(size_t size)
85331 }
85332 #endif /* !CONFIG_SLOB */
85333
85334 -void *__kmalloc(size_t size, gfp_t flags);
85335 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
85336 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
85337
85338 #ifdef CONFIG_NUMA
85339 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
85340 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
85341 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
85342 #else
85343 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
85344 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
85345 index 8235dfb..47ce586 100644
85346 --- a/include/linux/slab_def.h
85347 +++ b/include/linux/slab_def.h
85348 @@ -38,7 +38,7 @@ struct kmem_cache {
85349 /* 4) cache creation/removal */
85350 const char *name;
85351 struct list_head list;
85352 - int refcount;
85353 + atomic_t refcount;
85354 int object_size;
85355 int align;
85356
85357 @@ -54,10 +54,14 @@ struct kmem_cache {
85358 unsigned long node_allocs;
85359 unsigned long node_frees;
85360 unsigned long node_overflow;
85361 - atomic_t allochit;
85362 - atomic_t allocmiss;
85363 - atomic_t freehit;
85364 - atomic_t freemiss;
85365 + atomic_unchecked_t allochit;
85366 + atomic_unchecked_t allocmiss;
85367 + atomic_unchecked_t freehit;
85368 + atomic_unchecked_t freemiss;
85369 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
85370 + atomic_unchecked_t sanitized;
85371 + atomic_unchecked_t not_sanitized;
85372 +#endif
85373
85374 /*
85375 * If debugging is enabled, then the allocator can add additional
85376 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
85377 index d82abd4..408c3a0 100644
85378 --- a/include/linux/slub_def.h
85379 +++ b/include/linux/slub_def.h
85380 @@ -74,7 +74,7 @@ struct kmem_cache {
85381 struct kmem_cache_order_objects max;
85382 struct kmem_cache_order_objects min;
85383 gfp_t allocflags; /* gfp flags to use on each alloc */
85384 - int refcount; /* Refcount for slab cache destroy */
85385 + atomic_t refcount; /* Refcount for slab cache destroy */
85386 void (*ctor)(void *);
85387 int inuse; /* Offset to metadata */
85388 int align; /* Alignment */
85389 diff --git a/include/linux/smp.h b/include/linux/smp.h
85390 index 34347f2..8739978 100644
85391 --- a/include/linux/smp.h
85392 +++ b/include/linux/smp.h
85393 @@ -174,7 +174,9 @@ static inline void kick_all_cpus_sync(void) { }
85394 #endif
85395
85396 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
85397 +#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
85398 #define put_cpu() preempt_enable()
85399 +#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
85400
85401 /*
85402 * Callback to arch code if there's nosmp or maxcpus=0 on the
85403 diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
85404 index 46cca4c..3323536 100644
85405 --- a/include/linux/sock_diag.h
85406 +++ b/include/linux/sock_diag.h
85407 @@ -11,7 +11,7 @@ struct sock;
85408 struct sock_diag_handler {
85409 __u8 family;
85410 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
85411 -};
85412 +} __do_const;
85413
85414 int sock_diag_register(const struct sock_diag_handler *h);
85415 void sock_diag_unregister(const struct sock_diag_handler *h);
85416 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
85417 index 680f9a3..f13aeb0 100644
85418 --- a/include/linux/sonet.h
85419 +++ b/include/linux/sonet.h
85420 @@ -7,7 +7,7 @@
85421 #include <uapi/linux/sonet.h>
85422
85423 struct k_sonet_stats {
85424 -#define __HANDLE_ITEM(i) atomic_t i
85425 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
85426 __SONET_ITEMS
85427 #undef __HANDLE_ITEM
85428 };
85429 diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
85430 index 07d8e53..dc934c9 100644
85431 --- a/include/linux/sunrpc/addr.h
85432 +++ b/include/linux/sunrpc/addr.h
85433 @@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
85434 {
85435 switch (sap->sa_family) {
85436 case AF_INET:
85437 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
85438 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
85439 case AF_INET6:
85440 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
85441 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
85442 }
85443 return 0;
85444 }
85445 @@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
85446 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
85447 const struct sockaddr *src)
85448 {
85449 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
85450 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
85451 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
85452
85453 dsin->sin_family = ssin->sin_family;
85454 @@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
85455 if (sa->sa_family != AF_INET6)
85456 return 0;
85457
85458 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
85459 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
85460 }
85461
85462 #endif /* _LINUX_SUNRPC_ADDR_H */
85463 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
85464 index 70736b9..37f33db 100644
85465 --- a/include/linux/sunrpc/clnt.h
85466 +++ b/include/linux/sunrpc/clnt.h
85467 @@ -97,7 +97,7 @@ struct rpc_procinfo {
85468 unsigned int p_timer; /* Which RTT timer to use */
85469 u32 p_statidx; /* Which procedure to account */
85470 const char * p_name; /* name of procedure */
85471 -};
85472 +} __do_const;
85473
85474 #ifdef __KERNEL__
85475
85476 diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
85477 index cf61ecd..a4a9bc0 100644
85478 --- a/include/linux/sunrpc/svc.h
85479 +++ b/include/linux/sunrpc/svc.h
85480 @@ -417,7 +417,7 @@ struct svc_procedure {
85481 unsigned int pc_count; /* call count */
85482 unsigned int pc_cachetype; /* cache info (NFS) */
85483 unsigned int pc_xdrressize; /* maximum size of XDR reply */
85484 -};
85485 +} __do_const;
85486
85487 /*
85488 * Function prototypes.
85489 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
85490 index 975da75..318c083 100644
85491 --- a/include/linux/sunrpc/svc_rdma.h
85492 +++ b/include/linux/sunrpc/svc_rdma.h
85493 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
85494 extern unsigned int svcrdma_max_requests;
85495 extern unsigned int svcrdma_max_req_size;
85496
85497 -extern atomic_t rdma_stat_recv;
85498 -extern atomic_t rdma_stat_read;
85499 -extern atomic_t rdma_stat_write;
85500 -extern atomic_t rdma_stat_sq_starve;
85501 -extern atomic_t rdma_stat_rq_starve;
85502 -extern atomic_t rdma_stat_rq_poll;
85503 -extern atomic_t rdma_stat_rq_prod;
85504 -extern atomic_t rdma_stat_sq_poll;
85505 -extern atomic_t rdma_stat_sq_prod;
85506 +extern atomic_unchecked_t rdma_stat_recv;
85507 +extern atomic_unchecked_t rdma_stat_read;
85508 +extern atomic_unchecked_t rdma_stat_write;
85509 +extern atomic_unchecked_t rdma_stat_sq_starve;
85510 +extern atomic_unchecked_t rdma_stat_rq_starve;
85511 +extern atomic_unchecked_t rdma_stat_rq_poll;
85512 +extern atomic_unchecked_t rdma_stat_rq_prod;
85513 +extern atomic_unchecked_t rdma_stat_sq_poll;
85514 +extern atomic_unchecked_t rdma_stat_sq_prod;
85515
85516 #define RPCRDMA_VERSION 1
85517
85518 diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
85519 index 8d71d65..f79586e 100644
85520 --- a/include/linux/sunrpc/svcauth.h
85521 +++ b/include/linux/sunrpc/svcauth.h
85522 @@ -120,7 +120,7 @@ struct auth_ops {
85523 int (*release)(struct svc_rqst *rq);
85524 void (*domain_release)(struct auth_domain *);
85525 int (*set_client)(struct svc_rqst *rq);
85526 -};
85527 +} __do_const;
85528
85529 #define SVC_GARBAGE 1
85530 #define SVC_SYSERR 2
85531 diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
85532 index e7a018e..49f8b17 100644
85533 --- a/include/linux/swiotlb.h
85534 +++ b/include/linux/swiotlb.h
85535 @@ -60,7 +60,8 @@ extern void
85536
85537 extern void
85538 swiotlb_free_coherent(struct device *hwdev, size_t size,
85539 - void *vaddr, dma_addr_t dma_handle);
85540 + void *vaddr, dma_addr_t dma_handle,
85541 + struct dma_attrs *attrs);
85542
85543 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
85544 unsigned long offset, size_t size,
85545 diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
85546 index 0f86d85..dff3419 100644
85547 --- a/include/linux/syscalls.h
85548 +++ b/include/linux/syscalls.h
85549 @@ -98,10 +98,16 @@ struct sigaltstack;
85550 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
85551
85552 #define __SC_DECL(t, a) t a
85553 +#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))
85554 #define __TYPE_IS_L(t) (__same_type((t)0, 0L))
85555 #define __TYPE_IS_UL(t) (__same_type((t)0, 0UL))
85556 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
85557 -#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
85558 +#define __SC_LONG(t, a) __typeof( \
85559 + __builtin_choose_expr( \
85560 + sizeof(t) > sizeof(int), \
85561 + (t) 0, \
85562 + __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
85563 + )) a
85564 #define __SC_CAST(t, a) (t) a
85565 #define __SC_ARGS(t, a) a
85566 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
85567 @@ -383,11 +389,11 @@ asmlinkage long sys_sync(void);
85568 asmlinkage long sys_fsync(unsigned int fd);
85569 asmlinkage long sys_fdatasync(unsigned int fd);
85570 asmlinkage long sys_bdflush(int func, long data);
85571 -asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
85572 - char __user *type, unsigned long flags,
85573 +asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
85574 + const char __user *type, unsigned long flags,
85575 void __user *data);
85576 -asmlinkage long sys_umount(char __user *name, int flags);
85577 -asmlinkage long sys_oldumount(char __user *name);
85578 +asmlinkage long sys_umount(const char __user *name, int flags);
85579 +asmlinkage long sys_oldumount(const char __user *name);
85580 asmlinkage long sys_truncate(const char __user *path, long length);
85581 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
85582 asmlinkage long sys_stat(const char __user *filename,
85583 @@ -599,7 +605,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
85584 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
85585 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
85586 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
85587 - struct sockaddr __user *, int);
85588 + struct sockaddr __user *, int) __intentional_overflow(0);
85589 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
85590 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
85591 unsigned int vlen, unsigned flags);
85592 diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
85593 index 27b3b0b..e093dd9 100644
85594 --- a/include/linux/syscore_ops.h
85595 +++ b/include/linux/syscore_ops.h
85596 @@ -16,7 +16,7 @@ struct syscore_ops {
85597 int (*suspend)(void);
85598 void (*resume)(void);
85599 void (*shutdown)(void);
85600 -};
85601 +} __do_const;
85602
85603 extern void register_syscore_ops(struct syscore_ops *ops);
85604 extern void unregister_syscore_ops(struct syscore_ops *ops);
85605 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
85606 index b7361f8..341a15a 100644
85607 --- a/include/linux/sysctl.h
85608 +++ b/include/linux/sysctl.h
85609 @@ -39,6 +39,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
85610
85611 extern int proc_dostring(struct ctl_table *, int,
85612 void __user *, size_t *, loff_t *);
85613 +extern int proc_dostring_modpriv(struct ctl_table *, int,
85614 + void __user *, size_t *, loff_t *);
85615 extern int proc_dointvec(struct ctl_table *, int,
85616 void __user *, size_t *, loff_t *);
85617 extern int proc_dointvec_minmax(struct ctl_table *, int,
85618 @@ -113,7 +115,8 @@ struct ctl_table
85619 struct ctl_table_poll *poll;
85620 void *extra1;
85621 void *extra2;
85622 -};
85623 +} __do_const __randomize_layout;
85624 +typedef struct ctl_table __no_const ctl_table_no_const;
85625
85626 struct ctl_node {
85627 struct rb_node node;
85628 diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
85629 index f97d0db..c1187dc 100644
85630 --- a/include/linux/sysfs.h
85631 +++ b/include/linux/sysfs.h
85632 @@ -34,7 +34,8 @@ struct attribute {
85633 struct lock_class_key *key;
85634 struct lock_class_key skey;
85635 #endif
85636 -};
85637 +} __do_const;
85638 +typedef struct attribute __no_const attribute_no_const;
85639
85640 /**
85641 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
85642 @@ -63,7 +64,8 @@ struct attribute_group {
85643 struct attribute *, int);
85644 struct attribute **attrs;
85645 struct bin_attribute **bin_attrs;
85646 -};
85647 +} __do_const;
85648 +typedef struct attribute_group __no_const attribute_group_no_const;
85649
85650 /**
85651 * Use these macros to make defining attributes easier. See include/linux/device.h
85652 @@ -128,7 +130,8 @@ struct bin_attribute {
85653 char *, loff_t, size_t);
85654 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
85655 struct vm_area_struct *vma);
85656 -};
85657 +} __do_const;
85658 +typedef struct bin_attribute __no_const bin_attribute_no_const;
85659
85660 /**
85661 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
85662 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
85663 index 387fa7d..3fcde6b 100644
85664 --- a/include/linux/sysrq.h
85665 +++ b/include/linux/sysrq.h
85666 @@ -16,6 +16,7 @@
85667
85668 #include <linux/errno.h>
85669 #include <linux/types.h>
85670 +#include <linux/compiler.h>
85671
85672 /* Possible values of bitmask for enabling sysrq functions */
85673 /* 0x0001 is reserved for enable everything */
85674 @@ -33,7 +34,7 @@ struct sysrq_key_op {
85675 char *help_msg;
85676 char *action_msg;
85677 int enable_mask;
85678 -};
85679 +} __do_const;
85680
85681 #ifdef CONFIG_MAGIC_SYSRQ
85682
85683 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
85684 index ff307b5..f1a4468 100644
85685 --- a/include/linux/thread_info.h
85686 +++ b/include/linux/thread_info.h
85687 @@ -145,6 +145,13 @@ static inline bool test_and_clear_restore_sigmask(void)
85688 #error "no set_restore_sigmask() provided and default one won't work"
85689 #endif
85690
85691 +extern void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size);
85692 +
85693 +static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
85694 +{
85695 + __check_object_size(ptr, n, to_user, __builtin_constant_p(n));
85696 +}
85697 +
85698 #endif /* __KERNEL__ */
85699
85700 #endif /* _LINUX_THREAD_INFO_H */
85701 diff --git a/include/linux/tty.h b/include/linux/tty.h
85702 index 8413294..44391c7 100644
85703 --- a/include/linux/tty.h
85704 +++ b/include/linux/tty.h
85705 @@ -202,7 +202,7 @@ struct tty_port {
85706 const struct tty_port_operations *ops; /* Port operations */
85707 spinlock_t lock; /* Lock protecting tty field */
85708 int blocked_open; /* Waiting to open */
85709 - int count; /* Usage count */
85710 + atomic_t count; /* Usage count */
85711 wait_queue_head_t open_wait; /* Open waiters */
85712 wait_queue_head_t close_wait; /* Close waiters */
85713 wait_queue_head_t delta_msr_wait; /* Modem status change */
85714 @@ -284,7 +284,7 @@ struct tty_struct {
85715 /* If the tty has a pending do_SAK, queue it here - akpm */
85716 struct work_struct SAK_work;
85717 struct tty_port *port;
85718 -};
85719 +} __randomize_layout;
85720
85721 /* Each of a tty's open files has private_data pointing to tty_file_private */
85722 struct tty_file_private {
85723 @@ -548,7 +548,7 @@ extern int tty_port_open(struct tty_port *port,
85724 struct tty_struct *tty, struct file *filp);
85725 static inline int tty_port_users(struct tty_port *port)
85726 {
85727 - return port->count + port->blocked_open;
85728 + return atomic_read(&port->count) + port->blocked_open;
85729 }
85730
85731 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
85732 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
85733 index e48c608..6a19af2 100644
85734 --- a/include/linux/tty_driver.h
85735 +++ b/include/linux/tty_driver.h
85736 @@ -287,7 +287,7 @@ struct tty_operations {
85737 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
85738 #endif
85739 const struct file_operations *proc_fops;
85740 -};
85741 +} __do_const __randomize_layout;
85742
85743 struct tty_driver {
85744 int magic; /* magic number for this structure */
85745 @@ -321,7 +321,7 @@ struct tty_driver {
85746
85747 const struct tty_operations *ops;
85748 struct list_head tty_drivers;
85749 -};
85750 +} __randomize_layout;
85751
85752 extern struct list_head tty_drivers;
85753
85754 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
85755 index 00c9d68..bc0188b 100644
85756 --- a/include/linux/tty_ldisc.h
85757 +++ b/include/linux/tty_ldisc.h
85758 @@ -215,7 +215,7 @@ struct tty_ldisc_ops {
85759
85760 struct module *owner;
85761
85762 - int refcount;
85763 + atomic_t refcount;
85764 };
85765
85766 struct tty_ldisc {
85767 diff --git a/include/linux/types.h b/include/linux/types.h
85768 index a0bb704..f511c77 100644
85769 --- a/include/linux/types.h
85770 +++ b/include/linux/types.h
85771 @@ -177,10 +177,26 @@ typedef struct {
85772 int counter;
85773 } atomic_t;
85774
85775 +#ifdef CONFIG_PAX_REFCOUNT
85776 +typedef struct {
85777 + int counter;
85778 +} atomic_unchecked_t;
85779 +#else
85780 +typedef atomic_t atomic_unchecked_t;
85781 +#endif
85782 +
85783 #ifdef CONFIG_64BIT
85784 typedef struct {
85785 long counter;
85786 } atomic64_t;
85787 +
85788 +#ifdef CONFIG_PAX_REFCOUNT
85789 +typedef struct {
85790 + long counter;
85791 +} atomic64_unchecked_t;
85792 +#else
85793 +typedef atomic64_t atomic64_unchecked_t;
85794 +#endif
85795 #endif
85796
85797 struct list_head {
85798 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
85799 index ecd3319..8a36ded 100644
85800 --- a/include/linux/uaccess.h
85801 +++ b/include/linux/uaccess.h
85802 @@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
85803 long ret; \
85804 mm_segment_t old_fs = get_fs(); \
85805 \
85806 - set_fs(KERNEL_DS); \
85807 pagefault_disable(); \
85808 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
85809 - pagefault_enable(); \
85810 + set_fs(KERNEL_DS); \
85811 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
85812 set_fs(old_fs); \
85813 + pagefault_enable(); \
85814 ret; \
85815 })
85816
85817 diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
85818 index 2d1f9b6..d7a9fce 100644
85819 --- a/include/linux/uidgid.h
85820 +++ b/include/linux/uidgid.h
85821 @@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
85822
85823 #endif /* CONFIG_USER_NS */
85824
85825 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
85826 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
85827 +#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
85828 +#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
85829 +
85830 #endif /* _LINUX_UIDGID_H */
85831 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
85832 index 99c1b4d..562e6f3 100644
85833 --- a/include/linux/unaligned/access_ok.h
85834 +++ b/include/linux/unaligned/access_ok.h
85835 @@ -4,34 +4,34 @@
85836 #include <linux/kernel.h>
85837 #include <asm/byteorder.h>
85838
85839 -static inline u16 get_unaligned_le16(const void *p)
85840 +static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
85841 {
85842 - return le16_to_cpup((__le16 *)p);
85843 + return le16_to_cpup((const __le16 *)p);
85844 }
85845
85846 -static inline u32 get_unaligned_le32(const void *p)
85847 +static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
85848 {
85849 - return le32_to_cpup((__le32 *)p);
85850 + return le32_to_cpup((const __le32 *)p);
85851 }
85852
85853 -static inline u64 get_unaligned_le64(const void *p)
85854 +static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
85855 {
85856 - return le64_to_cpup((__le64 *)p);
85857 + return le64_to_cpup((const __le64 *)p);
85858 }
85859
85860 -static inline u16 get_unaligned_be16(const void *p)
85861 +static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
85862 {
85863 - return be16_to_cpup((__be16 *)p);
85864 + return be16_to_cpup((const __be16 *)p);
85865 }
85866
85867 -static inline u32 get_unaligned_be32(const void *p)
85868 +static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
85869 {
85870 - return be32_to_cpup((__be32 *)p);
85871 + return be32_to_cpup((const __be32 *)p);
85872 }
85873
85874 -static inline u64 get_unaligned_be64(const void *p)
85875 +static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
85876 {
85877 - return be64_to_cpup((__be64 *)p);
85878 + return be64_to_cpup((const __be64 *)p);
85879 }
85880
85881 static inline void put_unaligned_le16(u16 val, void *p)
85882 diff --git a/include/linux/uprobes.h b/include/linux/uprobes.h
85883 index 4f844c6..60beb5d 100644
85884 --- a/include/linux/uprobes.h
85885 +++ b/include/linux/uprobes.h
85886 @@ -98,11 +98,11 @@ struct uprobes_state {
85887 struct xol_area *xol_area;
85888 };
85889
85890 -extern int __weak set_swbp(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
85891 -extern int __weak set_orig_insn(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
85892 -extern bool __weak is_swbp_insn(uprobe_opcode_t *insn);
85893 -extern bool __weak is_trap_insn(uprobe_opcode_t *insn);
85894 -extern unsigned long __weak uprobe_get_swbp_addr(struct pt_regs *regs);
85895 +extern int set_swbp(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
85896 +extern int set_orig_insn(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
85897 +extern bool is_swbp_insn(uprobe_opcode_t *insn);
85898 +extern bool is_trap_insn(uprobe_opcode_t *insn);
85899 +extern unsigned long uprobe_get_swbp_addr(struct pt_regs *regs);
85900 extern unsigned long uprobe_get_trap_addr(struct pt_regs *regs);
85901 extern int uprobe_write_opcode(struct mm_struct *mm, unsigned long vaddr, uprobe_opcode_t);
85902 extern int uprobe_register(struct inode *inode, loff_t offset, struct uprobe_consumer *uc);
85903 @@ -128,8 +128,8 @@ extern bool arch_uprobe_xol_was_trapped(struct task_struct *tsk);
85904 extern int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val, void *data);
85905 extern void arch_uprobe_abort_xol(struct arch_uprobe *aup, struct pt_regs *regs);
85906 extern unsigned long arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs *regs);
85907 -extern bool __weak arch_uprobe_ignore(struct arch_uprobe *aup, struct pt_regs *regs);
85908 -extern void __weak arch_uprobe_copy_ixol(struct page *page, unsigned long vaddr,
85909 +extern bool arch_uprobe_ignore(struct arch_uprobe *aup, struct pt_regs *regs);
85910 +extern void arch_uprobe_copy_ixol(struct page *page, unsigned long vaddr,
85911 void *src, unsigned long len);
85912 #else /* !CONFIG_UPROBES */
85913 struct uprobes_state {
85914 diff --git a/include/linux/usb.h b/include/linux/usb.h
85915 index d2465bc..5256de4 100644
85916 --- a/include/linux/usb.h
85917 +++ b/include/linux/usb.h
85918 @@ -571,7 +571,7 @@ struct usb_device {
85919 int maxchild;
85920
85921 u32 quirks;
85922 - atomic_t urbnum;
85923 + atomic_unchecked_t urbnum;
85924
85925 unsigned long active_duration;
85926
85927 @@ -1655,7 +1655,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
85928
85929 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
85930 __u8 request, __u8 requesttype, __u16 value, __u16 index,
85931 - void *data, __u16 size, int timeout);
85932 + void *data, __u16 size, int timeout) __intentional_overflow(-1);
85933 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
85934 void *data, int len, int *actual_length, int timeout);
85935 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
85936 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
85937 index d5952bb..9a626d4 100644
85938 --- a/include/linux/usb/renesas_usbhs.h
85939 +++ b/include/linux/usb/renesas_usbhs.h
85940 @@ -39,7 +39,7 @@ enum {
85941 */
85942 struct renesas_usbhs_driver_callback {
85943 int (*notify_hotplug)(struct platform_device *pdev);
85944 -};
85945 +} __no_const;
85946
85947 /*
85948 * callback functions for platform
85949 diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
85950 index e953726..8edb26a 100644
85951 --- a/include/linux/user_namespace.h
85952 +++ b/include/linux/user_namespace.h
85953 @@ -33,7 +33,7 @@ struct user_namespace {
85954 struct key *persistent_keyring_register;
85955 struct rw_semaphore persistent_keyring_register_sem;
85956 #endif
85957 -};
85958 +} __randomize_layout;
85959
85960 extern struct user_namespace init_user_ns;
85961
85962 diff --git a/include/linux/utsname.h b/include/linux/utsname.h
85963 index 239e277..22a5cf5 100644
85964 --- a/include/linux/utsname.h
85965 +++ b/include/linux/utsname.h
85966 @@ -24,7 +24,7 @@ struct uts_namespace {
85967 struct new_utsname name;
85968 struct user_namespace *user_ns;
85969 unsigned int proc_inum;
85970 -};
85971 +} __randomize_layout;
85972 extern struct uts_namespace init_uts_ns;
85973
85974 #ifdef CONFIG_UTS_NS
85975 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
85976 index 6f8fbcf..4efc177 100644
85977 --- a/include/linux/vermagic.h
85978 +++ b/include/linux/vermagic.h
85979 @@ -25,9 +25,42 @@
85980 #define MODULE_ARCH_VERMAGIC ""
85981 #endif
85982
85983 +#ifdef CONFIG_PAX_REFCOUNT
85984 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
85985 +#else
85986 +#define MODULE_PAX_REFCOUNT ""
85987 +#endif
85988 +
85989 +#ifdef CONSTIFY_PLUGIN
85990 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
85991 +#else
85992 +#define MODULE_CONSTIFY_PLUGIN ""
85993 +#endif
85994 +
85995 +#ifdef STACKLEAK_PLUGIN
85996 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
85997 +#else
85998 +#define MODULE_STACKLEAK_PLUGIN ""
85999 +#endif
86000 +
86001 +#ifdef RANDSTRUCT_PLUGIN
86002 +#include <generated/randomize_layout_hash.h>
86003 +#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
86004 +#else
86005 +#define MODULE_RANDSTRUCT_PLUGIN
86006 +#endif
86007 +
86008 +#ifdef CONFIG_GRKERNSEC
86009 +#define MODULE_GRSEC "GRSEC "
86010 +#else
86011 +#define MODULE_GRSEC ""
86012 +#endif
86013 +
86014 #define VERMAGIC_STRING \
86015 UTS_RELEASE " " \
86016 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
86017 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
86018 - MODULE_ARCH_VERMAGIC
86019 + MODULE_ARCH_VERMAGIC \
86020 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
86021 + MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
86022
86023 diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
86024 index b483abd..af305ad 100644
86025 --- a/include/linux/vga_switcheroo.h
86026 +++ b/include/linux/vga_switcheroo.h
86027 @@ -63,9 +63,9 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
86028
86029 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
86030
86031 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
86032 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
86033 void vga_switcheroo_fini_domain_pm_ops(struct device *dev);
86034 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
86035 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
86036 #else
86037
86038 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
86039 @@ -82,9 +82,9 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
86040
86041 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
86042
86043 -static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
86044 +static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
86045 static inline void vga_switcheroo_fini_domain_pm_ops(struct device *dev) {}
86046 -static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
86047 +static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
86048
86049 #endif
86050 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
86051 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
86052 index b87696f..1d11de7 100644
86053 --- a/include/linux/vmalloc.h
86054 +++ b/include/linux/vmalloc.h
86055 @@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
86056 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
86057 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
86058 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
86059 +
86060 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
86061 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
86062 +#endif
86063 +
86064 /* bits [20..32] reserved for arch specific ioremap internals */
86065
86066 /*
86067 @@ -82,6 +87,10 @@ extern void *vmap(struct page **pages, unsigned int count,
86068 unsigned long flags, pgprot_t prot);
86069 extern void vunmap(const void *addr);
86070
86071 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86072 +extern void unmap_process_stacks(struct task_struct *task);
86073 +#endif
86074 +
86075 extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,
86076 unsigned long uaddr, void *kaddr,
86077 unsigned long size);
86078 @@ -142,7 +151,7 @@ extern void free_vm_area(struct vm_struct *area);
86079
86080 /* for /dev/kmem */
86081 extern long vread(char *buf, char *addr, unsigned long count);
86082 -extern long vwrite(char *buf, char *addr, unsigned long count);
86083 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
86084
86085 /*
86086 * Internals. Dont't use..
86087 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
86088 index 82e7db7..f8ce3d0 100644
86089 --- a/include/linux/vmstat.h
86090 +++ b/include/linux/vmstat.h
86091 @@ -108,18 +108,18 @@ static inline void vm_events_fold_cpu(int cpu)
86092 /*
86093 * Zone based page accounting with per cpu differentials.
86094 */
86095 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
86096 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
86097
86098 static inline void zone_page_state_add(long x, struct zone *zone,
86099 enum zone_stat_item item)
86100 {
86101 - atomic_long_add(x, &zone->vm_stat[item]);
86102 - atomic_long_add(x, &vm_stat[item]);
86103 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
86104 + atomic_long_add_unchecked(x, &vm_stat[item]);
86105 }
86106
86107 -static inline unsigned long global_page_state(enum zone_stat_item item)
86108 +static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
86109 {
86110 - long x = atomic_long_read(&vm_stat[item]);
86111 + long x = atomic_long_read_unchecked(&vm_stat[item]);
86112 #ifdef CONFIG_SMP
86113 if (x < 0)
86114 x = 0;
86115 @@ -127,10 +127,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
86116 return x;
86117 }
86118
86119 -static inline unsigned long zone_page_state(struct zone *zone,
86120 +static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
86121 enum zone_stat_item item)
86122 {
86123 - long x = atomic_long_read(&zone->vm_stat[item]);
86124 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
86125 #ifdef CONFIG_SMP
86126 if (x < 0)
86127 x = 0;
86128 @@ -147,7 +147,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
86129 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
86130 enum zone_stat_item item)
86131 {
86132 - long x = atomic_long_read(&zone->vm_stat[item]);
86133 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
86134
86135 #ifdef CONFIG_SMP
86136 int cpu;
86137 @@ -234,14 +234,14 @@ static inline void __mod_zone_page_state(struct zone *zone,
86138
86139 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
86140 {
86141 - atomic_long_inc(&zone->vm_stat[item]);
86142 - atomic_long_inc(&vm_stat[item]);
86143 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
86144 + atomic_long_inc_unchecked(&vm_stat[item]);
86145 }
86146
86147 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
86148 {
86149 - atomic_long_dec(&zone->vm_stat[item]);
86150 - atomic_long_dec(&vm_stat[item]);
86151 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
86152 + atomic_long_dec_unchecked(&vm_stat[item]);
86153 }
86154
86155 static inline void __inc_zone_page_state(struct page *page,
86156 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
86157 index 91b0a68..0e9adf6 100644
86158 --- a/include/linux/xattr.h
86159 +++ b/include/linux/xattr.h
86160 @@ -28,7 +28,7 @@ struct xattr_handler {
86161 size_t size, int handler_flags);
86162 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
86163 size_t size, int flags, int handler_flags);
86164 -};
86165 +} __do_const;
86166
86167 struct xattr {
86168 const char *name;
86169 @@ -37,6 +37,9 @@ struct xattr {
86170 };
86171
86172 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
86173 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
86174 +ssize_t pax_getxattr(struct dentry *, void *, size_t);
86175 +#endif
86176 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
86177 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
86178 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
86179 diff --git a/include/linux/zlib.h b/include/linux/zlib.h
86180 index 92dbbd3..13ab0b3 100644
86181 --- a/include/linux/zlib.h
86182 +++ b/include/linux/zlib.h
86183 @@ -31,6 +31,7 @@
86184 #define _ZLIB_H
86185
86186 #include <linux/zconf.h>
86187 +#include <linux/compiler.h>
86188
86189 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
86190 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
86191 @@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
86192
86193 /* basic functions */
86194
86195 -extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
86196 +extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
86197 /*
86198 Returns the number of bytes that needs to be allocated for a per-
86199 stream workspace with the specified parameters. A pointer to this
86200 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
86201 index eb76cfd..9fd0e7c 100644
86202 --- a/include/media/v4l2-dev.h
86203 +++ b/include/media/v4l2-dev.h
86204 @@ -75,7 +75,7 @@ struct v4l2_file_operations {
86205 int (*mmap) (struct file *, struct vm_area_struct *);
86206 int (*open) (struct file *);
86207 int (*release) (struct file *);
86208 -};
86209 +} __do_const;
86210
86211 /*
86212 * Newer version of video_device, handled by videodev2.c
86213 diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
86214 index ffb69da..040393e 100644
86215 --- a/include/media/v4l2-device.h
86216 +++ b/include/media/v4l2-device.h
86217 @@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
86218 this function returns 0. If the name ends with a digit (e.g. cx18),
86219 then the name will be set to cx18-0 since cx180 looks really odd. */
86220 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
86221 - atomic_t *instance);
86222 + atomic_unchecked_t *instance);
86223
86224 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
86225 Since the parent disappears this ensures that v4l2_dev doesn't have an
86226 diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
86227 index d9fa68f..45c88d1 100644
86228 --- a/include/net/9p/transport.h
86229 +++ b/include/net/9p/transport.h
86230 @@ -63,7 +63,7 @@ struct p9_trans_module {
86231 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
86232 int (*zc_request)(struct p9_client *, struct p9_req_t *,
86233 char *, char *, int , int, int, int);
86234 -};
86235 +} __do_const;
86236
86237 void v9fs_register_trans(struct p9_trans_module *m);
86238 void v9fs_unregister_trans(struct p9_trans_module *m);
86239 diff --git a/include/net/af_unix.h b/include/net/af_unix.h
86240 index a175ba4..196eb8242 100644
86241 --- a/include/net/af_unix.h
86242 +++ b/include/net/af_unix.h
86243 @@ -36,7 +36,7 @@ struct unix_skb_parms {
86244 u32 secid; /* Security ID */
86245 #endif
86246 u32 consumed;
86247 -};
86248 +} __randomize_layout;
86249
86250 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
86251 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
86252 diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
86253 index 8df15ad..837fbedd 100644
86254 --- a/include/net/bluetooth/l2cap.h
86255 +++ b/include/net/bluetooth/l2cap.h
86256 @@ -608,7 +608,7 @@ struct l2cap_ops {
86257 unsigned char *kdata,
86258 struct iovec *iov,
86259 int len);
86260 -};
86261 +} __do_const;
86262
86263 struct l2cap_conn {
86264 struct hci_conn *hcon;
86265 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
86266 index f2ae33d..c457cf0 100644
86267 --- a/include/net/caif/cfctrl.h
86268 +++ b/include/net/caif/cfctrl.h
86269 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
86270 void (*radioset_rsp)(void);
86271 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
86272 struct cflayer *client_layer);
86273 -};
86274 +} __no_const;
86275
86276 /* Link Setup Parameters for CAIF-Links. */
86277 struct cfctrl_link_param {
86278 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
86279 struct cfctrl {
86280 struct cfsrvl serv;
86281 struct cfctrl_rsp res;
86282 - atomic_t req_seq_no;
86283 - atomic_t rsp_seq_no;
86284 + atomic_unchecked_t req_seq_no;
86285 + atomic_unchecked_t rsp_seq_no;
86286 struct list_head list;
86287 /* Protects from simultaneous access to first_req list */
86288 spinlock_t info_list_lock;
86289 diff --git a/include/net/flow.h b/include/net/flow.h
86290 index 8109a15..504466d 100644
86291 --- a/include/net/flow.h
86292 +++ b/include/net/flow.h
86293 @@ -231,6 +231,6 @@ void flow_cache_fini(struct net *net);
86294
86295 void flow_cache_flush(struct net *net);
86296 void flow_cache_flush_deferred(struct net *net);
86297 -extern atomic_t flow_cache_genid;
86298 +extern atomic_unchecked_t flow_cache_genid;
86299
86300 #endif
86301 diff --git a/include/net/genetlink.h b/include/net/genetlink.h
86302 index af10c2c..a431cc5 100644
86303 --- a/include/net/genetlink.h
86304 +++ b/include/net/genetlink.h
86305 @@ -120,7 +120,7 @@ struct genl_ops {
86306 u8 cmd;
86307 u8 internal_flags;
86308 u8 flags;
86309 -};
86310 +} __do_const;
86311
86312 int __genl_register_family(struct genl_family *family);
86313
86314 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
86315 index 734d9b5..48a9a4b 100644
86316 --- a/include/net/gro_cells.h
86317 +++ b/include/net/gro_cells.h
86318 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
86319 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
86320
86321 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
86322 - atomic_long_inc(&dev->rx_dropped);
86323 + atomic_long_inc_unchecked(&dev->rx_dropped);
86324 kfree_skb(skb);
86325 return;
86326 }
86327 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
86328 index 5fbe656..9ed3d8b 100644
86329 --- a/include/net/inet_connection_sock.h
86330 +++ b/include/net/inet_connection_sock.h
86331 @@ -63,7 +63,7 @@ struct inet_connection_sock_af_ops {
86332 int (*bind_conflict)(const struct sock *sk,
86333 const struct inet_bind_bucket *tb, bool relax);
86334 void (*mtu_reduced)(struct sock *sk);
86335 -};
86336 +} __do_const;
86337
86338 /** inet_connection_sock - INET connection oriented sock
86339 *
86340 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
86341 index 01d590e..f69c61d 100644
86342 --- a/include/net/inetpeer.h
86343 +++ b/include/net/inetpeer.h
86344 @@ -47,7 +47,7 @@ struct inet_peer {
86345 */
86346 union {
86347 struct {
86348 - atomic_t rid; /* Frag reception counter */
86349 + atomic_unchecked_t rid; /* Frag reception counter */
86350 };
86351 struct rcu_head rcu;
86352 struct inet_peer *gc_next;
86353 diff --git a/include/net/ip.h b/include/net/ip.h
86354 index db4a771..965a42a 100644
86355 --- a/include/net/ip.h
86356 +++ b/include/net/ip.h
86357 @@ -316,7 +316,7 @@ static inline unsigned int ip_skb_dst_mtu(const struct sk_buff *skb)
86358 }
86359 }
86360
86361 -u32 ip_idents_reserve(u32 hash, int segs);
86362 +u32 ip_idents_reserve(u32 hash, int segs) __intentional_overflow(-1);
86363 void __ip_select_ident(struct iphdr *iph, int segs);
86364
86365 static inline void ip_select_ident_segs(struct sk_buff *skb, struct sock *sk, int segs)
86366 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
86367 index 9922093..a1755d6 100644
86368 --- a/include/net/ip_fib.h
86369 +++ b/include/net/ip_fib.h
86370 @@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
86371
86372 #define FIB_RES_SADDR(net, res) \
86373 ((FIB_RES_NH(res).nh_saddr_genid == \
86374 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
86375 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
86376 FIB_RES_NH(res).nh_saddr : \
86377 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
86378 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
86379 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
86380 index 624a8a5..b1e2a24 100644
86381 --- a/include/net/ip_vs.h
86382 +++ b/include/net/ip_vs.h
86383 @@ -558,7 +558,7 @@ struct ip_vs_conn {
86384 struct ip_vs_conn *control; /* Master control connection */
86385 atomic_t n_control; /* Number of controlled ones */
86386 struct ip_vs_dest *dest; /* real server */
86387 - atomic_t in_pkts; /* incoming packet counter */
86388 + atomic_unchecked_t in_pkts; /* incoming packet counter */
86389
86390 /* packet transmitter for different forwarding methods. If it
86391 mangles the packet, it must return NF_DROP or better NF_STOLEN,
86392 @@ -705,7 +705,7 @@ struct ip_vs_dest {
86393 __be16 port; /* port number of the server */
86394 union nf_inet_addr addr; /* IP address of the server */
86395 volatile unsigned int flags; /* dest status flags */
86396 - atomic_t conn_flags; /* flags to copy to conn */
86397 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
86398 atomic_t weight; /* server weight */
86399
86400 atomic_t refcnt; /* reference counter */
86401 @@ -960,11 +960,11 @@ struct netns_ipvs {
86402 /* ip_vs_lblc */
86403 int sysctl_lblc_expiration;
86404 struct ctl_table_header *lblc_ctl_header;
86405 - struct ctl_table *lblc_ctl_table;
86406 + ctl_table_no_const *lblc_ctl_table;
86407 /* ip_vs_lblcr */
86408 int sysctl_lblcr_expiration;
86409 struct ctl_table_header *lblcr_ctl_header;
86410 - struct ctl_table *lblcr_ctl_table;
86411 + ctl_table_no_const *lblcr_ctl_table;
86412 /* ip_vs_est */
86413 struct list_head est_list; /* estimator list */
86414 spinlock_t est_lock;
86415 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
86416 index 8d4f588..2e37ad2 100644
86417 --- a/include/net/irda/ircomm_tty.h
86418 +++ b/include/net/irda/ircomm_tty.h
86419 @@ -33,6 +33,7 @@
86420 #include <linux/termios.h>
86421 #include <linux/timer.h>
86422 #include <linux/tty.h> /* struct tty_struct */
86423 +#include <asm/local.h>
86424
86425 #include <net/irda/irias_object.h>
86426 #include <net/irda/ircomm_core.h>
86427 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
86428 index 714cc9a..ea05f3e 100644
86429 --- a/include/net/iucv/af_iucv.h
86430 +++ b/include/net/iucv/af_iucv.h
86431 @@ -149,7 +149,7 @@ struct iucv_skb_cb {
86432 struct iucv_sock_list {
86433 struct hlist_head head;
86434 rwlock_t lock;
86435 - atomic_t autobind_name;
86436 + atomic_unchecked_t autobind_name;
86437 };
86438
86439 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
86440 diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
86441 index f3be818..bf46196 100644
86442 --- a/include/net/llc_c_ac.h
86443 +++ b/include/net/llc_c_ac.h
86444 @@ -87,7 +87,7 @@
86445 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
86446 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
86447
86448 -typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
86449 +typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
86450
86451 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
86452 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
86453 diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
86454 index 3948cf1..83b28c4 100644
86455 --- a/include/net/llc_c_ev.h
86456 +++ b/include/net/llc_c_ev.h
86457 @@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
86458 return (struct llc_conn_state_ev *)skb->cb;
86459 }
86460
86461 -typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
86462 -typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
86463 +typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
86464 +typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
86465
86466 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
86467 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
86468 diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
86469 index 0e79cfb..f46db31 100644
86470 --- a/include/net/llc_c_st.h
86471 +++ b/include/net/llc_c_st.h
86472 @@ -37,7 +37,7 @@ struct llc_conn_state_trans {
86473 u8 next_state;
86474 llc_conn_ev_qfyr_t *ev_qualifiers;
86475 llc_conn_action_t *ev_actions;
86476 -};
86477 +} __do_const;
86478
86479 struct llc_conn_state {
86480 u8 current_state;
86481 diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
86482 index a61b98c..aade1eb 100644
86483 --- a/include/net/llc_s_ac.h
86484 +++ b/include/net/llc_s_ac.h
86485 @@ -23,7 +23,7 @@
86486 #define SAP_ACT_TEST_IND 9
86487
86488 /* All action functions must look like this */
86489 -typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
86490 +typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
86491
86492 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
86493 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
86494 diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
86495 index 567c681..cd73ac02 100644
86496 --- a/include/net/llc_s_st.h
86497 +++ b/include/net/llc_s_st.h
86498 @@ -20,7 +20,7 @@ struct llc_sap_state_trans {
86499 llc_sap_ev_t ev;
86500 u8 next_state;
86501 llc_sap_action_t *ev_actions;
86502 -};
86503 +} __do_const;
86504
86505 struct llc_sap_state {
86506 u8 curr_state;
86507 diff --git a/include/net/mac80211.h b/include/net/mac80211.h
86508 index dae2e24..89336e6 100644
86509 --- a/include/net/mac80211.h
86510 +++ b/include/net/mac80211.h
86511 @@ -4650,7 +4650,7 @@ struct rate_control_ops {
86512 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
86513
86514 u32 (*get_expected_throughput)(void *priv_sta);
86515 -};
86516 +} __do_const;
86517
86518 static inline int rate_supported(struct ieee80211_sta *sta,
86519 enum ieee80211_band band,
86520 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
86521 index 47f4254..fd095bc 100644
86522 --- a/include/net/neighbour.h
86523 +++ b/include/net/neighbour.h
86524 @@ -163,7 +163,7 @@ struct neigh_ops {
86525 void (*error_report)(struct neighbour *, struct sk_buff *);
86526 int (*output)(struct neighbour *, struct sk_buff *);
86527 int (*connected_output)(struct neighbour *, struct sk_buff *);
86528 -};
86529 +} __do_const;
86530
86531 struct pneigh_entry {
86532 struct pneigh_entry *next;
86533 @@ -217,7 +217,7 @@ struct neigh_table {
86534 struct neigh_statistics __percpu *stats;
86535 struct neigh_hash_table __rcu *nht;
86536 struct pneigh_entry **phash_buckets;
86537 -};
86538 +} __randomize_layout;
86539
86540 static inline int neigh_parms_family(struct neigh_parms *p)
86541 {
86542 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
86543 index e0d6466..e2f3003 100644
86544 --- a/include/net/net_namespace.h
86545 +++ b/include/net/net_namespace.h
86546 @@ -129,8 +129,8 @@ struct net {
86547 struct netns_ipvs *ipvs;
86548 #endif
86549 struct sock *diag_nlsk;
86550 - atomic_t fnhe_genid;
86551 -};
86552 + atomic_unchecked_t fnhe_genid;
86553 +} __randomize_layout;
86554
86555 #include <linux/seq_file_net.h>
86556
86557 @@ -286,7 +286,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
86558 #define __net_init __init
86559 #define __net_exit __exit_refok
86560 #define __net_initdata __initdata
86561 +#ifdef CONSTIFY_PLUGIN
86562 #define __net_initconst __initconst
86563 +#else
86564 +#define __net_initconst __initdata
86565 +#endif
86566 #endif
86567
86568 struct pernet_operations {
86569 @@ -296,7 +300,7 @@ struct pernet_operations {
86570 void (*exit_batch)(struct list_head *net_exit_list);
86571 int *id;
86572 size_t size;
86573 -};
86574 +} __do_const;
86575
86576 /*
86577 * Use these carefully. If you implement a network device and it
86578 @@ -344,12 +348,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
86579
86580 static inline int rt_genid_ipv4(struct net *net)
86581 {
86582 - return atomic_read(&net->ipv4.rt_genid);
86583 + return atomic_read_unchecked(&net->ipv4.rt_genid);
86584 }
86585
86586 static inline void rt_genid_bump_ipv4(struct net *net)
86587 {
86588 - atomic_inc(&net->ipv4.rt_genid);
86589 + atomic_inc_unchecked(&net->ipv4.rt_genid);
86590 }
86591
86592 extern void (*__fib6_flush_trees)(struct net *net);
86593 @@ -376,12 +380,12 @@ static inline void rt_genid_bump_all(struct net *net)
86594
86595 static inline int fnhe_genid(struct net *net)
86596 {
86597 - return atomic_read(&net->fnhe_genid);
86598 + return atomic_read_unchecked(&net->fnhe_genid);
86599 }
86600
86601 static inline void fnhe_genid_bump(struct net *net)
86602 {
86603 - atomic_inc(&net->fnhe_genid);
86604 + atomic_inc_unchecked(&net->fnhe_genid);
86605 }
86606
86607 #endif /* __NET_NET_NAMESPACE_H */
86608 diff --git a/include/net/netdma.h b/include/net/netdma.h
86609 index 8ba8ce2..99b7fff 100644
86610 --- a/include/net/netdma.h
86611 +++ b/include/net/netdma.h
86612 @@ -24,7 +24,7 @@
86613 #include <linux/dmaengine.h>
86614 #include <linux/skbuff.h>
86615
86616 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
86617 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
86618 struct sk_buff *skb, int offset, struct iovec *to,
86619 size_t len, struct dma_pinned_list *pinned_list);
86620
86621 diff --git a/include/net/netlink.h b/include/net/netlink.h
86622 index 6c10762..3e5de0c 100644
86623 --- a/include/net/netlink.h
86624 +++ b/include/net/netlink.h
86625 @@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
86626 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
86627 {
86628 if (mark)
86629 - skb_trim(skb, (unsigned char *) mark - skb->data);
86630 + skb_trim(skb, (const unsigned char *) mark - skb->data);
86631 }
86632
86633 /**
86634 diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
86635 index 29d6a94..235d3d8 100644
86636 --- a/include/net/netns/conntrack.h
86637 +++ b/include/net/netns/conntrack.h
86638 @@ -14,10 +14,10 @@ struct nf_conntrack_ecache;
86639 struct nf_proto_net {
86640 #ifdef CONFIG_SYSCTL
86641 struct ctl_table_header *ctl_table_header;
86642 - struct ctl_table *ctl_table;
86643 + ctl_table_no_const *ctl_table;
86644 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
86645 struct ctl_table_header *ctl_compat_header;
86646 - struct ctl_table *ctl_compat_table;
86647 + ctl_table_no_const *ctl_compat_table;
86648 #endif
86649 #endif
86650 unsigned int users;
86651 @@ -60,7 +60,7 @@ struct nf_ip_net {
86652 struct nf_icmp_net icmpv6;
86653 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
86654 struct ctl_table_header *ctl_table_header;
86655 - struct ctl_table *ctl_table;
86656 + ctl_table_no_const *ctl_table;
86657 #endif
86658 };
86659
86660 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
86661 index aec5e12..807233f 100644
86662 --- a/include/net/netns/ipv4.h
86663 +++ b/include/net/netns/ipv4.h
86664 @@ -82,7 +82,7 @@ struct netns_ipv4 {
86665
86666 struct ping_group_range ping_group_range;
86667
86668 - atomic_t dev_addr_genid;
86669 + atomic_unchecked_t dev_addr_genid;
86670
86671 #ifdef CONFIG_SYSCTL
86672 unsigned long *sysctl_local_reserved_ports;
86673 @@ -96,6 +96,6 @@ struct netns_ipv4 {
86674 struct fib_rules_ops *mr_rules_ops;
86675 #endif
86676 #endif
86677 - atomic_t rt_genid;
86678 + atomic_unchecked_t rt_genid;
86679 };
86680 #endif
86681 diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
86682 index eade27a..42894dd 100644
86683 --- a/include/net/netns/ipv6.h
86684 +++ b/include/net/netns/ipv6.h
86685 @@ -75,8 +75,8 @@ struct netns_ipv6 {
86686 struct fib_rules_ops *mr6_rules_ops;
86687 #endif
86688 #endif
86689 - atomic_t dev_addr_genid;
86690 - atomic_t rt_genid;
86691 + atomic_unchecked_t dev_addr_genid;
86692 + atomic_unchecked_t rt_genid;
86693 };
86694
86695 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
86696 diff --git a/include/net/netns/xfrm.h b/include/net/netns/xfrm.h
86697 index 3492434..209f58c 100644
86698 --- a/include/net/netns/xfrm.h
86699 +++ b/include/net/netns/xfrm.h
86700 @@ -64,7 +64,7 @@ struct netns_xfrm {
86701
86702 /* flow cache part */
86703 struct flow_cache flow_cache_global;
86704 - atomic_t flow_cache_genid;
86705 + atomic_unchecked_t flow_cache_genid;
86706 struct list_head flow_cache_gc_list;
86707 spinlock_t flow_cache_gc_lock;
86708 struct work_struct flow_cache_gc_work;
86709 diff --git a/include/net/ping.h b/include/net/ping.h
86710 index 026479b..d9b2829 100644
86711 --- a/include/net/ping.h
86712 +++ b/include/net/ping.h
86713 @@ -54,7 +54,7 @@ struct ping_iter_state {
86714
86715 extern struct proto ping_prot;
86716 #if IS_ENABLED(CONFIG_IPV6)
86717 -extern struct pingv6_ops pingv6_ops;
86718 +extern struct pingv6_ops *pingv6_ops;
86719 #endif
86720
86721 struct pingfakehdr {
86722 diff --git a/include/net/protocol.h b/include/net/protocol.h
86723 index d6fcc1f..ca277058 100644
86724 --- a/include/net/protocol.h
86725 +++ b/include/net/protocol.h
86726 @@ -49,7 +49,7 @@ struct net_protocol {
86727 * socket lookup?
86728 */
86729 icmp_strict_tag_validation:1;
86730 -};
86731 +} __do_const;
86732
86733 #if IS_ENABLED(CONFIG_IPV6)
86734 struct inet6_protocol {
86735 @@ -62,7 +62,7 @@ struct inet6_protocol {
86736 u8 type, u8 code, int offset,
86737 __be32 info);
86738 unsigned int flags; /* INET6_PROTO_xxx */
86739 -};
86740 +} __do_const;
86741
86742 #define INET6_PROTO_NOPOLICY 0x1
86743 #define INET6_PROTO_FINAL 0x2
86744 diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
86745 index e21b9f9..0191ef0 100644
86746 --- a/include/net/rtnetlink.h
86747 +++ b/include/net/rtnetlink.h
86748 @@ -93,7 +93,7 @@ struct rtnl_link_ops {
86749 int (*fill_slave_info)(struct sk_buff *skb,
86750 const struct net_device *dev,
86751 const struct net_device *slave_dev);
86752 -};
86753 +} __do_const;
86754
86755 int __rtnl_link_register(struct rtnl_link_ops *ops);
86756 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
86757 diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
86758 index 4a5b9a3..ca27d73 100644
86759 --- a/include/net/sctp/checksum.h
86760 +++ b/include/net/sctp/checksum.h
86761 @@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
86762 unsigned int offset)
86763 {
86764 struct sctphdr *sh = sctp_hdr(skb);
86765 - __le32 ret, old = sh->checksum;
86766 - const struct skb_checksum_ops ops = {
86767 + __le32 ret, old = sh->checksum;
86768 + static const struct skb_checksum_ops ops = {
86769 .update = sctp_csum_update,
86770 .combine = sctp_csum_combine,
86771 };
86772 diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
86773 index 72a31db..aaa63d9 100644
86774 --- a/include/net/sctp/sm.h
86775 +++ b/include/net/sctp/sm.h
86776 @@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
86777 typedef struct {
86778 sctp_state_fn_t *fn;
86779 const char *name;
86780 -} sctp_sm_table_entry_t;
86781 +} __do_const sctp_sm_table_entry_t;
86782
86783 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
86784 * currently in use.
86785 @@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
86786 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
86787
86788 /* Extern declarations for major data structures. */
86789 -extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
86790 +extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
86791
86792
86793 /* Get the size of a DATA chunk payload. */
86794 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
86795 index 4ff3f67..89ae38e 100644
86796 --- a/include/net/sctp/structs.h
86797 +++ b/include/net/sctp/structs.h
86798 @@ -509,7 +509,7 @@ struct sctp_pf {
86799 void (*to_sk_saddr)(union sctp_addr *, struct sock *sk);
86800 void (*to_sk_daddr)(union sctp_addr *, struct sock *sk);
86801 struct sctp_af *af;
86802 -};
86803 +} __do_const;
86804
86805
86806 /* Structure to track chunk fragments that have been acked, but peer
86807 diff --git a/include/net/sock.h b/include/net/sock.h
86808 index b9a5bd0..dcd5f3c 100644
86809 --- a/include/net/sock.h
86810 +++ b/include/net/sock.h
86811 @@ -356,7 +356,7 @@ struct sock {
86812 unsigned int sk_napi_id;
86813 unsigned int sk_ll_usec;
86814 #endif
86815 - atomic_t sk_drops;
86816 + atomic_unchecked_t sk_drops;
86817 int sk_rcvbuf;
86818
86819 struct sk_filter __rcu *sk_filter;
86820 @@ -1053,7 +1053,7 @@ struct proto {
86821 void (*destroy_cgroup)(struct mem_cgroup *memcg);
86822 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
86823 #endif
86824 -};
86825 +} __randomize_layout;
86826
86827 /*
86828 * Bits in struct cg_proto.flags
86829 @@ -1240,7 +1240,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
86830 return ret >> PAGE_SHIFT;
86831 }
86832
86833 -static inline long
86834 +static inline long __intentional_overflow(-1)
86835 sk_memory_allocated(const struct sock *sk)
86836 {
86837 struct proto *prot = sk->sk_prot;
86838 @@ -1385,7 +1385,7 @@ struct sock_iocb {
86839 struct scm_cookie *scm;
86840 struct msghdr *msg, async_msg;
86841 struct kiocb *kiocb;
86842 -};
86843 +} __randomize_layout;
86844
86845 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
86846 {
86847 @@ -1820,7 +1820,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
86848 }
86849
86850 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
86851 - char __user *from, char *to,
86852 + char __user *from, unsigned char *to,
86853 int copy, int offset)
86854 {
86855 if (skb->ip_summed == CHECKSUM_NONE) {
86856 @@ -2091,7 +2091,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
86857 }
86858 }
86859
86860 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
86861 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
86862
86863 /**
86864 * sk_page_frag - return an appropriate page_frag
86865 diff --git a/include/net/tcp.h b/include/net/tcp.h
86866 index 590e01a..76498f3 100644
86867 --- a/include/net/tcp.h
86868 +++ b/include/net/tcp.h
86869 @@ -523,7 +523,7 @@ void tcp_retransmit_timer(struct sock *sk);
86870 void tcp_xmit_retransmit_queue(struct sock *);
86871 void tcp_simple_retransmit(struct sock *);
86872 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
86873 -int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
86874 +int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
86875
86876 void tcp_send_probe0(struct sock *);
86877 void tcp_send_partial(struct sock *);
86878 @@ -696,8 +696,8 @@ struct tcp_skb_cb {
86879 struct inet6_skb_parm h6;
86880 #endif
86881 } header; /* For incoming frames */
86882 - __u32 seq; /* Starting sequence number */
86883 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
86884 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
86885 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
86886 __u32 when; /* used to compute rtt's */
86887 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
86888
86889 @@ -713,7 +713,7 @@ struct tcp_skb_cb {
86890
86891 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
86892 /* 1 byte hole */
86893 - __u32 ack_seq; /* Sequence number ACK'd */
86894 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
86895 };
86896
86897 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
86898 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
86899 index 721e9c3b..3c81bbf 100644
86900 --- a/include/net/xfrm.h
86901 +++ b/include/net/xfrm.h
86902 @@ -285,7 +285,6 @@ struct xfrm_dst;
86903 struct xfrm_policy_afinfo {
86904 unsigned short family;
86905 struct dst_ops *dst_ops;
86906 - void (*garbage_collect)(struct net *net);
86907 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
86908 const xfrm_address_t *saddr,
86909 const xfrm_address_t *daddr);
86910 @@ -303,7 +302,7 @@ struct xfrm_policy_afinfo {
86911 struct net_device *dev,
86912 const struct flowi *fl);
86913 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
86914 -};
86915 +} __do_const;
86916
86917 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
86918 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
86919 @@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
86920 int (*transport_finish)(struct sk_buff *skb,
86921 int async);
86922 void (*local_error)(struct sk_buff *skb, u32 mtu);
86923 -};
86924 +} __do_const;
86925
86926 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
86927 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
86928 @@ -437,7 +436,7 @@ struct xfrm_mode {
86929 struct module *owner;
86930 unsigned int encap;
86931 int flags;
86932 -};
86933 +} __do_const;
86934
86935 /* Flags for xfrm_mode. */
86936 enum {
86937 @@ -534,7 +533,7 @@ struct xfrm_policy {
86938 struct timer_list timer;
86939
86940 struct flow_cache_object flo;
86941 - atomic_t genid;
86942 + atomic_unchecked_t genid;
86943 u32 priority;
86944 u32 index;
86945 struct xfrm_mark mark;
86946 @@ -1167,6 +1166,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
86947 }
86948
86949 void xfrm_garbage_collect(struct net *net);
86950 +void xfrm_garbage_collect_deferred(struct net *net);
86951
86952 #else
86953
86954 @@ -1205,6 +1205,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
86955 static inline void xfrm_garbage_collect(struct net *net)
86956 {
86957 }
86958 +static inline void xfrm_garbage_collect_deferred(struct net *net)
86959 +{
86960 +}
86961 #endif
86962
86963 static __inline__
86964 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
86965 index 1017e0b..227aa4d 100644
86966 --- a/include/rdma/iw_cm.h
86967 +++ b/include/rdma/iw_cm.h
86968 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
86969 int backlog);
86970
86971 int (*destroy_listen)(struct iw_cm_id *cm_id);
86972 -};
86973 +} __no_const;
86974
86975 /**
86976 * iw_create_cm_id - Create an IW CM identifier.
86977 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
86978 index 52beadf..598734c 100644
86979 --- a/include/scsi/libfc.h
86980 +++ b/include/scsi/libfc.h
86981 @@ -771,6 +771,7 @@ struct libfc_function_template {
86982 */
86983 void (*disc_stop_final) (struct fc_lport *);
86984 };
86985 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
86986
86987 /**
86988 * struct fc_disc - Discovery context
86989 @@ -875,7 +876,7 @@ struct fc_lport {
86990 struct fc_vport *vport;
86991
86992 /* Operational Information */
86993 - struct libfc_function_template tt;
86994 + libfc_function_template_no_const tt;
86995 u8 link_up;
86996 u8 qfull;
86997 enum fc_lport_state state;
86998 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
86999 index 1a0d184..4fb841f 100644
87000 --- a/include/scsi/scsi_device.h
87001 +++ b/include/scsi/scsi_device.h
87002 @@ -185,9 +185,9 @@ struct scsi_device {
87003 unsigned int max_device_blocked; /* what device_blocked counts down from */
87004 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
87005
87006 - atomic_t iorequest_cnt;
87007 - atomic_t iodone_cnt;
87008 - atomic_t ioerr_cnt;
87009 + atomic_unchecked_t iorequest_cnt;
87010 + atomic_unchecked_t iodone_cnt;
87011 + atomic_unchecked_t ioerr_cnt;
87012
87013 struct device sdev_gendev,
87014 sdev_dev;
87015 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
87016 index 007a0bc..7188db8 100644
87017 --- a/include/scsi/scsi_transport_fc.h
87018 +++ b/include/scsi/scsi_transport_fc.h
87019 @@ -756,7 +756,8 @@ struct fc_function_template {
87020 unsigned long show_host_system_hostname:1;
87021
87022 unsigned long disable_target_scan:1;
87023 -};
87024 +} __do_const;
87025 +typedef struct fc_function_template __no_const fc_function_template_no_const;
87026
87027
87028 /**
87029 diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
87030 index ae6c3b8..fd748ac 100644
87031 --- a/include/sound/compress_driver.h
87032 +++ b/include/sound/compress_driver.h
87033 @@ -128,7 +128,7 @@ struct snd_compr_ops {
87034 struct snd_compr_caps *caps);
87035 int (*get_codec_caps) (struct snd_compr_stream *stream,
87036 struct snd_compr_codec_caps *codec);
87037 -};
87038 +} __no_const;
87039
87040 /**
87041 * struct snd_compr: Compressed device
87042 diff --git a/include/sound/soc.h b/include/sound/soc.h
87043 index c83a334..27c8038 100644
87044 --- a/include/sound/soc.h
87045 +++ b/include/sound/soc.h
87046 @@ -817,7 +817,7 @@ struct snd_soc_codec_driver {
87047 /* probe ordering - for components with runtime dependencies */
87048 int probe_order;
87049 int remove_order;
87050 -};
87051 +} __do_const;
87052
87053 /* SoC platform interface */
87054 struct snd_soc_platform_driver {
87055 @@ -861,7 +861,7 @@ struct snd_soc_platform_driver {
87056 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
87057 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
87058 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
87059 -};
87060 +} __do_const;
87061
87062 struct snd_soc_dai_link_component {
87063 const char *name;
87064 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
87065 index 9ec9864..e2ee1ee 100644
87066 --- a/include/target/target_core_base.h
87067 +++ b/include/target/target_core_base.h
87068 @@ -761,7 +761,7 @@ struct se_device {
87069 atomic_long_t write_bytes;
87070 /* Active commands on this virtual SE device */
87071 atomic_t simple_cmds;
87072 - atomic_t dev_ordered_id;
87073 + atomic_unchecked_t dev_ordered_id;
87074 atomic_t dev_ordered_sync;
87075 atomic_t dev_qf_count;
87076 int export_count;
87077 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
87078 new file mode 100644
87079 index 0000000..fb634b7
87080 --- /dev/null
87081 +++ b/include/trace/events/fs.h
87082 @@ -0,0 +1,53 @@
87083 +#undef TRACE_SYSTEM
87084 +#define TRACE_SYSTEM fs
87085 +
87086 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
87087 +#define _TRACE_FS_H
87088 +
87089 +#include <linux/fs.h>
87090 +#include <linux/tracepoint.h>
87091 +
87092 +TRACE_EVENT(do_sys_open,
87093 +
87094 + TP_PROTO(const char *filename, int flags, int mode),
87095 +
87096 + TP_ARGS(filename, flags, mode),
87097 +
87098 + TP_STRUCT__entry(
87099 + __string( filename, filename )
87100 + __field( int, flags )
87101 + __field( int, mode )
87102 + ),
87103 +
87104 + TP_fast_assign(
87105 + __assign_str(filename, filename);
87106 + __entry->flags = flags;
87107 + __entry->mode = mode;
87108 + ),
87109 +
87110 + TP_printk("\"%s\" %x %o",
87111 + __get_str(filename), __entry->flags, __entry->mode)
87112 +);
87113 +
87114 +TRACE_EVENT(open_exec,
87115 +
87116 + TP_PROTO(const char *filename),
87117 +
87118 + TP_ARGS(filename),
87119 +
87120 + TP_STRUCT__entry(
87121 + __string( filename, filename )
87122 + ),
87123 +
87124 + TP_fast_assign(
87125 + __assign_str(filename, filename);
87126 + ),
87127 +
87128 + TP_printk("\"%s\"",
87129 + __get_str(filename))
87130 +);
87131 +
87132 +#endif /* _TRACE_FS_H */
87133 +
87134 +/* This part must be outside protection */
87135 +#include <trace/define_trace.h>
87136 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
87137 index 3608beb..df39d8a 100644
87138 --- a/include/trace/events/irq.h
87139 +++ b/include/trace/events/irq.h
87140 @@ -36,7 +36,7 @@ struct softirq_action;
87141 */
87142 TRACE_EVENT(irq_handler_entry,
87143
87144 - TP_PROTO(int irq, struct irqaction *action),
87145 + TP_PROTO(int irq, const struct irqaction *action),
87146
87147 TP_ARGS(irq, action),
87148
87149 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
87150 */
87151 TRACE_EVENT(irq_handler_exit,
87152
87153 - TP_PROTO(int irq, struct irqaction *action, int ret),
87154 + TP_PROTO(int irq, const struct irqaction *action, int ret),
87155
87156 TP_ARGS(irq, action, ret),
87157
87158 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
87159 index 7caf44c..23c6f27 100644
87160 --- a/include/uapi/linux/a.out.h
87161 +++ b/include/uapi/linux/a.out.h
87162 @@ -39,6 +39,14 @@ enum machine_type {
87163 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
87164 };
87165
87166 +/* Constants for the N_FLAGS field */
87167 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
87168 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
87169 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
87170 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
87171 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
87172 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
87173 +
87174 #if !defined (N_MAGIC)
87175 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
87176 #endif
87177 diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
87178 index 22b6ad3..aeba37e 100644
87179 --- a/include/uapi/linux/bcache.h
87180 +++ b/include/uapi/linux/bcache.h
87181 @@ -5,6 +5,7 @@
87182 * Bcache on disk data structures
87183 */
87184
87185 +#include <linux/compiler.h>
87186 #include <asm/types.h>
87187
87188 #define BITMASK(name, type, field, offset, size) \
87189 @@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
87190 /* Btree keys - all units are in sectors */
87191
87192 struct bkey {
87193 - __u64 high;
87194 - __u64 low;
87195 + __u64 high __intentional_overflow(-1);
87196 + __u64 low __intentional_overflow(-1);
87197 __u64 ptr[];
87198 };
87199
87200 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
87201 index d876736..ccce5c0 100644
87202 --- a/include/uapi/linux/byteorder/little_endian.h
87203 +++ b/include/uapi/linux/byteorder/little_endian.h
87204 @@ -42,51 +42,51 @@
87205
87206 static inline __le64 __cpu_to_le64p(const __u64 *p)
87207 {
87208 - return (__force __le64)*p;
87209 + return (__force const __le64)*p;
87210 }
87211 -static inline __u64 __le64_to_cpup(const __le64 *p)
87212 +static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
87213 {
87214 - return (__force __u64)*p;
87215 + return (__force const __u64)*p;
87216 }
87217 static inline __le32 __cpu_to_le32p(const __u32 *p)
87218 {
87219 - return (__force __le32)*p;
87220 + return (__force const __le32)*p;
87221 }
87222 static inline __u32 __le32_to_cpup(const __le32 *p)
87223 {
87224 - return (__force __u32)*p;
87225 + return (__force const __u32)*p;
87226 }
87227 static inline __le16 __cpu_to_le16p(const __u16 *p)
87228 {
87229 - return (__force __le16)*p;
87230 + return (__force const __le16)*p;
87231 }
87232 static inline __u16 __le16_to_cpup(const __le16 *p)
87233 {
87234 - return (__force __u16)*p;
87235 + return (__force const __u16)*p;
87236 }
87237 static inline __be64 __cpu_to_be64p(const __u64 *p)
87238 {
87239 - return (__force __be64)__swab64p(p);
87240 + return (__force const __be64)__swab64p(p);
87241 }
87242 static inline __u64 __be64_to_cpup(const __be64 *p)
87243 {
87244 - return __swab64p((__u64 *)p);
87245 + return __swab64p((const __u64 *)p);
87246 }
87247 static inline __be32 __cpu_to_be32p(const __u32 *p)
87248 {
87249 - return (__force __be32)__swab32p(p);
87250 + return (__force const __be32)__swab32p(p);
87251 }
87252 -static inline __u32 __be32_to_cpup(const __be32 *p)
87253 +static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
87254 {
87255 - return __swab32p((__u32 *)p);
87256 + return __swab32p((const __u32 *)p);
87257 }
87258 static inline __be16 __cpu_to_be16p(const __u16 *p)
87259 {
87260 - return (__force __be16)__swab16p(p);
87261 + return (__force const __be16)__swab16p(p);
87262 }
87263 static inline __u16 __be16_to_cpup(const __be16 *p)
87264 {
87265 - return __swab16p((__u16 *)p);
87266 + return __swab16p((const __u16 *)p);
87267 }
87268 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
87269 #define __le64_to_cpus(x) do { (void)(x); } while (0)
87270 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
87271 index ef6103b..d4e65dd 100644
87272 --- a/include/uapi/linux/elf.h
87273 +++ b/include/uapi/linux/elf.h
87274 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
87275 #define PT_GNU_EH_FRAME 0x6474e550
87276
87277 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
87278 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
87279 +
87280 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
87281 +
87282 +/* Constants for the e_flags field */
87283 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
87284 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
87285 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
87286 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
87287 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
87288 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
87289
87290 /*
87291 * Extended Numbering
87292 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
87293 #define DT_DEBUG 21
87294 #define DT_TEXTREL 22
87295 #define DT_JMPREL 23
87296 +#define DT_FLAGS 30
87297 + #define DF_TEXTREL 0x00000004
87298 #define DT_ENCODING 32
87299 #define OLD_DT_LOOS 0x60000000
87300 #define DT_LOOS 0x6000000d
87301 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
87302 #define PF_W 0x2
87303 #define PF_X 0x1
87304
87305 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
87306 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
87307 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
87308 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
87309 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
87310 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
87311 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
87312 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
87313 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
87314 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
87315 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
87316 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
87317 +
87318 typedef struct elf32_phdr{
87319 Elf32_Word p_type;
87320 Elf32_Off p_offset;
87321 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
87322 #define EI_OSABI 7
87323 #define EI_PAD 8
87324
87325 +#define EI_PAX 14
87326 +
87327 #define ELFMAG0 0x7f /* EI_MAG */
87328 #define ELFMAG1 'E'
87329 #define ELFMAG2 'L'
87330 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
87331 index aa169c4..6a2771d 100644
87332 --- a/include/uapi/linux/personality.h
87333 +++ b/include/uapi/linux/personality.h
87334 @@ -30,6 +30,7 @@ enum {
87335 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
87336 ADDR_NO_RANDOMIZE | \
87337 ADDR_COMPAT_LAYOUT | \
87338 + ADDR_LIMIT_3GB | \
87339 MMAP_PAGE_ZERO)
87340
87341 /*
87342 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
87343 index 7530e74..e714828 100644
87344 --- a/include/uapi/linux/screen_info.h
87345 +++ b/include/uapi/linux/screen_info.h
87346 @@ -43,7 +43,8 @@ struct screen_info {
87347 __u16 pages; /* 0x32 */
87348 __u16 vesa_attributes; /* 0x34 */
87349 __u32 capabilities; /* 0x36 */
87350 - __u8 _reserved[6]; /* 0x3a */
87351 + __u16 vesapm_size; /* 0x3a */
87352 + __u8 _reserved[4]; /* 0x3c */
87353 } __attribute__((packed));
87354
87355 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
87356 diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
87357 index 0e011eb..82681b1 100644
87358 --- a/include/uapi/linux/swab.h
87359 +++ b/include/uapi/linux/swab.h
87360 @@ -43,7 +43,7 @@
87361 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
87362 */
87363
87364 -static inline __attribute_const__ __u16 __fswab16(__u16 val)
87365 +static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
87366 {
87367 #ifdef __HAVE_BUILTIN_BSWAP16__
87368 return __builtin_bswap16(val);
87369 @@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
87370 #endif
87371 }
87372
87373 -static inline __attribute_const__ __u32 __fswab32(__u32 val)
87374 +static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
87375 {
87376 #ifdef __HAVE_BUILTIN_BSWAP32__
87377 return __builtin_bswap32(val);
87378 @@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
87379 #endif
87380 }
87381
87382 -static inline __attribute_const__ __u64 __fswab64(__u64 val)
87383 +static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
87384 {
87385 #ifdef __HAVE_BUILTIN_BSWAP64__
87386 return __builtin_bswap64(val);
87387 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
87388 index 43aaba1..1c30b48 100644
87389 --- a/include/uapi/linux/sysctl.h
87390 +++ b/include/uapi/linux/sysctl.h
87391 @@ -155,8 +155,6 @@ enum
87392 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
87393 };
87394
87395 -
87396 -
87397 /* CTL_VM names: */
87398 enum
87399 {
87400 diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
87401 index 778a329..1416ffb 100644
87402 --- a/include/uapi/linux/videodev2.h
87403 +++ b/include/uapi/linux/videodev2.h
87404 @@ -1285,7 +1285,7 @@ struct v4l2_ext_control {
87405 union {
87406 __s32 value;
87407 __s64 value64;
87408 - char *string;
87409 + char __user *string;
87410 __u8 *p_u8;
87411 __u16 *p_u16;
87412 __u32 *p_u32;
87413 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
87414 index 1590c49..5eab462 100644
87415 --- a/include/uapi/linux/xattr.h
87416 +++ b/include/uapi/linux/xattr.h
87417 @@ -73,5 +73,9 @@
87418 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
87419 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
87420
87421 +/* User namespace */
87422 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
87423 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
87424 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
87425
87426 #endif /* _UAPI_LINUX_XATTR_H */
87427 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
87428 index f9466fa..f4e2b81 100644
87429 --- a/include/video/udlfb.h
87430 +++ b/include/video/udlfb.h
87431 @@ -53,10 +53,10 @@ struct dlfb_data {
87432 u32 pseudo_palette[256];
87433 int blank_mode; /*one of FB_BLANK_ */
87434 /* blit-only rendering path metrics, exposed through sysfs */
87435 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
87436 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
87437 - atomic_t bytes_sent; /* to usb, after compression including overhead */
87438 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
87439 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
87440 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
87441 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
87442 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
87443 };
87444
87445 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
87446 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
87447 index 30f5362..8ed8ac9 100644
87448 --- a/include/video/uvesafb.h
87449 +++ b/include/video/uvesafb.h
87450 @@ -122,6 +122,7 @@ struct uvesafb_par {
87451 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
87452 u8 pmi_setpal; /* PMI for palette changes */
87453 u16 *pmi_base; /* protected mode interface location */
87454 + u8 *pmi_code; /* protected mode code location */
87455 void *pmi_start;
87456 void *pmi_pal;
87457 u8 *vbe_state_orig; /*
87458 diff --git a/init/Kconfig b/init/Kconfig
87459 index 80a6907..baf7d53 100644
87460 --- a/init/Kconfig
87461 +++ b/init/Kconfig
87462 @@ -1150,6 +1150,7 @@ endif # CGROUPS
87463
87464 config CHECKPOINT_RESTORE
87465 bool "Checkpoint/restore support" if EXPERT
87466 + depends on !GRKERNSEC
87467 default n
87468 help
87469 Enables additional kernel features in a sake of checkpoint/restore.
87470 @@ -1635,7 +1636,7 @@ config SLUB_DEBUG
87471
87472 config COMPAT_BRK
87473 bool "Disable heap randomization"
87474 - default y
87475 + default n
87476 help
87477 Randomizing heap placement makes heap exploits harder, but it
87478 also breaks ancient binaries (including anything libc5 based).
87479 @@ -1923,7 +1924,7 @@ config INIT_ALL_POSSIBLE
87480 config STOP_MACHINE
87481 bool
87482 default y
87483 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
87484 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
87485 help
87486 Need stop_machine() primitive.
87487
87488 diff --git a/init/Makefile b/init/Makefile
87489 index 7bc47ee..6da2dc7 100644
87490 --- a/init/Makefile
87491 +++ b/init/Makefile
87492 @@ -2,6 +2,9 @@
87493 # Makefile for the linux kernel.
87494 #
87495
87496 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
87497 +asflags-y := $(GCC_PLUGINS_AFLAGS)
87498 +
87499 obj-y := main.o version.o mounts.o
87500 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
87501 obj-y += noinitramfs.o
87502 diff --git a/init/do_mounts.c b/init/do_mounts.c
87503 index 82f2288..ea1430a 100644
87504 --- a/init/do_mounts.c
87505 +++ b/init/do_mounts.c
87506 @@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
87507 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
87508 {
87509 struct super_block *s;
87510 - int err = sys_mount(name, "/root", fs, flags, data);
87511 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
87512 if (err)
87513 return err;
87514
87515 - sys_chdir("/root");
87516 + sys_chdir((const char __force_user *)"/root");
87517 s = current->fs->pwd.dentry->d_sb;
87518 ROOT_DEV = s->s_dev;
87519 printk(KERN_INFO
87520 @@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
87521 va_start(args, fmt);
87522 vsprintf(buf, fmt, args);
87523 va_end(args);
87524 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
87525 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
87526 if (fd >= 0) {
87527 sys_ioctl(fd, FDEJECT, 0);
87528 sys_close(fd);
87529 }
87530 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
87531 - fd = sys_open("/dev/console", O_RDWR, 0);
87532 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
87533 if (fd >= 0) {
87534 sys_ioctl(fd, TCGETS, (long)&termios);
87535 termios.c_lflag &= ~ICANON;
87536 sys_ioctl(fd, TCSETSF, (long)&termios);
87537 - sys_read(fd, &c, 1);
87538 + sys_read(fd, (char __user *)&c, 1);
87539 termios.c_lflag |= ICANON;
87540 sys_ioctl(fd, TCSETSF, (long)&termios);
87541 sys_close(fd);
87542 @@ -589,8 +589,8 @@ void __init prepare_namespace(void)
87543 mount_root();
87544 out:
87545 devtmpfs_mount("dev");
87546 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
87547 - sys_chroot(".");
87548 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
87549 + sys_chroot((const char __force_user *)".");
87550 }
87551
87552 static bool is_tmpfs;
87553 diff --git a/init/do_mounts.h b/init/do_mounts.h
87554 index f5b978a..69dbfe8 100644
87555 --- a/init/do_mounts.h
87556 +++ b/init/do_mounts.h
87557 @@ -15,15 +15,15 @@ extern int root_mountflags;
87558
87559 static inline int create_dev(char *name, dev_t dev)
87560 {
87561 - sys_unlink(name);
87562 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
87563 + sys_unlink((char __force_user *)name);
87564 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
87565 }
87566
87567 #if BITS_PER_LONG == 32
87568 static inline u32 bstat(char *name)
87569 {
87570 struct stat64 stat;
87571 - if (sys_stat64(name, &stat) != 0)
87572 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
87573 return 0;
87574 if (!S_ISBLK(stat.st_mode))
87575 return 0;
87576 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
87577 static inline u32 bstat(char *name)
87578 {
87579 struct stat stat;
87580 - if (sys_newstat(name, &stat) != 0)
87581 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
87582 return 0;
87583 if (!S_ISBLK(stat.st_mode))
87584 return 0;
87585 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
87586 index 3e0878e..8a9d7a0 100644
87587 --- a/init/do_mounts_initrd.c
87588 +++ b/init/do_mounts_initrd.c
87589 @@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
87590 {
87591 sys_unshare(CLONE_FS | CLONE_FILES);
87592 /* stdin/stdout/stderr for /linuxrc */
87593 - sys_open("/dev/console", O_RDWR, 0);
87594 + sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
87595 sys_dup(0);
87596 sys_dup(0);
87597 /* move initrd over / and chdir/chroot in initrd root */
87598 - sys_chdir("/root");
87599 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
87600 - sys_chroot(".");
87601 + sys_chdir((const char __force_user *)"/root");
87602 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
87603 + sys_chroot((const char __force_user *)".");
87604 sys_setsid();
87605 return 0;
87606 }
87607 @@ -59,8 +59,8 @@ static void __init handle_initrd(void)
87608 create_dev("/dev/root.old", Root_RAM0);
87609 /* mount initrd on rootfs' /root */
87610 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
87611 - sys_mkdir("/old", 0700);
87612 - sys_chdir("/old");
87613 + sys_mkdir((const char __force_user *)"/old", 0700);
87614 + sys_chdir((const char __force_user *)"/old");
87615
87616 /* try loading default modules from initrd */
87617 load_default_modules();
87618 @@ -80,31 +80,31 @@ static void __init handle_initrd(void)
87619 current->flags &= ~PF_FREEZER_SKIP;
87620
87621 /* move initrd to rootfs' /old */
87622 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
87623 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
87624 /* switch root and cwd back to / of rootfs */
87625 - sys_chroot("..");
87626 + sys_chroot((const char __force_user *)"..");
87627
87628 if (new_decode_dev(real_root_dev) == Root_RAM0) {
87629 - sys_chdir("/old");
87630 + sys_chdir((const char __force_user *)"/old");
87631 return;
87632 }
87633
87634 - sys_chdir("/");
87635 + sys_chdir((const char __force_user *)"/");
87636 ROOT_DEV = new_decode_dev(real_root_dev);
87637 mount_root();
87638
87639 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
87640 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
87641 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
87642 if (!error)
87643 printk("okay\n");
87644 else {
87645 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
87646 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
87647 if (error == -ENOENT)
87648 printk("/initrd does not exist. Ignored.\n");
87649 else
87650 printk("failed\n");
87651 printk(KERN_NOTICE "Unmounting old root\n");
87652 - sys_umount("/old", MNT_DETACH);
87653 + sys_umount((char __force_user *)"/old", MNT_DETACH);
87654 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
87655 if (fd < 0) {
87656 error = fd;
87657 @@ -127,11 +127,11 @@ int __init initrd_load(void)
87658 * mounted in the normal path.
87659 */
87660 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
87661 - sys_unlink("/initrd.image");
87662 + sys_unlink((const char __force_user *)"/initrd.image");
87663 handle_initrd();
87664 return 1;
87665 }
87666 }
87667 - sys_unlink("/initrd.image");
87668 + sys_unlink((const char __force_user *)"/initrd.image");
87669 return 0;
87670 }
87671 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
87672 index 8cb6db5..d729f50 100644
87673 --- a/init/do_mounts_md.c
87674 +++ b/init/do_mounts_md.c
87675 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
87676 partitioned ? "_d" : "", minor,
87677 md_setup_args[ent].device_names);
87678
87679 - fd = sys_open(name, 0, 0);
87680 + fd = sys_open((char __force_user *)name, 0, 0);
87681 if (fd < 0) {
87682 printk(KERN_ERR "md: open failed - cannot start "
87683 "array %s\n", name);
87684 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
87685 * array without it
87686 */
87687 sys_close(fd);
87688 - fd = sys_open(name, 0, 0);
87689 + fd = sys_open((char __force_user *)name, 0, 0);
87690 sys_ioctl(fd, BLKRRPART, 0);
87691 }
87692 sys_close(fd);
87693 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
87694
87695 wait_for_device_probe();
87696
87697 - fd = sys_open("/dev/md0", 0, 0);
87698 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
87699 if (fd >= 0) {
87700 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
87701 sys_close(fd);
87702 diff --git a/init/init_task.c b/init/init_task.c
87703 index ba0a7f36..2bcf1d5 100644
87704 --- a/init/init_task.c
87705 +++ b/init/init_task.c
87706 @@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
87707 * Initial thread structure. Alignment of this is handled by a special
87708 * linker map entry.
87709 */
87710 +#ifdef CONFIG_X86
87711 +union thread_union init_thread_union __init_task_data;
87712 +#else
87713 union thread_union init_thread_union __init_task_data =
87714 { INIT_THREAD_INFO(init_task) };
87715 +#endif
87716 diff --git a/init/initramfs.c b/init/initramfs.c
87717 index bece48c..e911bd8 100644
87718 --- a/init/initramfs.c
87719 +++ b/init/initramfs.c
87720 @@ -25,7 +25,7 @@ static ssize_t __init xwrite(int fd, const char *p, size_t count)
87721
87722 /* sys_write only can write MAX_RW_COUNT aka 2G-4K bytes at most */
87723 while (count) {
87724 - ssize_t rv = sys_write(fd, p, count);
87725 + ssize_t rv = sys_write(fd, (char __force_user *)p, count);
87726
87727 if (rv < 0) {
87728 if (rv == -EINTR || rv == -EAGAIN)
87729 @@ -107,7 +107,7 @@ static void __init free_hash(void)
87730 }
87731 }
87732
87733 -static long __init do_utime(char *filename, time_t mtime)
87734 +static long __init do_utime(char __force_user *filename, time_t mtime)
87735 {
87736 struct timespec t[2];
87737
87738 @@ -142,7 +142,7 @@ static void __init dir_utime(void)
87739 struct dir_entry *de, *tmp;
87740 list_for_each_entry_safe(de, tmp, &dir_list, list) {
87741 list_del(&de->list);
87742 - do_utime(de->name, de->mtime);
87743 + do_utime((char __force_user *)de->name, de->mtime);
87744 kfree(de->name);
87745 kfree(de);
87746 }
87747 @@ -304,7 +304,7 @@ static int __init maybe_link(void)
87748 if (nlink >= 2) {
87749 char *old = find_link(major, minor, ino, mode, collected);
87750 if (old)
87751 - return (sys_link(old, collected) < 0) ? -1 : 1;
87752 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
87753 }
87754 return 0;
87755 }
87756 @@ -313,11 +313,11 @@ static void __init clean_path(char *path, umode_t mode)
87757 {
87758 struct stat st;
87759
87760 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
87761 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
87762 if (S_ISDIR(st.st_mode))
87763 - sys_rmdir(path);
87764 + sys_rmdir((char __force_user *)path);
87765 else
87766 - sys_unlink(path);
87767 + sys_unlink((char __force_user *)path);
87768 }
87769 }
87770
87771 @@ -338,7 +338,7 @@ static int __init do_name(void)
87772 int openflags = O_WRONLY|O_CREAT;
87773 if (ml != 1)
87774 openflags |= O_TRUNC;
87775 - wfd = sys_open(collected, openflags, mode);
87776 + wfd = sys_open((char __force_user *)collected, openflags, mode);
87777
87778 if (wfd >= 0) {
87779 sys_fchown(wfd, uid, gid);
87780 @@ -350,17 +350,17 @@ static int __init do_name(void)
87781 }
87782 }
87783 } else if (S_ISDIR(mode)) {
87784 - sys_mkdir(collected, mode);
87785 - sys_chown(collected, uid, gid);
87786 - sys_chmod(collected, mode);
87787 + sys_mkdir((char __force_user *)collected, mode);
87788 + sys_chown((char __force_user *)collected, uid, gid);
87789 + sys_chmod((char __force_user *)collected, mode);
87790 dir_add(collected, mtime);
87791 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
87792 S_ISFIFO(mode) || S_ISSOCK(mode)) {
87793 if (maybe_link() == 0) {
87794 - sys_mknod(collected, mode, rdev);
87795 - sys_chown(collected, uid, gid);
87796 - sys_chmod(collected, mode);
87797 - do_utime(collected, mtime);
87798 + sys_mknod((char __force_user *)collected, mode, rdev);
87799 + sys_chown((char __force_user *)collected, uid, gid);
87800 + sys_chmod((char __force_user *)collected, mode);
87801 + do_utime((char __force_user *)collected, mtime);
87802 }
87803 }
87804 return 0;
87805 @@ -372,7 +372,7 @@ static int __init do_copy(void)
87806 if (xwrite(wfd, victim, body_len) != body_len)
87807 error("write error");
87808 sys_close(wfd);
87809 - do_utime(vcollected, mtime);
87810 + do_utime((char __force_user *)vcollected, mtime);
87811 kfree(vcollected);
87812 eat(body_len);
87813 state = SkipIt;
87814 @@ -390,9 +390,9 @@ static int __init do_symlink(void)
87815 {
87816 collected[N_ALIGN(name_len) + body_len] = '\0';
87817 clean_path(collected, 0);
87818 - sys_symlink(collected + N_ALIGN(name_len), collected);
87819 - sys_lchown(collected, uid, gid);
87820 - do_utime(collected, mtime);
87821 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
87822 + sys_lchown((char __force_user *)collected, uid, gid);
87823 + do_utime((char __force_user *)collected, mtime);
87824 state = SkipIt;
87825 next_state = Reset;
87826 return 0;
87827 diff --git a/init/main.c b/init/main.c
87828 index d0f4b59..0c4b184 100644
87829 --- a/init/main.c
87830 +++ b/init/main.c
87831 @@ -98,6 +98,8 @@ extern void radix_tree_init(void);
87832 static inline void mark_rodata_ro(void) { }
87833 #endif
87834
87835 +extern void grsecurity_init(void);
87836 +
87837 /*
87838 * Debug helper: via this flag we know that we are in 'early bootup code'
87839 * where only the boot processor is running with IRQ disabled. This means
87840 @@ -159,6 +161,75 @@ static int __init set_reset_devices(char *str)
87841
87842 __setup("reset_devices", set_reset_devices);
87843
87844 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
87845 +kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
87846 +static int __init setup_grsec_proc_gid(char *str)
87847 +{
87848 + grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
87849 + return 1;
87850 +}
87851 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
87852 +#endif
87853 +
87854 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
87855 +unsigned long pax_user_shadow_base __read_only;
87856 +EXPORT_SYMBOL(pax_user_shadow_base);
87857 +extern char pax_enter_kernel_user[];
87858 +extern char pax_exit_kernel_user[];
87859 +#endif
87860 +
87861 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
87862 +static int __init setup_pax_nouderef(char *str)
87863 +{
87864 +#ifdef CONFIG_X86_32
87865 + unsigned int cpu;
87866 + struct desc_struct *gdt;
87867 +
87868 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
87869 + gdt = get_cpu_gdt_table(cpu);
87870 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
87871 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
87872 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
87873 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
87874 + }
87875 + loadsegment(ds, __KERNEL_DS);
87876 + loadsegment(es, __KERNEL_DS);
87877 + loadsegment(ss, __KERNEL_DS);
87878 +#else
87879 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
87880 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
87881 + clone_pgd_mask = ~(pgdval_t)0UL;
87882 + pax_user_shadow_base = 0UL;
87883 + setup_clear_cpu_cap(X86_FEATURE_PCID);
87884 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
87885 +#endif
87886 +
87887 + return 0;
87888 +}
87889 +early_param("pax_nouderef", setup_pax_nouderef);
87890 +
87891 +#ifdef CONFIG_X86_64
87892 +static int __init setup_pax_weakuderef(char *str)
87893 +{
87894 + if (clone_pgd_mask != ~(pgdval_t)0UL)
87895 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
87896 + return 1;
87897 +}
87898 +__setup("pax_weakuderef", setup_pax_weakuderef);
87899 +#endif
87900 +#endif
87901 +
87902 +#ifdef CONFIG_PAX_SOFTMODE
87903 +int pax_softmode;
87904 +
87905 +static int __init setup_pax_softmode(char *str)
87906 +{
87907 + get_option(&str, &pax_softmode);
87908 + return 1;
87909 +}
87910 +__setup("pax_softmode=", setup_pax_softmode);
87911 +#endif
87912 +
87913 static const char *argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
87914 const char *envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
87915 static const char *panic_later, *panic_param;
87916 @@ -728,7 +799,7 @@ static bool __init_or_module initcall_blacklisted(initcall_t fn)
87917 struct blacklist_entry *entry;
87918 char *fn_name;
87919
87920 - fn_name = kasprintf(GFP_KERNEL, "%pf", fn);
87921 + fn_name = kasprintf(GFP_KERNEL, "%pX", fn);
87922 if (!fn_name)
87923 return false;
87924
87925 @@ -780,7 +851,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
87926 {
87927 int count = preempt_count();
87928 int ret;
87929 - char msgbuf[64];
87930 + const char *msg1 = "", *msg2 = "";
87931
87932 if (initcall_blacklisted(fn))
87933 return -EPERM;
87934 @@ -790,18 +861,17 @@ int __init_or_module do_one_initcall(initcall_t fn)
87935 else
87936 ret = fn();
87937
87938 - msgbuf[0] = 0;
87939 -
87940 if (preempt_count() != count) {
87941 - sprintf(msgbuf, "preemption imbalance ");
87942 + msg1 = " preemption imbalance";
87943 preempt_count_set(count);
87944 }
87945 if (irqs_disabled()) {
87946 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
87947 + msg2 = " disabled interrupts";
87948 local_irq_enable();
87949 }
87950 - WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
87951 + WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
87952
87953 + add_latent_entropy();
87954 return ret;
87955 }
87956
87957 @@ -908,8 +978,8 @@ static int run_init_process(const char *init_filename)
87958 {
87959 argv_init[0] = init_filename;
87960 return do_execve(getname_kernel(init_filename),
87961 - (const char __user *const __user *)argv_init,
87962 - (const char __user *const __user *)envp_init);
87963 + (const char __user *const __force_user *)argv_init,
87964 + (const char __user *const __force_user *)envp_init);
87965 }
87966
87967 static int try_to_run_init_process(const char *init_filename)
87968 @@ -926,6 +996,10 @@ static int try_to_run_init_process(const char *init_filename)
87969 return ret;
87970 }
87971
87972 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
87973 +extern int gr_init_ran;
87974 +#endif
87975 +
87976 static noinline void __init kernel_init_freeable(void);
87977
87978 static int __ref kernel_init(void *unused)
87979 @@ -950,6 +1024,11 @@ static int __ref kernel_init(void *unused)
87980 ramdisk_execute_command, ret);
87981 }
87982
87983 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
87984 + /* if no initrd was used, be extra sure we enforce chroot restrictions */
87985 + gr_init_ran = 1;
87986 +#endif
87987 +
87988 /*
87989 * We try each of these until one succeeds.
87990 *
87991 @@ -1005,7 +1084,7 @@ static noinline void __init kernel_init_freeable(void)
87992 do_basic_setup();
87993
87994 /* Open the /dev/console on the rootfs, this should never fail */
87995 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
87996 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
87997 pr_err("Warning: unable to open an initial console.\n");
87998
87999 (void) sys_dup(0);
88000 @@ -1018,11 +1097,13 @@ static noinline void __init kernel_init_freeable(void)
88001 if (!ramdisk_execute_command)
88002 ramdisk_execute_command = "/init";
88003
88004 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
88005 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
88006 ramdisk_execute_command = NULL;
88007 prepare_namespace();
88008 }
88009
88010 + grsecurity_init();
88011 +
88012 /*
88013 * Ok, we have completed the initial bootup, and
88014 * we're essentially up and running. Get rid of the
88015 diff --git a/ipc/compat.c b/ipc/compat.c
88016 index b5ef4f7..ff31d87 100644
88017 --- a/ipc/compat.c
88018 +++ b/ipc/compat.c
88019 @@ -396,7 +396,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
88020 COMPAT_SHMLBA);
88021 if (err < 0)
88022 return err;
88023 - return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
88024 + return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
88025 }
88026 case SHMDT:
88027 return sys_shmdt(compat_ptr(ptr));
88028 diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
88029 index e8075b2..76f2c6a 100644
88030 --- a/ipc/ipc_sysctl.c
88031 +++ b/ipc/ipc_sysctl.c
88032 @@ -30,7 +30,7 @@ static void *get_ipc(struct ctl_table *table)
88033 static int proc_ipc_dointvec(struct ctl_table *table, int write,
88034 void __user *buffer, size_t *lenp, loff_t *ppos)
88035 {
88036 - struct ctl_table ipc_table;
88037 + ctl_table_no_const ipc_table;
88038
88039 memcpy(&ipc_table, table, sizeof(ipc_table));
88040 ipc_table.data = get_ipc(table);
88041 @@ -41,7 +41,7 @@ static int proc_ipc_dointvec(struct ctl_table *table, int write,
88042 static int proc_ipc_dointvec_minmax(struct ctl_table *table, int write,
88043 void __user *buffer, size_t *lenp, loff_t *ppos)
88044 {
88045 - struct ctl_table ipc_table;
88046 + ctl_table_no_const ipc_table;
88047
88048 memcpy(&ipc_table, table, sizeof(ipc_table));
88049 ipc_table.data = get_ipc(table);
88050 @@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(struct ctl_table *table, int write,
88051 static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
88052 void __user *buffer, size_t *lenp, loff_t *ppos)
88053 {
88054 - struct ctl_table ipc_table;
88055 + ctl_table_no_const ipc_table;
88056 size_t lenp_bef = *lenp;
88057 int rc;
88058
88059 @@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
88060 static int proc_ipc_doulongvec_minmax(struct ctl_table *table, int write,
88061 void __user *buffer, size_t *lenp, loff_t *ppos)
88062 {
88063 - struct ctl_table ipc_table;
88064 + ctl_table_no_const ipc_table;
88065 memcpy(&ipc_table, table, sizeof(ipc_table));
88066 ipc_table.data = get_ipc(table);
88067
88068 @@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
88069 static int proc_ipcauto_dointvec_minmax(struct ctl_table *table, int write,
88070 void __user *buffer, size_t *lenp, loff_t *ppos)
88071 {
88072 - struct ctl_table ipc_table;
88073 + ctl_table_no_const ipc_table;
88074 int oldval;
88075 int rc;
88076
88077 diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
88078 index 68d4e95..1477ded 100644
88079 --- a/ipc/mq_sysctl.c
88080 +++ b/ipc/mq_sysctl.c
88081 @@ -25,7 +25,7 @@ static void *get_mq(struct ctl_table *table)
88082 static int proc_mq_dointvec(struct ctl_table *table, int write,
88083 void __user *buffer, size_t *lenp, loff_t *ppos)
88084 {
88085 - struct ctl_table mq_table;
88086 + ctl_table_no_const mq_table;
88087 memcpy(&mq_table, table, sizeof(mq_table));
88088 mq_table.data = get_mq(table);
88089
88090 @@ -35,7 +35,7 @@ static int proc_mq_dointvec(struct ctl_table *table, int write,
88091 static int proc_mq_dointvec_minmax(struct ctl_table *table, int write,
88092 void __user *buffer, size_t *lenp, loff_t *ppos)
88093 {
88094 - struct ctl_table mq_table;
88095 + ctl_table_no_const mq_table;
88096 memcpy(&mq_table, table, sizeof(mq_table));
88097 mq_table.data = get_mq(table);
88098
88099 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
88100 index 4fcf39a..d3cc2ec 100644
88101 --- a/ipc/mqueue.c
88102 +++ b/ipc/mqueue.c
88103 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
88104 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
88105 info->attr.mq_msgsize);
88106
88107 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
88108 spin_lock(&mq_lock);
88109 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
88110 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
88111 diff --git a/ipc/shm.c b/ipc/shm.c
88112 index 7fc9f9f..95e201f 100644
88113 --- a/ipc/shm.c
88114 +++ b/ipc/shm.c
88115 @@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
88116 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
88117 #endif
88118
88119 +#ifdef CONFIG_GRKERNSEC
88120 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
88121 + const u64 shm_createtime, const kuid_t cuid,
88122 + const int shmid);
88123 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
88124 + const u64 shm_createtime);
88125 +#endif
88126 +
88127 void shm_init_ns(struct ipc_namespace *ns)
88128 {
88129 ns->shm_ctlmax = SHMMAX;
88130 @@ -559,6 +567,9 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
88131 shp->shm_lprid = 0;
88132 shp->shm_atim = shp->shm_dtim = 0;
88133 shp->shm_ctim = get_seconds();
88134 +#ifdef CONFIG_GRKERNSEC
88135 + shp->shm_createtime = ktime_get_ns();
88136 +#endif
88137 shp->shm_segsz = size;
88138 shp->shm_nattch = 0;
88139 shp->shm_file = file;
88140 @@ -1095,6 +1106,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
88141 f_mode = FMODE_READ | FMODE_WRITE;
88142 }
88143 if (shmflg & SHM_EXEC) {
88144 +
88145 +#ifdef CONFIG_PAX_MPROTECT
88146 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
88147 + goto out;
88148 +#endif
88149 +
88150 prot |= PROT_EXEC;
88151 acc_mode |= S_IXUGO;
88152 }
88153 @@ -1119,6 +1136,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
88154 if (err)
88155 goto out_unlock;
88156
88157 +#ifdef CONFIG_GRKERNSEC
88158 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
88159 + shp->shm_perm.cuid, shmid) ||
88160 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
88161 + err = -EACCES;
88162 + goto out_unlock;
88163 + }
88164 +#endif
88165 +
88166 ipc_lock_object(&shp->shm_perm);
88167
88168 /* check if shm_destroy() is tearing down shp */
88169 @@ -1131,6 +1157,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
88170 path = shp->shm_file->f_path;
88171 path_get(&path);
88172 shp->shm_nattch++;
88173 +#ifdef CONFIG_GRKERNSEC
88174 + shp->shm_lapid = current->pid;
88175 +#endif
88176 size = i_size_read(path.dentry->d_inode);
88177 ipc_unlock_object(&shp->shm_perm);
88178 rcu_read_unlock();
88179 diff --git a/ipc/util.c b/ipc/util.c
88180 index 27d74e6..8be0be2 100644
88181 --- a/ipc/util.c
88182 +++ b/ipc/util.c
88183 @@ -71,6 +71,8 @@ struct ipc_proc_iface {
88184 int (*show)(struct seq_file *, void *);
88185 };
88186
88187 +extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
88188 +
88189 static void ipc_memory_notifier(struct work_struct *work)
88190 {
88191 ipcns_notify(IPCNS_MEMCHANGED);
88192 @@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
88193 granted_mode >>= 6;
88194 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
88195 granted_mode >>= 3;
88196 +
88197 + if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
88198 + return -1;
88199 +
88200 /* is there some bit set in requested_mode but not in granted_mode? */
88201 if ((requested_mode & ~granted_mode & 0007) &&
88202 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
88203 diff --git a/kernel/audit.c b/kernel/audit.c
88204 index 6726aa6..bb864a9 100644
88205 --- a/kernel/audit.c
88206 +++ b/kernel/audit.c
88207 @@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
88208 3) suppressed due to audit_rate_limit
88209 4) suppressed due to audit_backlog_limit
88210 */
88211 -static atomic_t audit_lost = ATOMIC_INIT(0);
88212 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
88213
88214 /* The netlink socket. */
88215 static struct sock *audit_sock;
88216 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
88217 unsigned long now;
88218 int print;
88219
88220 - atomic_inc(&audit_lost);
88221 + atomic_inc_unchecked(&audit_lost);
88222
88223 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
88224
88225 @@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
88226 if (print) {
88227 if (printk_ratelimit())
88228 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
88229 - atomic_read(&audit_lost),
88230 + atomic_read_unchecked(&audit_lost),
88231 audit_rate_limit,
88232 audit_backlog_limit);
88233 audit_panic(message);
88234 @@ -840,7 +840,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
88235 s.pid = audit_pid;
88236 s.rate_limit = audit_rate_limit;
88237 s.backlog_limit = audit_backlog_limit;
88238 - s.lost = atomic_read(&audit_lost);
88239 + s.lost = atomic_read_unchecked(&audit_lost);
88240 s.backlog = skb_queue_len(&audit_skb_queue);
88241 s.version = AUDIT_VERSION_LATEST;
88242 s.backlog_wait_time = audit_backlog_wait_time;
88243 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
88244 index 21eae3c..66db239 100644
88245 --- a/kernel/auditsc.c
88246 +++ b/kernel/auditsc.c
88247 @@ -2023,7 +2023,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
88248 }
88249
88250 /* global counter which is incremented every time something logs in */
88251 -static atomic_t session_id = ATOMIC_INIT(0);
88252 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
88253
88254 static int audit_set_loginuid_perm(kuid_t loginuid)
88255 {
88256 @@ -2090,7 +2090,7 @@ int audit_set_loginuid(kuid_t loginuid)
88257
88258 /* are we setting or clearing? */
88259 if (uid_valid(loginuid))
88260 - sessionid = (unsigned int)atomic_inc_return(&session_id);
88261 + sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
88262
88263 task->sessionid = sessionid;
88264 task->loginuid = loginuid;
88265 diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
88266 index 7f0dbcb..b54bb2c 100644
88267 --- a/kernel/bpf/core.c
88268 +++ b/kernel/bpf/core.c
88269 @@ -22,6 +22,7 @@
88270 */
88271 #include <linux/filter.h>
88272 #include <linux/skbuff.h>
88273 +#include <linux/vmalloc.h>
88274 #include <asm/unaligned.h>
88275
88276 /* Registers */
88277 @@ -63,6 +64,67 @@ void *bpf_internal_load_pointer_neg_helper(const struct sk_buff *skb, int k, uns
88278 return NULL;
88279 }
88280
88281 +struct bpf_prog *bpf_prog_alloc(unsigned int size, gfp_t gfp_extra_flags)
88282 +{
88283 + gfp_t gfp_flags = GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO |
88284 + gfp_extra_flags;
88285 + struct bpf_work_struct *ws;
88286 + struct bpf_prog *fp;
88287 +
88288 + size = round_up(size, PAGE_SIZE);
88289 + fp = __vmalloc(size, gfp_flags, PAGE_KERNEL);
88290 + if (fp == NULL)
88291 + return NULL;
88292 +
88293 + ws = kmalloc(sizeof(*ws), GFP_KERNEL | gfp_extra_flags);
88294 + if (ws == NULL) {
88295 + vfree(fp);
88296 + return NULL;
88297 + }
88298 +
88299 + fp->pages = size / PAGE_SIZE;
88300 + fp->work = ws;
88301 +
88302 + return fp;
88303 +}
88304 +EXPORT_SYMBOL_GPL(bpf_prog_alloc);
88305 +
88306 +struct bpf_prog *bpf_prog_realloc(struct bpf_prog *fp_old, unsigned int size,
88307 + gfp_t gfp_extra_flags)
88308 +{
88309 + gfp_t gfp_flags = GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO |
88310 + gfp_extra_flags;
88311 + struct bpf_prog *fp;
88312 +
88313 + BUG_ON(fp_old == NULL);
88314 +
88315 + size = round_up(size, PAGE_SIZE);
88316 + if (size <= fp_old->pages * PAGE_SIZE)
88317 + return fp_old;
88318 +
88319 + fp = __vmalloc(size, gfp_flags, PAGE_KERNEL);
88320 + if (fp != NULL) {
88321 + memcpy(fp, fp_old, fp_old->pages * PAGE_SIZE);
88322 + fp->pages = size / PAGE_SIZE;
88323 +
88324 + /* We keep fp->work from fp_old around in the new
88325 + * reallocated structure.
88326 + */
88327 + fp_old->work = NULL;
88328 + __bpf_prog_free(fp_old);
88329 + }
88330 +
88331 + return fp;
88332 +}
88333 +EXPORT_SYMBOL_GPL(bpf_prog_realloc);
88334 +
88335 +void __bpf_prog_free(struct bpf_prog *fp)
88336 +{
88337 + kfree(fp->work);
88338 + vfree(fp);
88339 +}
88340 +EXPORT_SYMBOL_GPL(__bpf_prog_free);
88341 +
88342 /* Base function for offset calculation. Needs to go into .text section,
88343 * therefore keeping it non-static as well; will also be used by JITs
88344 * anyway later on, so do not let the compiler omit it.
88345 @@ -523,12 +585,26 @@ void bpf_prog_select_runtime(struct bpf_prog *fp)
88346
88347 /* Probe if internal BPF can be JITed */
88348 bpf_int_jit_compile(fp);
88349 + /* Lock whole bpf_prog as read-only */
88350 + bpf_prog_lock_ro(fp);
88351 }
88352 EXPORT_SYMBOL_GPL(bpf_prog_select_runtime);
88353
88354 -/* free internal BPF program */
88355 +static void bpf_prog_free_deferred(struct work_struct *work)
88356 +{
88357 + struct bpf_work_struct *ws;
88358 +
88359 + ws = container_of(work, struct bpf_work_struct, work);
88360 + bpf_jit_free(ws->prog);
88361 +}
88362 +
88363 +/* Free internal BPF program */
88364 void bpf_prog_free(struct bpf_prog *fp)
88365 {
88366 - bpf_jit_free(fp);
88367 + struct bpf_work_struct *ws = fp->work;
88368 +
88369 + INIT_WORK(&ws->work, bpf_prog_free_deferred);
88370 + ws->prog = fp;
88371 + schedule_work(&ws->work);
88372 }
88373 EXPORT_SYMBOL_GPL(bpf_prog_free);
88374 diff --git a/kernel/capability.c b/kernel/capability.c
88375 index 989f5bf..d317ca0 100644
88376 --- a/kernel/capability.c
88377 +++ b/kernel/capability.c
88378 @@ -192,6 +192,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
88379 * before modification is attempted and the application
88380 * fails.
88381 */
88382 + if (tocopy > ARRAY_SIZE(kdata))
88383 + return -EFAULT;
88384 +
88385 if (copy_to_user(dataptr, kdata, tocopy
88386 * sizeof(struct __user_cap_data_struct))) {
88387 return -EFAULT;
88388 @@ -297,10 +300,11 @@ bool has_ns_capability(struct task_struct *t,
88389 int ret;
88390
88391 rcu_read_lock();
88392 - ret = security_capable(__task_cred(t), ns, cap);
88393 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
88394 + gr_task_is_capable(t, __task_cred(t), cap);
88395 rcu_read_unlock();
88396
88397 - return (ret == 0);
88398 + return ret;
88399 }
88400
88401 /**
88402 @@ -337,10 +341,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
88403 int ret;
88404
88405 rcu_read_lock();
88406 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
88407 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
88408 rcu_read_unlock();
88409
88410 - return (ret == 0);
88411 + return ret;
88412 }
88413
88414 /**
88415 @@ -378,7 +382,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
88416 BUG();
88417 }
88418
88419 - if (security_capable(current_cred(), ns, cap) == 0) {
88420 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
88421 current->flags |= PF_SUPERPRIV;
88422 return true;
88423 }
88424 @@ -386,6 +390,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
88425 }
88426 EXPORT_SYMBOL(ns_capable);
88427
88428 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
88429 +{
88430 + if (unlikely(!cap_valid(cap))) {
88431 + printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
88432 + BUG();
88433 + }
88434 +
88435 + if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
88436 + current->flags |= PF_SUPERPRIV;
88437 + return true;
88438 + }
88439 + return false;
88440 +}
88441 +EXPORT_SYMBOL(ns_capable_nolog);
88442 +
88443 /**
88444 * file_ns_capable - Determine if the file's opener had a capability in effect
88445 * @file: The file we want to check
88446 @@ -427,6 +446,12 @@ bool capable(int cap)
88447 }
88448 EXPORT_SYMBOL(capable);
88449
88450 +bool capable_nolog(int cap)
88451 +{
88452 + return ns_capable_nolog(&init_user_ns, cap);
88453 +}
88454 +EXPORT_SYMBOL(capable_nolog);
88455 +
88456 /**
88457 * capable_wrt_inode_uidgid - Check nsown_capable and uid and gid mapped
88458 * @inode: The inode in question
88459 @@ -444,3 +469,12 @@ bool capable_wrt_inode_uidgid(const struct inode *inode, int cap)
88460 kgid_has_mapping(ns, inode->i_gid);
88461 }
88462 EXPORT_SYMBOL(capable_wrt_inode_uidgid);
88463 +
88464 +bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap)
88465 +{
88466 + struct user_namespace *ns = current_user_ns();
88467 +
88468 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid) &&
88469 + kgid_has_mapping(ns, inode->i_gid);
88470 +}
88471 +EXPORT_SYMBOL(capable_wrt_inode_uidgid_nolog);
88472 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
88473 index 3a73f99..4f29fea 100644
88474 --- a/kernel/cgroup.c
88475 +++ b/kernel/cgroup.c
88476 @@ -5341,6 +5341,14 @@ static void cgroup_release_agent(struct work_struct *work)
88477 release_list);
88478 list_del_init(&cgrp->release_list);
88479 raw_spin_unlock(&release_list_lock);
88480 +
88481 + /*
88482 + * don't bother calling call_usermodehelper if we haven't
88483 + * configured a binary to execute
88484 + */
88485 + if (cgrp->root->release_agent_path[0] == '\0')
88486 + goto continue_free;
88487 +
88488 pathbuf = kmalloc(PATH_MAX, GFP_KERNEL);
88489 if (!pathbuf)
88490 goto continue_free;
88491 @@ -5539,7 +5547,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
88492 struct task_struct *task;
88493 int count = 0;
88494
88495 - seq_printf(seq, "css_set %p\n", cset);
88496 + seq_printf(seq, "css_set %pK\n", cset);
88497
88498 list_for_each_entry(task, &cset->tasks, cg_list) {
88499 if (count++ > MAX_TASKS_SHOWN_PER_CSS)
88500 diff --git a/kernel/compat.c b/kernel/compat.c
88501 index ebb3c36..1df606e 100644
88502 --- a/kernel/compat.c
88503 +++ b/kernel/compat.c
88504 @@ -13,6 +13,7 @@
88505
88506 #include <linux/linkage.h>
88507 #include <linux/compat.h>
88508 +#include <linux/module.h>
88509 #include <linux/errno.h>
88510 #include <linux/time.h>
88511 #include <linux/signal.h>
88512 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
88513 mm_segment_t oldfs;
88514 long ret;
88515
88516 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
88517 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
88518 oldfs = get_fs();
88519 set_fs(KERNEL_DS);
88520 ret = hrtimer_nanosleep_restart(restart);
88521 @@ -252,7 +253,7 @@ COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec __user *, rqtp,
88522 oldfs = get_fs();
88523 set_fs(KERNEL_DS);
88524 ret = hrtimer_nanosleep(&tu,
88525 - rmtp ? (struct timespec __user *)&rmt : NULL,
88526 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
88527 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
88528 set_fs(oldfs);
88529
88530 @@ -379,7 +380,7 @@ COMPAT_SYSCALL_DEFINE1(sigpending, compat_old_sigset_t __user *, set)
88531 mm_segment_t old_fs = get_fs();
88532
88533 set_fs(KERNEL_DS);
88534 - ret = sys_sigpending((old_sigset_t __user *) &s);
88535 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
88536 set_fs(old_fs);
88537 if (ret == 0)
88538 ret = put_user(s, set);
88539 @@ -469,7 +470,7 @@ COMPAT_SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
88540 mm_segment_t old_fs = get_fs();
88541
88542 set_fs(KERNEL_DS);
88543 - ret = sys_old_getrlimit(resource, (struct rlimit __user *)&r);
88544 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
88545 set_fs(old_fs);
88546
88547 if (!ret) {
88548 @@ -551,8 +552,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
88549 set_fs (KERNEL_DS);
88550 ret = sys_wait4(pid,
88551 (stat_addr ?
88552 - (unsigned int __user *) &status : NULL),
88553 - options, (struct rusage __user *) &r);
88554 + (unsigned int __force_user *) &status : NULL),
88555 + options, (struct rusage __force_user *) &r);
88556 set_fs (old_fs);
88557
88558 if (ret > 0) {
88559 @@ -578,8 +579,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
88560 memset(&info, 0, sizeof(info));
88561
88562 set_fs(KERNEL_DS);
88563 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
88564 - uru ? (struct rusage __user *)&ru : NULL);
88565 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
88566 + uru ? (struct rusage __force_user *)&ru : NULL);
88567 set_fs(old_fs);
88568
88569 if ((ret < 0) || (info.si_signo == 0))
88570 @@ -713,8 +714,8 @@ COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
88571 oldfs = get_fs();
88572 set_fs(KERNEL_DS);
88573 err = sys_timer_settime(timer_id, flags,
88574 - (struct itimerspec __user *) &newts,
88575 - (struct itimerspec __user *) &oldts);
88576 + (struct itimerspec __force_user *) &newts,
88577 + (struct itimerspec __force_user *) &oldts);
88578 set_fs(oldfs);
88579 if (!err && old && put_compat_itimerspec(old, &oldts))
88580 return -EFAULT;
88581 @@ -731,7 +732,7 @@ COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
88582 oldfs = get_fs();
88583 set_fs(KERNEL_DS);
88584 err = sys_timer_gettime(timer_id,
88585 - (struct itimerspec __user *) &ts);
88586 + (struct itimerspec __force_user *) &ts);
88587 set_fs(oldfs);
88588 if (!err && put_compat_itimerspec(setting, &ts))
88589 return -EFAULT;
88590 @@ -750,7 +751,7 @@ COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock,
88591 oldfs = get_fs();
88592 set_fs(KERNEL_DS);
88593 err = sys_clock_settime(which_clock,
88594 - (struct timespec __user *) &ts);
88595 + (struct timespec __force_user *) &ts);
88596 set_fs(oldfs);
88597 return err;
88598 }
88599 @@ -765,7 +766,7 @@ COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock,
88600 oldfs = get_fs();
88601 set_fs(KERNEL_DS);
88602 err = sys_clock_gettime(which_clock,
88603 - (struct timespec __user *) &ts);
88604 + (struct timespec __force_user *) &ts);
88605 set_fs(oldfs);
88606 if (!err && compat_put_timespec(&ts, tp))
88607 return -EFAULT;
88608 @@ -785,7 +786,7 @@ COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock,
88609
88610 oldfs = get_fs();
88611 set_fs(KERNEL_DS);
88612 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
88613 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
88614 set_fs(oldfs);
88615
88616 err = compat_put_timex(utp, &txc);
88617 @@ -805,7 +806,7 @@ COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock,
88618 oldfs = get_fs();
88619 set_fs(KERNEL_DS);
88620 err = sys_clock_getres(which_clock,
88621 - (struct timespec __user *) &ts);
88622 + (struct timespec __force_user *) &ts);
88623 set_fs(oldfs);
88624 if (!err && tp && compat_put_timespec(&ts, tp))
88625 return -EFAULT;
88626 @@ -819,7 +820,7 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
88627 struct timespec tu;
88628 struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
88629
88630 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
88631 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
88632 oldfs = get_fs();
88633 set_fs(KERNEL_DS);
88634 err = clock_nanosleep_restart(restart);
88635 @@ -851,8 +852,8 @@ COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags,
88636 oldfs = get_fs();
88637 set_fs(KERNEL_DS);
88638 err = sys_clock_nanosleep(which_clock, flags,
88639 - (struct timespec __user *) &in,
88640 - (struct timespec __user *) &out);
88641 + (struct timespec __force_user *) &in,
88642 + (struct timespec __force_user *) &out);
88643 set_fs(oldfs);
88644
88645 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
88646 @@ -1146,7 +1147,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
88647 mm_segment_t old_fs = get_fs();
88648
88649 set_fs(KERNEL_DS);
88650 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
88651 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
88652 set_fs(old_fs);
88653 if (compat_put_timespec(&t, interval))
88654 return -EFAULT;
88655 diff --git a/kernel/configs.c b/kernel/configs.c
88656 index c18b1f1..b9a0132 100644
88657 --- a/kernel/configs.c
88658 +++ b/kernel/configs.c
88659 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
88660 struct proc_dir_entry *entry;
88661
88662 /* create the current config file */
88663 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
88664 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
88665 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
88666 + &ikconfig_file_ops);
88667 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
88668 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
88669 + &ikconfig_file_ops);
88670 +#endif
88671 +#else
88672 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
88673 &ikconfig_file_ops);
88674 +#endif
88675 +
88676 if (!entry)
88677 return -ENOMEM;
88678
88679 diff --git a/kernel/cred.c b/kernel/cred.c
88680 index e0573a4..26c0fd3 100644
88681 --- a/kernel/cred.c
88682 +++ b/kernel/cred.c
88683 @@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
88684 validate_creds(cred);
88685 alter_cred_subscribers(cred, -1);
88686 put_cred(cred);
88687 +
88688 +#ifdef CONFIG_GRKERNSEC_SETXID
88689 + cred = (struct cred *) tsk->delayed_cred;
88690 + if (cred != NULL) {
88691 + tsk->delayed_cred = NULL;
88692 + validate_creds(cred);
88693 + alter_cred_subscribers(cred, -1);
88694 + put_cred(cred);
88695 + }
88696 +#endif
88697 }
88698
88699 /**
88700 @@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
88701 * Always returns 0 thus allowing this function to be tail-called at the end
88702 * of, say, sys_setgid().
88703 */
88704 -int commit_creds(struct cred *new)
88705 +static int __commit_creds(struct cred *new)
88706 {
88707 struct task_struct *task = current;
88708 const struct cred *old = task->real_cred;
88709 @@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
88710
88711 get_cred(new); /* we will require a ref for the subj creds too */
88712
88713 + gr_set_role_label(task, new->uid, new->gid);
88714 +
88715 /* dumpability changes */
88716 if (!uid_eq(old->euid, new->euid) ||
88717 !gid_eq(old->egid, new->egid) ||
88718 @@ -479,6 +491,105 @@ int commit_creds(struct cred *new)
88719 put_cred(old);
88720 return 0;
88721 }
88722 +#ifdef CONFIG_GRKERNSEC_SETXID
88723 +extern int set_user(struct cred *new);
88724 +
88725 +void gr_delayed_cred_worker(void)
88726 +{
88727 + const struct cred *new = current->delayed_cred;
88728 + struct cred *ncred;
88729 +
88730 + current->delayed_cred = NULL;
88731 +
88732 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
88733 + // from doing get_cred on it when queueing this
88734 + put_cred(new);
88735 + return;
88736 + } else if (new == NULL)
88737 + return;
88738 +
88739 + ncred = prepare_creds();
88740 + if (!ncred)
88741 + goto die;
88742 + // uids
88743 + ncred->uid = new->uid;
88744 + ncred->euid = new->euid;
88745 + ncred->suid = new->suid;
88746 + ncred->fsuid = new->fsuid;
88747 + // gids
88748 + ncred->gid = new->gid;
88749 + ncred->egid = new->egid;
88750 + ncred->sgid = new->sgid;
88751 + ncred->fsgid = new->fsgid;
88752 + // groups
88753 + set_groups(ncred, new->group_info);
88754 + // caps
88755 + ncred->securebits = new->securebits;
88756 + ncred->cap_inheritable = new->cap_inheritable;
88757 + ncred->cap_permitted = new->cap_permitted;
88758 + ncred->cap_effective = new->cap_effective;
88759 + ncred->cap_bset = new->cap_bset;
88760 +
88761 + if (set_user(ncred)) {
88762 + abort_creds(ncred);
88763 + goto die;
88764 + }
88765 +
88766 + // from doing get_cred on it when queueing this
88767 + put_cred(new);
88768 +
88769 + __commit_creds(ncred);
88770 + return;
88771 +die:
88772 + // from doing get_cred on it when queueing this
88773 + put_cred(new);
88774 + do_group_exit(SIGKILL);
88775 +}
88776 +#endif
88777 +
88778 +int commit_creds(struct cred *new)
88779 +{
88780 +#ifdef CONFIG_GRKERNSEC_SETXID
88781 + int ret;
88782 + int schedule_it = 0;
88783 + struct task_struct *t;
88784 + unsigned oldsecurebits = current_cred()->securebits;
88785 +
88786 + /* we won't get called with tasklist_lock held for writing
88787 + and interrupts disabled as the cred struct in that case is
88788 + init_cred
88789 + */
88790 + if (grsec_enable_setxid && !current_is_single_threaded() &&
88791 + uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
88792 + !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
88793 + schedule_it = 1;
88794 + }
88795 + ret = __commit_creds(new);
88796 + if (schedule_it) {
88797 + rcu_read_lock();
88798 + read_lock(&tasklist_lock);
88799 + for (t = next_thread(current); t != current;
88800 + t = next_thread(t)) {
88801 + /* we'll check if the thread has uid 0 in
88802 + * the delayed worker routine
88803 + */
88804 + if (task_securebits(t) == oldsecurebits &&
88805 + t->delayed_cred == NULL) {
88806 + t->delayed_cred = get_cred(new);
88807 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
88808 + set_tsk_need_resched(t);
88809 + }
88810 + }
88811 + read_unlock(&tasklist_lock);
88812 + rcu_read_unlock();
88813 + }
88814 +
88815 + return ret;
88816 +#else
88817 + return __commit_creds(new);
88818 +#endif
88819 +}
88820 +
88821 EXPORT_SYMBOL(commit_creds);
88822
88823 /**
88824 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
88825 index 1adf62b..7736e06 100644
88826 --- a/kernel/debug/debug_core.c
88827 +++ b/kernel/debug/debug_core.c
88828 @@ -124,7 +124,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
88829 */
88830 static atomic_t masters_in_kgdb;
88831 static atomic_t slaves_in_kgdb;
88832 -static atomic_t kgdb_break_tasklet_var;
88833 +static atomic_unchecked_t kgdb_break_tasklet_var;
88834 atomic_t kgdb_setting_breakpoint;
88835
88836 struct task_struct *kgdb_usethread;
88837 @@ -134,7 +134,7 @@ int kgdb_single_step;
88838 static pid_t kgdb_sstep_pid;
88839
88840 /* to keep track of the CPU which is doing the single stepping*/
88841 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
88842 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
88843
88844 /*
88845 * If you are debugging a problem where roundup (the collection of
88846 @@ -549,7 +549,7 @@ return_normal:
88847 * kernel will only try for the value of sstep_tries before
88848 * giving up and continuing on.
88849 */
88850 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
88851 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
88852 (kgdb_info[cpu].task &&
88853 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
88854 atomic_set(&kgdb_active, -1);
88855 @@ -647,8 +647,8 @@ cpu_master_loop:
88856 }
88857
88858 kgdb_restore:
88859 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
88860 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
88861 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
88862 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
88863 if (kgdb_info[sstep_cpu].task)
88864 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
88865 else
88866 @@ -925,18 +925,18 @@ static void kgdb_unregister_callbacks(void)
88867 static void kgdb_tasklet_bpt(unsigned long ing)
88868 {
88869 kgdb_breakpoint();
88870 - atomic_set(&kgdb_break_tasklet_var, 0);
88871 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
88872 }
88873
88874 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
88875
88876 void kgdb_schedule_breakpoint(void)
88877 {
88878 - if (atomic_read(&kgdb_break_tasklet_var) ||
88879 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
88880 atomic_read(&kgdb_active) != -1 ||
88881 atomic_read(&kgdb_setting_breakpoint))
88882 return;
88883 - atomic_inc(&kgdb_break_tasklet_var);
88884 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
88885 tasklet_schedule(&kgdb_tasklet_breakpoint);
88886 }
88887 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
88888 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
88889 index 379650b..30c5180 100644
88890 --- a/kernel/debug/kdb/kdb_main.c
88891 +++ b/kernel/debug/kdb/kdb_main.c
88892 @@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
88893 continue;
88894
88895 kdb_printf("%-20s%8u 0x%p ", mod->name,
88896 - mod->core_size, (void *)mod);
88897 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
88898 #ifdef CONFIG_MODULE_UNLOAD
88899 kdb_printf("%4ld ", module_refcount(mod));
88900 #endif
88901 @@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
88902 kdb_printf(" (Loading)");
88903 else
88904 kdb_printf(" (Live)");
88905 - kdb_printf(" 0x%p", mod->module_core);
88906 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
88907
88908 #ifdef CONFIG_MODULE_UNLOAD
88909 {
88910 diff --git a/kernel/events/core.c b/kernel/events/core.c
88911 index 658f232..32e9595 100644
88912 --- a/kernel/events/core.c
88913 +++ b/kernel/events/core.c
88914 @@ -161,8 +161,15 @@ static struct srcu_struct pmus_srcu;
88915 * 0 - disallow raw tracepoint access for unpriv
88916 * 1 - disallow cpu events for unpriv
88917 * 2 - disallow kernel profiling for unpriv
88918 + * 3 - disallow all unpriv perf event use
88919 */
88920 -int sysctl_perf_event_paranoid __read_mostly = 1;
88921 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
88922 +int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
88923 +#elif defined(CONFIG_GRKERNSEC_HIDESYM)
88924 +int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
88925 +#else
88926 +int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
88927 +#endif
88928
88929 /* Minimum for 512 kiB + 1 user control page */
88930 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
88931 @@ -188,7 +195,7 @@ void update_perf_cpu_limits(void)
88932
88933 tmp *= sysctl_perf_cpu_time_max_percent;
88934 do_div(tmp, 100);
88935 - ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
88936 + ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
88937 }
88938
88939 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
88940 @@ -294,7 +301,7 @@ void perf_sample_event_took(u64 sample_len_ns)
88941 }
88942 }
88943
88944 -static atomic64_t perf_event_id;
88945 +static atomic64_unchecked_t perf_event_id;
88946
88947 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
88948 enum event_type_t event_type);
88949 @@ -3051,7 +3058,7 @@ static void __perf_event_read(void *info)
88950
88951 static inline u64 perf_event_count(struct perf_event *event)
88952 {
88953 - return local64_read(&event->count) + atomic64_read(&event->child_count);
88954 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
88955 }
88956
88957 static u64 perf_event_read(struct perf_event *event)
88958 @@ -3430,9 +3437,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
88959 mutex_lock(&event->child_mutex);
88960 total += perf_event_read(event);
88961 *enabled += event->total_time_enabled +
88962 - atomic64_read(&event->child_total_time_enabled);
88963 + atomic64_read_unchecked(&event->child_total_time_enabled);
88964 *running += event->total_time_running +
88965 - atomic64_read(&event->child_total_time_running);
88966 + atomic64_read_unchecked(&event->child_total_time_running);
88967
88968 list_for_each_entry(child, &event->child_list, child_list) {
88969 total += perf_event_read(child);
88970 @@ -3881,10 +3888,10 @@ void perf_event_update_userpage(struct perf_event *event)
88971 userpg->offset -= local64_read(&event->hw.prev_count);
88972
88973 userpg->time_enabled = enabled +
88974 - atomic64_read(&event->child_total_time_enabled);
88975 + atomic64_read_unchecked(&event->child_total_time_enabled);
88976
88977 userpg->time_running = running +
88978 - atomic64_read(&event->child_total_time_running);
88979 + atomic64_read_unchecked(&event->child_total_time_running);
88980
88981 arch_perf_update_userpage(userpg, now);
88982
88983 @@ -4448,7 +4455,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
88984
88985 /* Data. */
88986 sp = perf_user_stack_pointer(regs);
88987 - rem = __output_copy_user(handle, (void *) sp, dump_size);
88988 + rem = __output_copy_user(handle, (void __user *) sp, dump_size);
88989 dyn_size = dump_size - rem;
88990
88991 perf_output_skip(handle, rem);
88992 @@ -4539,11 +4546,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
88993 values[n++] = perf_event_count(event);
88994 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
88995 values[n++] = enabled +
88996 - atomic64_read(&event->child_total_time_enabled);
88997 + atomic64_read_unchecked(&event->child_total_time_enabled);
88998 }
88999 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
89000 values[n++] = running +
89001 - atomic64_read(&event->child_total_time_running);
89002 + atomic64_read_unchecked(&event->child_total_time_running);
89003 }
89004 if (read_format & PERF_FORMAT_ID)
89005 values[n++] = primary_event_id(event);
89006 @@ -6858,7 +6865,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
89007 event->parent = parent_event;
89008
89009 event->ns = get_pid_ns(task_active_pid_ns(current));
89010 - event->id = atomic64_inc_return(&perf_event_id);
89011 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
89012
89013 event->state = PERF_EVENT_STATE_INACTIVE;
89014
89015 @@ -7137,6 +7144,11 @@ SYSCALL_DEFINE5(perf_event_open,
89016 if (flags & ~PERF_FLAG_ALL)
89017 return -EINVAL;
89018
89019 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
89020 + if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
89021 + return -EACCES;
89022 +#endif
89023 +
89024 err = perf_copy_attr(attr_uptr, &attr);
89025 if (err)
89026 return err;
89027 @@ -7489,10 +7501,10 @@ static void sync_child_event(struct perf_event *child_event,
89028 /*
89029 * Add back the child's count to the parent's count:
89030 */
89031 - atomic64_add(child_val, &parent_event->child_count);
89032 - atomic64_add(child_event->total_time_enabled,
89033 + atomic64_add_unchecked(child_val, &parent_event->child_count);
89034 + atomic64_add_unchecked(child_event->total_time_enabled,
89035 &parent_event->child_total_time_enabled);
89036 - atomic64_add(child_event->total_time_running,
89037 + atomic64_add_unchecked(child_event->total_time_running,
89038 &parent_event->child_total_time_running);
89039
89040 /*
89041 diff --git a/kernel/events/internal.h b/kernel/events/internal.h
89042 index 569b2187..19940d9 100644
89043 --- a/kernel/events/internal.h
89044 +++ b/kernel/events/internal.h
89045 @@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
89046 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
89047 }
89048
89049 -#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
89050 +#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
89051 static inline unsigned long \
89052 func_name(struct perf_output_handle *handle, \
89053 - const void *buf, unsigned long len) \
89054 + const void user *buf, unsigned long len) \
89055 { \
89056 unsigned long size, written; \
89057 \
89058 @@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
89059 return 0;
89060 }
89061
89062 -DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
89063 +DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
89064
89065 static inline unsigned long
89066 memcpy_skip(void *dst, const void *src, unsigned long n)
89067 @@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
89068 return 0;
89069 }
89070
89071 -DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
89072 +DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
89073
89074 #ifndef arch_perf_out_copy_user
89075 #define arch_perf_out_copy_user arch_perf_out_copy_user
89076 @@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
89077 }
89078 #endif
89079
89080 -DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
89081 +DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
89082
89083 /* Callchain handling */
89084 extern struct perf_callchain_entry *
89085 diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
89086 index 1d0af8a..9913530 100644
89087 --- a/kernel/events/uprobes.c
89088 +++ b/kernel/events/uprobes.c
89089 @@ -1671,7 +1671,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
89090 {
89091 struct page *page;
89092 uprobe_opcode_t opcode;
89093 - int result;
89094 + long result;
89095
89096 pagefault_disable();
89097 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
89098 diff --git a/kernel/exit.c b/kernel/exit.c
89099 index 32c58f7..9eb6907 100644
89100 --- a/kernel/exit.c
89101 +++ b/kernel/exit.c
89102 @@ -173,6 +173,10 @@ void release_task(struct task_struct *p)
89103 struct task_struct *leader;
89104 int zap_leader;
89105 repeat:
89106 +#ifdef CONFIG_NET
89107 + gr_del_task_from_ip_table(p);
89108 +#endif
89109 +
89110 /* don't need to get the RCU readlock here - the process is dead and
89111 * can't be modifying its own credentials. But shut RCU-lockdep up */
89112 rcu_read_lock();
89113 @@ -668,6 +672,8 @@ void do_exit(long code)
89114 struct task_struct *tsk = current;
89115 int group_dead;
89116
89117 + set_fs(USER_DS);
89118 +
89119 profile_task_exit(tsk);
89120
89121 WARN_ON(blk_needs_flush_plug(tsk));
89122 @@ -684,7 +690,6 @@ void do_exit(long code)
89123 * mm_release()->clear_child_tid() from writing to a user-controlled
89124 * kernel address.
89125 */
89126 - set_fs(USER_DS);
89127
89128 ptrace_event(PTRACE_EVENT_EXIT, code);
89129
89130 @@ -742,6 +747,9 @@ void do_exit(long code)
89131 tsk->exit_code = code;
89132 taskstats_exit(tsk, group_dead);
89133
89134 + gr_acl_handle_psacct(tsk, code);
89135 + gr_acl_handle_exit();
89136 +
89137 exit_mm(tsk);
89138
89139 if (group_dead)
89140 @@ -859,7 +867,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
89141 * Take down every thread in the group. This is called by fatal signals
89142 * as well as by sys_exit_group (below).
89143 */
89144 -void
89145 +__noreturn void
89146 do_group_exit(int exit_code)
89147 {
89148 struct signal_struct *sig = current->signal;
89149 diff --git a/kernel/fork.c b/kernel/fork.c
89150 index a91e47d..71c9064 100644
89151 --- a/kernel/fork.c
89152 +++ b/kernel/fork.c
89153 @@ -183,6 +183,48 @@ void thread_info_cache_init(void)
89154 # endif
89155 #endif
89156
89157 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
89158 +static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
89159 + int node, void **lowmem_stack)
89160 +{
89161 + struct page *pages[THREAD_SIZE / PAGE_SIZE];
89162 + void *ret = NULL;
89163 + unsigned int i;
89164 +
89165 + *lowmem_stack = alloc_thread_info_node(tsk, node);
89166 + if (*lowmem_stack == NULL)
89167 + goto out;
89168 +
89169 + for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++)
89170 + pages[i] = virt_to_page(*lowmem_stack + (i * PAGE_SIZE));
89171 +
89172 + /* use VM_IOREMAP to gain THREAD_SIZE alignment */
89173 + ret = vmap(pages, THREAD_SIZE / PAGE_SIZE, VM_IOREMAP, PAGE_KERNEL);
89174 + if (ret == NULL) {
89175 + free_thread_info(*lowmem_stack);
89176 + *lowmem_stack = NULL;
89177 + }
89178 +
89179 +out:
89180 + return ret;
89181 +}
89182 +
89183 +static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
89184 +{
89185 + unmap_process_stacks(tsk);
89186 +}
89187 +#else
89188 +static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
89189 + int node, void **lowmem_stack)
89190 +{
89191 + return alloc_thread_info_node(tsk, node);
89192 +}
89193 +static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
89194 +{
89195 + free_thread_info(ti);
89196 +}
89197 +#endif
89198 +
89199 /* SLAB cache for signal_struct structures (tsk->signal) */
89200 static struct kmem_cache *signal_cachep;
89201
89202 @@ -201,18 +243,22 @@ struct kmem_cache *vm_area_cachep;
89203 /* SLAB cache for mm_struct structures (tsk->mm) */
89204 static struct kmem_cache *mm_cachep;
89205
89206 -static void account_kernel_stack(struct thread_info *ti, int account)
89207 +static void account_kernel_stack(struct task_struct *tsk, struct thread_info *ti, int account)
89208 {
89209 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
89210 + struct zone *zone = page_zone(virt_to_page(tsk->lowmem_stack));
89211 +#else
89212 struct zone *zone = page_zone(virt_to_page(ti));
89213 +#endif
89214
89215 mod_zone_page_state(zone, NR_KERNEL_STACK, account);
89216 }
89217
89218 void free_task(struct task_struct *tsk)
89219 {
89220 - account_kernel_stack(tsk->stack, -1);
89221 + account_kernel_stack(tsk, tsk->stack, -1);
89222 arch_release_thread_info(tsk->stack);
89223 - free_thread_info(tsk->stack);
89224 + gr_free_thread_info(tsk, tsk->stack);
89225 rt_mutex_debug_task_free(tsk);
89226 ftrace_graph_exit_task(tsk);
89227 put_seccomp_filter(tsk);
89228 @@ -299,6 +345,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89229 struct task_struct *tsk;
89230 struct thread_info *ti;
89231 unsigned long *stackend;
89232 + void *lowmem_stack;
89233 int node = tsk_fork_get_node(orig);
89234 int err;
89235
89236 @@ -306,7 +353,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89237 if (!tsk)
89238 return NULL;
89239
89240 - ti = alloc_thread_info_node(tsk, node);
89241 + ti = gr_alloc_thread_info_node(tsk, node, &lowmem_stack);
89242 if (!ti)
89243 goto free_tsk;
89244
89245 @@ -315,6 +362,9 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89246 goto free_ti;
89247
89248 tsk->stack = ti;
89249 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
89250 + tsk->lowmem_stack = lowmem_stack;
89251 +#endif
89252 #ifdef CONFIG_SECCOMP
89253 /*
89254 * We must handle setting up seccomp filters once we're under
89255 @@ -332,7 +382,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89256 *stackend = STACK_END_MAGIC; /* for overflow detection */
89257
89258 #ifdef CONFIG_CC_STACKPROTECTOR
89259 - tsk->stack_canary = get_random_int();
89260 + tsk->stack_canary = pax_get_random_long();
89261 #endif
89262
89263 /*
89264 @@ -346,24 +396,92 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89265 tsk->splice_pipe = NULL;
89266 tsk->task_frag.page = NULL;
89267
89268 - account_kernel_stack(ti, 1);
89269 + account_kernel_stack(tsk, ti, 1);
89270
89271 return tsk;
89272
89273 free_ti:
89274 - free_thread_info(ti);
89275 + gr_free_thread_info(tsk, ti);
89276 free_tsk:
89277 free_task_struct(tsk);
89278 return NULL;
89279 }
89280
89281 #ifdef CONFIG_MMU
89282 -static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89283 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
89284 +{
89285 + struct vm_area_struct *tmp;
89286 + unsigned long charge;
89287 + struct file *file;
89288 + int retval;
89289 +
89290 + charge = 0;
89291 + if (mpnt->vm_flags & VM_ACCOUNT) {
89292 + unsigned long len = vma_pages(mpnt);
89293 +
89294 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
89295 + goto fail_nomem;
89296 + charge = len;
89297 + }
89298 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
89299 + if (!tmp)
89300 + goto fail_nomem;
89301 + *tmp = *mpnt;
89302 + tmp->vm_mm = mm;
89303 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
89304 + retval = vma_dup_policy(mpnt, tmp);
89305 + if (retval)
89306 + goto fail_nomem_policy;
89307 + if (anon_vma_fork(tmp, mpnt))
89308 + goto fail_nomem_anon_vma_fork;
89309 + tmp->vm_flags &= ~VM_LOCKED;
89310 + tmp->vm_next = tmp->vm_prev = NULL;
89311 + tmp->vm_mirror = NULL;
89312 + file = tmp->vm_file;
89313 + if (file) {
89314 + struct inode *inode = file_inode(file);
89315 + struct address_space *mapping = file->f_mapping;
89316 +
89317 + get_file(file);
89318 + if (tmp->vm_flags & VM_DENYWRITE)
89319 + atomic_dec(&inode->i_writecount);
89320 + mutex_lock(&mapping->i_mmap_mutex);
89321 + if (tmp->vm_flags & VM_SHARED)
89322 + atomic_inc(&mapping->i_mmap_writable);
89323 + flush_dcache_mmap_lock(mapping);
89324 + /* insert tmp into the share list, just after mpnt */
89325 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
89326 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
89327 + else
89328 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
89329 + flush_dcache_mmap_unlock(mapping);
89330 + mutex_unlock(&mapping->i_mmap_mutex);
89331 + }
89332 +
89333 + /*
89334 + * Clear hugetlb-related page reserves for children. This only
89335 + * affects MAP_PRIVATE mappings. Faults generated by the child
89336 + * are not guaranteed to succeed, even if read-only
89337 + */
89338 + if (is_vm_hugetlb_page(tmp))
89339 + reset_vma_resv_huge_pages(tmp);
89340 +
89341 + return tmp;
89342 +
89343 +fail_nomem_anon_vma_fork:
89344 + mpol_put(vma_policy(tmp));
89345 +fail_nomem_policy:
89346 + kmem_cache_free(vm_area_cachep, tmp);
89347 +fail_nomem:
89348 + vm_unacct_memory(charge);
89349 + return NULL;
89350 +}
89351 +
89352 +static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89353 {
89354 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
89355 struct rb_node **rb_link, *rb_parent;
89356 int retval;
89357 - unsigned long charge;
89358
89359 uprobe_start_dup_mmap();
89360 down_write(&oldmm->mmap_sem);
89361 @@ -391,55 +509,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89362
89363 prev = NULL;
89364 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
89365 - struct file *file;
89366 -
89367 if (mpnt->vm_flags & VM_DONTCOPY) {
89368 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
89369 -vma_pages(mpnt));
89370 continue;
89371 }
89372 - charge = 0;
89373 - if (mpnt->vm_flags & VM_ACCOUNT) {
89374 - unsigned long len = vma_pages(mpnt);
89375 -
89376 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
89377 - goto fail_nomem;
89378 - charge = len;
89379 - }
89380 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
89381 - if (!tmp)
89382 - goto fail_nomem;
89383 - *tmp = *mpnt;
89384 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
89385 - retval = vma_dup_policy(mpnt, tmp);
89386 - if (retval)
89387 - goto fail_nomem_policy;
89388 - tmp->vm_mm = mm;
89389 - if (anon_vma_fork(tmp, mpnt))
89390 - goto fail_nomem_anon_vma_fork;
89391 - tmp->vm_flags &= ~VM_LOCKED;
89392 - tmp->vm_next = tmp->vm_prev = NULL;
89393 - file = tmp->vm_file;
89394 - if (file) {
89395 - struct inode *inode = file_inode(file);
89396 - struct address_space *mapping = file->f_mapping;
89397 -
89398 - get_file(file);
89399 - if (tmp->vm_flags & VM_DENYWRITE)
89400 - atomic_dec(&inode->i_writecount);
89401 - mutex_lock(&mapping->i_mmap_mutex);
89402 - if (tmp->vm_flags & VM_SHARED)
89403 - atomic_inc(&mapping->i_mmap_writable);
89404 - flush_dcache_mmap_lock(mapping);
89405 - /* insert tmp into the share list, just after mpnt */
89406 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
89407 - vma_nonlinear_insert(tmp,
89408 - &mapping->i_mmap_nonlinear);
89409 - else
89410 - vma_interval_tree_insert_after(tmp, mpnt,
89411 - &mapping->i_mmap);
89412 - flush_dcache_mmap_unlock(mapping);
89413 - mutex_unlock(&mapping->i_mmap_mutex);
89414 + tmp = dup_vma(mm, oldmm, mpnt);
89415 + if (!tmp) {
89416 + retval = -ENOMEM;
89417 + goto out;
89418 }
89419
89420 /*
89421 @@ -471,6 +549,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89422 if (retval)
89423 goto out;
89424 }
89425 +
89426 +#ifdef CONFIG_PAX_SEGMEXEC
89427 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
89428 + struct vm_area_struct *mpnt_m;
89429 +
89430 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
89431 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
89432 +
89433 + if (!mpnt->vm_mirror)
89434 + continue;
89435 +
89436 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
89437 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
89438 + mpnt->vm_mirror = mpnt_m;
89439 + } else {
89440 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
89441 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
89442 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
89443 + mpnt->vm_mirror->vm_mirror = mpnt;
89444 + }
89445 + }
89446 + BUG_ON(mpnt_m);
89447 + }
89448 +#endif
89449 +
89450 /* a new mm has just been created */
89451 arch_dup_mmap(oldmm, mm);
89452 retval = 0;
89453 @@ -480,14 +583,6 @@ out:
89454 up_write(&oldmm->mmap_sem);
89455 uprobe_end_dup_mmap();
89456 return retval;
89457 -fail_nomem_anon_vma_fork:
89458 - mpol_put(vma_policy(tmp));
89459 -fail_nomem_policy:
89460 - kmem_cache_free(vm_area_cachep, tmp);
89461 -fail_nomem:
89462 - retval = -ENOMEM;
89463 - vm_unacct_memory(charge);
89464 - goto out;
89465 }
89466
89467 static inline int mm_alloc_pgd(struct mm_struct *mm)
89468 @@ -729,8 +824,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
89469 return ERR_PTR(err);
89470
89471 mm = get_task_mm(task);
89472 - if (mm && mm != current->mm &&
89473 - !ptrace_may_access(task, mode)) {
89474 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
89475 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
89476 mmput(mm);
89477 mm = ERR_PTR(-EACCES);
89478 }
89479 @@ -933,13 +1028,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
89480 spin_unlock(&fs->lock);
89481 return -EAGAIN;
89482 }
89483 - fs->users++;
89484 + atomic_inc(&fs->users);
89485 spin_unlock(&fs->lock);
89486 return 0;
89487 }
89488 tsk->fs = copy_fs_struct(fs);
89489 if (!tsk->fs)
89490 return -ENOMEM;
89491 + /* Carry through gr_chroot_dentry and is_chrooted instead
89492 + of recomputing it here. Already copied when the task struct
89493 + is duplicated. This allows pivot_root to not be treated as
89494 + a chroot
89495 + */
89496 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
89497 +
89498 return 0;
89499 }
89500
89501 @@ -1173,7 +1275,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
89502 * parts of the process environment (as per the clone
89503 * flags). The actual kick-off is left to the caller.
89504 */
89505 -static struct task_struct *copy_process(unsigned long clone_flags,
89506 +static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
89507 unsigned long stack_start,
89508 unsigned long stack_size,
89509 int __user *child_tidptr,
89510 @@ -1244,6 +1346,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
89511 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
89512 #endif
89513 retval = -EAGAIN;
89514 +
89515 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
89516 +
89517 if (atomic_read(&p->real_cred->user->processes) >=
89518 task_rlimit(p, RLIMIT_NPROC)) {
89519 if (p->real_cred->user != INIT_USER &&
89520 @@ -1493,6 +1598,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
89521 goto bad_fork_free_pid;
89522 }
89523
89524 + /* synchronizes with gr_set_acls()
89525 + we need to call this past the point of no return for fork()
89526 + */
89527 + gr_copy_label(p);
89528 +
89529 if (likely(p->pid)) {
89530 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
89531
89532 @@ -1583,6 +1693,8 @@ bad_fork_cleanup_count:
89533 bad_fork_free:
89534 free_task(p);
89535 fork_out:
89536 + gr_log_forkfail(retval);
89537 +
89538 return ERR_PTR(retval);
89539 }
89540
89541 @@ -1644,6 +1756,7 @@ long do_fork(unsigned long clone_flags,
89542
89543 p = copy_process(clone_flags, stack_start, stack_size,
89544 child_tidptr, NULL, trace);
89545 + add_latent_entropy();
89546 /*
89547 * Do this prior waking up the new thread - the thread pointer
89548 * might get invalid after that point, if the thread exits quickly.
89549 @@ -1660,6 +1773,8 @@ long do_fork(unsigned long clone_flags,
89550 if (clone_flags & CLONE_PARENT_SETTID)
89551 put_user(nr, parent_tidptr);
89552
89553 + gr_handle_brute_check();
89554 +
89555 if (clone_flags & CLONE_VFORK) {
89556 p->vfork_done = &vfork;
89557 init_completion(&vfork);
89558 @@ -1778,7 +1893,7 @@ void __init proc_caches_init(void)
89559 mm_cachep = kmem_cache_create("mm_struct",
89560 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
89561 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
89562 - vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
89563 + vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
89564 mmap_init();
89565 nsproxy_cache_init();
89566 }
89567 @@ -1818,7 +1933,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
89568 return 0;
89569
89570 /* don't need lock here; in the worst case we'll do useless copy */
89571 - if (fs->users == 1)
89572 + if (atomic_read(&fs->users) == 1)
89573 return 0;
89574
89575 *new_fsp = copy_fs_struct(fs);
89576 @@ -1930,7 +2045,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
89577 fs = current->fs;
89578 spin_lock(&fs->lock);
89579 current->fs = new_fs;
89580 - if (--fs->users)
89581 + gr_set_chroot_entries(current, &current->fs->root);
89582 + if (atomic_dec_return(&fs->users))
89583 new_fs = NULL;
89584 else
89585 new_fs = fs;
89586 diff --git a/kernel/futex.c b/kernel/futex.c
89587 index 22b3f1b..6820bc0 100644
89588 --- a/kernel/futex.c
89589 +++ b/kernel/futex.c
89590 @@ -202,7 +202,7 @@ struct futex_pi_state {
89591 atomic_t refcount;
89592
89593 union futex_key key;
89594 -};
89595 +} __randomize_layout;
89596
89597 /**
89598 * struct futex_q - The hashed futex queue entry, one per waiting task
89599 @@ -236,7 +236,7 @@ struct futex_q {
89600 struct rt_mutex_waiter *rt_waiter;
89601 union futex_key *requeue_pi_key;
89602 u32 bitset;
89603 -};
89604 +} __randomize_layout;
89605
89606 static const struct futex_q futex_q_init = {
89607 /* list gets initialized in queue_me()*/
89608 @@ -396,6 +396,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
89609 struct page *page, *page_head;
89610 int err, ro = 0;
89611
89612 +#ifdef CONFIG_PAX_SEGMEXEC
89613 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
89614 + return -EFAULT;
89615 +#endif
89616 +
89617 /*
89618 * The futex address must be "naturally" aligned.
89619 */
89620 @@ -595,7 +600,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
89621
89622 static int get_futex_value_locked(u32 *dest, u32 __user *from)
89623 {
89624 - int ret;
89625 + unsigned long ret;
89626
89627 pagefault_disable();
89628 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
89629 @@ -3000,6 +3005,7 @@ static void __init futex_detect_cmpxchg(void)
89630 {
89631 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
89632 u32 curval;
89633 + mm_segment_t oldfs;
89634
89635 /*
89636 * This will fail and we want it. Some arch implementations do
89637 @@ -3011,8 +3017,11 @@ static void __init futex_detect_cmpxchg(void)
89638 * implementation, the non-functional ones will return
89639 * -ENOSYS.
89640 */
89641 + oldfs = get_fs();
89642 + set_fs(USER_DS);
89643 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
89644 futex_cmpxchg_enabled = 1;
89645 + set_fs(oldfs);
89646 #endif
89647 }
89648
89649 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
89650 index 55c8c93..9ba7ad6 100644
89651 --- a/kernel/futex_compat.c
89652 +++ b/kernel/futex_compat.c
89653 @@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
89654 return 0;
89655 }
89656
89657 -static void __user *futex_uaddr(struct robust_list __user *entry,
89658 +static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
89659 compat_long_t futex_offset)
89660 {
89661 compat_uptr_t base = ptr_to_compat(entry);
89662 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
89663 index b358a80..fc25240 100644
89664 --- a/kernel/gcov/base.c
89665 +++ b/kernel/gcov/base.c
89666 @@ -114,11 +114,6 @@ void gcov_enable_events(void)
89667 }
89668
89669 #ifdef CONFIG_MODULES
89670 -static inline int within(void *addr, void *start, unsigned long size)
89671 -{
89672 - return ((addr >= start) && (addr < start + size));
89673 -}
89674 -
89675 /* Update list and generate events when modules are unloaded. */
89676 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
89677 void *data)
89678 @@ -133,7 +128,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
89679
89680 /* Remove entries located in module from linked list. */
89681 while ((info = gcov_info_next(info))) {
89682 - if (within(info, mod->module_core, mod->core_size)) {
89683 + if (within_module_core_rw((unsigned long)info, mod)) {
89684 gcov_info_unlink(prev, info);
89685 if (gcov_events_enabled)
89686 gcov_event(GCOV_REMOVE, info);
89687 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
89688 index 9019f15..9a3c42e 100644
89689 --- a/kernel/jump_label.c
89690 +++ b/kernel/jump_label.c
89691 @@ -14,6 +14,7 @@
89692 #include <linux/err.h>
89693 #include <linux/static_key.h>
89694 #include <linux/jump_label_ratelimit.h>
89695 +#include <linux/mm.h>
89696
89697 #ifdef HAVE_JUMP_LABEL
89698
89699 @@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
89700
89701 size = (((unsigned long)stop - (unsigned long)start)
89702 / sizeof(struct jump_entry));
89703 + pax_open_kernel();
89704 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
89705 + pax_close_kernel();
89706 }
89707
89708 static void jump_label_update(struct static_key *key, int enable);
89709 @@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
89710 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
89711 struct jump_entry *iter;
89712
89713 + pax_open_kernel();
89714 for (iter = iter_start; iter < iter_stop; iter++) {
89715 if (within_module_init(iter->code, mod))
89716 iter->code = 0;
89717 }
89718 + pax_close_kernel();
89719 }
89720
89721 static int
89722 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
89723 index ae51670..c1a9796 100644
89724 --- a/kernel/kallsyms.c
89725 +++ b/kernel/kallsyms.c
89726 @@ -11,6 +11,9 @@
89727 * Changed the compression method from stem compression to "table lookup"
89728 * compression (see scripts/kallsyms.c for a more complete description)
89729 */
89730 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89731 +#define __INCLUDED_BY_HIDESYM 1
89732 +#endif
89733 #include <linux/kallsyms.h>
89734 #include <linux/module.h>
89735 #include <linux/init.h>
89736 @@ -54,12 +57,33 @@ extern const unsigned long kallsyms_markers[] __weak;
89737
89738 static inline int is_kernel_inittext(unsigned long addr)
89739 {
89740 + if (system_state != SYSTEM_BOOTING)
89741 + return 0;
89742 +
89743 if (addr >= (unsigned long)_sinittext
89744 && addr <= (unsigned long)_einittext)
89745 return 1;
89746 return 0;
89747 }
89748
89749 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89750 +#ifdef CONFIG_MODULES
89751 +static inline int is_module_text(unsigned long addr)
89752 +{
89753 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
89754 + return 1;
89755 +
89756 + addr = ktla_ktva(addr);
89757 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
89758 +}
89759 +#else
89760 +static inline int is_module_text(unsigned long addr)
89761 +{
89762 + return 0;
89763 +}
89764 +#endif
89765 +#endif
89766 +
89767 static inline int is_kernel_text(unsigned long addr)
89768 {
89769 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
89770 @@ -70,13 +94,28 @@ static inline int is_kernel_text(unsigned long addr)
89771
89772 static inline int is_kernel(unsigned long addr)
89773 {
89774 +
89775 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89776 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
89777 + return 1;
89778 +
89779 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
89780 +#else
89781 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
89782 +#endif
89783 +
89784 return 1;
89785 return in_gate_area_no_mm(addr);
89786 }
89787
89788 static int is_ksym_addr(unsigned long addr)
89789 {
89790 +
89791 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89792 + if (is_module_text(addr))
89793 + return 0;
89794 +#endif
89795 +
89796 if (all_var)
89797 return is_kernel(addr);
89798
89799 @@ -481,7 +520,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
89800
89801 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
89802 {
89803 - iter->name[0] = '\0';
89804 iter->nameoff = get_symbol_offset(new_pos);
89805 iter->pos = new_pos;
89806 }
89807 @@ -529,6 +567,11 @@ static int s_show(struct seq_file *m, void *p)
89808 {
89809 struct kallsym_iter *iter = m->private;
89810
89811 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89812 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
89813 + return 0;
89814 +#endif
89815 +
89816 /* Some debugging symbols have no name. Ignore them. */
89817 if (!iter->name[0])
89818 return 0;
89819 @@ -542,6 +585,7 @@ static int s_show(struct seq_file *m, void *p)
89820 */
89821 type = iter->exported ? toupper(iter->type) :
89822 tolower(iter->type);
89823 +
89824 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
89825 type, iter->name, iter->module_name);
89826 } else
89827 @@ -567,7 +611,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
89828 struct kallsym_iter *iter;
89829 int ret;
89830
89831 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
89832 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
89833 if (!iter)
89834 return -ENOMEM;
89835 reset_iter(iter, 0);
89836 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
89837 index 0aa69ea..a7fcafb 100644
89838 --- a/kernel/kcmp.c
89839 +++ b/kernel/kcmp.c
89840 @@ -100,6 +100,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
89841 struct task_struct *task1, *task2;
89842 int ret;
89843
89844 +#ifdef CONFIG_GRKERNSEC
89845 + return -ENOSYS;
89846 +#endif
89847 +
89848 rcu_read_lock();
89849
89850 /*
89851 diff --git a/kernel/kexec.c b/kernel/kexec.c
89852 index 2bee072..8979af8 100644
89853 --- a/kernel/kexec.c
89854 +++ b/kernel/kexec.c
89855 @@ -1349,7 +1349,8 @@ COMPAT_SYSCALL_DEFINE4(kexec_load, compat_ulong_t, entry,
89856 compat_ulong_t, flags)
89857 {
89858 struct compat_kexec_segment in;
89859 - struct kexec_segment out, __user *ksegments;
89860 + struct kexec_segment out;
89861 + struct kexec_segment __user *ksegments;
89862 unsigned long i, result;
89863
89864 /* Don't allow clients that don't understand the native
89865 diff --git a/kernel/kmod.c b/kernel/kmod.c
89866 index 8637e04..8b1d0d8 100644
89867 --- a/kernel/kmod.c
89868 +++ b/kernel/kmod.c
89869 @@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
89870 kfree(info->argv);
89871 }
89872
89873 -static int call_modprobe(char *module_name, int wait)
89874 +static int call_modprobe(char *module_name, char *module_param, int wait)
89875 {
89876 struct subprocess_info *info;
89877 static char *envp[] = {
89878 @@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
89879 NULL
89880 };
89881
89882 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
89883 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
89884 if (!argv)
89885 goto out;
89886
89887 @@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
89888 argv[1] = "-q";
89889 argv[2] = "--";
89890 argv[3] = module_name; /* check free_modprobe_argv() */
89891 - argv[4] = NULL;
89892 + argv[4] = module_param;
89893 + argv[5] = NULL;
89894
89895 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
89896 NULL, free_modprobe_argv, NULL);
89897 @@ -129,9 +130,8 @@ out:
89898 * If module auto-loading support is disabled then this function
89899 * becomes a no-operation.
89900 */
89901 -int __request_module(bool wait, const char *fmt, ...)
89902 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
89903 {
89904 - va_list args;
89905 char module_name[MODULE_NAME_LEN];
89906 unsigned int max_modprobes;
89907 int ret;
89908 @@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
89909 if (!modprobe_path[0])
89910 return 0;
89911
89912 - va_start(args, fmt);
89913 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
89914 - va_end(args);
89915 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
89916 if (ret >= MODULE_NAME_LEN)
89917 return -ENAMETOOLONG;
89918
89919 @@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
89920 if (ret)
89921 return ret;
89922
89923 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
89924 + if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
89925 + /* hack to workaround consolekit/udisks stupidity */
89926 + read_lock(&tasklist_lock);
89927 + if (!strcmp(current->comm, "mount") &&
89928 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
89929 + read_unlock(&tasklist_lock);
89930 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
89931 + return -EPERM;
89932 + }
89933 + read_unlock(&tasklist_lock);
89934 + }
89935 +#endif
89936 +
89937 /* If modprobe needs a service that is in a module, we get a recursive
89938 * loop. Limit the number of running kmod threads to max_threads/2 or
89939 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
89940 @@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
89941
89942 trace_module_request(module_name, wait, _RET_IP_);
89943
89944 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
89945 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
89946
89947 atomic_dec(&kmod_concurrent);
89948 return ret;
89949 }
89950 +
89951 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
89952 +{
89953 + va_list args;
89954 + int ret;
89955 +
89956 + va_start(args, fmt);
89957 + ret = ____request_module(wait, module_param, fmt, args);
89958 + va_end(args);
89959 +
89960 + return ret;
89961 +}
89962 +
89963 +int __request_module(bool wait, const char *fmt, ...)
89964 +{
89965 + va_list args;
89966 + int ret;
89967 +
89968 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
89969 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
89970 + char module_param[MODULE_NAME_LEN];
89971 +
89972 + memset(module_param, 0, sizeof(module_param));
89973 +
89974 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
89975 +
89976 + va_start(args, fmt);
89977 + ret = ____request_module(wait, module_param, fmt, args);
89978 + va_end(args);
89979 +
89980 + return ret;
89981 + }
89982 +#endif
89983 +
89984 + va_start(args, fmt);
89985 + ret = ____request_module(wait, NULL, fmt, args);
89986 + va_end(args);
89987 +
89988 + return ret;
89989 +}
89990 +
89991 EXPORT_SYMBOL(__request_module);
89992 #endif /* CONFIG_MODULES */
89993
89994 @@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
89995 */
89996 set_user_nice(current, 0);
89997
89998 +#ifdef CONFIG_GRKERNSEC
89999 + /* this is race-free as far as userland is concerned as we copied
90000 + out the path to be used prior to this point and are now operating
90001 + on that copy
90002 + */
90003 + if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
90004 + strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
90005 + strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
90006 + printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
90007 + retval = -EPERM;
90008 + goto fail;
90009 + }
90010 +#endif
90011 +
90012 retval = -ENOMEM;
90013 new = prepare_kernel_cred(current);
90014 if (!new)
90015 @@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
90016 commit_creds(new);
90017
90018 retval = do_execve(getname_kernel(sub_info->path),
90019 - (const char __user *const __user *)sub_info->argv,
90020 - (const char __user *const __user *)sub_info->envp);
90021 + (const char __user *const __force_user *)sub_info->argv,
90022 + (const char __user *const __force_user *)sub_info->envp);
90023 if (!retval)
90024 return 0;
90025
90026 @@ -260,6 +327,10 @@ static int call_helper(void *data)
90027
90028 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
90029 {
90030 +#ifdef CONFIG_GRKERNSEC
90031 + kfree(info->path);
90032 + info->path = info->origpath;
90033 +#endif
90034 if (info->cleanup)
90035 (*info->cleanup)(info);
90036 kfree(info);
90037 @@ -300,7 +371,7 @@ static int wait_for_helper(void *data)
90038 *
90039 * Thus the __user pointer cast is valid here.
90040 */
90041 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
90042 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
90043
90044 /*
90045 * If ret is 0, either ____call_usermodehelper failed and the
90046 @@ -539,7 +610,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
90047 goto out;
90048
90049 INIT_WORK(&sub_info->work, __call_usermodehelper);
90050 +#ifdef CONFIG_GRKERNSEC
90051 + sub_info->origpath = path;
90052 + sub_info->path = kstrdup(path, gfp_mask);
90053 +#else
90054 sub_info->path = path;
90055 +#endif
90056 sub_info->argv = argv;
90057 sub_info->envp = envp;
90058
90059 @@ -647,7 +723,7 @@ EXPORT_SYMBOL(call_usermodehelper);
90060 static int proc_cap_handler(struct ctl_table *table, int write,
90061 void __user *buffer, size_t *lenp, loff_t *ppos)
90062 {
90063 - struct ctl_table t;
90064 + ctl_table_no_const t;
90065 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
90066 kernel_cap_t new_cap;
90067 int err, i;
90068 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
90069 index 3995f54..e247879 100644
90070 --- a/kernel/kprobes.c
90071 +++ b/kernel/kprobes.c
90072 @@ -31,6 +31,9 @@
90073 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
90074 * <prasanna@in.ibm.com> added function-return probes.
90075 */
90076 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90077 +#define __INCLUDED_BY_HIDESYM 1
90078 +#endif
90079 #include <linux/kprobes.h>
90080 #include <linux/hash.h>
90081 #include <linux/init.h>
90082 @@ -122,12 +125,12 @@ enum kprobe_slot_state {
90083
90084 static void *alloc_insn_page(void)
90085 {
90086 - return module_alloc(PAGE_SIZE);
90087 + return module_alloc_exec(PAGE_SIZE);
90088 }
90089
90090 static void free_insn_page(void *page)
90091 {
90092 - module_free(NULL, page);
90093 + module_free_exec(NULL, page);
90094 }
90095
90096 struct kprobe_insn_cache kprobe_insn_slots = {
90097 @@ -2187,11 +2190,11 @@ static void report_probe(struct seq_file *pi, struct kprobe *p,
90098 kprobe_type = "k";
90099
90100 if (sym)
90101 - seq_printf(pi, "%p %s %s+0x%x %s ",
90102 + seq_printf(pi, "%pK %s %s+0x%x %s ",
90103 p->addr, kprobe_type, sym, offset,
90104 (modname ? modname : " "));
90105 else
90106 - seq_printf(pi, "%p %s %p ",
90107 + seq_printf(pi, "%pK %s %pK ",
90108 p->addr, kprobe_type, p->addr);
90109
90110 if (!pp)
90111 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
90112 index 6683cce..daf8999 100644
90113 --- a/kernel/ksysfs.c
90114 +++ b/kernel/ksysfs.c
90115 @@ -50,6 +50,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
90116 {
90117 if (count+1 > UEVENT_HELPER_PATH_LEN)
90118 return -ENOENT;
90119 + if (!capable(CAP_SYS_ADMIN))
90120 + return -EPERM;
90121 memcpy(uevent_helper, buf, count);
90122 uevent_helper[count] = '\0';
90123 if (count && uevent_helper[count-1] == '\n')
90124 @@ -176,7 +178,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
90125 return count;
90126 }
90127
90128 -static struct bin_attribute notes_attr = {
90129 +static bin_attribute_no_const notes_attr __read_only = {
90130 .attr = {
90131 .name = "notes",
90132 .mode = S_IRUGO,
90133 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
90134 index 88d0d44..e9ce0ee 100644
90135 --- a/kernel/locking/lockdep.c
90136 +++ b/kernel/locking/lockdep.c
90137 @@ -599,6 +599,10 @@ static int static_obj(void *obj)
90138 end = (unsigned long) &_end,
90139 addr = (unsigned long) obj;
90140
90141 +#ifdef CONFIG_PAX_KERNEXEC
90142 + start = ktla_ktva(start);
90143 +#endif
90144 +
90145 /*
90146 * static variable?
90147 */
90148 @@ -740,6 +744,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
90149 if (!static_obj(lock->key)) {
90150 debug_locks_off();
90151 printk("INFO: trying to register non-static key.\n");
90152 + printk("lock:%pS key:%pS.\n", lock, lock->key);
90153 printk("the code is fine but needs lockdep annotation.\n");
90154 printk("turning off the locking correctness validator.\n");
90155 dump_stack();
90156 @@ -3081,7 +3086,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
90157 if (!class)
90158 return 0;
90159 }
90160 - atomic_inc((atomic_t *)&class->ops);
90161 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
90162 if (very_verbose(class)) {
90163 printk("\nacquire class [%p] %s", class->key, class->name);
90164 if (class->name_version > 1)
90165 diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
90166 index ef43ac4..2720dfa 100644
90167 --- a/kernel/locking/lockdep_proc.c
90168 +++ b/kernel/locking/lockdep_proc.c
90169 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
90170 return 0;
90171 }
90172
90173 - seq_printf(m, "%p", class->key);
90174 + seq_printf(m, "%pK", class->key);
90175 #ifdef CONFIG_DEBUG_LOCKDEP
90176 seq_printf(m, " OPS:%8ld", class->ops);
90177 #endif
90178 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
90179
90180 list_for_each_entry(entry, &class->locks_after, entry) {
90181 if (entry->distance == 1) {
90182 - seq_printf(m, " -> [%p] ", entry->class->key);
90183 + seq_printf(m, " -> [%pK] ", entry->class->key);
90184 print_name(m, entry->class);
90185 seq_puts(m, "\n");
90186 }
90187 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
90188 if (!class->key)
90189 continue;
90190
90191 - seq_printf(m, "[%p] ", class->key);
90192 + seq_printf(m, "[%pK] ", class->key);
90193 print_name(m, class);
90194 seq_puts(m, "\n");
90195 }
90196 @@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
90197 if (!i)
90198 seq_line(m, '-', 40-namelen, namelen);
90199
90200 - snprintf(ip, sizeof(ip), "[<%p>]",
90201 + snprintf(ip, sizeof(ip), "[<%pK>]",
90202 (void *)class->contention_point[i]);
90203 seq_printf(m, "%40s %14lu %29s %pS\n",
90204 name, stats->contention_point[i],
90205 @@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
90206 if (!i)
90207 seq_line(m, '-', 40-namelen, namelen);
90208
90209 - snprintf(ip, sizeof(ip), "[<%p>]",
90210 + snprintf(ip, sizeof(ip), "[<%pK>]",
90211 (void *)class->contending_point[i]);
90212 seq_printf(m, "%40s %14lu %29s %pS\n",
90213 name, stats->contending_point[i],
90214 diff --git a/kernel/locking/mcs_spinlock.c b/kernel/locking/mcs_spinlock.c
90215 index 9887a90..0cd2b1d 100644
90216 --- a/kernel/locking/mcs_spinlock.c
90217 +++ b/kernel/locking/mcs_spinlock.c
90218 @@ -100,7 +100,7 @@ bool osq_lock(struct optimistic_spin_queue *lock)
90219
90220 prev = decode_cpu(old);
90221 node->prev = prev;
90222 - ACCESS_ONCE(prev->next) = node;
90223 + ACCESS_ONCE_RW(prev->next) = node;
90224
90225 /*
90226 * Normally @prev is untouchable after the above store; because at that
90227 @@ -172,8 +172,8 @@ unqueue:
90228 * it will wait in Step-A.
90229 */
90230
90231 - ACCESS_ONCE(next->prev) = prev;
90232 - ACCESS_ONCE(prev->next) = next;
90233 + ACCESS_ONCE_RW(next->prev) = prev;
90234 + ACCESS_ONCE_RW(prev->next) = next;
90235
90236 return false;
90237 }
90238 @@ -195,13 +195,13 @@ void osq_unlock(struct optimistic_spin_queue *lock)
90239 node = this_cpu_ptr(&osq_node);
90240 next = xchg(&node->next, NULL);
90241 if (next) {
90242 - ACCESS_ONCE(next->locked) = 1;
90243 + ACCESS_ONCE_RW(next->locked) = 1;
90244 return;
90245 }
90246
90247 next = osq_wait_next(lock, node, NULL);
90248 if (next)
90249 - ACCESS_ONCE(next->locked) = 1;
90250 + ACCESS_ONCE_RW(next->locked) = 1;
90251 }
90252
90253 #endif
90254 diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h
90255 index 23e89c5..8558eac 100644
90256 --- a/kernel/locking/mcs_spinlock.h
90257 +++ b/kernel/locking/mcs_spinlock.h
90258 @@ -81,7 +81,7 @@ void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node)
90259 */
90260 return;
90261 }
90262 - ACCESS_ONCE(prev->next) = node;
90263 + ACCESS_ONCE_RW(prev->next) = node;
90264
90265 /* Wait until the lock holder passes the lock down. */
90266 arch_mcs_spin_lock_contended(&node->locked);
90267 diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
90268 index 5cf6731..ce3bc5a 100644
90269 --- a/kernel/locking/mutex-debug.c
90270 +++ b/kernel/locking/mutex-debug.c
90271 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
90272 }
90273
90274 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
90275 - struct thread_info *ti)
90276 + struct task_struct *task)
90277 {
90278 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
90279
90280 /* Mark the current thread as blocked on the lock: */
90281 - ti->task->blocked_on = waiter;
90282 + task->blocked_on = waiter;
90283 }
90284
90285 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
90286 - struct thread_info *ti)
90287 + struct task_struct *task)
90288 {
90289 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
90290 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
90291 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
90292 - ti->task->blocked_on = NULL;
90293 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
90294 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
90295 + task->blocked_on = NULL;
90296
90297 list_del_init(&waiter->list);
90298 waiter->task = NULL;
90299 diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
90300 index 0799fd3..d06ae3b 100644
90301 --- a/kernel/locking/mutex-debug.h
90302 +++ b/kernel/locking/mutex-debug.h
90303 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
90304 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
90305 extern void debug_mutex_add_waiter(struct mutex *lock,
90306 struct mutex_waiter *waiter,
90307 - struct thread_info *ti);
90308 + struct task_struct *task);
90309 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
90310 - struct thread_info *ti);
90311 + struct task_struct *task);
90312 extern void debug_mutex_unlock(struct mutex *lock);
90313 extern void debug_mutex_init(struct mutex *lock, const char *name,
90314 struct lock_class_key *key);
90315 diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
90316 index ae712b2..d0d4a41 100644
90317 --- a/kernel/locking/mutex.c
90318 +++ b/kernel/locking/mutex.c
90319 @@ -486,7 +486,7 @@ slowpath:
90320 goto skip_wait;
90321
90322 debug_mutex_lock_common(lock, &waiter);
90323 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
90324 + debug_mutex_add_waiter(lock, &waiter, task);
90325
90326 /* add waiting tasks to the end of the waitqueue (FIFO): */
90327 list_add_tail(&waiter.list, &lock->wait_list);
90328 @@ -531,7 +531,7 @@ slowpath:
90329 schedule_preempt_disabled();
90330 spin_lock_mutex(&lock->wait_lock, flags);
90331 }
90332 - mutex_remove_waiter(lock, &waiter, current_thread_info());
90333 + mutex_remove_waiter(lock, &waiter, task);
90334 /* set it to 0 if there are no waiters left: */
90335 if (likely(list_empty(&lock->wait_list)))
90336 atomic_set(&lock->count, 0);
90337 @@ -568,7 +568,7 @@ skip_wait:
90338 return 0;
90339
90340 err:
90341 - mutex_remove_waiter(lock, &waiter, task_thread_info(task));
90342 + mutex_remove_waiter(lock, &waiter, task);
90343 spin_unlock_mutex(&lock->wait_lock, flags);
90344 debug_mutex_free_waiter(&waiter);
90345 mutex_release(&lock->dep_map, 1, ip);
90346 diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
90347 index 1d96dd0..994ff19 100644
90348 --- a/kernel/locking/rtmutex-tester.c
90349 +++ b/kernel/locking/rtmutex-tester.c
90350 @@ -22,7 +22,7 @@
90351 #define MAX_RT_TEST_MUTEXES 8
90352
90353 static spinlock_t rttest_lock;
90354 -static atomic_t rttest_event;
90355 +static atomic_unchecked_t rttest_event;
90356
90357 struct test_thread_data {
90358 int opcode;
90359 @@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90360
90361 case RTTEST_LOCKCONT:
90362 td->mutexes[td->opdata] = 1;
90363 - td->event = atomic_add_return(1, &rttest_event);
90364 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90365 return 0;
90366
90367 case RTTEST_RESET:
90368 @@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90369 return 0;
90370
90371 case RTTEST_RESETEVENT:
90372 - atomic_set(&rttest_event, 0);
90373 + atomic_set_unchecked(&rttest_event, 0);
90374 return 0;
90375
90376 default:
90377 @@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90378 return ret;
90379
90380 td->mutexes[id] = 1;
90381 - td->event = atomic_add_return(1, &rttest_event);
90382 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90383 rt_mutex_lock(&mutexes[id]);
90384 - td->event = atomic_add_return(1, &rttest_event);
90385 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90386 td->mutexes[id] = 4;
90387 return 0;
90388
90389 @@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90390 return ret;
90391
90392 td->mutexes[id] = 1;
90393 - td->event = atomic_add_return(1, &rttest_event);
90394 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90395 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
90396 - td->event = atomic_add_return(1, &rttest_event);
90397 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90398 td->mutexes[id] = ret ? 0 : 4;
90399 return ret ? -EINTR : 0;
90400
90401 @@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90402 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
90403 return ret;
90404
90405 - td->event = atomic_add_return(1, &rttest_event);
90406 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90407 rt_mutex_unlock(&mutexes[id]);
90408 - td->event = atomic_add_return(1, &rttest_event);
90409 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90410 td->mutexes[id] = 0;
90411 return 0;
90412
90413 @@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
90414 break;
90415
90416 td->mutexes[dat] = 2;
90417 - td->event = atomic_add_return(1, &rttest_event);
90418 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90419 break;
90420
90421 default:
90422 @@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
90423 return;
90424
90425 td->mutexes[dat] = 3;
90426 - td->event = atomic_add_return(1, &rttest_event);
90427 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90428 break;
90429
90430 case RTTEST_LOCKNOWAIT:
90431 @@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
90432 return;
90433
90434 td->mutexes[dat] = 1;
90435 - td->event = atomic_add_return(1, &rttest_event);
90436 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90437 return;
90438
90439 default:
90440 diff --git a/kernel/module.c b/kernel/module.c
90441 index 1c47139..6242887 100644
90442 --- a/kernel/module.c
90443 +++ b/kernel/module.c
90444 @@ -60,6 +60,7 @@
90445 #include <linux/jump_label.h>
90446 #include <linux/pfn.h>
90447 #include <linux/bsearch.h>
90448 +#include <linux/grsecurity.h>
90449 #include <uapi/linux/module.h>
90450 #include "module-internal.h"
90451
90452 @@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
90453
90454 /* Bounds of module allocation, for speeding __module_address.
90455 * Protected by module_mutex. */
90456 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
90457 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
90458 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
90459
90460 int register_module_notifier(struct notifier_block * nb)
90461 {
90462 @@ -323,7 +325,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
90463 return true;
90464
90465 list_for_each_entry_rcu(mod, &modules, list) {
90466 - struct symsearch arr[] = {
90467 + struct symsearch modarr[] = {
90468 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
90469 NOT_GPL_ONLY, false },
90470 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
90471 @@ -348,7 +350,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
90472 if (mod->state == MODULE_STATE_UNFORMED)
90473 continue;
90474
90475 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
90476 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
90477 return true;
90478 }
90479 return false;
90480 @@ -488,7 +490,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
90481 if (!pcpusec->sh_size)
90482 return 0;
90483
90484 - if (align > PAGE_SIZE) {
90485 + if (align-1 >= PAGE_SIZE) {
90486 pr_warn("%s: per-cpu alignment %li > %li\n",
90487 mod->name, align, PAGE_SIZE);
90488 align = PAGE_SIZE;
90489 @@ -1060,7 +1062,7 @@ struct module_attribute module_uevent =
90490 static ssize_t show_coresize(struct module_attribute *mattr,
90491 struct module_kobject *mk, char *buffer)
90492 {
90493 - return sprintf(buffer, "%u\n", mk->mod->core_size);
90494 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
90495 }
90496
90497 static struct module_attribute modinfo_coresize =
90498 @@ -1069,7 +1071,7 @@ static struct module_attribute modinfo_coresize =
90499 static ssize_t show_initsize(struct module_attribute *mattr,
90500 struct module_kobject *mk, char *buffer)
90501 {
90502 - return sprintf(buffer, "%u\n", mk->mod->init_size);
90503 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
90504 }
90505
90506 static struct module_attribute modinfo_initsize =
90507 @@ -1161,12 +1163,29 @@ static int check_version(Elf_Shdr *sechdrs,
90508 goto bad_version;
90509 }
90510
90511 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
90512 + /*
90513 + * avoid potentially printing jibberish on attempted load
90514 + * of a module randomized with a different seed
90515 + */
90516 + pr_warn("no symbol version for %s\n", symname);
90517 +#else
90518 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
90519 +#endif
90520 return 0;
90521
90522 bad_version:
90523 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
90524 + /*
90525 + * avoid potentially printing jibberish on attempted load
90526 + * of a module randomized with a different seed
90527 + */
90528 + printk("attempted module disagrees about version of symbol %s\n",
90529 + symname);
90530 +#else
90531 printk("%s: disagrees about version of symbol %s\n",
90532 mod->name, symname);
90533 +#endif
90534 return 0;
90535 }
90536
90537 @@ -1282,7 +1301,7 @@ resolve_symbol_wait(struct module *mod,
90538 */
90539 #ifdef CONFIG_SYSFS
90540
90541 -#ifdef CONFIG_KALLSYMS
90542 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
90543 static inline bool sect_empty(const Elf_Shdr *sect)
90544 {
90545 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
90546 @@ -1422,7 +1441,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
90547 {
90548 unsigned int notes, loaded, i;
90549 struct module_notes_attrs *notes_attrs;
90550 - struct bin_attribute *nattr;
90551 + bin_attribute_no_const *nattr;
90552
90553 /* failed to create section attributes, so can't create notes */
90554 if (!mod->sect_attrs)
90555 @@ -1534,7 +1553,7 @@ static void del_usage_links(struct module *mod)
90556 static int module_add_modinfo_attrs(struct module *mod)
90557 {
90558 struct module_attribute *attr;
90559 - struct module_attribute *temp_attr;
90560 + module_attribute_no_const *temp_attr;
90561 int error = 0;
90562 int i;
90563
90564 @@ -1755,21 +1774,21 @@ static void set_section_ro_nx(void *base,
90565
90566 static void unset_module_core_ro_nx(struct module *mod)
90567 {
90568 - set_page_attributes(mod->module_core + mod->core_text_size,
90569 - mod->module_core + mod->core_size,
90570 + set_page_attributes(mod->module_core_rw,
90571 + mod->module_core_rw + mod->core_size_rw,
90572 set_memory_x);
90573 - set_page_attributes(mod->module_core,
90574 - mod->module_core + mod->core_ro_size,
90575 + set_page_attributes(mod->module_core_rx,
90576 + mod->module_core_rx + mod->core_size_rx,
90577 set_memory_rw);
90578 }
90579
90580 static void unset_module_init_ro_nx(struct module *mod)
90581 {
90582 - set_page_attributes(mod->module_init + mod->init_text_size,
90583 - mod->module_init + mod->init_size,
90584 + set_page_attributes(mod->module_init_rw,
90585 + mod->module_init_rw + mod->init_size_rw,
90586 set_memory_x);
90587 - set_page_attributes(mod->module_init,
90588 - mod->module_init + mod->init_ro_size,
90589 + set_page_attributes(mod->module_init_rx,
90590 + mod->module_init_rx + mod->init_size_rx,
90591 set_memory_rw);
90592 }
90593
90594 @@ -1782,14 +1801,14 @@ void set_all_modules_text_rw(void)
90595 list_for_each_entry_rcu(mod, &modules, list) {
90596 if (mod->state == MODULE_STATE_UNFORMED)
90597 continue;
90598 - if ((mod->module_core) && (mod->core_text_size)) {
90599 - set_page_attributes(mod->module_core,
90600 - mod->module_core + mod->core_text_size,
90601 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
90602 + set_page_attributes(mod->module_core_rx,
90603 + mod->module_core_rx + mod->core_size_rx,
90604 set_memory_rw);
90605 }
90606 - if ((mod->module_init) && (mod->init_text_size)) {
90607 - set_page_attributes(mod->module_init,
90608 - mod->module_init + mod->init_text_size,
90609 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
90610 + set_page_attributes(mod->module_init_rx,
90611 + mod->module_init_rx + mod->init_size_rx,
90612 set_memory_rw);
90613 }
90614 }
90615 @@ -1805,14 +1824,14 @@ void set_all_modules_text_ro(void)
90616 list_for_each_entry_rcu(mod, &modules, list) {
90617 if (mod->state == MODULE_STATE_UNFORMED)
90618 continue;
90619 - if ((mod->module_core) && (mod->core_text_size)) {
90620 - set_page_attributes(mod->module_core,
90621 - mod->module_core + mod->core_text_size,
90622 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
90623 + set_page_attributes(mod->module_core_rx,
90624 + mod->module_core_rx + mod->core_size_rx,
90625 set_memory_ro);
90626 }
90627 - if ((mod->module_init) && (mod->init_text_size)) {
90628 - set_page_attributes(mod->module_init,
90629 - mod->module_init + mod->init_text_size,
90630 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
90631 + set_page_attributes(mod->module_init_rx,
90632 + mod->module_init_rx + mod->init_size_rx,
90633 set_memory_ro);
90634 }
90635 }
90636 @@ -1865,16 +1884,19 @@ static void free_module(struct module *mod)
90637
90638 /* This may be NULL, but that's OK */
90639 unset_module_init_ro_nx(mod);
90640 - module_free(mod, mod->module_init);
90641 + module_free(mod, mod->module_init_rw);
90642 + module_free_exec(mod, mod->module_init_rx);
90643 kfree(mod->args);
90644 percpu_modfree(mod);
90645
90646 /* Free lock-classes: */
90647 - lockdep_free_key_range(mod->module_core, mod->core_size);
90648 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
90649 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
90650
90651 /* Finally, free the core (containing the module structure) */
90652 unset_module_core_ro_nx(mod);
90653 - module_free(mod, mod->module_core);
90654 + module_free_exec(mod, mod->module_core_rx);
90655 + module_free(mod, mod->module_core_rw);
90656
90657 #ifdef CONFIG_MPU
90658 update_protections(current->mm);
90659 @@ -1943,9 +1965,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
90660 int ret = 0;
90661 const struct kernel_symbol *ksym;
90662
90663 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
90664 + int is_fs_load = 0;
90665 + int register_filesystem_found = 0;
90666 + char *p;
90667 +
90668 + p = strstr(mod->args, "grsec_modharden_fs");
90669 + if (p) {
90670 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
90671 + /* copy \0 as well */
90672 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
90673 + is_fs_load = 1;
90674 + }
90675 +#endif
90676 +
90677 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
90678 const char *name = info->strtab + sym[i].st_name;
90679
90680 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
90681 + /* it's a real shame this will never get ripped and copied
90682 + upstream! ;(
90683 + */
90684 + if (is_fs_load && !strcmp(name, "register_filesystem"))
90685 + register_filesystem_found = 1;
90686 +#endif
90687 +
90688 switch (sym[i].st_shndx) {
90689 case SHN_COMMON:
90690 /* Ignore common symbols */
90691 @@ -1970,7 +2014,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
90692 ksym = resolve_symbol_wait(mod, info, name);
90693 /* Ok if resolved. */
90694 if (ksym && !IS_ERR(ksym)) {
90695 + pax_open_kernel();
90696 sym[i].st_value = ksym->value;
90697 + pax_close_kernel();
90698 break;
90699 }
90700
90701 @@ -1989,11 +2035,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
90702 secbase = (unsigned long)mod_percpu(mod);
90703 else
90704 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
90705 + pax_open_kernel();
90706 sym[i].st_value += secbase;
90707 + pax_close_kernel();
90708 break;
90709 }
90710 }
90711
90712 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
90713 + if (is_fs_load && !register_filesystem_found) {
90714 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
90715 + ret = -EPERM;
90716 + }
90717 +#endif
90718 +
90719 return ret;
90720 }
90721
90722 @@ -2077,22 +2132,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
90723 || s->sh_entsize != ~0UL
90724 || strstarts(sname, ".init"))
90725 continue;
90726 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
90727 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
90728 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
90729 + else
90730 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
90731 pr_debug("\t%s\n", sname);
90732 }
90733 - switch (m) {
90734 - case 0: /* executable */
90735 - mod->core_size = debug_align(mod->core_size);
90736 - mod->core_text_size = mod->core_size;
90737 - break;
90738 - case 1: /* RO: text and ro-data */
90739 - mod->core_size = debug_align(mod->core_size);
90740 - mod->core_ro_size = mod->core_size;
90741 - break;
90742 - case 3: /* whole core */
90743 - mod->core_size = debug_align(mod->core_size);
90744 - break;
90745 - }
90746 }
90747
90748 pr_debug("Init section allocation order:\n");
90749 @@ -2106,23 +2151,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
90750 || s->sh_entsize != ~0UL
90751 || !strstarts(sname, ".init"))
90752 continue;
90753 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
90754 - | INIT_OFFSET_MASK);
90755 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
90756 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
90757 + else
90758 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
90759 + s->sh_entsize |= INIT_OFFSET_MASK;
90760 pr_debug("\t%s\n", sname);
90761 }
90762 - switch (m) {
90763 - case 0: /* executable */
90764 - mod->init_size = debug_align(mod->init_size);
90765 - mod->init_text_size = mod->init_size;
90766 - break;
90767 - case 1: /* RO: text and ro-data */
90768 - mod->init_size = debug_align(mod->init_size);
90769 - mod->init_ro_size = mod->init_size;
90770 - break;
90771 - case 3: /* whole init */
90772 - mod->init_size = debug_align(mod->init_size);
90773 - break;
90774 - }
90775 }
90776 }
90777
90778 @@ -2295,7 +2330,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
90779
90780 /* Put symbol section at end of init part of module. */
90781 symsect->sh_flags |= SHF_ALLOC;
90782 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
90783 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
90784 info->index.sym) | INIT_OFFSET_MASK;
90785 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
90786
90787 @@ -2312,13 +2347,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
90788 }
90789
90790 /* Append room for core symbols at end of core part. */
90791 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
90792 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
90793 - mod->core_size += strtab_size;
90794 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
90795 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
90796 + mod->core_size_rx += strtab_size;
90797
90798 /* Put string table section at end of init part of module. */
90799 strsect->sh_flags |= SHF_ALLOC;
90800 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
90801 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
90802 info->index.str) | INIT_OFFSET_MASK;
90803 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
90804 }
90805 @@ -2336,12 +2371,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
90806 /* Make sure we get permanent strtab: don't use info->strtab. */
90807 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
90808
90809 + pax_open_kernel();
90810 +
90811 /* Set types up while we still have access to sections. */
90812 for (i = 0; i < mod->num_symtab; i++)
90813 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
90814
90815 - mod->core_symtab = dst = mod->module_core + info->symoffs;
90816 - mod->core_strtab = s = mod->module_core + info->stroffs;
90817 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
90818 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
90819 src = mod->symtab;
90820 for (ndst = i = 0; i < mod->num_symtab; i++) {
90821 if (i == 0 ||
90822 @@ -2353,6 +2390,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
90823 }
90824 }
90825 mod->core_num_syms = ndst;
90826 +
90827 + pax_close_kernel();
90828 }
90829 #else
90830 static inline void layout_symtab(struct module *mod, struct load_info *info)
90831 @@ -2386,17 +2425,33 @@ void * __weak module_alloc(unsigned long size)
90832 return vmalloc_exec(size);
90833 }
90834
90835 -static void *module_alloc_update_bounds(unsigned long size)
90836 +static void *module_alloc_update_bounds_rw(unsigned long size)
90837 {
90838 void *ret = module_alloc(size);
90839
90840 if (ret) {
90841 mutex_lock(&module_mutex);
90842 /* Update module bounds. */
90843 - if ((unsigned long)ret < module_addr_min)
90844 - module_addr_min = (unsigned long)ret;
90845 - if ((unsigned long)ret + size > module_addr_max)
90846 - module_addr_max = (unsigned long)ret + size;
90847 + if ((unsigned long)ret < module_addr_min_rw)
90848 + module_addr_min_rw = (unsigned long)ret;
90849 + if ((unsigned long)ret + size > module_addr_max_rw)
90850 + module_addr_max_rw = (unsigned long)ret + size;
90851 + mutex_unlock(&module_mutex);
90852 + }
90853 + return ret;
90854 +}
90855 +
90856 +static void *module_alloc_update_bounds_rx(unsigned long size)
90857 +{
90858 + void *ret = module_alloc_exec(size);
90859 +
90860 + if (ret) {
90861 + mutex_lock(&module_mutex);
90862 + /* Update module bounds. */
90863 + if ((unsigned long)ret < module_addr_min_rx)
90864 + module_addr_min_rx = (unsigned long)ret;
90865 + if ((unsigned long)ret + size > module_addr_max_rx)
90866 + module_addr_max_rx = (unsigned long)ret + size;
90867 mutex_unlock(&module_mutex);
90868 }
90869 return ret;
90870 @@ -2650,7 +2705,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
90871 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
90872
90873 if (info->index.sym == 0) {
90874 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
90875 + /*
90876 + * avoid potentially printing jibberish on attempted load
90877 + * of a module randomized with a different seed
90878 + */
90879 + pr_warn("module has no symbols (stripped?)\n");
90880 +#else
90881 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
90882 +#endif
90883 return ERR_PTR(-ENOEXEC);
90884 }
90885
90886 @@ -2666,8 +2729,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
90887 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
90888 {
90889 const char *modmagic = get_modinfo(info, "vermagic");
90890 + const char *license = get_modinfo(info, "license");
90891 int err;
90892
90893 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
90894 + if (!license || !license_is_gpl_compatible(license))
90895 + return -ENOEXEC;
90896 +#endif
90897 +
90898 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
90899 modmagic = NULL;
90900
90901 @@ -2692,7 +2761,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
90902 }
90903
90904 /* Set up license info based on the info section */
90905 - set_license(mod, get_modinfo(info, "license"));
90906 + set_license(mod, license);
90907
90908 return 0;
90909 }
90910 @@ -2786,7 +2855,7 @@ static int move_module(struct module *mod, struct load_info *info)
90911 void *ptr;
90912
90913 /* Do the allocs. */
90914 - ptr = module_alloc_update_bounds(mod->core_size);
90915 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
90916 /*
90917 * The pointer to this block is stored in the module structure
90918 * which is inside the block. Just mark it as not being a
90919 @@ -2796,11 +2865,11 @@ static int move_module(struct module *mod, struct load_info *info)
90920 if (!ptr)
90921 return -ENOMEM;
90922
90923 - memset(ptr, 0, mod->core_size);
90924 - mod->module_core = ptr;
90925 + memset(ptr, 0, mod->core_size_rw);
90926 + mod->module_core_rw = ptr;
90927
90928 - if (mod->init_size) {
90929 - ptr = module_alloc_update_bounds(mod->init_size);
90930 + if (mod->init_size_rw) {
90931 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
90932 /*
90933 * The pointer to this block is stored in the module structure
90934 * which is inside the block. This block doesn't need to be
90935 @@ -2809,13 +2878,45 @@ static int move_module(struct module *mod, struct load_info *info)
90936 */
90937 kmemleak_ignore(ptr);
90938 if (!ptr) {
90939 - module_free(mod, mod->module_core);
90940 + module_free(mod, mod->module_core_rw);
90941 return -ENOMEM;
90942 }
90943 - memset(ptr, 0, mod->init_size);
90944 - mod->module_init = ptr;
90945 + memset(ptr, 0, mod->init_size_rw);
90946 + mod->module_init_rw = ptr;
90947 } else
90948 - mod->module_init = NULL;
90949 + mod->module_init_rw = NULL;
90950 +
90951 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
90952 + kmemleak_not_leak(ptr);
90953 + if (!ptr) {
90954 + if (mod->module_init_rw)
90955 + module_free(mod, mod->module_init_rw);
90956 + module_free(mod, mod->module_core_rw);
90957 + return -ENOMEM;
90958 + }
90959 +
90960 + pax_open_kernel();
90961 + memset(ptr, 0, mod->core_size_rx);
90962 + pax_close_kernel();
90963 + mod->module_core_rx = ptr;
90964 +
90965 + if (mod->init_size_rx) {
90966 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
90967 + kmemleak_ignore(ptr);
90968 + if (!ptr && mod->init_size_rx) {
90969 + module_free_exec(mod, mod->module_core_rx);
90970 + if (mod->module_init_rw)
90971 + module_free(mod, mod->module_init_rw);
90972 + module_free(mod, mod->module_core_rw);
90973 + return -ENOMEM;
90974 + }
90975 +
90976 + pax_open_kernel();
90977 + memset(ptr, 0, mod->init_size_rx);
90978 + pax_close_kernel();
90979 + mod->module_init_rx = ptr;
90980 + } else
90981 + mod->module_init_rx = NULL;
90982
90983 /* Transfer each section which specifies SHF_ALLOC */
90984 pr_debug("final section addresses:\n");
90985 @@ -2826,16 +2927,45 @@ static int move_module(struct module *mod, struct load_info *info)
90986 if (!(shdr->sh_flags & SHF_ALLOC))
90987 continue;
90988
90989 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
90990 - dest = mod->module_init
90991 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
90992 - else
90993 - dest = mod->module_core + shdr->sh_entsize;
90994 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
90995 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
90996 + dest = mod->module_init_rw
90997 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
90998 + else
90999 + dest = mod->module_init_rx
91000 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
91001 + } else {
91002 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
91003 + dest = mod->module_core_rw + shdr->sh_entsize;
91004 + else
91005 + dest = mod->module_core_rx + shdr->sh_entsize;
91006 + }
91007 +
91008 + if (shdr->sh_type != SHT_NOBITS) {
91009 +
91010 +#ifdef CONFIG_PAX_KERNEXEC
91011 +#ifdef CONFIG_X86_64
91012 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
91013 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
91014 +#endif
91015 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
91016 + pax_open_kernel();
91017 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
91018 + pax_close_kernel();
91019 + } else
91020 +#endif
91021
91022 - if (shdr->sh_type != SHT_NOBITS)
91023 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
91024 + }
91025 /* Update sh_addr to point to copy in image. */
91026 - shdr->sh_addr = (unsigned long)dest;
91027 +
91028 +#ifdef CONFIG_PAX_KERNEXEC
91029 + if (shdr->sh_flags & SHF_EXECINSTR)
91030 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
91031 + else
91032 +#endif
91033 +
91034 + shdr->sh_addr = (unsigned long)dest;
91035 pr_debug("\t0x%lx %s\n",
91036 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
91037 }
91038 @@ -2892,12 +3022,12 @@ static void flush_module_icache(const struct module *mod)
91039 * Do it before processing of module parameters, so the module
91040 * can provide parameter accessor functions of its own.
91041 */
91042 - if (mod->module_init)
91043 - flush_icache_range((unsigned long)mod->module_init,
91044 - (unsigned long)mod->module_init
91045 - + mod->init_size);
91046 - flush_icache_range((unsigned long)mod->module_core,
91047 - (unsigned long)mod->module_core + mod->core_size);
91048 + if (mod->module_init_rx)
91049 + flush_icache_range((unsigned long)mod->module_init_rx,
91050 + (unsigned long)mod->module_init_rx
91051 + + mod->init_size_rx);
91052 + flush_icache_range((unsigned long)mod->module_core_rx,
91053 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
91054
91055 set_fs(old_fs);
91056 }
91057 @@ -2954,8 +3084,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
91058 static void module_deallocate(struct module *mod, struct load_info *info)
91059 {
91060 percpu_modfree(mod);
91061 - module_free(mod, mod->module_init);
91062 - module_free(mod, mod->module_core);
91063 + module_free_exec(mod, mod->module_init_rx);
91064 + module_free_exec(mod, mod->module_core_rx);
91065 + module_free(mod, mod->module_init_rw);
91066 + module_free(mod, mod->module_core_rw);
91067 }
91068
91069 int __weak module_finalize(const Elf_Ehdr *hdr,
91070 @@ -2968,7 +3100,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
91071 static int post_relocation(struct module *mod, const struct load_info *info)
91072 {
91073 /* Sort exception table now relocations are done. */
91074 + pax_open_kernel();
91075 sort_extable(mod->extable, mod->extable + mod->num_exentries);
91076 + pax_close_kernel();
91077
91078 /* Copy relocated percpu area over. */
91079 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
91080 @@ -3077,11 +3211,12 @@ static int do_init_module(struct module *mod)
91081 mod->strtab = mod->core_strtab;
91082 #endif
91083 unset_module_init_ro_nx(mod);
91084 - module_free(mod, mod->module_init);
91085 - mod->module_init = NULL;
91086 - mod->init_size = 0;
91087 - mod->init_ro_size = 0;
91088 - mod->init_text_size = 0;
91089 + module_free(mod, mod->module_init_rw);
91090 + module_free_exec(mod, mod->module_init_rx);
91091 + mod->module_init_rw = NULL;
91092 + mod->module_init_rx = NULL;
91093 + mod->init_size_rw = 0;
91094 + mod->init_size_rx = 0;
91095 mutex_unlock(&module_mutex);
91096 wake_up_all(&module_wq);
91097
91098 @@ -3149,16 +3284,16 @@ static int complete_formation(struct module *mod, struct load_info *info)
91099 module_bug_finalize(info->hdr, info->sechdrs, mod);
91100
91101 /* Set RO and NX regions for core */
91102 - set_section_ro_nx(mod->module_core,
91103 - mod->core_text_size,
91104 - mod->core_ro_size,
91105 - mod->core_size);
91106 + set_section_ro_nx(mod->module_core_rx,
91107 + mod->core_size_rx,
91108 + mod->core_size_rx,
91109 + mod->core_size_rx);
91110
91111 /* Set RO and NX regions for init */
91112 - set_section_ro_nx(mod->module_init,
91113 - mod->init_text_size,
91114 - mod->init_ro_size,
91115 - mod->init_size);
91116 + set_section_ro_nx(mod->module_init_rx,
91117 + mod->init_size_rx,
91118 + mod->init_size_rx,
91119 + mod->init_size_rx);
91120
91121 /* Mark state as coming so strong_try_module_get() ignores us,
91122 * but kallsyms etc. can see us. */
91123 @@ -3242,9 +3377,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
91124 if (err)
91125 goto free_unload;
91126
91127 + /* Now copy in args */
91128 + mod->args = strndup_user(uargs, ~0UL >> 1);
91129 + if (IS_ERR(mod->args)) {
91130 + err = PTR_ERR(mod->args);
91131 + goto free_unload;
91132 + }
91133 +
91134 /* Set up MODINFO_ATTR fields */
91135 setup_modinfo(mod, info);
91136
91137 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
91138 + {
91139 + char *p, *p2;
91140 +
91141 + if (strstr(mod->args, "grsec_modharden_netdev")) {
91142 + 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);
91143 + err = -EPERM;
91144 + goto free_modinfo;
91145 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
91146 + p += sizeof("grsec_modharden_normal") - 1;
91147 + p2 = strstr(p, "_");
91148 + if (p2) {
91149 + *p2 = '\0';
91150 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
91151 + *p2 = '_';
91152 + }
91153 + err = -EPERM;
91154 + goto free_modinfo;
91155 + }
91156 + }
91157 +#endif
91158 +
91159 /* Fix up syms, so that st_value is a pointer to location. */
91160 err = simplify_symbols(mod, info);
91161 if (err < 0)
91162 @@ -3260,13 +3424,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
91163
91164 flush_module_icache(mod);
91165
91166 - /* Now copy in args */
91167 - mod->args = strndup_user(uargs, ~0UL >> 1);
91168 - if (IS_ERR(mod->args)) {
91169 - err = PTR_ERR(mod->args);
91170 - goto free_arch_cleanup;
91171 - }
91172 -
91173 dynamic_debug_setup(info->debug, info->num_debug);
91174
91175 /* Ftrace init must be called in the MODULE_STATE_UNFORMED state */
91176 @@ -3314,11 +3471,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
91177 ddebug_cleanup:
91178 dynamic_debug_remove(info->debug);
91179 synchronize_sched();
91180 - kfree(mod->args);
91181 - free_arch_cleanup:
91182 module_arch_cleanup(mod);
91183 free_modinfo:
91184 free_modinfo(mod);
91185 + kfree(mod->args);
91186 free_unload:
91187 module_unload_free(mod);
91188 unlink_mod:
91189 @@ -3403,10 +3559,16 @@ static const char *get_ksymbol(struct module *mod,
91190 unsigned long nextval;
91191
91192 /* At worse, next value is at end of module */
91193 - if (within_module_init(addr, mod))
91194 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
91195 + if (within_module_init_rx(addr, mod))
91196 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
91197 + else if (within_module_init_rw(addr, mod))
91198 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
91199 + else if (within_module_core_rx(addr, mod))
91200 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
91201 + else if (within_module_core_rw(addr, mod))
91202 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
91203 else
91204 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
91205 + return NULL;
91206
91207 /* Scan for closest preceding symbol, and next symbol. (ELF
91208 starts real symbols at 1). */
91209 @@ -3654,7 +3816,7 @@ static int m_show(struct seq_file *m, void *p)
91210 return 0;
91211
91212 seq_printf(m, "%s %u",
91213 - mod->name, mod->init_size + mod->core_size);
91214 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
91215 print_unload_info(m, mod);
91216
91217 /* Informative for users. */
91218 @@ -3663,7 +3825,7 @@ static int m_show(struct seq_file *m, void *p)
91219 mod->state == MODULE_STATE_COMING ? "Loading":
91220 "Live");
91221 /* Used by oprofile and other similar tools. */
91222 - seq_printf(m, " 0x%pK", mod->module_core);
91223 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
91224
91225 /* Taints info */
91226 if (mod->taints)
91227 @@ -3699,7 +3861,17 @@ static const struct file_operations proc_modules_operations = {
91228
91229 static int __init proc_modules_init(void)
91230 {
91231 +#ifndef CONFIG_GRKERNSEC_HIDESYM
91232 +#ifdef CONFIG_GRKERNSEC_PROC_USER
91233 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
91234 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
91235 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
91236 +#else
91237 proc_create("modules", 0, NULL, &proc_modules_operations);
91238 +#endif
91239 +#else
91240 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
91241 +#endif
91242 return 0;
91243 }
91244 module_init(proc_modules_init);
91245 @@ -3760,7 +3932,8 @@ struct module *__module_address(unsigned long addr)
91246 {
91247 struct module *mod;
91248
91249 - if (addr < module_addr_min || addr > module_addr_max)
91250 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
91251 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
91252 return NULL;
91253
91254 list_for_each_entry_rcu(mod, &modules, list) {
91255 @@ -3801,11 +3974,20 @@ bool is_module_text_address(unsigned long addr)
91256 */
91257 struct module *__module_text_address(unsigned long addr)
91258 {
91259 - struct module *mod = __module_address(addr);
91260 + struct module *mod;
91261 +
91262 +#ifdef CONFIG_X86_32
91263 + addr = ktla_ktva(addr);
91264 +#endif
91265 +
91266 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
91267 + return NULL;
91268 +
91269 + mod = __module_address(addr);
91270 +
91271 if (mod) {
91272 /* Make sure it's within the text section. */
91273 - if (!within(addr, mod->module_init, mod->init_text_size)
91274 - && !within(addr, mod->module_core, mod->core_text_size))
91275 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
91276 mod = NULL;
91277 }
91278 return mod;
91279 diff --git a/kernel/notifier.c b/kernel/notifier.c
91280 index 4803da6..1c5eea6 100644
91281 --- a/kernel/notifier.c
91282 +++ b/kernel/notifier.c
91283 @@ -5,6 +5,7 @@
91284 #include <linux/rcupdate.h>
91285 #include <linux/vmalloc.h>
91286 #include <linux/reboot.h>
91287 +#include <linux/mm.h>
91288
91289 /*
91290 * Notifier list for kernel code which wants to be called
91291 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
91292 while ((*nl) != NULL) {
91293 if (n->priority > (*nl)->priority)
91294 break;
91295 - nl = &((*nl)->next);
91296 + nl = (struct notifier_block **)&((*nl)->next);
91297 }
91298 - n->next = *nl;
91299 + pax_open_kernel();
91300 + *(const void **)&n->next = *nl;
91301 rcu_assign_pointer(*nl, n);
91302 + pax_close_kernel();
91303 return 0;
91304 }
91305
91306 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
91307 return 0;
91308 if (n->priority > (*nl)->priority)
91309 break;
91310 - nl = &((*nl)->next);
91311 + nl = (struct notifier_block **)&((*nl)->next);
91312 }
91313 - n->next = *nl;
91314 + pax_open_kernel();
91315 + *(const void **)&n->next = *nl;
91316 rcu_assign_pointer(*nl, n);
91317 + pax_close_kernel();
91318 return 0;
91319 }
91320
91321 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
91322 {
91323 while ((*nl) != NULL) {
91324 if ((*nl) == n) {
91325 + pax_open_kernel();
91326 rcu_assign_pointer(*nl, n->next);
91327 + pax_close_kernel();
91328 return 0;
91329 }
91330 - nl = &((*nl)->next);
91331 + nl = (struct notifier_block **)&((*nl)->next);
91332 }
91333 return -ENOENT;
91334 }
91335 diff --git a/kernel/padata.c b/kernel/padata.c
91336 index 161402f..598814c 100644
91337 --- a/kernel/padata.c
91338 +++ b/kernel/padata.c
91339 @@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
91340 * seq_nr mod. number of cpus in use.
91341 */
91342
91343 - seq_nr = atomic_inc_return(&pd->seq_nr);
91344 + seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
91345 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
91346
91347 return padata_index_to_cpu(pd, cpu_index);
91348 @@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
91349 padata_init_pqueues(pd);
91350 padata_init_squeues(pd);
91351 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
91352 - atomic_set(&pd->seq_nr, -1);
91353 + atomic_set_unchecked(&pd->seq_nr, -1);
91354 atomic_set(&pd->reorder_objects, 0);
91355 atomic_set(&pd->refcnt, 0);
91356 pd->pinst = pinst;
91357 diff --git a/kernel/panic.c b/kernel/panic.c
91358 index d09dc5c..9abbdff 100644
91359 --- a/kernel/panic.c
91360 +++ b/kernel/panic.c
91361 @@ -53,7 +53,7 @@ EXPORT_SYMBOL(panic_blink);
91362 /*
91363 * Stop ourself in panic -- architecture code may override this
91364 */
91365 -void __weak panic_smp_self_stop(void)
91366 +void __weak __noreturn panic_smp_self_stop(void)
91367 {
91368 while (1)
91369 cpu_relax();
91370 @@ -421,7 +421,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
91371 disable_trace_on_warning();
91372
91373 pr_warn("------------[ cut here ]------------\n");
91374 - pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
91375 + pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
91376 raw_smp_processor_id(), current->pid, file, line, caller);
91377
91378 if (args)
91379 @@ -475,7 +475,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
91380 */
91381 __visible void __stack_chk_fail(void)
91382 {
91383 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
91384 + dump_stack();
91385 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
91386 __builtin_return_address(0));
91387 }
91388 EXPORT_SYMBOL(__stack_chk_fail);
91389 diff --git a/kernel/pid.c b/kernel/pid.c
91390 index 9b9a266..c20ef80 100644
91391 --- a/kernel/pid.c
91392 +++ b/kernel/pid.c
91393 @@ -33,6 +33,7 @@
91394 #include <linux/rculist.h>
91395 #include <linux/bootmem.h>
91396 #include <linux/hash.h>
91397 +#include <linux/security.h>
91398 #include <linux/pid_namespace.h>
91399 #include <linux/init_task.h>
91400 #include <linux/syscalls.h>
91401 @@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
91402
91403 int pid_max = PID_MAX_DEFAULT;
91404
91405 -#define RESERVED_PIDS 300
91406 +#define RESERVED_PIDS 500
91407
91408 int pid_max_min = RESERVED_PIDS + 1;
91409 int pid_max_max = PID_MAX_LIMIT;
91410 @@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
91411 */
91412 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
91413 {
91414 + struct task_struct *task;
91415 +
91416 rcu_lockdep_assert(rcu_read_lock_held(),
91417 "find_task_by_pid_ns() needs rcu_read_lock()"
91418 " protection");
91419 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
91420 +
91421 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
91422 +
91423 + if (gr_pid_is_chrooted(task))
91424 + return NULL;
91425 +
91426 + return task;
91427 }
91428
91429 struct task_struct *find_task_by_vpid(pid_t vnr)
91430 @@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
91431 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
91432 }
91433
91434 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
91435 +{
91436 + rcu_lockdep_assert(rcu_read_lock_held(),
91437 + "find_task_by_pid_ns() needs rcu_read_lock()"
91438 + " protection");
91439 + return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
91440 +}
91441 +
91442 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
91443 {
91444 struct pid *pid;
91445 diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
91446 index db95d8e..a0ca23f 100644
91447 --- a/kernel/pid_namespace.c
91448 +++ b/kernel/pid_namespace.c
91449 @@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
91450 void __user *buffer, size_t *lenp, loff_t *ppos)
91451 {
91452 struct pid_namespace *pid_ns = task_active_pid_ns(current);
91453 - struct ctl_table tmp = *table;
91454 + ctl_table_no_const tmp = *table;
91455
91456 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
91457 return -EPERM;
91458 diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
91459 index e4e4121..71faf14 100644
91460 --- a/kernel/power/Kconfig
91461 +++ b/kernel/power/Kconfig
91462 @@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
91463 config HIBERNATION
91464 bool "Hibernation (aka 'suspend to disk')"
91465 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
91466 + depends on !GRKERNSEC_KMEM
91467 + depends on !PAX_MEMORY_SANITIZE
91468 select HIBERNATE_CALLBACKS
91469 select LZO_COMPRESS
91470 select LZO_DECOMPRESS
91471 diff --git a/kernel/power/process.c b/kernel/power/process.c
91472 index 7a37cf3..3e4c1c8 100644
91473 --- a/kernel/power/process.c
91474 +++ b/kernel/power/process.c
91475 @@ -35,6 +35,7 @@ static int try_to_freeze_tasks(bool user_only)
91476 unsigned int elapsed_msecs;
91477 bool wakeup = false;
91478 int sleep_usecs = USEC_PER_MSEC;
91479 + bool timedout = false;
91480
91481 do_gettimeofday(&start);
91482
91483 @@ -45,13 +46,20 @@ static int try_to_freeze_tasks(bool user_only)
91484
91485 while (true) {
91486 todo = 0;
91487 + if (time_after(jiffies, end_time))
91488 + timedout = true;
91489 read_lock(&tasklist_lock);
91490 do_each_thread(g, p) {
91491 if (p == current || !freeze_task(p))
91492 continue;
91493
91494 - if (!freezer_should_skip(p))
91495 + if (!freezer_should_skip(p)) {
91496 todo++;
91497 + if (timedout) {
91498 + printk(KERN_ERR "Task refusing to freeze:\n");
91499 + sched_show_task(p);
91500 + }
91501 + }
91502 } while_each_thread(g, p);
91503 read_unlock(&tasklist_lock);
91504
91505 @@ -60,7 +68,7 @@ static int try_to_freeze_tasks(bool user_only)
91506 todo += wq_busy;
91507 }
91508
91509 - if (!todo || time_after(jiffies, end_time))
91510 + if (!todo || timedout)
91511 break;
91512
91513 if (pm_wakeup_pending()) {
91514 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
91515 index 1ce7706..3b07c49 100644
91516 --- a/kernel/printk/printk.c
91517 +++ b/kernel/printk/printk.c
91518 @@ -490,6 +490,11 @@ static int check_syslog_permissions(int type, bool from_file)
91519 if (from_file && type != SYSLOG_ACTION_OPEN)
91520 return 0;
91521
91522 +#ifdef CONFIG_GRKERNSEC_DMESG
91523 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
91524 + return -EPERM;
91525 +#endif
91526 +
91527 if (syslog_action_restricted(type)) {
91528 if (capable(CAP_SYSLOG))
91529 return 0;
91530 diff --git a/kernel/profile.c b/kernel/profile.c
91531 index 54bf5ba..df6e0a2 100644
91532 --- a/kernel/profile.c
91533 +++ b/kernel/profile.c
91534 @@ -37,7 +37,7 @@ struct profile_hit {
91535 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
91536 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
91537
91538 -static atomic_t *prof_buffer;
91539 +static atomic_unchecked_t *prof_buffer;
91540 static unsigned long prof_len, prof_shift;
91541
91542 int prof_on __read_mostly;
91543 @@ -256,7 +256,7 @@ static void profile_flip_buffers(void)
91544 hits[i].pc = 0;
91545 continue;
91546 }
91547 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
91548 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
91549 hits[i].hits = hits[i].pc = 0;
91550 }
91551 }
91552 @@ -317,9 +317,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
91553 * Add the current hit(s) and flush the write-queue out
91554 * to the global buffer:
91555 */
91556 - atomic_add(nr_hits, &prof_buffer[pc]);
91557 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
91558 for (i = 0; i < NR_PROFILE_HIT; ++i) {
91559 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
91560 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
91561 hits[i].pc = hits[i].hits = 0;
91562 }
91563 out:
91564 @@ -394,7 +394,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
91565 {
91566 unsigned long pc;
91567 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
91568 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
91569 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
91570 }
91571 #endif /* !CONFIG_SMP */
91572
91573 @@ -490,7 +490,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
91574 return -EFAULT;
91575 buf++; p++; count--; read++;
91576 }
91577 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
91578 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
91579 if (copy_to_user(buf, (void *)pnt, count))
91580 return -EFAULT;
91581 read += count;
91582 @@ -521,7 +521,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
91583 }
91584 #endif
91585 profile_discard_flip_buffers();
91586 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
91587 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
91588 return count;
91589 }
91590
91591 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
91592 index 54e7522..5b82dd6 100644
91593 --- a/kernel/ptrace.c
91594 +++ b/kernel/ptrace.c
91595 @@ -321,7 +321,7 @@ static int ptrace_attach(struct task_struct *task, long request,
91596 if (seize)
91597 flags |= PT_SEIZED;
91598 rcu_read_lock();
91599 - if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
91600 + if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
91601 flags |= PT_PTRACE_CAP;
91602 rcu_read_unlock();
91603 task->ptrace = flags;
91604 @@ -532,7 +532,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
91605 break;
91606 return -EIO;
91607 }
91608 - if (copy_to_user(dst, buf, retval))
91609 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
91610 return -EFAULT;
91611 copied += retval;
91612 src += retval;
91613 @@ -800,7 +800,7 @@ int ptrace_request(struct task_struct *child, long request,
91614 bool seized = child->ptrace & PT_SEIZED;
91615 int ret = -EIO;
91616 siginfo_t siginfo, *si;
91617 - void __user *datavp = (void __user *) data;
91618 + void __user *datavp = (__force void __user *) data;
91619 unsigned long __user *datalp = datavp;
91620 unsigned long flags;
91621
91622 @@ -1046,14 +1046,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
91623 goto out;
91624 }
91625
91626 + if (gr_handle_ptrace(child, request)) {
91627 + ret = -EPERM;
91628 + goto out_put_task_struct;
91629 + }
91630 +
91631 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
91632 ret = ptrace_attach(child, request, addr, data);
91633 /*
91634 * Some architectures need to do book-keeping after
91635 * a ptrace attach.
91636 */
91637 - if (!ret)
91638 + if (!ret) {
91639 arch_ptrace_attach(child);
91640 + gr_audit_ptrace(child);
91641 + }
91642 goto out_put_task_struct;
91643 }
91644
91645 @@ -1081,7 +1088,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
91646 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
91647 if (copied != sizeof(tmp))
91648 return -EIO;
91649 - return put_user(tmp, (unsigned long __user *)data);
91650 + return put_user(tmp, (__force unsigned long __user *)data);
91651 }
91652
91653 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
91654 @@ -1175,7 +1182,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
91655 }
91656
91657 COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
91658 - compat_long_t, addr, compat_long_t, data)
91659 + compat_ulong_t, addr, compat_ulong_t, data)
91660 {
91661 struct task_struct *child;
91662 long ret;
91663 @@ -1191,14 +1198,21 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
91664 goto out;
91665 }
91666
91667 + if (gr_handle_ptrace(child, request)) {
91668 + ret = -EPERM;
91669 + goto out_put_task_struct;
91670 + }
91671 +
91672 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
91673 ret = ptrace_attach(child, request, addr, data);
91674 /*
91675 * Some architectures need to do book-keeping after
91676 * a ptrace attach.
91677 */
91678 - if (!ret)
91679 + if (!ret) {
91680 arch_ptrace_attach(child);
91681 + gr_audit_ptrace(child);
91682 + }
91683 goto out_put_task_struct;
91684 }
91685
91686 diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
91687 index 948a769..5ca842b 100644
91688 --- a/kernel/rcu/rcutorture.c
91689 +++ b/kernel/rcu/rcutorture.c
91690 @@ -124,12 +124,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
91691 rcu_torture_count) = { 0 };
91692 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
91693 rcu_torture_batch) = { 0 };
91694 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
91695 -static atomic_t n_rcu_torture_alloc;
91696 -static atomic_t n_rcu_torture_alloc_fail;
91697 -static atomic_t n_rcu_torture_free;
91698 -static atomic_t n_rcu_torture_mberror;
91699 -static atomic_t n_rcu_torture_error;
91700 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
91701 +static atomic_unchecked_t n_rcu_torture_alloc;
91702 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
91703 +static atomic_unchecked_t n_rcu_torture_free;
91704 +static atomic_unchecked_t n_rcu_torture_mberror;
91705 +static atomic_unchecked_t n_rcu_torture_error;
91706 static long n_rcu_torture_barrier_error;
91707 static long n_rcu_torture_boost_ktrerror;
91708 static long n_rcu_torture_boost_rterror;
91709 @@ -200,11 +200,11 @@ rcu_torture_alloc(void)
91710
91711 spin_lock_bh(&rcu_torture_lock);
91712 if (list_empty(&rcu_torture_freelist)) {
91713 - atomic_inc(&n_rcu_torture_alloc_fail);
91714 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
91715 spin_unlock_bh(&rcu_torture_lock);
91716 return NULL;
91717 }
91718 - atomic_inc(&n_rcu_torture_alloc);
91719 + atomic_inc_unchecked(&n_rcu_torture_alloc);
91720 p = rcu_torture_freelist.next;
91721 list_del_init(p);
91722 spin_unlock_bh(&rcu_torture_lock);
91723 @@ -217,7 +217,7 @@ rcu_torture_alloc(void)
91724 static void
91725 rcu_torture_free(struct rcu_torture *p)
91726 {
91727 - atomic_inc(&n_rcu_torture_free);
91728 + atomic_inc_unchecked(&n_rcu_torture_free);
91729 spin_lock_bh(&rcu_torture_lock);
91730 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
91731 spin_unlock_bh(&rcu_torture_lock);
91732 @@ -301,7 +301,7 @@ rcu_torture_pipe_update_one(struct rcu_torture *rp)
91733 i = rp->rtort_pipe_count;
91734 if (i > RCU_TORTURE_PIPE_LEN)
91735 i = RCU_TORTURE_PIPE_LEN;
91736 - atomic_inc(&rcu_torture_wcount[i]);
91737 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
91738 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
91739 rp->rtort_mbtest = 0;
91740 return true;
91741 @@ -808,7 +808,7 @@ rcu_torture_writer(void *arg)
91742 i = old_rp->rtort_pipe_count;
91743 if (i > RCU_TORTURE_PIPE_LEN)
91744 i = RCU_TORTURE_PIPE_LEN;
91745 - atomic_inc(&rcu_torture_wcount[i]);
91746 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
91747 old_rp->rtort_pipe_count++;
91748 switch (synctype[torture_random(&rand) % nsynctypes]) {
91749 case RTWS_DEF_FREE:
91750 @@ -926,7 +926,7 @@ static void rcu_torture_timer(unsigned long unused)
91751 return;
91752 }
91753 if (p->rtort_mbtest == 0)
91754 - atomic_inc(&n_rcu_torture_mberror);
91755 + atomic_inc_unchecked(&n_rcu_torture_mberror);
91756 spin_lock(&rand_lock);
91757 cur_ops->read_delay(&rand);
91758 n_rcu_torture_timers++;
91759 @@ -996,7 +996,7 @@ rcu_torture_reader(void *arg)
91760 continue;
91761 }
91762 if (p->rtort_mbtest == 0)
91763 - atomic_inc(&n_rcu_torture_mberror);
91764 + atomic_inc_unchecked(&n_rcu_torture_mberror);
91765 cur_ops->read_delay(&rand);
91766 preempt_disable();
91767 pipe_count = p->rtort_pipe_count;
91768 @@ -1054,15 +1054,15 @@ rcu_torture_printk(char *page)
91769 }
91770 page += sprintf(page, "%s%s ", torture_type, TORTURE_FLAG);
91771 page += sprintf(page,
91772 - "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
91773 + "rtc: %pP ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
91774 rcu_torture_current,
91775 rcu_torture_current_version,
91776 list_empty(&rcu_torture_freelist),
91777 - atomic_read(&n_rcu_torture_alloc),
91778 - atomic_read(&n_rcu_torture_alloc_fail),
91779 - atomic_read(&n_rcu_torture_free));
91780 + atomic_read_unchecked(&n_rcu_torture_alloc),
91781 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
91782 + atomic_read_unchecked(&n_rcu_torture_free));
91783 page += sprintf(page, "rtmbe: %d rtbke: %ld rtbre: %ld ",
91784 - atomic_read(&n_rcu_torture_mberror),
91785 + atomic_read_unchecked(&n_rcu_torture_mberror),
91786 n_rcu_torture_boost_ktrerror,
91787 n_rcu_torture_boost_rterror);
91788 page += sprintf(page, "rtbf: %ld rtb: %ld nt: %ld ",
91789 @@ -1075,14 +1075,14 @@ rcu_torture_printk(char *page)
91790 n_barrier_attempts,
91791 n_rcu_torture_barrier_error);
91792 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
91793 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
91794 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
91795 n_rcu_torture_barrier_error != 0 ||
91796 n_rcu_torture_boost_ktrerror != 0 ||
91797 n_rcu_torture_boost_rterror != 0 ||
91798 n_rcu_torture_boost_failure != 0 ||
91799 i > 1) {
91800 page += sprintf(page, "!!! ");
91801 - atomic_inc(&n_rcu_torture_error);
91802 + atomic_inc_unchecked(&n_rcu_torture_error);
91803 WARN_ON_ONCE(1);
91804 }
91805 page += sprintf(page, "Reader Pipe: ");
91806 @@ -1096,7 +1096,7 @@ rcu_torture_printk(char *page)
91807 page += sprintf(page, "Free-Block Circulation: ");
91808 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
91809 page += sprintf(page, " %d",
91810 - atomic_read(&rcu_torture_wcount[i]));
91811 + atomic_read_unchecked(&rcu_torture_wcount[i]));
91812 }
91813 page += sprintf(page, "\n");
91814 if (cur_ops->stats)
91815 @@ -1461,7 +1461,7 @@ rcu_torture_cleanup(void)
91816
91817 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
91818
91819 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
91820 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
91821 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
91822 else if (torture_onoff_failures())
91823 rcu_torture_print_module_parms(cur_ops,
91824 @@ -1584,18 +1584,18 @@ rcu_torture_init(void)
91825
91826 rcu_torture_current = NULL;
91827 rcu_torture_current_version = 0;
91828 - atomic_set(&n_rcu_torture_alloc, 0);
91829 - atomic_set(&n_rcu_torture_alloc_fail, 0);
91830 - atomic_set(&n_rcu_torture_free, 0);
91831 - atomic_set(&n_rcu_torture_mberror, 0);
91832 - atomic_set(&n_rcu_torture_error, 0);
91833 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
91834 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
91835 + atomic_set_unchecked(&n_rcu_torture_free, 0);
91836 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
91837 + atomic_set_unchecked(&n_rcu_torture_error, 0);
91838 n_rcu_torture_barrier_error = 0;
91839 n_rcu_torture_boost_ktrerror = 0;
91840 n_rcu_torture_boost_rterror = 0;
91841 n_rcu_torture_boost_failure = 0;
91842 n_rcu_torture_boosts = 0;
91843 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
91844 - atomic_set(&rcu_torture_wcount[i], 0);
91845 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
91846 for_each_possible_cpu(cpu) {
91847 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
91848 per_cpu(rcu_torture_count, cpu)[i] = 0;
91849 diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
91850 index d9efcc1..ea543e9 100644
91851 --- a/kernel/rcu/tiny.c
91852 +++ b/kernel/rcu/tiny.c
91853 @@ -42,7 +42,7 @@
91854 /* Forward declarations for tiny_plugin.h. */
91855 struct rcu_ctrlblk;
91856 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
91857 -static void rcu_process_callbacks(struct softirq_action *unused);
91858 +static void rcu_process_callbacks(void);
91859 static void __call_rcu(struct rcu_head *head,
91860 void (*func)(struct rcu_head *rcu),
91861 struct rcu_ctrlblk *rcp);
91862 @@ -308,7 +308,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
91863 false));
91864 }
91865
91866 -static void rcu_process_callbacks(struct softirq_action *unused)
91867 +static __latent_entropy void rcu_process_callbacks(void)
91868 {
91869 __rcu_process_callbacks(&rcu_sched_ctrlblk);
91870 __rcu_process_callbacks(&rcu_bh_ctrlblk);
91871 diff --git a/kernel/rcu/tiny_plugin.h b/kernel/rcu/tiny_plugin.h
91872 index 858c565..7efd915 100644
91873 --- a/kernel/rcu/tiny_plugin.h
91874 +++ b/kernel/rcu/tiny_plugin.h
91875 @@ -152,17 +152,17 @@ static void check_cpu_stall(struct rcu_ctrlblk *rcp)
91876 dump_stack();
91877 }
91878 if (*rcp->curtail && ULONG_CMP_GE(j, js))
91879 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies +
91880 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies +
91881 3 * rcu_jiffies_till_stall_check() + 3;
91882 else if (ULONG_CMP_GE(j, js))
91883 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91884 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91885 }
91886
91887 static void reset_cpu_stall_ticks(struct rcu_ctrlblk *rcp)
91888 {
91889 rcp->ticks_this_gp = 0;
91890 rcp->gp_start = jiffies;
91891 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91892 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91893 }
91894
91895 static void check_cpu_stalls(void)
91896 diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
91897 index 89a404a..f42a019 100644
91898 --- a/kernel/rcu/tree.c
91899 +++ b/kernel/rcu/tree.c
91900 @@ -263,7 +263,7 @@ static void rcu_momentary_dyntick_idle(void)
91901 */
91902 rdtp = this_cpu_ptr(&rcu_dynticks);
91903 smp_mb__before_atomic(); /* Earlier stuff before QS. */
91904 - atomic_add(2, &rdtp->dynticks); /* QS. */
91905 + atomic_add_unchecked(2, &rdtp->dynticks); /* QS. */
91906 smp_mb__after_atomic(); /* Later stuff after QS. */
91907 break;
91908 }
91909 @@ -523,9 +523,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
91910 rcu_prepare_for_idle(smp_processor_id());
91911 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
91912 smp_mb__before_atomic(); /* See above. */
91913 - atomic_inc(&rdtp->dynticks);
91914 + atomic_inc_unchecked(&rdtp->dynticks);
91915 smp_mb__after_atomic(); /* Force ordering with next sojourn. */
91916 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
91917 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
91918
91919 /*
91920 * It is illegal to enter an extended quiescent state while
91921 @@ -643,10 +643,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
91922 int user)
91923 {
91924 smp_mb__before_atomic(); /* Force ordering w/previous sojourn. */
91925 - atomic_inc(&rdtp->dynticks);
91926 + atomic_inc_unchecked(&rdtp->dynticks);
91927 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
91928 smp_mb__after_atomic(); /* See above. */
91929 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
91930 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
91931 rcu_cleanup_after_idle(smp_processor_id());
91932 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
91933 if (!user && !is_idle_task(current)) {
91934 @@ -767,14 +767,14 @@ void rcu_nmi_enter(void)
91935 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
91936
91937 if (rdtp->dynticks_nmi_nesting == 0 &&
91938 - (atomic_read(&rdtp->dynticks) & 0x1))
91939 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
91940 return;
91941 rdtp->dynticks_nmi_nesting++;
91942 smp_mb__before_atomic(); /* Force delay from prior write. */
91943 - atomic_inc(&rdtp->dynticks);
91944 + atomic_inc_unchecked(&rdtp->dynticks);
91945 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
91946 smp_mb__after_atomic(); /* See above. */
91947 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
91948 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
91949 }
91950
91951 /**
91952 @@ -793,9 +793,9 @@ void rcu_nmi_exit(void)
91953 return;
91954 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
91955 smp_mb__before_atomic(); /* See above. */
91956 - atomic_inc(&rdtp->dynticks);
91957 + atomic_inc_unchecked(&rdtp->dynticks);
91958 smp_mb__after_atomic(); /* Force delay to next write. */
91959 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
91960 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
91961 }
91962
91963 /**
91964 @@ -808,7 +808,7 @@ void rcu_nmi_exit(void)
91965 */
91966 bool notrace __rcu_is_watching(void)
91967 {
91968 - return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
91969 + return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
91970 }
91971
91972 /**
91973 @@ -891,7 +891,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
91974 static int dyntick_save_progress_counter(struct rcu_data *rdp,
91975 bool *isidle, unsigned long *maxj)
91976 {
91977 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
91978 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
91979 rcu_sysidle_check_cpu(rdp, isidle, maxj);
91980 if ((rdp->dynticks_snap & 0x1) == 0) {
91981 trace_rcu_fqs(rdp->rsp->name, rdp->gpnum, rdp->cpu, TPS("dti"));
91982 @@ -920,7 +920,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
91983 int *rcrmp;
91984 unsigned int snap;
91985
91986 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
91987 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
91988 snap = (unsigned int)rdp->dynticks_snap;
91989
91990 /*
91991 @@ -983,10 +983,10 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
91992 rdp->rsp->gp_start + jiffies_till_sched_qs) ||
91993 ULONG_CMP_GE(jiffies, rdp->rsp->jiffies_resched)) {
91994 if (!(ACCESS_ONCE(*rcrmp) & rdp->rsp->flavor_mask)) {
91995 - ACCESS_ONCE(rdp->cond_resched_completed) =
91996 + ACCESS_ONCE_RW(rdp->cond_resched_completed) =
91997 ACCESS_ONCE(rdp->mynode->completed);
91998 smp_mb(); /* ->cond_resched_completed before *rcrmp. */
91999 - ACCESS_ONCE(*rcrmp) =
92000 + ACCESS_ONCE_RW(*rcrmp) =
92001 ACCESS_ONCE(*rcrmp) + rdp->rsp->flavor_mask;
92002 resched_cpu(rdp->cpu); /* Force CPU into scheduler. */
92003 rdp->rsp->jiffies_resched += 5; /* Enable beating. */
92004 @@ -1008,7 +1008,7 @@ static void record_gp_stall_check_time(struct rcu_state *rsp)
92005 rsp->gp_start = j;
92006 smp_wmb(); /* Record start time before stall time. */
92007 j1 = rcu_jiffies_till_stall_check();
92008 - ACCESS_ONCE(rsp->jiffies_stall) = j + j1;
92009 + ACCESS_ONCE_RW(rsp->jiffies_stall) = j + j1;
92010 rsp->jiffies_resched = j + j1 / 2;
92011 }
92012
92013 @@ -1049,7 +1049,7 @@ static void print_other_cpu_stall(struct rcu_state *rsp)
92014 raw_spin_unlock_irqrestore(&rnp->lock, flags);
92015 return;
92016 }
92017 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
92018 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
92019 raw_spin_unlock_irqrestore(&rnp->lock, flags);
92020
92021 /*
92022 @@ -1126,7 +1126,7 @@ static void print_cpu_stall(struct rcu_state *rsp)
92023
92024 raw_spin_lock_irqsave(&rnp->lock, flags);
92025 if (ULONG_CMP_GE(jiffies, ACCESS_ONCE(rsp->jiffies_stall)))
92026 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies +
92027 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies +
92028 3 * rcu_jiffies_till_stall_check() + 3;
92029 raw_spin_unlock_irqrestore(&rnp->lock, flags);
92030
92031 @@ -1210,7 +1210,7 @@ void rcu_cpu_stall_reset(void)
92032 struct rcu_state *rsp;
92033
92034 for_each_rcu_flavor(rsp)
92035 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
92036 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
92037 }
92038
92039 /*
92040 @@ -1596,7 +1596,7 @@ static int rcu_gp_init(struct rcu_state *rsp)
92041 raw_spin_unlock_irq(&rnp->lock);
92042 return 0;
92043 }
92044 - ACCESS_ONCE(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
92045 + ACCESS_ONCE_RW(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
92046
92047 if (WARN_ON_ONCE(rcu_gp_in_progress(rsp))) {
92048 /*
92049 @@ -1637,9 +1637,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
92050 rdp = this_cpu_ptr(rsp->rda);
92051 rcu_preempt_check_blocked_tasks(rnp);
92052 rnp->qsmask = rnp->qsmaskinit;
92053 - ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
92054 + ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
92055 WARN_ON_ONCE(rnp->completed != rsp->completed);
92056 - ACCESS_ONCE(rnp->completed) = rsp->completed;
92057 + ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
92058 if (rnp == rdp->mynode)
92059 (void)__note_gp_changes(rsp, rnp, rdp);
92060 rcu_preempt_boost_start_gp(rnp);
92061 @@ -1684,7 +1684,7 @@ static int rcu_gp_fqs(struct rcu_state *rsp, int fqs_state_in)
92062 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
92063 raw_spin_lock_irq(&rnp->lock);
92064 smp_mb__after_unlock_lock();
92065 - ACCESS_ONCE(rsp->gp_flags) &= ~RCU_GP_FLAG_FQS;
92066 + ACCESS_ONCE_RW(rsp->gp_flags) &= ~RCU_GP_FLAG_FQS;
92067 raw_spin_unlock_irq(&rnp->lock);
92068 }
92069 return fqs_state;
92070 @@ -1729,7 +1729,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
92071 rcu_for_each_node_breadth_first(rsp, rnp) {
92072 raw_spin_lock_irq(&rnp->lock);
92073 smp_mb__after_unlock_lock();
92074 - ACCESS_ONCE(rnp->completed) = rsp->gpnum;
92075 + ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
92076 rdp = this_cpu_ptr(rsp->rda);
92077 if (rnp == rdp->mynode)
92078 needgp = __note_gp_changes(rsp, rnp, rdp) || needgp;
92079 @@ -1744,14 +1744,14 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
92080 rcu_nocb_gp_set(rnp, nocb);
92081
92082 /* Declare grace period done. */
92083 - ACCESS_ONCE(rsp->completed) = rsp->gpnum;
92084 + ACCESS_ONCE_RW(rsp->completed) = rsp->gpnum;
92085 trace_rcu_grace_period(rsp->name, rsp->completed, TPS("end"));
92086 rsp->fqs_state = RCU_GP_IDLE;
92087 rdp = this_cpu_ptr(rsp->rda);
92088 /* Advance CBs to reduce false positives below. */
92089 needgp = rcu_advance_cbs(rsp, rnp, rdp) || needgp;
92090 if (needgp || cpu_needs_another_gp(rsp, rdp)) {
92091 - ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92092 + ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92093 trace_rcu_grace_period(rsp->name,
92094 ACCESS_ONCE(rsp->gpnum),
92095 TPS("newreq"));
92096 @@ -1876,7 +1876,7 @@ rcu_start_gp_advanced(struct rcu_state *rsp, struct rcu_node *rnp,
92097 */
92098 return false;
92099 }
92100 - ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92101 + ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92102 trace_rcu_grace_period(rsp->name, ACCESS_ONCE(rsp->gpnum),
92103 TPS("newreq"));
92104
92105 @@ -2097,7 +2097,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
92106 rsp->qlen += rdp->qlen;
92107 rdp->n_cbs_orphaned += rdp->qlen;
92108 rdp->qlen_lazy = 0;
92109 - ACCESS_ONCE(rdp->qlen) = 0;
92110 + ACCESS_ONCE_RW(rdp->qlen) = 0;
92111 }
92112
92113 /*
92114 @@ -2344,7 +2344,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
92115 }
92116 smp_mb(); /* List handling before counting for rcu_barrier(). */
92117 rdp->qlen_lazy -= count_lazy;
92118 - ACCESS_ONCE(rdp->qlen) = rdp->qlen - count;
92119 + ACCESS_ONCE_RW(rdp->qlen) = rdp->qlen - count;
92120 rdp->n_cbs_invoked += count;
92121
92122 /* Reinstate batch limit if we have worked down the excess. */
92123 @@ -2505,7 +2505,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
92124 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
92125 return; /* Someone beat us to it. */
92126 }
92127 - ACCESS_ONCE(rsp->gp_flags) |= RCU_GP_FLAG_FQS;
92128 + ACCESS_ONCE_RW(rsp->gp_flags) |= RCU_GP_FLAG_FQS;
92129 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
92130 rcu_gp_kthread_wake(rsp);
92131 }
92132 @@ -2550,7 +2550,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
92133 /*
92134 * Do RCU core processing for the current CPU.
92135 */
92136 -static void rcu_process_callbacks(struct softirq_action *unused)
92137 +static void rcu_process_callbacks(void)
92138 {
92139 struct rcu_state *rsp;
92140
92141 @@ -2662,7 +2662,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
92142 WARN_ON_ONCE((unsigned long)head & 0x1); /* Misaligned rcu_head! */
92143 if (debug_rcu_head_queue(head)) {
92144 /* Probable double call_rcu(), so leak the callback. */
92145 - ACCESS_ONCE(head->func) = rcu_leak_callback;
92146 + ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
92147 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
92148 return;
92149 }
92150 @@ -2690,7 +2690,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
92151 local_irq_restore(flags);
92152 return;
92153 }
92154 - ACCESS_ONCE(rdp->qlen) = rdp->qlen + 1;
92155 + ACCESS_ONCE_RW(rdp->qlen) = rdp->qlen + 1;
92156 if (lazy)
92157 rdp->qlen_lazy++;
92158 else
92159 @@ -2965,11 +2965,11 @@ void synchronize_sched_expedited(void)
92160 * counter wrap on a 32-bit system. Quite a few more CPUs would of
92161 * course be required on a 64-bit system.
92162 */
92163 - if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
92164 + if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
92165 (ulong)atomic_long_read(&rsp->expedited_done) +
92166 ULONG_MAX / 8)) {
92167 synchronize_sched();
92168 - atomic_long_inc(&rsp->expedited_wrap);
92169 + atomic_long_inc_unchecked(&rsp->expedited_wrap);
92170 return;
92171 }
92172
92173 @@ -2977,7 +2977,7 @@ void synchronize_sched_expedited(void)
92174 * Take a ticket. Note that atomic_inc_return() implies a
92175 * full memory barrier.
92176 */
92177 - snap = atomic_long_inc_return(&rsp->expedited_start);
92178 + snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
92179 firstsnap = snap;
92180 get_online_cpus();
92181 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
92182 @@ -2990,14 +2990,14 @@ void synchronize_sched_expedited(void)
92183 synchronize_sched_expedited_cpu_stop,
92184 NULL) == -EAGAIN) {
92185 put_online_cpus();
92186 - atomic_long_inc(&rsp->expedited_tryfail);
92187 + atomic_long_inc_unchecked(&rsp->expedited_tryfail);
92188
92189 /* Check to see if someone else did our work for us. */
92190 s = atomic_long_read(&rsp->expedited_done);
92191 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
92192 /* ensure test happens before caller kfree */
92193 smp_mb__before_atomic(); /* ^^^ */
92194 - atomic_long_inc(&rsp->expedited_workdone1);
92195 + atomic_long_inc_unchecked(&rsp->expedited_workdone1);
92196 return;
92197 }
92198
92199 @@ -3006,7 +3006,7 @@ void synchronize_sched_expedited(void)
92200 udelay(trycount * num_online_cpus());
92201 } else {
92202 wait_rcu_gp(call_rcu_sched);
92203 - atomic_long_inc(&rsp->expedited_normal);
92204 + atomic_long_inc_unchecked(&rsp->expedited_normal);
92205 return;
92206 }
92207
92208 @@ -3015,7 +3015,7 @@ void synchronize_sched_expedited(void)
92209 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
92210 /* ensure test happens before caller kfree */
92211 smp_mb__before_atomic(); /* ^^^ */
92212 - atomic_long_inc(&rsp->expedited_workdone2);
92213 + atomic_long_inc_unchecked(&rsp->expedited_workdone2);
92214 return;
92215 }
92216
92217 @@ -3027,10 +3027,10 @@ void synchronize_sched_expedited(void)
92218 * period works for us.
92219 */
92220 get_online_cpus();
92221 - snap = atomic_long_read(&rsp->expedited_start);
92222 + snap = atomic_long_read_unchecked(&rsp->expedited_start);
92223 smp_mb(); /* ensure read is before try_stop_cpus(). */
92224 }
92225 - atomic_long_inc(&rsp->expedited_stoppedcpus);
92226 + atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
92227
92228 /*
92229 * Everyone up to our most recent fetch is covered by our grace
92230 @@ -3039,16 +3039,16 @@ void synchronize_sched_expedited(void)
92231 * than we did already did their update.
92232 */
92233 do {
92234 - atomic_long_inc(&rsp->expedited_done_tries);
92235 + atomic_long_inc_unchecked(&rsp->expedited_done_tries);
92236 s = atomic_long_read(&rsp->expedited_done);
92237 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
92238 /* ensure test happens before caller kfree */
92239 smp_mb__before_atomic(); /* ^^^ */
92240 - atomic_long_inc(&rsp->expedited_done_lost);
92241 + atomic_long_inc_unchecked(&rsp->expedited_done_lost);
92242 break;
92243 }
92244 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
92245 - atomic_long_inc(&rsp->expedited_done_exit);
92246 + atomic_long_inc_unchecked(&rsp->expedited_done_exit);
92247
92248 put_online_cpus();
92249 }
92250 @@ -3254,7 +3254,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
92251 * ACCESS_ONCE() to prevent the compiler from speculating
92252 * the increment to precede the early-exit check.
92253 */
92254 - ACCESS_ONCE(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92255 + ACCESS_ONCE_RW(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92256 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
92257 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
92258 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
92259 @@ -3304,7 +3304,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
92260
92261 /* Increment ->n_barrier_done to prevent duplicate work. */
92262 smp_mb(); /* Keep increment after above mechanism. */
92263 - ACCESS_ONCE(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92264 + ACCESS_ONCE_RW(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92265 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
92266 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
92267 smp_mb(); /* Keep increment before caller's subsequent code. */
92268 @@ -3349,10 +3349,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
92269 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
92270 init_callback_list(rdp);
92271 rdp->qlen_lazy = 0;
92272 - ACCESS_ONCE(rdp->qlen) = 0;
92273 + ACCESS_ONCE_RW(rdp->qlen) = 0;
92274 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
92275 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
92276 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
92277 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
92278 rdp->cpu = cpu;
92279 rdp->rsp = rsp;
92280 rcu_boot_init_nocb_percpu_data(rdp);
92281 @@ -3385,8 +3385,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp)
92282 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
92283 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
92284 rcu_sysidle_init_percpu_data(rdp->dynticks);
92285 - atomic_set(&rdp->dynticks->dynticks,
92286 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
92287 + atomic_set_unchecked(&rdp->dynticks->dynticks,
92288 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
92289 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
92290
92291 /* Add CPU to rcu_node bitmasks. */
92292 diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
92293 index 6a86eb7..022b506 100644
92294 --- a/kernel/rcu/tree.h
92295 +++ b/kernel/rcu/tree.h
92296 @@ -87,11 +87,11 @@ struct rcu_dynticks {
92297 long long dynticks_nesting; /* Track irq/process nesting level. */
92298 /* Process level is worth LLONG_MAX/2. */
92299 int dynticks_nmi_nesting; /* Track NMI nesting level. */
92300 - atomic_t dynticks; /* Even value for idle, else odd. */
92301 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
92302 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
92303 long long dynticks_idle_nesting;
92304 /* irq/process nesting level from idle. */
92305 - atomic_t dynticks_idle; /* Even value for idle, else odd. */
92306 + atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
92307 /* "Idle" excludes userspace execution. */
92308 unsigned long dynticks_idle_jiffies;
92309 /* End of last non-NMI non-idle period. */
92310 @@ -461,17 +461,17 @@ struct rcu_state {
92311 /* _rcu_barrier(). */
92312 /* End of fields guarded by barrier_mutex. */
92313
92314 - atomic_long_t expedited_start; /* Starting ticket. */
92315 - atomic_long_t expedited_done; /* Done ticket. */
92316 - atomic_long_t expedited_wrap; /* # near-wrap incidents. */
92317 - atomic_long_t expedited_tryfail; /* # acquisition failures. */
92318 - atomic_long_t expedited_workdone1; /* # done by others #1. */
92319 - atomic_long_t expedited_workdone2; /* # done by others #2. */
92320 - atomic_long_t expedited_normal; /* # fallbacks to normal. */
92321 - atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
92322 - atomic_long_t expedited_done_tries; /* # tries to update _done. */
92323 - atomic_long_t expedited_done_lost; /* # times beaten to _done. */
92324 - atomic_long_t expedited_done_exit; /* # times exited _done loop. */
92325 + atomic_long_unchecked_t expedited_start; /* Starting ticket. */
92326 + atomic_long_t expedited_done; /* Done ticket. */
92327 + atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
92328 + atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
92329 + atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
92330 + atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
92331 + atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
92332 + atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
92333 + atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
92334 + atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
92335 + atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
92336
92337 unsigned long jiffies_force_qs; /* Time at which to invoke */
92338 /* force_quiescent_state(). */
92339 diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
92340 index a7997e2..9787c9e 100644
92341 --- a/kernel/rcu/tree_plugin.h
92342 +++ b/kernel/rcu/tree_plugin.h
92343 @@ -735,7 +735,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
92344 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
92345 {
92346 return !rcu_preempted_readers_exp(rnp) &&
92347 - ACCESS_ONCE(rnp->expmask) == 0;
92348 + ACCESS_ONCE_RW(rnp->expmask) == 0;
92349 }
92350
92351 /*
92352 @@ -897,7 +897,7 @@ void synchronize_rcu_expedited(void)
92353
92354 /* Clean up and exit. */
92355 smp_mb(); /* ensure expedited GP seen before counter increment. */
92356 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
92357 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
92358 unlock_mb_ret:
92359 mutex_unlock(&sync_rcu_preempt_exp_mutex);
92360 mb_ret:
92361 @@ -1452,7 +1452,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
92362 free_cpumask_var(cm);
92363 }
92364
92365 -static struct smp_hotplug_thread rcu_cpu_thread_spec = {
92366 +static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
92367 .store = &rcu_cpu_kthread_task,
92368 .thread_should_run = rcu_cpu_kthread_should_run,
92369 .thread_fn = rcu_cpu_kthread,
92370 @@ -1932,7 +1932,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
92371 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
92372 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
92373 cpu, ticks_value, ticks_title,
92374 - atomic_read(&rdtp->dynticks) & 0xfff,
92375 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
92376 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
92377 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
92378 fast_no_hz);
92379 @@ -2076,7 +2076,7 @@ static void wake_nocb_leader(struct rcu_data *rdp, bool force)
92380 return;
92381 if (ACCESS_ONCE(rdp_leader->nocb_leader_sleep) || force) {
92382 /* Prior xchg orders against prior callback enqueue. */
92383 - ACCESS_ONCE(rdp_leader->nocb_leader_sleep) = false;
92384 + ACCESS_ONCE_RW(rdp_leader->nocb_leader_sleep) = false;
92385 wake_up(&rdp_leader->nocb_wq);
92386 }
92387 }
92388 @@ -2101,7 +2101,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
92389
92390 /* Enqueue the callback on the nocb list and update counts. */
92391 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
92392 - ACCESS_ONCE(*old_rhpp) = rhp;
92393 + ACCESS_ONCE_RW(*old_rhpp) = rhp;
92394 atomic_long_add(rhcount, &rdp->nocb_q_count);
92395 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
92396
92397 @@ -2272,7 +2272,7 @@ wait_again:
92398 continue; /* No CBs here, try next follower. */
92399
92400 /* Move callbacks to wait-for-GP list, which is empty. */
92401 - ACCESS_ONCE(rdp->nocb_head) = NULL;
92402 + ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
92403 rdp->nocb_gp_tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
92404 rdp->nocb_gp_count = atomic_long_xchg(&rdp->nocb_q_count, 0);
92405 rdp->nocb_gp_count_lazy =
92406 @@ -2398,7 +2398,7 @@ static int rcu_nocb_kthread(void *arg)
92407 list = ACCESS_ONCE(rdp->nocb_follower_head);
92408 BUG_ON(!list);
92409 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, "WokeNonEmpty");
92410 - ACCESS_ONCE(rdp->nocb_follower_head) = NULL;
92411 + ACCESS_ONCE_RW(rdp->nocb_follower_head) = NULL;
92412 tail = xchg(&rdp->nocb_follower_tail, &rdp->nocb_follower_head);
92413 c = atomic_long_xchg(&rdp->nocb_follower_count, 0);
92414 cl = atomic_long_xchg(&rdp->nocb_follower_count_lazy, 0);
92415 @@ -2428,8 +2428,8 @@ static int rcu_nocb_kthread(void *arg)
92416 list = next;
92417 }
92418 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
92419 - ACCESS_ONCE(rdp->nocb_p_count) -= c;
92420 - ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
92421 + ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
92422 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
92423 rdp->n_nocbs_invoked += c;
92424 }
92425 return 0;
92426 @@ -2446,7 +2446,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
92427 {
92428 if (!rcu_nocb_need_deferred_wakeup(rdp))
92429 return;
92430 - ACCESS_ONCE(rdp->nocb_defer_wakeup) = false;
92431 + ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = false;
92432 wake_nocb_leader(rdp, false);
92433 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWakeEmpty"));
92434 }
92435 @@ -2510,7 +2510,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
92436 t = kthread_run(rcu_nocb_kthread, rdp,
92437 "rcuo%c/%d", rsp->abbr, cpu);
92438 BUG_ON(IS_ERR(t));
92439 - ACCESS_ONCE(rdp->nocb_kthread) = t;
92440 + ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
92441 }
92442 }
92443
92444 @@ -2641,11 +2641,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
92445
92446 /* Record start of fully idle period. */
92447 j = jiffies;
92448 - ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
92449 + ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
92450 smp_mb__before_atomic();
92451 - atomic_inc(&rdtp->dynticks_idle);
92452 + atomic_inc_unchecked(&rdtp->dynticks_idle);
92453 smp_mb__after_atomic();
92454 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
92455 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
92456 }
92457
92458 /*
92459 @@ -2710,9 +2710,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
92460
92461 /* Record end of idle period. */
92462 smp_mb__before_atomic();
92463 - atomic_inc(&rdtp->dynticks_idle);
92464 + atomic_inc_unchecked(&rdtp->dynticks_idle);
92465 smp_mb__after_atomic();
92466 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
92467 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
92468
92469 /*
92470 * If we are the timekeeping CPU, we are permitted to be non-idle
92471 @@ -2753,7 +2753,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
92472 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
92473
92474 /* Pick up current idle and NMI-nesting counter and check. */
92475 - cur = atomic_read(&rdtp->dynticks_idle);
92476 + cur = atomic_read_unchecked(&rdtp->dynticks_idle);
92477 if (cur & 0x1) {
92478 *isidle = false; /* We are not idle! */
92479 return;
92480 @@ -2802,7 +2802,7 @@ static void rcu_sysidle(unsigned long j)
92481 case RCU_SYSIDLE_NOT:
92482
92483 /* First time all are idle, so note a short idle period. */
92484 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
92485 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
92486 break;
92487
92488 case RCU_SYSIDLE_SHORT:
92489 @@ -2840,7 +2840,7 @@ static void rcu_sysidle_cancel(void)
92490 {
92491 smp_mb();
92492 if (full_sysidle_state > RCU_SYSIDLE_SHORT)
92493 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
92494 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
92495 }
92496
92497 /*
92498 @@ -2888,7 +2888,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
92499 smp_mb(); /* grace period precedes setting inuse. */
92500
92501 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
92502 - ACCESS_ONCE(rshp->inuse) = 0;
92503 + ACCESS_ONCE_RW(rshp->inuse) = 0;
92504 }
92505
92506 /*
92507 diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
92508 index 5cdc62e..cc52e88 100644
92509 --- a/kernel/rcu/tree_trace.c
92510 +++ b/kernel/rcu/tree_trace.c
92511 @@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
92512 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
92513 rdp->passed_quiesce, rdp->qs_pending);
92514 seq_printf(m, " dt=%d/%llx/%d df=%lu",
92515 - atomic_read(&rdp->dynticks->dynticks),
92516 + atomic_read_unchecked(&rdp->dynticks->dynticks),
92517 rdp->dynticks->dynticks_nesting,
92518 rdp->dynticks->dynticks_nmi_nesting,
92519 rdp->dynticks_fqs);
92520 @@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
92521 struct rcu_state *rsp = (struct rcu_state *)m->private;
92522
92523 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",
92524 - atomic_long_read(&rsp->expedited_start),
92525 + atomic_long_read_unchecked(&rsp->expedited_start),
92526 atomic_long_read(&rsp->expedited_done),
92527 - atomic_long_read(&rsp->expedited_wrap),
92528 - atomic_long_read(&rsp->expedited_tryfail),
92529 - atomic_long_read(&rsp->expedited_workdone1),
92530 - atomic_long_read(&rsp->expedited_workdone2),
92531 - atomic_long_read(&rsp->expedited_normal),
92532 - atomic_long_read(&rsp->expedited_stoppedcpus),
92533 - atomic_long_read(&rsp->expedited_done_tries),
92534 - atomic_long_read(&rsp->expedited_done_lost),
92535 - atomic_long_read(&rsp->expedited_done_exit));
92536 + atomic_long_read_unchecked(&rsp->expedited_wrap),
92537 + atomic_long_read_unchecked(&rsp->expedited_tryfail),
92538 + atomic_long_read_unchecked(&rsp->expedited_workdone1),
92539 + atomic_long_read_unchecked(&rsp->expedited_workdone2),
92540 + atomic_long_read_unchecked(&rsp->expedited_normal),
92541 + atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
92542 + atomic_long_read_unchecked(&rsp->expedited_done_tries),
92543 + atomic_long_read_unchecked(&rsp->expedited_done_lost),
92544 + atomic_long_read_unchecked(&rsp->expedited_done_exit));
92545 return 0;
92546 }
92547
92548 diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
92549 index 4056d79..c11741a 100644
92550 --- a/kernel/rcu/update.c
92551 +++ b/kernel/rcu/update.c
92552 @@ -308,10 +308,10 @@ int rcu_jiffies_till_stall_check(void)
92553 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
92554 */
92555 if (till_stall_check < 3) {
92556 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
92557 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
92558 till_stall_check = 3;
92559 } else if (till_stall_check > 300) {
92560 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
92561 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
92562 till_stall_check = 300;
92563 }
92564 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
92565 diff --git a/kernel/resource.c b/kernel/resource.c
92566 index 60c5a38..ed77193 100644
92567 --- a/kernel/resource.c
92568 +++ b/kernel/resource.c
92569 @@ -161,8 +161,18 @@ static const struct file_operations proc_iomem_operations = {
92570
92571 static int __init ioresources_init(void)
92572 {
92573 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
92574 +#ifdef CONFIG_GRKERNSEC_PROC_USER
92575 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
92576 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
92577 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
92578 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
92579 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
92580 +#endif
92581 +#else
92582 proc_create("ioports", 0, NULL, &proc_ioports_operations);
92583 proc_create("iomem", 0, NULL, &proc_iomem_operations);
92584 +#endif
92585 return 0;
92586 }
92587 __initcall(ioresources_init);
92588 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
92589 index e73efba..c9bfbd4 100644
92590 --- a/kernel/sched/auto_group.c
92591 +++ b/kernel/sched/auto_group.c
92592 @@ -11,7 +11,7 @@
92593
92594 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
92595 static struct autogroup autogroup_default;
92596 -static atomic_t autogroup_seq_nr;
92597 +static atomic_unchecked_t autogroup_seq_nr;
92598
92599 void __init autogroup_init(struct task_struct *init_task)
92600 {
92601 @@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
92602
92603 kref_init(&ag->kref);
92604 init_rwsem(&ag->lock);
92605 - ag->id = atomic_inc_return(&autogroup_seq_nr);
92606 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
92607 ag->tg = tg;
92608 #ifdef CONFIG_RT_GROUP_SCHED
92609 /*
92610 diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
92611 index a63f4dc..349bbb0 100644
92612 --- a/kernel/sched/completion.c
92613 +++ b/kernel/sched/completion.c
92614 @@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
92615 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
92616 * or number of jiffies left till timeout) if completed.
92617 */
92618 -long __sched
92619 +long __sched __intentional_overflow(-1)
92620 wait_for_completion_interruptible_timeout(struct completion *x,
92621 unsigned long timeout)
92622 {
92623 @@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
92624 *
92625 * Return: -ERESTARTSYS if interrupted, 0 if completed.
92626 */
92627 -int __sched wait_for_completion_killable(struct completion *x)
92628 +int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
92629 {
92630 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
92631 if (t == -ERESTARTSYS)
92632 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
92633 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
92634 * or number of jiffies left till timeout) if completed.
92635 */
92636 -long __sched
92637 +long __sched __intentional_overflow(-1)
92638 wait_for_completion_killable_timeout(struct completion *x,
92639 unsigned long timeout)
92640 {
92641 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
92642 index 6d7cb91..420f2d2 100644
92643 --- a/kernel/sched/core.c
92644 +++ b/kernel/sched/core.c
92645 @@ -1857,7 +1857,7 @@ void set_numabalancing_state(bool enabled)
92646 int sysctl_numa_balancing(struct ctl_table *table, int write,
92647 void __user *buffer, size_t *lenp, loff_t *ppos)
92648 {
92649 - struct ctl_table t;
92650 + ctl_table_no_const t;
92651 int err;
92652 int state = numabalancing_enabled;
92653
92654 @@ -2324,8 +2324,10 @@ context_switch(struct rq *rq, struct task_struct *prev,
92655 next->active_mm = oldmm;
92656 atomic_inc(&oldmm->mm_count);
92657 enter_lazy_tlb(oldmm, next);
92658 - } else
92659 + } else {
92660 switch_mm(oldmm, mm, next);
92661 + populate_stack();
92662 + }
92663
92664 if (!prev->mm) {
92665 prev->active_mm = NULL;
92666 @@ -3107,6 +3109,8 @@ int can_nice(const struct task_struct *p, const int nice)
92667 /* convert nice value [19,-20] to rlimit style value [1,40] */
92668 int nice_rlim = nice_to_rlimit(nice);
92669
92670 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
92671 +
92672 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
92673 capable(CAP_SYS_NICE));
92674 }
92675 @@ -3133,7 +3137,8 @@ SYSCALL_DEFINE1(nice, int, increment)
92676 nice = task_nice(current) + increment;
92677
92678 nice = clamp_val(nice, MIN_NICE, MAX_NICE);
92679 - if (increment < 0 && !can_nice(current, nice))
92680 + if (increment < 0 && (!can_nice(current, nice) ||
92681 + gr_handle_chroot_nice()))
92682 return -EPERM;
92683
92684 retval = security_task_setnice(current, nice);
92685 @@ -3412,6 +3417,7 @@ recheck:
92686 if (policy != p->policy && !rlim_rtprio)
92687 return -EPERM;
92688
92689 + gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
92690 /* can't increase priority */
92691 if (attr->sched_priority > p->rt_priority &&
92692 attr->sched_priority > rlim_rtprio)
92693 @@ -4802,6 +4808,7 @@ void idle_task_exit(void)
92694
92695 if (mm != &init_mm) {
92696 switch_mm(mm, &init_mm, current);
92697 + populate_stack();
92698 finish_arch_post_lock_switch();
92699 }
92700 mmdrop(mm);
92701 @@ -4897,7 +4904,7 @@ static void migrate_tasks(unsigned int dead_cpu)
92702
92703 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
92704
92705 -static struct ctl_table sd_ctl_dir[] = {
92706 +static ctl_table_no_const sd_ctl_dir[] __read_only = {
92707 {
92708 .procname = "sched_domain",
92709 .mode = 0555,
92710 @@ -4914,17 +4921,17 @@ static struct ctl_table sd_ctl_root[] = {
92711 {}
92712 };
92713
92714 -static struct ctl_table *sd_alloc_ctl_entry(int n)
92715 +static ctl_table_no_const *sd_alloc_ctl_entry(int n)
92716 {
92717 - struct ctl_table *entry =
92718 + ctl_table_no_const *entry =
92719 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
92720
92721 return entry;
92722 }
92723
92724 -static void sd_free_ctl_entry(struct ctl_table **tablep)
92725 +static void sd_free_ctl_entry(ctl_table_no_const *tablep)
92726 {
92727 - struct ctl_table *entry;
92728 + ctl_table_no_const *entry;
92729
92730 /*
92731 * In the intermediate directories, both the child directory and
92732 @@ -4932,22 +4939,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
92733 * will always be set. In the lowest directory the names are
92734 * static strings and all have proc handlers.
92735 */
92736 - for (entry = *tablep; entry->mode; entry++) {
92737 - if (entry->child)
92738 - sd_free_ctl_entry(&entry->child);
92739 + for (entry = tablep; entry->mode; entry++) {
92740 + if (entry->child) {
92741 + sd_free_ctl_entry(entry->child);
92742 + pax_open_kernel();
92743 + entry->child = NULL;
92744 + pax_close_kernel();
92745 + }
92746 if (entry->proc_handler == NULL)
92747 kfree(entry->procname);
92748 }
92749
92750 - kfree(*tablep);
92751 - *tablep = NULL;
92752 + kfree(tablep);
92753 }
92754
92755 static int min_load_idx = 0;
92756 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
92757
92758 static void
92759 -set_table_entry(struct ctl_table *entry,
92760 +set_table_entry(ctl_table_no_const *entry,
92761 const char *procname, void *data, int maxlen,
92762 umode_t mode, proc_handler *proc_handler,
92763 bool load_idx)
92764 @@ -4967,7 +4977,7 @@ set_table_entry(struct ctl_table *entry,
92765 static struct ctl_table *
92766 sd_alloc_ctl_domain_table(struct sched_domain *sd)
92767 {
92768 - struct ctl_table *table = sd_alloc_ctl_entry(14);
92769 + ctl_table_no_const *table = sd_alloc_ctl_entry(14);
92770
92771 if (table == NULL)
92772 return NULL;
92773 @@ -5005,9 +5015,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
92774 return table;
92775 }
92776
92777 -static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
92778 +static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
92779 {
92780 - struct ctl_table *entry, *table;
92781 + ctl_table_no_const *entry, *table;
92782 struct sched_domain *sd;
92783 int domain_num = 0, i;
92784 char buf[32];
92785 @@ -5034,11 +5044,13 @@ static struct ctl_table_header *sd_sysctl_header;
92786 static void register_sched_domain_sysctl(void)
92787 {
92788 int i, cpu_num = num_possible_cpus();
92789 - struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
92790 + ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
92791 char buf[32];
92792
92793 WARN_ON(sd_ctl_dir[0].child);
92794 + pax_open_kernel();
92795 sd_ctl_dir[0].child = entry;
92796 + pax_close_kernel();
92797
92798 if (entry == NULL)
92799 return;
92800 @@ -5061,8 +5073,12 @@ static void unregister_sched_domain_sysctl(void)
92801 if (sd_sysctl_header)
92802 unregister_sysctl_table(sd_sysctl_header);
92803 sd_sysctl_header = NULL;
92804 - if (sd_ctl_dir[0].child)
92805 - sd_free_ctl_entry(&sd_ctl_dir[0].child);
92806 + if (sd_ctl_dir[0].child) {
92807 + sd_free_ctl_entry(sd_ctl_dir[0].child);
92808 + pax_open_kernel();
92809 + sd_ctl_dir[0].child = NULL;
92810 + pax_close_kernel();
92811 + }
92812 }
92813 #else
92814 static void register_sched_domain_sysctl(void)
92815 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
92816 index bfa3c86..e58767c 100644
92817 --- a/kernel/sched/fair.c
92818 +++ b/kernel/sched/fair.c
92819 @@ -1873,7 +1873,7 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)
92820
92821 static void reset_ptenuma_scan(struct task_struct *p)
92822 {
92823 - ACCESS_ONCE(p->mm->numa_scan_seq)++;
92824 + ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
92825 p->mm->numa_scan_offset = 0;
92826 }
92827
92828 @@ -7339,7 +7339,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
92829 * run_rebalance_domains is triggered when needed from the scheduler tick.
92830 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
92831 */
92832 -static void run_rebalance_domains(struct softirq_action *h)
92833 +static __latent_entropy void run_rebalance_domains(void)
92834 {
92835 struct rq *this_rq = this_rq();
92836 enum cpu_idle_type idle = this_rq->idle_balance ?
92837 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
92838 index 579712f..a338a9d 100644
92839 --- a/kernel/sched/sched.h
92840 +++ b/kernel/sched/sched.h
92841 @@ -1146,7 +1146,7 @@ struct sched_class {
92842 #ifdef CONFIG_FAIR_GROUP_SCHED
92843 void (*task_move_group) (struct task_struct *p, int on_rq);
92844 #endif
92845 -};
92846 +} __do_const;
92847
92848 static inline void put_prev_task(struct rq *rq, struct task_struct *prev)
92849 {
92850 diff --git a/kernel/seccomp.c b/kernel/seccomp.c
92851 index 44eb005..84922be 100644
92852 --- a/kernel/seccomp.c
92853 +++ b/kernel/seccomp.c
92854 @@ -395,16 +395,15 @@ static struct seccomp_filter *seccomp_prepare_filter(struct sock_fprog *fprog)
92855 if (!filter)
92856 goto free_prog;
92857
92858 - filter->prog = kzalloc(bpf_prog_size(new_len),
92859 - GFP_KERNEL|__GFP_NOWARN);
92860 + filter->prog = bpf_prog_alloc(bpf_prog_size(new_len), __GFP_NOWARN);
92861 if (!filter->prog)
92862 goto free_filter;
92863
92864 ret = bpf_convert_filter(fp, fprog->len, filter->prog->insnsi, &new_len);
92865 if (ret)
92866 goto free_filter_prog;
92867 - kfree(fp);
92868
92869 + kfree(fp);
92870 atomic_set(&filter->usage, 1);
92871 filter->prog->len = new_len;
92872
92873 @@ -413,7 +412,7 @@ static struct seccomp_filter *seccomp_prepare_filter(struct sock_fprog *fprog)
92874 return filter;
92875
92876 free_filter_prog:
92877 - kfree(filter->prog);
92878 + __bpf_prog_free(filter->prog);
92879 free_filter:
92880 kfree(filter);
92881 free_prog:
92882 diff --git a/kernel/signal.c b/kernel/signal.c
92883 index 8f0876f..1153a5a 100644
92884 --- a/kernel/signal.c
92885 +++ b/kernel/signal.c
92886 @@ -53,12 +53,12 @@ static struct kmem_cache *sigqueue_cachep;
92887
92888 int print_fatal_signals __read_mostly;
92889
92890 -static void __user *sig_handler(struct task_struct *t, int sig)
92891 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
92892 {
92893 return t->sighand->action[sig - 1].sa.sa_handler;
92894 }
92895
92896 -static int sig_handler_ignored(void __user *handler, int sig)
92897 +static int sig_handler_ignored(__sighandler_t handler, int sig)
92898 {
92899 /* Is it explicitly or implicitly ignored? */
92900 return handler == SIG_IGN ||
92901 @@ -67,7 +67,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
92902
92903 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
92904 {
92905 - void __user *handler;
92906 + __sighandler_t handler;
92907
92908 handler = sig_handler(t, sig);
92909
92910 @@ -372,6 +372,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
92911 atomic_inc(&user->sigpending);
92912 rcu_read_unlock();
92913
92914 + if (!override_rlimit)
92915 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
92916 +
92917 if (override_rlimit ||
92918 atomic_read(&user->sigpending) <=
92919 task_rlimit(t, RLIMIT_SIGPENDING)) {
92920 @@ -499,7 +502,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
92921
92922 int unhandled_signal(struct task_struct *tsk, int sig)
92923 {
92924 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
92925 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
92926 if (is_global_init(tsk))
92927 return 1;
92928 if (handler != SIG_IGN && handler != SIG_DFL)
92929 @@ -793,6 +796,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
92930 }
92931 }
92932
92933 + /* allow glibc communication via tgkill to other threads in our
92934 + thread group */
92935 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
92936 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
92937 + && gr_handle_signal(t, sig))
92938 + return -EPERM;
92939 +
92940 return security_task_kill(t, info, sig, 0);
92941 }
92942
92943 @@ -1176,7 +1186,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
92944 return send_signal(sig, info, p, 1);
92945 }
92946
92947 -static int
92948 +int
92949 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
92950 {
92951 return send_signal(sig, info, t, 0);
92952 @@ -1213,6 +1223,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
92953 unsigned long int flags;
92954 int ret, blocked, ignored;
92955 struct k_sigaction *action;
92956 + int is_unhandled = 0;
92957
92958 spin_lock_irqsave(&t->sighand->siglock, flags);
92959 action = &t->sighand->action[sig-1];
92960 @@ -1227,9 +1238,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
92961 }
92962 if (action->sa.sa_handler == SIG_DFL)
92963 t->signal->flags &= ~SIGNAL_UNKILLABLE;
92964 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
92965 + is_unhandled = 1;
92966 ret = specific_send_sig_info(sig, info, t);
92967 spin_unlock_irqrestore(&t->sighand->siglock, flags);
92968
92969 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
92970 + normal operation */
92971 + if (is_unhandled) {
92972 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
92973 + gr_handle_crash(t, sig);
92974 + }
92975 +
92976 return ret;
92977 }
92978
92979 @@ -1300,8 +1320,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
92980 ret = check_kill_permission(sig, info, p);
92981 rcu_read_unlock();
92982
92983 - if (!ret && sig)
92984 + if (!ret && sig) {
92985 ret = do_send_sig_info(sig, info, p, true);
92986 + if (!ret)
92987 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
92988 + }
92989
92990 return ret;
92991 }
92992 @@ -2903,7 +2926,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
92993 int error = -ESRCH;
92994
92995 rcu_read_lock();
92996 - p = find_task_by_vpid(pid);
92997 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
92998 + /* allow glibc communication via tgkill to other threads in our
92999 + thread group */
93000 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
93001 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
93002 + p = find_task_by_vpid_unrestricted(pid);
93003 + else
93004 +#endif
93005 + p = find_task_by_vpid(pid);
93006 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
93007 error = check_kill_permission(sig, info, p);
93008 /*
93009 @@ -3236,8 +3267,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
93010 }
93011 seg = get_fs();
93012 set_fs(KERNEL_DS);
93013 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
93014 - (stack_t __force __user *) &uoss,
93015 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
93016 + (stack_t __force_user *) &uoss,
93017 compat_user_stack_pointer());
93018 set_fs(seg);
93019 if (ret >= 0 && uoss_ptr) {
93020 diff --git a/kernel/smpboot.c b/kernel/smpboot.c
93021 index eb89e18..a4e6792 100644
93022 --- a/kernel/smpboot.c
93023 +++ b/kernel/smpboot.c
93024 @@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
93025 }
93026 smpboot_unpark_thread(plug_thread, cpu);
93027 }
93028 - list_add(&plug_thread->list, &hotplug_threads);
93029 + pax_list_add(&plug_thread->list, &hotplug_threads);
93030 out:
93031 mutex_unlock(&smpboot_threads_lock);
93032 return ret;
93033 @@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
93034 {
93035 get_online_cpus();
93036 mutex_lock(&smpboot_threads_lock);
93037 - list_del(&plug_thread->list);
93038 + pax_list_del(&plug_thread->list);
93039 smpboot_destroy_threads(plug_thread);
93040 mutex_unlock(&smpboot_threads_lock);
93041 put_online_cpus();
93042 diff --git a/kernel/softirq.c b/kernel/softirq.c
93043 index 5918d22..e95d1926 100644
93044 --- a/kernel/softirq.c
93045 +++ b/kernel/softirq.c
93046 @@ -53,7 +53,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
93047 EXPORT_SYMBOL(irq_stat);
93048 #endif
93049
93050 -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
93051 +static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
93052
93053 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
93054
93055 @@ -266,7 +266,7 @@ restart:
93056 kstat_incr_softirqs_this_cpu(vec_nr);
93057
93058 trace_softirq_entry(vec_nr);
93059 - h->action(h);
93060 + h->action();
93061 trace_softirq_exit(vec_nr);
93062 if (unlikely(prev_count != preempt_count())) {
93063 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
93064 @@ -426,7 +426,7 @@ void __raise_softirq_irqoff(unsigned int nr)
93065 or_softirq_pending(1UL << nr);
93066 }
93067
93068 -void open_softirq(int nr, void (*action)(struct softirq_action *))
93069 +void __init open_softirq(int nr, void (*action)(void))
93070 {
93071 softirq_vec[nr].action = action;
93072 }
93073 @@ -478,7 +478,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
93074 }
93075 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
93076
93077 -static void tasklet_action(struct softirq_action *a)
93078 +static void tasklet_action(void)
93079 {
93080 struct tasklet_struct *list;
93081
93082 @@ -514,7 +514,7 @@ static void tasklet_action(struct softirq_action *a)
93083 }
93084 }
93085
93086 -static void tasklet_hi_action(struct softirq_action *a)
93087 +static __latent_entropy void tasklet_hi_action(void)
93088 {
93089 struct tasklet_struct *list;
93090
93091 @@ -741,7 +741,7 @@ static struct notifier_block cpu_nfb = {
93092 .notifier_call = cpu_callback
93093 };
93094
93095 -static struct smp_hotplug_thread softirq_threads = {
93096 +static struct smp_hotplug_thread softirq_threads __read_only = {
93097 .store = &ksoftirqd,
93098 .thread_should_run = ksoftirqd_should_run,
93099 .thread_fn = run_ksoftirqd,
93100 diff --git a/kernel/sys.c b/kernel/sys.c
93101 index ce81291..df2ca85 100644
93102 --- a/kernel/sys.c
93103 +++ b/kernel/sys.c
93104 @@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
93105 error = -EACCES;
93106 goto out;
93107 }
93108 +
93109 + if (gr_handle_chroot_setpriority(p, niceval)) {
93110 + error = -EACCES;
93111 + goto out;
93112 + }
93113 +
93114 no_nice = security_task_setnice(p, niceval);
93115 if (no_nice) {
93116 error = no_nice;
93117 @@ -351,6 +357,20 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
93118 goto error;
93119 }
93120
93121 + if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
93122 + goto error;
93123 +
93124 + if (!gid_eq(new->gid, old->gid)) {
93125 + /* make sure we generate a learn log for what will
93126 + end up being a role transition after a full-learning
93127 + policy is generated
93128 + CAP_SETGID is required to perform a transition
93129 + we may not log a CAP_SETGID check above, e.g.
93130 + in the case where new rgid = old egid
93131 + */
93132 + gr_learn_cap(current, new, CAP_SETGID);
93133 + }
93134 +
93135 if (rgid != (gid_t) -1 ||
93136 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
93137 new->sgid = new->egid;
93138 @@ -386,6 +406,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
93139 old = current_cred();
93140
93141 retval = -EPERM;
93142 +
93143 + if (gr_check_group_change(kgid, kgid, kgid))
93144 + goto error;
93145 +
93146 if (ns_capable(old->user_ns, CAP_SETGID))
93147 new->gid = new->egid = new->sgid = new->fsgid = kgid;
93148 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
93149 @@ -403,7 +427,7 @@ error:
93150 /*
93151 * change the user struct in a credentials set to match the new UID
93152 */
93153 -static int set_user(struct cred *new)
93154 +int set_user(struct cred *new)
93155 {
93156 struct user_struct *new_user;
93157
93158 @@ -483,7 +507,18 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
93159 goto error;
93160 }
93161
93162 + if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
93163 + goto error;
93164 +
93165 if (!uid_eq(new->uid, old->uid)) {
93166 + /* make sure we generate a learn log for what will
93167 + end up being a role transition after a full-learning
93168 + policy is generated
93169 + CAP_SETUID is required to perform a transition
93170 + we may not log a CAP_SETUID check above, e.g.
93171 + in the case where new ruid = old euid
93172 + */
93173 + gr_learn_cap(current, new, CAP_SETUID);
93174 retval = set_user(new);
93175 if (retval < 0)
93176 goto error;
93177 @@ -533,6 +568,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
93178 old = current_cred();
93179
93180 retval = -EPERM;
93181 +
93182 + if (gr_check_crash_uid(kuid))
93183 + goto error;
93184 + if (gr_check_user_change(kuid, kuid, kuid))
93185 + goto error;
93186 +
93187 if (ns_capable(old->user_ns, CAP_SETUID)) {
93188 new->suid = new->uid = kuid;
93189 if (!uid_eq(kuid, old->uid)) {
93190 @@ -602,6 +643,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
93191 goto error;
93192 }
93193
93194 + if (gr_check_user_change(kruid, keuid, INVALID_UID))
93195 + goto error;
93196 +
93197 if (ruid != (uid_t) -1) {
93198 new->uid = kruid;
93199 if (!uid_eq(kruid, old->uid)) {
93200 @@ -684,6 +728,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
93201 goto error;
93202 }
93203
93204 + if (gr_check_group_change(krgid, kegid, INVALID_GID))
93205 + goto error;
93206 +
93207 if (rgid != (gid_t) -1)
93208 new->gid = krgid;
93209 if (egid != (gid_t) -1)
93210 @@ -745,12 +792,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
93211 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
93212 ns_capable(old->user_ns, CAP_SETUID)) {
93213 if (!uid_eq(kuid, old->fsuid)) {
93214 + if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
93215 + goto error;
93216 +
93217 new->fsuid = kuid;
93218 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
93219 goto change_okay;
93220 }
93221 }
93222
93223 +error:
93224 abort_creds(new);
93225 return old_fsuid;
93226
93227 @@ -783,12 +834,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
93228 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
93229 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
93230 ns_capable(old->user_ns, CAP_SETGID)) {
93231 + if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
93232 + goto error;
93233 +
93234 if (!gid_eq(kgid, old->fsgid)) {
93235 new->fsgid = kgid;
93236 goto change_okay;
93237 }
93238 }
93239
93240 +error:
93241 abort_creds(new);
93242 return old_fsgid;
93243
93244 @@ -1167,19 +1222,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
93245 return -EFAULT;
93246
93247 down_read(&uts_sem);
93248 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
93249 + error = __copy_to_user(name->sysname, &utsname()->sysname,
93250 __OLD_UTS_LEN);
93251 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
93252 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
93253 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
93254 __OLD_UTS_LEN);
93255 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
93256 - error |= __copy_to_user(&name->release, &utsname()->release,
93257 + error |= __copy_to_user(name->release, &utsname()->release,
93258 __OLD_UTS_LEN);
93259 error |= __put_user(0, name->release + __OLD_UTS_LEN);
93260 - error |= __copy_to_user(&name->version, &utsname()->version,
93261 + error |= __copy_to_user(name->version, &utsname()->version,
93262 __OLD_UTS_LEN);
93263 error |= __put_user(0, name->version + __OLD_UTS_LEN);
93264 - error |= __copy_to_user(&name->machine, &utsname()->machine,
93265 + error |= __copy_to_user(name->machine, &utsname()->machine,
93266 __OLD_UTS_LEN);
93267 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
93268 up_read(&uts_sem);
93269 @@ -1381,6 +1436,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
93270 */
93271 new_rlim->rlim_cur = 1;
93272 }
93273 + /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
93274 + is changed to a lower value. Since tasks can be created by the same
93275 + user in between this limit change and an execve by this task, force
93276 + a recheck only for this task by setting PF_NPROC_EXCEEDED
93277 + */
93278 + if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
93279 + tsk->flags |= PF_NPROC_EXCEEDED;
93280 }
93281 if (!retval) {
93282 if (old_rlim)
93283 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
93284 index 75875a7..cd8e838 100644
93285 --- a/kernel/sysctl.c
93286 +++ b/kernel/sysctl.c
93287 @@ -94,7 +94,6 @@
93288
93289
93290 #if defined(CONFIG_SYSCTL)
93291 -
93292 /* External variables not in a header file. */
93293 extern int max_threads;
93294 extern int suid_dumpable;
93295 @@ -115,19 +114,20 @@ extern int sysctl_nr_trim_pages;
93296
93297 /* Constants used for minimum and maximum */
93298 #ifdef CONFIG_LOCKUP_DETECTOR
93299 -static int sixty = 60;
93300 +static int sixty __read_only = 60;
93301 #endif
93302
93303 -static int __maybe_unused neg_one = -1;
93304 +static int __maybe_unused neg_one __read_only = -1;
93305
93306 -static int zero;
93307 -static int __maybe_unused one = 1;
93308 -static int __maybe_unused two = 2;
93309 -static int __maybe_unused four = 4;
93310 -static unsigned long one_ul = 1;
93311 -static int one_hundred = 100;
93312 +static int zero __read_only = 0;
93313 +static int __maybe_unused one __read_only = 1;
93314 +static int __maybe_unused two __read_only = 2;
93315 +static int __maybe_unused three __read_only = 3;
93316 +static int __maybe_unused four __read_only = 4;
93317 +static unsigned long one_ul __read_only = 1;
93318 +static int one_hundred __read_only = 100;
93319 #ifdef CONFIG_PRINTK
93320 -static int ten_thousand = 10000;
93321 +static int ten_thousand __read_only = 10000;
93322 #endif
93323
93324 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
93325 @@ -181,10 +181,8 @@ static int proc_taint(struct ctl_table *table, int write,
93326 void __user *buffer, size_t *lenp, loff_t *ppos);
93327 #endif
93328
93329 -#ifdef CONFIG_PRINTK
93330 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
93331 void __user *buffer, size_t *lenp, loff_t *ppos);
93332 -#endif
93333
93334 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
93335 void __user *buffer, size_t *lenp, loff_t *ppos);
93336 @@ -215,6 +213,8 @@ static int sysrq_sysctl_handler(struct ctl_table *table, int write,
93337
93338 #endif
93339
93340 +extern struct ctl_table grsecurity_table[];
93341 +
93342 static struct ctl_table kern_table[];
93343 static struct ctl_table vm_table[];
93344 static struct ctl_table fs_table[];
93345 @@ -229,6 +229,20 @@ extern struct ctl_table epoll_table[];
93346 int sysctl_legacy_va_layout;
93347 #endif
93348
93349 +#ifdef CONFIG_PAX_SOFTMODE
93350 +static struct ctl_table pax_table[] = {
93351 + {
93352 + .procname = "softmode",
93353 + .data = &pax_softmode,
93354 + .maxlen = sizeof(unsigned int),
93355 + .mode = 0600,
93356 + .proc_handler = &proc_dointvec,
93357 + },
93358 +
93359 + { }
93360 +};
93361 +#endif
93362 +
93363 /* The default sysctl tables: */
93364
93365 static struct ctl_table sysctl_base_table[] = {
93366 @@ -277,6 +291,22 @@ static int max_extfrag_threshold = 1000;
93367 #endif
93368
93369 static struct ctl_table kern_table[] = {
93370 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
93371 + {
93372 + .procname = "grsecurity",
93373 + .mode = 0500,
93374 + .child = grsecurity_table,
93375 + },
93376 +#endif
93377 +
93378 +#ifdef CONFIG_PAX_SOFTMODE
93379 + {
93380 + .procname = "pax",
93381 + .mode = 0500,
93382 + .child = pax_table,
93383 + },
93384 +#endif
93385 +
93386 {
93387 .procname = "sched_child_runs_first",
93388 .data = &sysctl_sched_child_runs_first,
93389 @@ -641,7 +671,7 @@ static struct ctl_table kern_table[] = {
93390 .data = &modprobe_path,
93391 .maxlen = KMOD_PATH_LEN,
93392 .mode = 0644,
93393 - .proc_handler = proc_dostring,
93394 + .proc_handler = proc_dostring_modpriv,
93395 },
93396 {
93397 .procname = "modules_disabled",
93398 @@ -808,16 +838,20 @@ static struct ctl_table kern_table[] = {
93399 .extra1 = &zero,
93400 .extra2 = &one,
93401 },
93402 +#endif
93403 {
93404 .procname = "kptr_restrict",
93405 .data = &kptr_restrict,
93406 .maxlen = sizeof(int),
93407 .mode = 0644,
93408 .proc_handler = proc_dointvec_minmax_sysadmin,
93409 +#ifdef CONFIG_GRKERNSEC_HIDESYM
93410 + .extra1 = &two,
93411 +#else
93412 .extra1 = &zero,
93413 +#endif
93414 .extra2 = &two,
93415 },
93416 -#endif
93417 {
93418 .procname = "ngroups_max",
93419 .data = &ngroups_max,
93420 @@ -1073,10 +1107,17 @@ static struct ctl_table kern_table[] = {
93421 */
93422 {
93423 .procname = "perf_event_paranoid",
93424 - .data = &sysctl_perf_event_paranoid,
93425 - .maxlen = sizeof(sysctl_perf_event_paranoid),
93426 + .data = &sysctl_perf_event_legitimately_concerned,
93427 + .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
93428 .mode = 0644,
93429 - .proc_handler = proc_dointvec,
93430 + /* go ahead, be a hero */
93431 + .proc_handler = proc_dointvec_minmax_sysadmin,
93432 + .extra1 = &neg_one,
93433 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
93434 + .extra2 = &three,
93435 +#else
93436 + .extra2 = &two,
93437 +#endif
93438 },
93439 {
93440 .procname = "perf_event_mlock_kb",
93441 @@ -1335,6 +1376,13 @@ static struct ctl_table vm_table[] = {
93442 .proc_handler = proc_dointvec_minmax,
93443 .extra1 = &zero,
93444 },
93445 + {
93446 + .procname = "heap_stack_gap",
93447 + .data = &sysctl_heap_stack_gap,
93448 + .maxlen = sizeof(sysctl_heap_stack_gap),
93449 + .mode = 0644,
93450 + .proc_handler = proc_doulongvec_minmax,
93451 + },
93452 #else
93453 {
93454 .procname = "nr_trim_pages",
93455 @@ -1824,6 +1872,16 @@ int proc_dostring(struct ctl_table *table, int write,
93456 (char __user *)buffer, lenp, ppos);
93457 }
93458
93459 +int proc_dostring_modpriv(struct ctl_table *table, int write,
93460 + void __user *buffer, size_t *lenp, loff_t *ppos)
93461 +{
93462 + if (write && !capable(CAP_SYS_MODULE))
93463 + return -EPERM;
93464 +
93465 + return _proc_do_string(table->data, table->maxlen, write,
93466 + buffer, lenp, ppos);
93467 +}
93468 +
93469 static size_t proc_skip_spaces(char **buf)
93470 {
93471 size_t ret;
93472 @@ -1929,6 +1987,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
93473 len = strlen(tmp);
93474 if (len > *size)
93475 len = *size;
93476 + if (len > sizeof(tmp))
93477 + len = sizeof(tmp);
93478 if (copy_to_user(*buf, tmp, len))
93479 return -EFAULT;
93480 *size -= len;
93481 @@ -2106,7 +2166,7 @@ int proc_dointvec(struct ctl_table *table, int write,
93482 static int proc_taint(struct ctl_table *table, int write,
93483 void __user *buffer, size_t *lenp, loff_t *ppos)
93484 {
93485 - struct ctl_table t;
93486 + ctl_table_no_const t;
93487 unsigned long tmptaint = get_taint();
93488 int err;
93489
93490 @@ -2134,7 +2194,6 @@ static int proc_taint(struct ctl_table *table, int write,
93491 return err;
93492 }
93493
93494 -#ifdef CONFIG_PRINTK
93495 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
93496 void __user *buffer, size_t *lenp, loff_t *ppos)
93497 {
93498 @@ -2143,7 +2202,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
93499
93500 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
93501 }
93502 -#endif
93503
93504 struct do_proc_dointvec_minmax_conv_param {
93505 int *min;
93506 @@ -2703,6 +2761,12 @@ int proc_dostring(struct ctl_table *table, int write,
93507 return -ENOSYS;
93508 }
93509
93510 +int proc_dostring_modpriv(struct ctl_table *table, int write,
93511 + void __user *buffer, size_t *lenp, loff_t *ppos)
93512 +{
93513 + return -ENOSYS;
93514 +}
93515 +
93516 int proc_dointvec(struct ctl_table *table, int write,
93517 void __user *buffer, size_t *lenp, loff_t *ppos)
93518 {
93519 @@ -2759,5 +2823,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
93520 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
93521 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
93522 EXPORT_SYMBOL(proc_dostring);
93523 +EXPORT_SYMBOL(proc_dostring_modpriv);
93524 EXPORT_SYMBOL(proc_doulongvec_minmax);
93525 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
93526 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
93527 index 13d2f7c..c93d0b0 100644
93528 --- a/kernel/taskstats.c
93529 +++ b/kernel/taskstats.c
93530 @@ -28,9 +28,12 @@
93531 #include <linux/fs.h>
93532 #include <linux/file.h>
93533 #include <linux/pid_namespace.h>
93534 +#include <linux/grsecurity.h>
93535 #include <net/genetlink.h>
93536 #include <linux/atomic.h>
93537
93538 +extern int gr_is_taskstats_denied(int pid);
93539 +
93540 /*
93541 * Maximum length of a cpumask that can be specified in
93542 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
93543 @@ -576,6 +579,9 @@ err:
93544
93545 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
93546 {
93547 + if (gr_is_taskstats_denied(current->pid))
93548 + return -EACCES;
93549 +
93550 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
93551 return cmd_attr_register_cpumask(info);
93552 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
93553 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
93554 index a7077d3..dd48a49 100644
93555 --- a/kernel/time/alarmtimer.c
93556 +++ b/kernel/time/alarmtimer.c
93557 @@ -823,7 +823,7 @@ static int __init alarmtimer_init(void)
93558 struct platform_device *pdev;
93559 int error = 0;
93560 int i;
93561 - struct k_clock alarm_clock = {
93562 + static struct k_clock alarm_clock = {
93563 .clock_getres = alarm_clock_getres,
93564 .clock_get = alarm_clock_get,
93565 .timer_create = alarm_timer_create,
93566 diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
93567 index 1c2fe7d..ce7483d 100644
93568 --- a/kernel/time/hrtimer.c
93569 +++ b/kernel/time/hrtimer.c
93570 @@ -1399,7 +1399,7 @@ void hrtimer_peek_ahead_timers(void)
93571 local_irq_restore(flags);
93572 }
93573
93574 -static void run_hrtimer_softirq(struct softirq_action *h)
93575 +static __latent_entropy void run_hrtimer_softirq(void)
93576 {
93577 hrtimer_peek_ahead_timers();
93578 }
93579 diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
93580 index 3b89464..5e38379 100644
93581 --- a/kernel/time/posix-cpu-timers.c
93582 +++ b/kernel/time/posix-cpu-timers.c
93583 @@ -1464,14 +1464,14 @@ struct k_clock clock_posix_cpu = {
93584
93585 static __init int init_posix_cpu_timers(void)
93586 {
93587 - struct k_clock process = {
93588 + static struct k_clock process = {
93589 .clock_getres = process_cpu_clock_getres,
93590 .clock_get = process_cpu_clock_get,
93591 .timer_create = process_cpu_timer_create,
93592 .nsleep = process_cpu_nsleep,
93593 .nsleep_restart = process_cpu_nsleep_restart,
93594 };
93595 - struct k_clock thread = {
93596 + static struct k_clock thread = {
93597 .clock_getres = thread_cpu_clock_getres,
93598 .clock_get = thread_cpu_clock_get,
93599 .timer_create = thread_cpu_timer_create,
93600 diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
93601 index 31ea01f..7fc61ef 100644
93602 --- a/kernel/time/posix-timers.c
93603 +++ b/kernel/time/posix-timers.c
93604 @@ -43,6 +43,7 @@
93605 #include <linux/hash.h>
93606 #include <linux/posix-clock.h>
93607 #include <linux/posix-timers.h>
93608 +#include <linux/grsecurity.h>
93609 #include <linux/syscalls.h>
93610 #include <linux/wait.h>
93611 #include <linux/workqueue.h>
93612 @@ -124,7 +125,7 @@ static DEFINE_SPINLOCK(hash_lock);
93613 * which we beg off on and pass to do_sys_settimeofday().
93614 */
93615
93616 -static struct k_clock posix_clocks[MAX_CLOCKS];
93617 +static struct k_clock *posix_clocks[MAX_CLOCKS];
93618
93619 /*
93620 * These ones are defined below.
93621 @@ -277,7 +278,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
93622 */
93623 static __init int init_posix_timers(void)
93624 {
93625 - struct k_clock clock_realtime = {
93626 + static struct k_clock clock_realtime = {
93627 .clock_getres = hrtimer_get_res,
93628 .clock_get = posix_clock_realtime_get,
93629 .clock_set = posix_clock_realtime_set,
93630 @@ -289,7 +290,7 @@ static __init int init_posix_timers(void)
93631 .timer_get = common_timer_get,
93632 .timer_del = common_timer_del,
93633 };
93634 - struct k_clock clock_monotonic = {
93635 + static struct k_clock clock_monotonic = {
93636 .clock_getres = hrtimer_get_res,
93637 .clock_get = posix_ktime_get_ts,
93638 .nsleep = common_nsleep,
93639 @@ -299,19 +300,19 @@ static __init int init_posix_timers(void)
93640 .timer_get = common_timer_get,
93641 .timer_del = common_timer_del,
93642 };
93643 - struct k_clock clock_monotonic_raw = {
93644 + static struct k_clock clock_monotonic_raw = {
93645 .clock_getres = hrtimer_get_res,
93646 .clock_get = posix_get_monotonic_raw,
93647 };
93648 - struct k_clock clock_realtime_coarse = {
93649 + static struct k_clock clock_realtime_coarse = {
93650 .clock_getres = posix_get_coarse_res,
93651 .clock_get = posix_get_realtime_coarse,
93652 };
93653 - struct k_clock clock_monotonic_coarse = {
93654 + static struct k_clock clock_monotonic_coarse = {
93655 .clock_getres = posix_get_coarse_res,
93656 .clock_get = posix_get_monotonic_coarse,
93657 };
93658 - struct k_clock clock_tai = {
93659 + static struct k_clock clock_tai = {
93660 .clock_getres = hrtimer_get_res,
93661 .clock_get = posix_get_tai,
93662 .nsleep = common_nsleep,
93663 @@ -321,7 +322,7 @@ static __init int init_posix_timers(void)
93664 .timer_get = common_timer_get,
93665 .timer_del = common_timer_del,
93666 };
93667 - struct k_clock clock_boottime = {
93668 + static struct k_clock clock_boottime = {
93669 .clock_getres = hrtimer_get_res,
93670 .clock_get = posix_get_boottime,
93671 .nsleep = common_nsleep,
93672 @@ -533,7 +534,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
93673 return;
93674 }
93675
93676 - posix_clocks[clock_id] = *new_clock;
93677 + posix_clocks[clock_id] = new_clock;
93678 }
93679 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
93680
93681 @@ -579,9 +580,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
93682 return (id & CLOCKFD_MASK) == CLOCKFD ?
93683 &clock_posix_dynamic : &clock_posix_cpu;
93684
93685 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
93686 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
93687 return NULL;
93688 - return &posix_clocks[id];
93689 + return posix_clocks[id];
93690 }
93691
93692 static int common_timer_create(struct k_itimer *new_timer)
93693 @@ -599,7 +600,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
93694 struct k_clock *kc = clockid_to_kclock(which_clock);
93695 struct k_itimer *new_timer;
93696 int error, new_timer_id;
93697 - sigevent_t event;
93698 + sigevent_t event = { };
93699 int it_id_set = IT_ID_NOT_SET;
93700
93701 if (!kc)
93702 @@ -1014,6 +1015,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
93703 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
93704 return -EFAULT;
93705
93706 + /* only the CLOCK_REALTIME clock can be set, all other clocks
93707 + have their clock_set fptr set to a nosettime dummy function
93708 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
93709 + call common_clock_set, which calls do_sys_settimeofday, which
93710 + we hook
93711 + */
93712 +
93713 return kc->clock_set(which_clock, &new_tp);
93714 }
93715
93716 diff --git a/kernel/time/time.c b/kernel/time/time.c
93717 index a9ae20f..d3fbde7 100644
93718 --- a/kernel/time/time.c
93719 +++ b/kernel/time/time.c
93720 @@ -173,6 +173,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
93721 return error;
93722
93723 if (tz) {
93724 + /* we log in do_settimeofday called below, so don't log twice
93725 + */
93726 + if (!tv)
93727 + gr_log_timechange();
93728 +
93729 sys_tz = *tz;
93730 update_vsyscall_tz();
93731 if (firsttime) {
93732 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
93733 index ec1791f..6a086cd 100644
93734 --- a/kernel/time/timekeeping.c
93735 +++ b/kernel/time/timekeeping.c
93736 @@ -15,6 +15,7 @@
93737 #include <linux/init.h>
93738 #include <linux/mm.h>
93739 #include <linux/sched.h>
93740 +#include <linux/grsecurity.h>
93741 #include <linux/syscore_ops.h>
93742 #include <linux/clocksource.h>
93743 #include <linux/jiffies.h>
93744 @@ -717,6 +718,8 @@ int do_settimeofday(const struct timespec *tv)
93745 if (!timespec_valid_strict(tv))
93746 return -EINVAL;
93747
93748 + gr_log_timechange();
93749 +
93750 raw_spin_lock_irqsave(&timekeeper_lock, flags);
93751 write_seqcount_begin(&tk_core.seq);
93752
93753 diff --git a/kernel/time/timer.c b/kernel/time/timer.c
93754 index 9bbb834..3caa8ed 100644
93755 --- a/kernel/time/timer.c
93756 +++ b/kernel/time/timer.c
93757 @@ -1394,7 +1394,7 @@ void update_process_times(int user_tick)
93758 /*
93759 * This function runs timers and the timer-tq in bottom half context.
93760 */
93761 -static void run_timer_softirq(struct softirq_action *h)
93762 +static __latent_entropy void run_timer_softirq(void)
93763 {
93764 struct tvec_base *base = __this_cpu_read(tvec_bases);
93765
93766 @@ -1457,7 +1457,7 @@ static void process_timeout(unsigned long __data)
93767 *
93768 * In all cases the return value is guaranteed to be non-negative.
93769 */
93770 -signed long __sched schedule_timeout(signed long timeout)
93771 +signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
93772 {
93773 struct timer_list timer;
93774 unsigned long expire;
93775 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
93776 index 61ed862..3b52c65 100644
93777 --- a/kernel/time/timer_list.c
93778 +++ b/kernel/time/timer_list.c
93779 @@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
93780
93781 static void print_name_offset(struct seq_file *m, void *sym)
93782 {
93783 +#ifdef CONFIG_GRKERNSEC_HIDESYM
93784 + SEQ_printf(m, "<%p>", NULL);
93785 +#else
93786 char symname[KSYM_NAME_LEN];
93787
93788 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
93789 SEQ_printf(m, "<%pK>", sym);
93790 else
93791 SEQ_printf(m, "%s", symname);
93792 +#endif
93793 }
93794
93795 static void
93796 @@ -119,7 +123,11 @@ next_one:
93797 static void
93798 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
93799 {
93800 +#ifdef CONFIG_GRKERNSEC_HIDESYM
93801 + SEQ_printf(m, " .base: %p\n", NULL);
93802 +#else
93803 SEQ_printf(m, " .base: %pK\n", base);
93804 +#endif
93805 SEQ_printf(m, " .index: %d\n",
93806 base->index);
93807 SEQ_printf(m, " .resolution: %Lu nsecs\n",
93808 @@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
93809 {
93810 struct proc_dir_entry *pe;
93811
93812 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
93813 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
93814 +#else
93815 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
93816 +#endif
93817 if (!pe)
93818 return -ENOMEM;
93819 return 0;
93820 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
93821 index 1fb08f2..ca4bb1e 100644
93822 --- a/kernel/time/timer_stats.c
93823 +++ b/kernel/time/timer_stats.c
93824 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
93825 static unsigned long nr_entries;
93826 static struct entry entries[MAX_ENTRIES];
93827
93828 -static atomic_t overflow_count;
93829 +static atomic_unchecked_t overflow_count;
93830
93831 /*
93832 * The entries are in a hash-table, for fast lookup:
93833 @@ -140,7 +140,7 @@ static void reset_entries(void)
93834 nr_entries = 0;
93835 memset(entries, 0, sizeof(entries));
93836 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
93837 - atomic_set(&overflow_count, 0);
93838 + atomic_set_unchecked(&overflow_count, 0);
93839 }
93840
93841 static struct entry *alloc_entry(void)
93842 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
93843 if (likely(entry))
93844 entry->count++;
93845 else
93846 - atomic_inc(&overflow_count);
93847 + atomic_inc_unchecked(&overflow_count);
93848
93849 out_unlock:
93850 raw_spin_unlock_irqrestore(lock, flags);
93851 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
93852
93853 static void print_name_offset(struct seq_file *m, unsigned long addr)
93854 {
93855 +#ifdef CONFIG_GRKERNSEC_HIDESYM
93856 + seq_printf(m, "<%p>", NULL);
93857 +#else
93858 char symname[KSYM_NAME_LEN];
93859
93860 if (lookup_symbol_name(addr, symname) < 0)
93861 - seq_printf(m, "<%p>", (void *)addr);
93862 + seq_printf(m, "<%pK>", (void *)addr);
93863 else
93864 seq_printf(m, "%s", symname);
93865 +#endif
93866 }
93867
93868 static int tstats_show(struct seq_file *m, void *v)
93869 @@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
93870
93871 seq_puts(m, "Timer Stats Version: v0.3\n");
93872 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
93873 - if (atomic_read(&overflow_count))
93874 - seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
93875 + if (atomic_read_unchecked(&overflow_count))
93876 + seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
93877 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
93878
93879 for (i = 0; i < nr_entries; i++) {
93880 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
93881 {
93882 struct proc_dir_entry *pe;
93883
93884 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
93885 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
93886 +#else
93887 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
93888 +#endif
93889 if (!pe)
93890 return -ENOMEM;
93891 return 0;
93892 diff --git a/kernel/torture.c b/kernel/torture.c
93893 index d600af2..27a4e9d 100644
93894 --- a/kernel/torture.c
93895 +++ b/kernel/torture.c
93896 @@ -484,7 +484,7 @@ static int torture_shutdown_notify(struct notifier_block *unused1,
93897 mutex_lock(&fullstop_mutex);
93898 if (ACCESS_ONCE(fullstop) == FULLSTOP_DONTSTOP) {
93899 VERBOSE_TOROUT_STRING("Unscheduled system shutdown detected");
93900 - ACCESS_ONCE(fullstop) = FULLSTOP_SHUTDOWN;
93901 + ACCESS_ONCE_RW(fullstop) = FULLSTOP_SHUTDOWN;
93902 } else {
93903 pr_warn("Concurrent rmmod and shutdown illegal!\n");
93904 }
93905 @@ -551,14 +551,14 @@ static int torture_stutter(void *arg)
93906 if (!torture_must_stop()) {
93907 if (stutter > 1) {
93908 schedule_timeout_interruptible(stutter - 1);
93909 - ACCESS_ONCE(stutter_pause_test) = 2;
93910 + ACCESS_ONCE_RW(stutter_pause_test) = 2;
93911 }
93912 schedule_timeout_interruptible(1);
93913 - ACCESS_ONCE(stutter_pause_test) = 1;
93914 + ACCESS_ONCE_RW(stutter_pause_test) = 1;
93915 }
93916 if (!torture_must_stop())
93917 schedule_timeout_interruptible(stutter);
93918 - ACCESS_ONCE(stutter_pause_test) = 0;
93919 + ACCESS_ONCE_RW(stutter_pause_test) = 0;
93920 torture_shutdown_absorb("torture_stutter");
93921 } while (!torture_must_stop());
93922 torture_kthread_stopping("torture_stutter");
93923 @@ -645,7 +645,7 @@ bool torture_cleanup(void)
93924 schedule_timeout_uninterruptible(10);
93925 return true;
93926 }
93927 - ACCESS_ONCE(fullstop) = FULLSTOP_RMMOD;
93928 + ACCESS_ONCE_RW(fullstop) = FULLSTOP_RMMOD;
93929 mutex_unlock(&fullstop_mutex);
93930 torture_shutdown_cleanup();
93931 torture_shuffle_cleanup();
93932 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
93933 index c1bd4ad..4b861dc 100644
93934 --- a/kernel/trace/blktrace.c
93935 +++ b/kernel/trace/blktrace.c
93936 @@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
93937 struct blk_trace *bt = filp->private_data;
93938 char buf[16];
93939
93940 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
93941 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
93942
93943 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
93944 }
93945 @@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
93946 return 1;
93947
93948 bt = buf->chan->private_data;
93949 - atomic_inc(&bt->dropped);
93950 + atomic_inc_unchecked(&bt->dropped);
93951 return 0;
93952 }
93953
93954 @@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
93955
93956 bt->dir = dir;
93957 bt->dev = dev;
93958 - atomic_set(&bt->dropped, 0);
93959 + atomic_set_unchecked(&bt->dropped, 0);
93960 INIT_LIST_HEAD(&bt->running_list);
93961
93962 ret = -EIO;
93963 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
93964 index 5916a8e..5cd3b1f 100644
93965 --- a/kernel/trace/ftrace.c
93966 +++ b/kernel/trace/ftrace.c
93967 @@ -2128,12 +2128,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
93968 if (unlikely(ftrace_disabled))
93969 return 0;
93970
93971 + ret = ftrace_arch_code_modify_prepare();
93972 + FTRACE_WARN_ON(ret);
93973 + if (ret)
93974 + return 0;
93975 +
93976 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
93977 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
93978 if (ret) {
93979 ftrace_bug(ret, ip);
93980 - return 0;
93981 }
93982 - return 1;
93983 + return ret ? 0 : 1;
93984 }
93985
93986 /*
93987 @@ -4458,8 +4463,10 @@ static int ftrace_process_locs(struct module *mod,
93988 if (!count)
93989 return 0;
93990
93991 + pax_open_kernel();
93992 sort(start, count, sizeof(*start),
93993 ftrace_cmp_ips, ftrace_swap_ips);
93994 + pax_close_kernel();
93995
93996 start_pg = ftrace_allocate_pages(count);
93997 if (!start_pg)
93998 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
93999 index a56e07c..d46f0ba 100644
94000 --- a/kernel/trace/ring_buffer.c
94001 +++ b/kernel/trace/ring_buffer.c
94002 @@ -352,9 +352,9 @@ struct buffer_data_page {
94003 */
94004 struct buffer_page {
94005 struct list_head list; /* list of buffer pages */
94006 - local_t write; /* index for next write */
94007 + local_unchecked_t write; /* index for next write */
94008 unsigned read; /* index for next read */
94009 - local_t entries; /* entries on this page */
94010 + local_unchecked_t entries; /* entries on this page */
94011 unsigned long real_end; /* real end of data */
94012 struct buffer_data_page *page; /* Actual data page */
94013 };
94014 @@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
94015 unsigned long last_overrun;
94016 local_t entries_bytes;
94017 local_t entries;
94018 - local_t overrun;
94019 - local_t commit_overrun;
94020 + local_unchecked_t overrun;
94021 + local_unchecked_t commit_overrun;
94022 local_t dropped_events;
94023 local_t committing;
94024 local_t commits;
94025 @@ -1032,8 +1032,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
94026 *
94027 * We add a counter to the write field to denote this.
94028 */
94029 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
94030 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
94031 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
94032 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
94033
94034 /*
94035 * Just make sure we have seen our old_write and synchronize
94036 @@ -1061,8 +1061,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
94037 * cmpxchg to only update if an interrupt did not already
94038 * do it for us. If the cmpxchg fails, we don't care.
94039 */
94040 - (void)local_cmpxchg(&next_page->write, old_write, val);
94041 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
94042 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
94043 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
94044
94045 /*
94046 * No need to worry about races with clearing out the commit.
94047 @@ -1429,12 +1429,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
94048
94049 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
94050 {
94051 - return local_read(&bpage->entries) & RB_WRITE_MASK;
94052 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
94053 }
94054
94055 static inline unsigned long rb_page_write(struct buffer_page *bpage)
94056 {
94057 - return local_read(&bpage->write) & RB_WRITE_MASK;
94058 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
94059 }
94060
94061 static int
94062 @@ -1529,7 +1529,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
94063 * bytes consumed in ring buffer from here.
94064 * Increment overrun to account for the lost events.
94065 */
94066 - local_add(page_entries, &cpu_buffer->overrun);
94067 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
94068 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
94069 }
94070
94071 @@ -2091,7 +2091,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
94072 * it is our responsibility to update
94073 * the counters.
94074 */
94075 - local_add(entries, &cpu_buffer->overrun);
94076 + local_add_unchecked(entries, &cpu_buffer->overrun);
94077 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
94078
94079 /*
94080 @@ -2241,7 +2241,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
94081 if (tail == BUF_PAGE_SIZE)
94082 tail_page->real_end = 0;
94083
94084 - local_sub(length, &tail_page->write);
94085 + local_sub_unchecked(length, &tail_page->write);
94086 return;
94087 }
94088
94089 @@ -2276,7 +2276,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
94090 rb_event_set_padding(event);
94091
94092 /* Set the write back to the previous setting */
94093 - local_sub(length, &tail_page->write);
94094 + local_sub_unchecked(length, &tail_page->write);
94095 return;
94096 }
94097
94098 @@ -2288,7 +2288,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
94099
94100 /* Set write to end of buffer */
94101 length = (tail + length) - BUF_PAGE_SIZE;
94102 - local_sub(length, &tail_page->write);
94103 + local_sub_unchecked(length, &tail_page->write);
94104 }
94105
94106 /*
94107 @@ -2314,7 +2314,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
94108 * about it.
94109 */
94110 if (unlikely(next_page == commit_page)) {
94111 - local_inc(&cpu_buffer->commit_overrun);
94112 + local_inc_unchecked(&cpu_buffer->commit_overrun);
94113 goto out_reset;
94114 }
94115
94116 @@ -2370,7 +2370,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
94117 cpu_buffer->tail_page) &&
94118 (cpu_buffer->commit_page ==
94119 cpu_buffer->reader_page))) {
94120 - local_inc(&cpu_buffer->commit_overrun);
94121 + local_inc_unchecked(&cpu_buffer->commit_overrun);
94122 goto out_reset;
94123 }
94124 }
94125 @@ -2418,7 +2418,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
94126 length += RB_LEN_TIME_EXTEND;
94127
94128 tail_page = cpu_buffer->tail_page;
94129 - write = local_add_return(length, &tail_page->write);
94130 + write = local_add_return_unchecked(length, &tail_page->write);
94131
94132 /* set write to only the index of the write */
94133 write &= RB_WRITE_MASK;
94134 @@ -2442,7 +2442,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
94135 kmemcheck_annotate_bitfield(event, bitfield);
94136 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
94137
94138 - local_inc(&tail_page->entries);
94139 + local_inc_unchecked(&tail_page->entries);
94140
94141 /*
94142 * If this is the first commit on the page, then update
94143 @@ -2475,7 +2475,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
94144
94145 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
94146 unsigned long write_mask =
94147 - local_read(&bpage->write) & ~RB_WRITE_MASK;
94148 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
94149 unsigned long event_length = rb_event_length(event);
94150 /*
94151 * This is on the tail page. It is possible that
94152 @@ -2485,7 +2485,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
94153 */
94154 old_index += write_mask;
94155 new_index += write_mask;
94156 - index = local_cmpxchg(&bpage->write, old_index, new_index);
94157 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
94158 if (index == old_index) {
94159 /* update counters */
94160 local_sub(event_length, &cpu_buffer->entries_bytes);
94161 @@ -2877,7 +2877,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
94162
94163 /* Do the likely case first */
94164 if (likely(bpage->page == (void *)addr)) {
94165 - local_dec(&bpage->entries);
94166 + local_dec_unchecked(&bpage->entries);
94167 return;
94168 }
94169
94170 @@ -2889,7 +2889,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
94171 start = bpage;
94172 do {
94173 if (bpage->page == (void *)addr) {
94174 - local_dec(&bpage->entries);
94175 + local_dec_unchecked(&bpage->entries);
94176 return;
94177 }
94178 rb_inc_page(cpu_buffer, &bpage);
94179 @@ -3173,7 +3173,7 @@ static inline unsigned long
94180 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
94181 {
94182 return local_read(&cpu_buffer->entries) -
94183 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
94184 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
94185 }
94186
94187 /**
94188 @@ -3262,7 +3262,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
94189 return 0;
94190
94191 cpu_buffer = buffer->buffers[cpu];
94192 - ret = local_read(&cpu_buffer->overrun);
94193 + ret = local_read_unchecked(&cpu_buffer->overrun);
94194
94195 return ret;
94196 }
94197 @@ -3285,7 +3285,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
94198 return 0;
94199
94200 cpu_buffer = buffer->buffers[cpu];
94201 - ret = local_read(&cpu_buffer->commit_overrun);
94202 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
94203
94204 return ret;
94205 }
94206 @@ -3370,7 +3370,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
94207 /* if you care about this being correct, lock the buffer */
94208 for_each_buffer_cpu(buffer, cpu) {
94209 cpu_buffer = buffer->buffers[cpu];
94210 - overruns += local_read(&cpu_buffer->overrun);
94211 + overruns += local_read_unchecked(&cpu_buffer->overrun);
94212 }
94213
94214 return overruns;
94215 @@ -3541,8 +3541,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
94216 /*
94217 * Reset the reader page to size zero.
94218 */
94219 - local_set(&cpu_buffer->reader_page->write, 0);
94220 - local_set(&cpu_buffer->reader_page->entries, 0);
94221 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
94222 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
94223 local_set(&cpu_buffer->reader_page->page->commit, 0);
94224 cpu_buffer->reader_page->real_end = 0;
94225
94226 @@ -3576,7 +3576,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
94227 * want to compare with the last_overrun.
94228 */
94229 smp_mb();
94230 - overwrite = local_read(&(cpu_buffer->overrun));
94231 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
94232
94233 /*
94234 * Here's the tricky part.
94235 @@ -4148,8 +4148,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
94236
94237 cpu_buffer->head_page
94238 = list_entry(cpu_buffer->pages, struct buffer_page, list);
94239 - local_set(&cpu_buffer->head_page->write, 0);
94240 - local_set(&cpu_buffer->head_page->entries, 0);
94241 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
94242 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
94243 local_set(&cpu_buffer->head_page->page->commit, 0);
94244
94245 cpu_buffer->head_page->read = 0;
94246 @@ -4159,14 +4159,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
94247
94248 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
94249 INIT_LIST_HEAD(&cpu_buffer->new_pages);
94250 - local_set(&cpu_buffer->reader_page->write, 0);
94251 - local_set(&cpu_buffer->reader_page->entries, 0);
94252 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
94253 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
94254 local_set(&cpu_buffer->reader_page->page->commit, 0);
94255 cpu_buffer->reader_page->read = 0;
94256
94257 local_set(&cpu_buffer->entries_bytes, 0);
94258 - local_set(&cpu_buffer->overrun, 0);
94259 - local_set(&cpu_buffer->commit_overrun, 0);
94260 + local_set_unchecked(&cpu_buffer->overrun, 0);
94261 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
94262 local_set(&cpu_buffer->dropped_events, 0);
94263 local_set(&cpu_buffer->entries, 0);
94264 local_set(&cpu_buffer->committing, 0);
94265 @@ -4571,8 +4571,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
94266 rb_init_page(bpage);
94267 bpage = reader->page;
94268 reader->page = *data_page;
94269 - local_set(&reader->write, 0);
94270 - local_set(&reader->entries, 0);
94271 + local_set_unchecked(&reader->write, 0);
94272 + local_set_unchecked(&reader->entries, 0);
94273 reader->read = 0;
94274 *data_page = bpage;
94275
94276 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
94277 index 1520933..c651ebc 100644
94278 --- a/kernel/trace/trace.c
94279 +++ b/kernel/trace/trace.c
94280 @@ -3488,7 +3488,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
94281 return 0;
94282 }
94283
94284 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
94285 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
94286 {
94287 /* do nothing if flag is already set */
94288 if (!!(trace_flags & mask) == !!enabled)
94289 diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
94290 index 385391f..8d2250f 100644
94291 --- a/kernel/trace/trace.h
94292 +++ b/kernel/trace/trace.h
94293 @@ -1280,7 +1280,7 @@ extern const char *__stop___tracepoint_str[];
94294 void trace_printk_init_buffers(void);
94295 void trace_printk_start_comm(void);
94296 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
94297 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
94298 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
94299
94300 /*
94301 * Normal trace_printk() and friends allocates special buffers
94302 diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
94303 index 57b67b1..66082a9 100644
94304 --- a/kernel/trace/trace_clock.c
94305 +++ b/kernel/trace/trace_clock.c
94306 @@ -124,7 +124,7 @@ u64 notrace trace_clock_global(void)
94307 return now;
94308 }
94309
94310 -static atomic64_t trace_counter;
94311 +static atomic64_unchecked_t trace_counter;
94312
94313 /*
94314 * trace_clock_counter(): simply an atomic counter.
94315 @@ -133,5 +133,5 @@ static atomic64_t trace_counter;
94316 */
94317 u64 notrace trace_clock_counter(void)
94318 {
94319 - return atomic64_add_return(1, &trace_counter);
94320 + return atomic64_inc_return_unchecked(&trace_counter);
94321 }
94322 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
94323 index ef06ce7..3ea161d 100644
94324 --- a/kernel/trace/trace_events.c
94325 +++ b/kernel/trace/trace_events.c
94326 @@ -1720,7 +1720,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
94327 return 0;
94328 }
94329
94330 -struct ftrace_module_file_ops;
94331 static void __add_event_to_tracers(struct ftrace_event_call *call);
94332
94333 /* Add an additional event_call dynamically */
94334 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
94335 index 0abd9b8..6a663a2 100644
94336 --- a/kernel/trace/trace_mmiotrace.c
94337 +++ b/kernel/trace/trace_mmiotrace.c
94338 @@ -24,7 +24,7 @@ struct header_iter {
94339 static struct trace_array *mmio_trace_array;
94340 static bool overrun_detected;
94341 static unsigned long prev_overruns;
94342 -static atomic_t dropped_count;
94343 +static atomic_unchecked_t dropped_count;
94344
94345 static void mmio_reset_data(struct trace_array *tr)
94346 {
94347 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
94348
94349 static unsigned long count_overruns(struct trace_iterator *iter)
94350 {
94351 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
94352 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
94353 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
94354
94355 if (over > prev_overruns)
94356 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
94357 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
94358 sizeof(*entry), 0, pc);
94359 if (!event) {
94360 - atomic_inc(&dropped_count);
94361 + atomic_inc_unchecked(&dropped_count);
94362 return;
94363 }
94364 entry = ring_buffer_event_data(event);
94365 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
94366 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
94367 sizeof(*entry), 0, pc);
94368 if (!event) {
94369 - atomic_inc(&dropped_count);
94370 + atomic_inc_unchecked(&dropped_count);
94371 return;
94372 }
94373 entry = ring_buffer_event_data(event);
94374 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
94375 index c6977d5..d243785 100644
94376 --- a/kernel/trace/trace_output.c
94377 +++ b/kernel/trace/trace_output.c
94378 @@ -712,14 +712,16 @@ int register_ftrace_event(struct trace_event *event)
94379 goto out;
94380 }
94381
94382 + pax_open_kernel();
94383 if (event->funcs->trace == NULL)
94384 - event->funcs->trace = trace_nop_print;
94385 + *(void **)&event->funcs->trace = trace_nop_print;
94386 if (event->funcs->raw == NULL)
94387 - event->funcs->raw = trace_nop_print;
94388 + *(void **)&event->funcs->raw = trace_nop_print;
94389 if (event->funcs->hex == NULL)
94390 - event->funcs->hex = trace_nop_print;
94391 + *(void **)&event->funcs->hex = trace_nop_print;
94392 if (event->funcs->binary == NULL)
94393 - event->funcs->binary = trace_nop_print;
94394 + *(void **)&event->funcs->binary = trace_nop_print;
94395 + pax_close_kernel();
94396
94397 key = event->type & (EVENT_HASHSIZE - 1);
94398
94399 diff --git a/kernel/trace/trace_seq.c b/kernel/trace/trace_seq.c
94400 index 1f24ed9..10407ec 100644
94401 --- a/kernel/trace/trace_seq.c
94402 +++ b/kernel/trace/trace_seq.c
94403 @@ -367,7 +367,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
94404
94405 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
94406 if (!IS_ERR(p)) {
94407 - p = mangle_path(s->buffer + s->len, p, "\n");
94408 + p = mangle_path(s->buffer + s->len, p, "\n\\");
94409 if (p) {
94410 s->len = p - s->buffer;
94411 return 1;
94412 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
94413 index 8a4e5cb..64f270d 100644
94414 --- a/kernel/trace/trace_stack.c
94415 +++ b/kernel/trace/trace_stack.c
94416 @@ -91,7 +91,7 @@ check_stack(unsigned long ip, unsigned long *stack)
94417 return;
94418
94419 /* we do not handle interrupt stacks yet */
94420 - if (!object_is_on_stack(stack))
94421 + if (!object_starts_on_stack(stack))
94422 return;
94423
94424 local_irq_save(flags);
94425 diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c
94426 index 7e3cd7a..5156a5fe 100644
94427 --- a/kernel/trace/trace_syscalls.c
94428 +++ b/kernel/trace/trace_syscalls.c
94429 @@ -602,6 +602,8 @@ static int perf_sysenter_enable(struct ftrace_event_call *call)
94430 int num;
94431
94432 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94433 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94434 + return -EINVAL;
94435
94436 mutex_lock(&syscall_trace_lock);
94437 if (!sys_perf_refcount_enter)
94438 @@ -622,6 +624,8 @@ static void perf_sysenter_disable(struct ftrace_event_call *call)
94439 int num;
94440
94441 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94442 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94443 + return;
94444
94445 mutex_lock(&syscall_trace_lock);
94446 sys_perf_refcount_enter--;
94447 @@ -674,6 +678,8 @@ static int perf_sysexit_enable(struct ftrace_event_call *call)
94448 int num;
94449
94450 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94451 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94452 + return -EINVAL;
94453
94454 mutex_lock(&syscall_trace_lock);
94455 if (!sys_perf_refcount_exit)
94456 @@ -694,6 +700,8 @@ static void perf_sysexit_disable(struct ftrace_event_call *call)
94457 int num;
94458
94459 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94460 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94461 + return;
94462
94463 mutex_lock(&syscall_trace_lock);
94464 sys_perf_refcount_exit--;
94465 diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
94466 index aa312b0..395f343 100644
94467 --- a/kernel/user_namespace.c
94468 +++ b/kernel/user_namespace.c
94469 @@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
94470 !kgid_has_mapping(parent_ns, group))
94471 return -EPERM;
94472
94473 +#ifdef CONFIG_GRKERNSEC
94474 + /*
94475 + * This doesn't really inspire confidence:
94476 + * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
94477 + * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
94478 + * Increases kernel attack surface in areas developers
94479 + * previously cared little about ("low importance due
94480 + * to requiring "root" capability")
94481 + * To be removed when this code receives *proper* review
94482 + */
94483 + if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
94484 + !capable(CAP_SETGID))
94485 + return -EPERM;
94486 +#endif
94487 +
94488 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
94489 if (!ns)
94490 return -ENOMEM;
94491 @@ -872,7 +887,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
94492 if (atomic_read(&current->mm->mm_users) > 1)
94493 return -EINVAL;
94494
94495 - if (current->fs->users != 1)
94496 + if (atomic_read(&current->fs->users) != 1)
94497 return -EINVAL;
94498
94499 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
94500 diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
94501 index c8eac43..4b5f08f 100644
94502 --- a/kernel/utsname_sysctl.c
94503 +++ b/kernel/utsname_sysctl.c
94504 @@ -47,7 +47,7 @@ static void put_uts(struct ctl_table *table, int write, void *which)
94505 static int proc_do_uts_string(struct ctl_table *table, int write,
94506 void __user *buffer, size_t *lenp, loff_t *ppos)
94507 {
94508 - struct ctl_table uts_table;
94509 + ctl_table_no_const uts_table;
94510 int r;
94511 memcpy(&uts_table, table, sizeof(uts_table));
94512 uts_table.data = get_uts(table, write);
94513 diff --git a/kernel/watchdog.c b/kernel/watchdog.c
94514 index a8d6914..8fbdb13 100644
94515 --- a/kernel/watchdog.c
94516 +++ b/kernel/watchdog.c
94517 @@ -521,7 +521,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
94518 static void watchdog_nmi_disable(unsigned int cpu) { return; }
94519 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
94520
94521 -static struct smp_hotplug_thread watchdog_threads = {
94522 +static struct smp_hotplug_thread watchdog_threads __read_only = {
94523 .store = &softlockup_watchdog,
94524 .thread_should_run = watchdog_should_run,
94525 .thread_fn = watchdog,
94526 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
94527 index 5dbe22a..872413c 100644
94528 --- a/kernel/workqueue.c
94529 +++ b/kernel/workqueue.c
94530 @@ -4507,7 +4507,7 @@ static void rebind_workers(struct worker_pool *pool)
94531 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
94532 worker_flags |= WORKER_REBOUND;
94533 worker_flags &= ~WORKER_UNBOUND;
94534 - ACCESS_ONCE(worker->flags) = worker_flags;
94535 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
94536 }
94537
94538 spin_unlock_irq(&pool->lock);
94539 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
94540 index a285900..5e3b26b 100644
94541 --- a/lib/Kconfig.debug
94542 +++ b/lib/Kconfig.debug
94543 @@ -882,7 +882,7 @@ config DEBUG_MUTEXES
94544
94545 config DEBUG_WW_MUTEX_SLOWPATH
94546 bool "Wait/wound mutex debugging: Slowpath testing"
94547 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94548 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94549 select DEBUG_LOCK_ALLOC
94550 select DEBUG_SPINLOCK
94551 select DEBUG_MUTEXES
94552 @@ -899,7 +899,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
94553
94554 config DEBUG_LOCK_ALLOC
94555 bool "Lock debugging: detect incorrect freeing of live locks"
94556 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94557 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94558 select DEBUG_SPINLOCK
94559 select DEBUG_MUTEXES
94560 select LOCKDEP
94561 @@ -913,7 +913,7 @@ config DEBUG_LOCK_ALLOC
94562
94563 config PROVE_LOCKING
94564 bool "Lock debugging: prove locking correctness"
94565 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94566 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94567 select LOCKDEP
94568 select DEBUG_SPINLOCK
94569 select DEBUG_MUTEXES
94570 @@ -964,7 +964,7 @@ config LOCKDEP
94571
94572 config LOCK_STAT
94573 bool "Lock usage statistics"
94574 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94575 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94576 select LOCKDEP
94577 select DEBUG_SPINLOCK
94578 select DEBUG_MUTEXES
94579 @@ -1437,6 +1437,7 @@ config LATENCYTOP
94580 depends on DEBUG_KERNEL
94581 depends on STACKTRACE_SUPPORT
94582 depends on PROC_FS
94583 + depends on !GRKERNSEC_HIDESYM
94584 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
94585 select KALLSYMS
94586 select KALLSYMS_ALL
94587 @@ -1453,7 +1454,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
94588 config DEBUG_STRICT_USER_COPY_CHECKS
94589 bool "Strict user copy size checks"
94590 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
94591 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
94592 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
94593 help
94594 Enabling this option turns a certain set of sanity checks for user
94595 copy operations into compile time failures.
94596 @@ -1581,7 +1582,7 @@ endmenu # runtime tests
94597
94598 config PROVIDE_OHCI1394_DMA_INIT
94599 bool "Remote debugging over FireWire early on boot"
94600 - depends on PCI && X86
94601 + depends on PCI && X86 && !GRKERNSEC
94602 help
94603 If you want to debug problems which hang or crash the kernel early
94604 on boot and the crashing machine has a FireWire port, you can use
94605 diff --git a/lib/Makefile b/lib/Makefile
94606 index d6b4bc4..a3724eb 100644
94607 --- a/lib/Makefile
94608 +++ b/lib/Makefile
94609 @@ -55,7 +55,7 @@ obj-$(CONFIG_BTREE) += btree.o
94610 obj-$(CONFIG_INTERVAL_TREE) += interval_tree.o
94611 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
94612 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
94613 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
94614 +obj-y += list_debug.o
94615 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
94616
94617 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
94618 diff --git a/lib/average.c b/lib/average.c
94619 index 114d1be..ab0350c 100644
94620 --- a/lib/average.c
94621 +++ b/lib/average.c
94622 @@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
94623 {
94624 unsigned long internal = ACCESS_ONCE(avg->internal);
94625
94626 - ACCESS_ONCE(avg->internal) = internal ?
94627 + ACCESS_ONCE_RW(avg->internal) = internal ?
94628 (((internal << avg->weight) - internal) +
94629 (val << avg->factor)) >> avg->weight :
94630 (val << avg->factor);
94631 diff --git a/lib/bitmap.c b/lib/bitmap.c
94632 index 33ce011..89e3d6f 100644
94633 --- a/lib/bitmap.c
94634 +++ b/lib/bitmap.c
94635 @@ -433,7 +433,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
94636 {
94637 int c, old_c, totaldigits, ndigits, nchunks, nbits;
94638 u32 chunk;
94639 - const char __user __force *ubuf = (const char __user __force *)buf;
94640 + const char __user *ubuf = (const char __force_user *)buf;
94641
94642 bitmap_zero(maskp, nmaskbits);
94643
94644 @@ -518,7 +518,7 @@ int bitmap_parse_user(const char __user *ubuf,
94645 {
94646 if (!access_ok(VERIFY_READ, ubuf, ulen))
94647 return -EFAULT;
94648 - return __bitmap_parse((const char __force *)ubuf,
94649 + return __bitmap_parse((const char __force_kernel *)ubuf,
94650 ulen, 1, maskp, nmaskbits);
94651
94652 }
94653 @@ -609,7 +609,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
94654 {
94655 unsigned a, b;
94656 int c, old_c, totaldigits;
94657 - const char __user __force *ubuf = (const char __user __force *)buf;
94658 + const char __user *ubuf = (const char __force_user *)buf;
94659 int exp_digit, in_range;
94660
94661 totaldigits = c = 0;
94662 @@ -704,7 +704,7 @@ int bitmap_parselist_user(const char __user *ubuf,
94663 {
94664 if (!access_ok(VERIFY_READ, ubuf, ulen))
94665 return -EFAULT;
94666 - return __bitmap_parselist((const char __force *)ubuf,
94667 + return __bitmap_parselist((const char __force_kernel *)ubuf,
94668 ulen, 1, maskp, nmaskbits);
94669 }
94670 EXPORT_SYMBOL(bitmap_parselist_user);
94671 diff --git a/lib/bug.c b/lib/bug.c
94672 index d1d7c78..b354235 100644
94673 --- a/lib/bug.c
94674 +++ b/lib/bug.c
94675 @@ -137,6 +137,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
94676 return BUG_TRAP_TYPE_NONE;
94677
94678 bug = find_bug(bugaddr);
94679 + if (!bug)
94680 + return BUG_TRAP_TYPE_NONE;
94681
94682 file = NULL;
94683 line = 0;
94684 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
94685 index 547f7f9..a6d4ba0 100644
94686 --- a/lib/debugobjects.c
94687 +++ b/lib/debugobjects.c
94688 @@ -289,7 +289,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
94689 if (limit > 4)
94690 return;
94691
94692 - is_on_stack = object_is_on_stack(addr);
94693 + is_on_stack = object_starts_on_stack(addr);
94694 if (is_on_stack == onstack)
94695 return;
94696
94697 diff --git a/lib/div64.c b/lib/div64.c
94698 index 4382ad7..08aa558 100644
94699 --- a/lib/div64.c
94700 +++ b/lib/div64.c
94701 @@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
94702 EXPORT_SYMBOL(__div64_32);
94703
94704 #ifndef div_s64_rem
94705 -s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
94706 +s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
94707 {
94708 u64 quotient;
94709
94710 @@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
94711 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
94712 */
94713 #ifndef div64_u64
94714 -u64 div64_u64(u64 dividend, u64 divisor)
94715 +u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
94716 {
94717 u32 high = divisor >> 32;
94718 u64 quot;
94719 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
94720 index 98f2d7e..899da5c 100644
94721 --- a/lib/dma-debug.c
94722 +++ b/lib/dma-debug.c
94723 @@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
94724
94725 void dma_debug_add_bus(struct bus_type *bus)
94726 {
94727 - struct notifier_block *nb;
94728 + notifier_block_no_const *nb;
94729
94730 if (global_disable)
94731 return;
94732 @@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
94733
94734 static void check_for_stack(struct device *dev, void *addr)
94735 {
94736 - if (object_is_on_stack(addr))
94737 + if (object_starts_on_stack(addr))
94738 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
94739 "stack [addr=%p]\n", addr);
94740 }
94741 diff --git a/lib/hash.c b/lib/hash.c
94742 index fea973f..386626f 100644
94743 --- a/lib/hash.c
94744 +++ b/lib/hash.c
94745 @@ -14,7 +14,7 @@
94746 #include <linux/hash.h>
94747 #include <linux/cache.h>
94748
94749 -static struct fast_hash_ops arch_hash_ops __read_mostly = {
94750 +static struct fast_hash_ops arch_hash_ops __read_only = {
94751 .hash = jhash,
94752 .hash2 = jhash2,
94753 };
94754 diff --git a/lib/inflate.c b/lib/inflate.c
94755 index 013a761..c28f3fc 100644
94756 --- a/lib/inflate.c
94757 +++ b/lib/inflate.c
94758 @@ -269,7 +269,7 @@ static void free(void *where)
94759 malloc_ptr = free_mem_ptr;
94760 }
94761 #else
94762 -#define malloc(a) kmalloc(a, GFP_KERNEL)
94763 +#define malloc(a) kmalloc((a), GFP_KERNEL)
94764 #define free(a) kfree(a)
94765 #endif
94766
94767 diff --git a/lib/ioremap.c b/lib/ioremap.c
94768 index 0c9216c..863bd89 100644
94769 --- a/lib/ioremap.c
94770 +++ b/lib/ioremap.c
94771 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
94772 unsigned long next;
94773
94774 phys_addr -= addr;
94775 - pmd = pmd_alloc(&init_mm, pud, addr);
94776 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
94777 if (!pmd)
94778 return -ENOMEM;
94779 do {
94780 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
94781 unsigned long next;
94782
94783 phys_addr -= addr;
94784 - pud = pud_alloc(&init_mm, pgd, addr);
94785 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
94786 if (!pud)
94787 return -ENOMEM;
94788 do {
94789 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
94790 index bd2bea9..6b3c95e 100644
94791 --- a/lib/is_single_threaded.c
94792 +++ b/lib/is_single_threaded.c
94793 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
94794 struct task_struct *p, *t;
94795 bool ret;
94796
94797 + if (!mm)
94798 + return true;
94799 +
94800 if (atomic_read(&task->signal->live) != 1)
94801 return false;
94802
94803 diff --git a/lib/kobject.c b/lib/kobject.c
94804 index 58751bb..93a1853 100644
94805 --- a/lib/kobject.c
94806 +++ b/lib/kobject.c
94807 @@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
94808
94809
94810 static DEFINE_SPINLOCK(kobj_ns_type_lock);
94811 -static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
94812 +static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
94813
94814 -int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
94815 +int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
94816 {
94817 enum kobj_ns_type type = ops->type;
94818 int error;
94819 diff --git a/lib/list_debug.c b/lib/list_debug.c
94820 index c24c2f7..f0296f4 100644
94821 --- a/lib/list_debug.c
94822 +++ b/lib/list_debug.c
94823 @@ -11,7 +11,9 @@
94824 #include <linux/bug.h>
94825 #include <linux/kernel.h>
94826 #include <linux/rculist.h>
94827 +#include <linux/mm.h>
94828
94829 +#ifdef CONFIG_DEBUG_LIST
94830 /*
94831 * Insert a new entry between two known consecutive entries.
94832 *
94833 @@ -19,21 +21,40 @@
94834 * the prev/next entries already!
94835 */
94836
94837 +static bool __list_add_debug(struct list_head *new,
94838 + struct list_head *prev,
94839 + struct list_head *next)
94840 +{
94841 + if (unlikely(next->prev != prev)) {
94842 + printk(KERN_ERR "list_add corruption. next->prev should be "
94843 + "prev (%p), but was %p. (next=%p).\n",
94844 + prev, next->prev, next);
94845 + BUG();
94846 + return false;
94847 + }
94848 + if (unlikely(prev->next != next)) {
94849 + printk(KERN_ERR "list_add corruption. prev->next should be "
94850 + "next (%p), but was %p. (prev=%p).\n",
94851 + next, prev->next, prev);
94852 + BUG();
94853 + return false;
94854 + }
94855 + if (unlikely(new == prev || new == next)) {
94856 + printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
94857 + new, prev, next);
94858 + BUG();
94859 + return false;
94860 + }
94861 + return true;
94862 +}
94863 +
94864 void __list_add(struct list_head *new,
94865 - struct list_head *prev,
94866 - struct list_head *next)
94867 + struct list_head *prev,
94868 + struct list_head *next)
94869 {
94870 - WARN(next->prev != prev,
94871 - "list_add corruption. next->prev should be "
94872 - "prev (%p), but was %p. (next=%p).\n",
94873 - prev, next->prev, next);
94874 - WARN(prev->next != next,
94875 - "list_add corruption. prev->next should be "
94876 - "next (%p), but was %p. (prev=%p).\n",
94877 - next, prev->next, prev);
94878 - WARN(new == prev || new == next,
94879 - "list_add double add: new=%p, prev=%p, next=%p.\n",
94880 - new, prev, next);
94881 + if (!__list_add_debug(new, prev, next))
94882 + return;
94883 +
94884 next->prev = new;
94885 new->next = next;
94886 new->prev = prev;
94887 @@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
94888 }
94889 EXPORT_SYMBOL(__list_add);
94890
94891 -void __list_del_entry(struct list_head *entry)
94892 +static bool __list_del_entry_debug(struct list_head *entry)
94893 {
94894 struct list_head *prev, *next;
94895
94896 prev = entry->prev;
94897 next = entry->next;
94898
94899 - if (WARN(next == LIST_POISON1,
94900 - "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
94901 - entry, LIST_POISON1) ||
94902 - WARN(prev == LIST_POISON2,
94903 - "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
94904 - entry, LIST_POISON2) ||
94905 - WARN(prev->next != entry,
94906 - "list_del corruption. prev->next should be %p, "
94907 - "but was %p\n", entry, prev->next) ||
94908 - WARN(next->prev != entry,
94909 - "list_del corruption. next->prev should be %p, "
94910 - "but was %p\n", entry, next->prev))
94911 + if (unlikely(next == LIST_POISON1)) {
94912 + printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
94913 + entry, LIST_POISON1);
94914 + BUG();
94915 + return false;
94916 + }
94917 + if (unlikely(prev == LIST_POISON2)) {
94918 + printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
94919 + entry, LIST_POISON2);
94920 + BUG();
94921 + return false;
94922 + }
94923 + if (unlikely(entry->prev->next != entry)) {
94924 + printk(KERN_ERR "list_del corruption. prev->next should be %p, "
94925 + "but was %p\n", entry, prev->next);
94926 + BUG();
94927 + return false;
94928 + }
94929 + if (unlikely(entry->next->prev != entry)) {
94930 + printk(KERN_ERR "list_del corruption. next->prev should be %p, "
94931 + "but was %p\n", entry, next->prev);
94932 + BUG();
94933 + return false;
94934 + }
94935 + return true;
94936 +}
94937 +
94938 +void __list_del_entry(struct list_head *entry)
94939 +{
94940 + if (!__list_del_entry_debug(entry))
94941 return;
94942
94943 - __list_del(prev, next);
94944 + __list_del(entry->prev, entry->next);
94945 }
94946 EXPORT_SYMBOL(__list_del_entry);
94947
94948 @@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
94949 void __list_add_rcu(struct list_head *new,
94950 struct list_head *prev, struct list_head *next)
94951 {
94952 - WARN(next->prev != prev,
94953 - "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
94954 - prev, next->prev, next);
94955 - WARN(prev->next != next,
94956 - "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
94957 - next, prev->next, prev);
94958 + if (!__list_add_debug(new, prev, next))
94959 + return;
94960 +
94961 new->next = next;
94962 new->prev = prev;
94963 rcu_assign_pointer(list_next_rcu(prev), new);
94964 next->prev = new;
94965 }
94966 EXPORT_SYMBOL(__list_add_rcu);
94967 +#endif
94968 +
94969 +void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
94970 +{
94971 +#ifdef CONFIG_DEBUG_LIST
94972 + if (!__list_add_debug(new, prev, next))
94973 + return;
94974 +#endif
94975 +
94976 + pax_open_kernel();
94977 + next->prev = new;
94978 + new->next = next;
94979 + new->prev = prev;
94980 + prev->next = new;
94981 + pax_close_kernel();
94982 +}
94983 +EXPORT_SYMBOL(__pax_list_add);
94984 +
94985 +void pax_list_del(struct list_head *entry)
94986 +{
94987 +#ifdef CONFIG_DEBUG_LIST
94988 + if (!__list_del_entry_debug(entry))
94989 + return;
94990 +#endif
94991 +
94992 + pax_open_kernel();
94993 + __list_del(entry->prev, entry->next);
94994 + entry->next = LIST_POISON1;
94995 + entry->prev = LIST_POISON2;
94996 + pax_close_kernel();
94997 +}
94998 +EXPORT_SYMBOL(pax_list_del);
94999 +
95000 +void pax_list_del_init(struct list_head *entry)
95001 +{
95002 + pax_open_kernel();
95003 + __list_del(entry->prev, entry->next);
95004 + INIT_LIST_HEAD(entry);
95005 + pax_close_kernel();
95006 +}
95007 +EXPORT_SYMBOL(pax_list_del_init);
95008 +
95009 +void __pax_list_add_rcu(struct list_head *new,
95010 + struct list_head *prev, struct list_head *next)
95011 +{
95012 +#ifdef CONFIG_DEBUG_LIST
95013 + if (!__list_add_debug(new, prev, next))
95014 + return;
95015 +#endif
95016 +
95017 + pax_open_kernel();
95018 + new->next = next;
95019 + new->prev = prev;
95020 + rcu_assign_pointer(list_next_rcu(prev), new);
95021 + next->prev = new;
95022 + pax_close_kernel();
95023 +}
95024 +EXPORT_SYMBOL(__pax_list_add_rcu);
95025 +
95026 +void pax_list_del_rcu(struct list_head *entry)
95027 +{
95028 +#ifdef CONFIG_DEBUG_LIST
95029 + if (!__list_del_entry_debug(entry))
95030 + return;
95031 +#endif
95032 +
95033 + pax_open_kernel();
95034 + __list_del(entry->prev, entry->next);
95035 + entry->next = LIST_POISON1;
95036 + entry->prev = LIST_POISON2;
95037 + pax_close_kernel();
95038 +}
95039 +EXPORT_SYMBOL(pax_list_del_rcu);
95040 diff --git a/lib/lockref.c b/lib/lockref.c
95041 index d2233de..fa1a2f6 100644
95042 --- a/lib/lockref.c
95043 +++ b/lib/lockref.c
95044 @@ -48,13 +48,13 @@
95045 void lockref_get(struct lockref *lockref)
95046 {
95047 CMPXCHG_LOOP(
95048 - new.count++;
95049 + __lockref_inc(&new);
95050 ,
95051 return;
95052 );
95053
95054 spin_lock(&lockref->lock);
95055 - lockref->count++;
95056 + __lockref_inc(lockref);
95057 spin_unlock(&lockref->lock);
95058 }
95059 EXPORT_SYMBOL(lockref_get);
95060 @@ -69,7 +69,7 @@ int lockref_get_not_zero(struct lockref *lockref)
95061 int retval;
95062
95063 CMPXCHG_LOOP(
95064 - new.count++;
95065 + __lockref_inc(&new);
95066 if (!old.count)
95067 return 0;
95068 ,
95069 @@ -79,7 +79,7 @@ int lockref_get_not_zero(struct lockref *lockref)
95070 spin_lock(&lockref->lock);
95071 retval = 0;
95072 if (lockref->count) {
95073 - lockref->count++;
95074 + __lockref_inc(lockref);
95075 retval = 1;
95076 }
95077 spin_unlock(&lockref->lock);
95078 @@ -96,7 +96,7 @@ EXPORT_SYMBOL(lockref_get_not_zero);
95079 int lockref_get_or_lock(struct lockref *lockref)
95080 {
95081 CMPXCHG_LOOP(
95082 - new.count++;
95083 + __lockref_inc(&new);
95084 if (!old.count)
95085 break;
95086 ,
95087 @@ -106,7 +106,7 @@ int lockref_get_or_lock(struct lockref *lockref)
95088 spin_lock(&lockref->lock);
95089 if (!lockref->count)
95090 return 0;
95091 - lockref->count++;
95092 + __lockref_inc(lockref);
95093 spin_unlock(&lockref->lock);
95094 return 1;
95095 }
95096 @@ -120,7 +120,7 @@ EXPORT_SYMBOL(lockref_get_or_lock);
95097 int lockref_put_or_lock(struct lockref *lockref)
95098 {
95099 CMPXCHG_LOOP(
95100 - new.count--;
95101 + __lockref_dec(&new);
95102 if (old.count <= 1)
95103 break;
95104 ,
95105 @@ -130,7 +130,7 @@ int lockref_put_or_lock(struct lockref *lockref)
95106 spin_lock(&lockref->lock);
95107 if (lockref->count <= 1)
95108 return 0;
95109 - lockref->count--;
95110 + __lockref_dec(lockref);
95111 spin_unlock(&lockref->lock);
95112 return 1;
95113 }
95114 @@ -157,7 +157,7 @@ int lockref_get_not_dead(struct lockref *lockref)
95115 int retval;
95116
95117 CMPXCHG_LOOP(
95118 - new.count++;
95119 + __lockref_inc(&new);
95120 if ((int)old.count < 0)
95121 return 0;
95122 ,
95123 @@ -167,7 +167,7 @@ int lockref_get_not_dead(struct lockref *lockref)
95124 spin_lock(&lockref->lock);
95125 retval = 0;
95126 if ((int) lockref->count >= 0) {
95127 - lockref->count++;
95128 + __lockref_inc(lockref);
95129 retval = 1;
95130 }
95131 spin_unlock(&lockref->lock);
95132 diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
95133 index a89cf09..1a42c2d 100644
95134 --- a/lib/percpu-refcount.c
95135 +++ b/lib/percpu-refcount.c
95136 @@ -29,7 +29,7 @@
95137 * can't hit 0 before we've added up all the percpu refs.
95138 */
95139
95140 -#define PCPU_COUNT_BIAS (1U << 31)
95141 +#define PCPU_COUNT_BIAS (1U << 30)
95142
95143 static unsigned __percpu *pcpu_count_ptr(struct percpu_ref *ref)
95144 {
95145 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
95146 index 3291a8e..346a91e 100644
95147 --- a/lib/radix-tree.c
95148 +++ b/lib/radix-tree.c
95149 @@ -67,7 +67,7 @@ struct radix_tree_preload {
95150 int nr;
95151 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
95152 };
95153 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
95154 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
95155
95156 static inline void *ptr_to_indirect(void *ptr)
95157 {
95158 diff --git a/lib/random32.c b/lib/random32.c
95159 index c9b6bf3..4752c6d4 100644
95160 --- a/lib/random32.c
95161 +++ b/lib/random32.c
95162 @@ -46,7 +46,7 @@ static inline void prandom_state_selftest(void)
95163 }
95164 #endif
95165
95166 -static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
95167 +static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
95168
95169 /**
95170 * prandom_u32_state - seeded pseudo-random number generator.
95171 diff --git a/lib/rbtree.c b/lib/rbtree.c
95172 index c16c81a..4dcbda1 100644
95173 --- a/lib/rbtree.c
95174 +++ b/lib/rbtree.c
95175 @@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
95176 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
95177
95178 static const struct rb_augment_callbacks dummy_callbacks = {
95179 - dummy_propagate, dummy_copy, dummy_rotate
95180 + .propagate = dummy_propagate,
95181 + .copy = dummy_copy,
95182 + .rotate = dummy_rotate
95183 };
95184
95185 void rb_insert_color(struct rb_node *node, struct rb_root *root)
95186 diff --git a/lib/show_mem.c b/lib/show_mem.c
95187 index 0922579..9d7adb9 100644
95188 --- a/lib/show_mem.c
95189 +++ b/lib/show_mem.c
95190 @@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
95191 quicklist_total_size());
95192 #endif
95193 #ifdef CONFIG_MEMORY_FAILURE
95194 - printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
95195 + printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
95196 #endif
95197 }
95198 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
95199 index bb2b201..46abaf9 100644
95200 --- a/lib/strncpy_from_user.c
95201 +++ b/lib/strncpy_from_user.c
95202 @@ -21,7 +21,7 @@
95203 */
95204 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
95205 {
95206 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95207 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95208 long res = 0;
95209
95210 /*
95211 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
95212 index a28df52..3d55877 100644
95213 --- a/lib/strnlen_user.c
95214 +++ b/lib/strnlen_user.c
95215 @@ -26,7 +26,7 @@
95216 */
95217 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
95218 {
95219 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95220 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95221 long align, res = 0;
95222 unsigned long c;
95223
95224 diff --git a/lib/swiotlb.c b/lib/swiotlb.c
95225 index 4abda07..b9d3765 100644
95226 --- a/lib/swiotlb.c
95227 +++ b/lib/swiotlb.c
95228 @@ -682,7 +682,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
95229
95230 void
95231 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
95232 - dma_addr_t dev_addr)
95233 + dma_addr_t dev_addr, struct dma_attrs *attrs)
95234 {
95235 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
95236
95237 diff --git a/lib/test_bpf.c b/lib/test_bpf.c
95238 index 89e0345..3347efe 100644
95239 --- a/lib/test_bpf.c
95240 +++ b/lib/test_bpf.c
95241 @@ -1798,7 +1798,7 @@ static struct bpf_prog *generate_filter(int which, int *err)
95242 break;
95243
95244 case INTERNAL:
95245 - fp = kzalloc(bpf_prog_size(flen), GFP_KERNEL);
95246 + fp = bpf_prog_alloc(bpf_prog_size(flen), 0);
95247 if (fp == NULL) {
95248 pr_cont("UNEXPECTED_FAIL no memory left\n");
95249 *err = -ENOMEM;
95250 diff --git a/lib/usercopy.c b/lib/usercopy.c
95251 index 4f5b1dd..7cab418 100644
95252 --- a/lib/usercopy.c
95253 +++ b/lib/usercopy.c
95254 @@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
95255 WARN(1, "Buffer overflow detected!\n");
95256 }
95257 EXPORT_SYMBOL(copy_from_user_overflow);
95258 +
95259 +void copy_to_user_overflow(void)
95260 +{
95261 + WARN(1, "Buffer overflow detected!\n");
95262 +}
95263 +EXPORT_SYMBOL(copy_to_user_overflow);
95264 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
95265 index 6fe2c84..2fe5ec6 100644
95266 --- a/lib/vsprintf.c
95267 +++ b/lib/vsprintf.c
95268 @@ -16,6 +16,9 @@
95269 * - scnprintf and vscnprintf
95270 */
95271
95272 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95273 +#define __INCLUDED_BY_HIDESYM 1
95274 +#endif
95275 #include <stdarg.h>
95276 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
95277 #include <linux/types.h>
95278 @@ -624,7 +627,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
95279 #ifdef CONFIG_KALLSYMS
95280 if (*fmt == 'B')
95281 sprint_backtrace(sym, value);
95282 - else if (*fmt != 'f' && *fmt != 's')
95283 + else if (*fmt != 'f' && *fmt != 's' && *fmt != 'X')
95284 sprint_symbol(sym, value);
95285 else
95286 sprint_symbol_no_offset(sym, value);
95287 @@ -1183,7 +1186,11 @@ char *address_val(char *buf, char *end, const void *addr,
95288 return number(buf, end, num, spec);
95289 }
95290
95291 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95292 +int kptr_restrict __read_mostly = 2;
95293 +#else
95294 int kptr_restrict __read_mostly;
95295 +#endif
95296
95297 /*
95298 * Show a '%p' thing. A kernel extension is that the '%p' is followed
95299 @@ -1194,8 +1201,10 @@ int kptr_restrict __read_mostly;
95300 *
95301 * - 'F' For symbolic function descriptor pointers with offset
95302 * - 'f' For simple symbolic function names without offset
95303 + * - 'X' For simple symbolic function names without offset approved for use with GRKERNSEC_HIDESYM
95304 * - 'S' For symbolic direct pointers with offset
95305 * - 's' For symbolic direct pointers without offset
95306 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
95307 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
95308 * - 'B' For backtraced symbolic direct pointers with offset
95309 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
95310 @@ -1263,12 +1272,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95311
95312 if (!ptr && *fmt != 'K') {
95313 /*
95314 - * Print (null) with the same width as a pointer so it makes
95315 + * Print (nil) with the same width as a pointer so it makes
95316 * tabular output look nice.
95317 */
95318 if (spec.field_width == -1)
95319 spec.field_width = default_width;
95320 - return string(buf, end, "(null)", spec);
95321 + return string(buf, end, "(nil)", spec);
95322 }
95323
95324 switch (*fmt) {
95325 @@ -1278,6 +1287,14 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95326 /* Fallthrough */
95327 case 'S':
95328 case 's':
95329 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95330 + break;
95331 +#else
95332 + return symbol_string(buf, end, ptr, spec, fmt);
95333 +#endif
95334 + case 'X':
95335 + ptr = dereference_function_descriptor(ptr);
95336 + case 'A':
95337 case 'B':
95338 return symbol_string(buf, end, ptr, spec, fmt);
95339 case 'R':
95340 @@ -1333,6 +1350,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95341 va_end(va);
95342 return buf;
95343 }
95344 + case 'P':
95345 + break;
95346 case 'K':
95347 /*
95348 * %pK cannot be used in IRQ context because its test
95349 @@ -1390,6 +1409,22 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95350 ((const struct file *)ptr)->f_path.dentry,
95351 spec, fmt);
95352 }
95353 +
95354 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95355 + /* 'P' = approved pointers to copy to userland,
95356 + as in the /proc/kallsyms case, as we make it display nothing
95357 + for non-root users, and the real contents for root users
95358 + 'X' = approved simple symbols
95359 + Also ignore 'K' pointers, since we force their NULLing for non-root users
95360 + above
95361 + */
95362 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'X' && *fmt != 'K' && is_usercopy_object(buf)) {
95363 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
95364 + dump_stack();
95365 + ptr = NULL;
95366 + }
95367 +#endif
95368 +
95369 spec.flags |= SMALL;
95370 if (spec.field_width == -1) {
95371 spec.field_width = default_width;
95372 @@ -2089,11 +2124,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
95373 typeof(type) value; \
95374 if (sizeof(type) == 8) { \
95375 args = PTR_ALIGN(args, sizeof(u32)); \
95376 - *(u32 *)&value = *(u32 *)args; \
95377 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
95378 + *(u32 *)&value = *(const u32 *)args; \
95379 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
95380 } else { \
95381 args = PTR_ALIGN(args, sizeof(type)); \
95382 - value = *(typeof(type) *)args; \
95383 + value = *(const typeof(type) *)args; \
95384 } \
95385 args += sizeof(type); \
95386 value; \
95387 @@ -2156,7 +2191,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
95388 case FORMAT_TYPE_STR: {
95389 const char *str_arg = args;
95390 args += strlen(str_arg) + 1;
95391 - str = string(str, end, (char *)str_arg, spec);
95392 + str = string(str, end, str_arg, spec);
95393 break;
95394 }
95395
95396 diff --git a/localversion-grsec b/localversion-grsec
95397 new file mode 100644
95398 index 0000000..7cd6065
95399 --- /dev/null
95400 +++ b/localversion-grsec
95401 @@ -0,0 +1 @@
95402 +-grsec
95403 diff --git a/mm/Kconfig b/mm/Kconfig
95404 index 886db21..f514de2 100644
95405 --- a/mm/Kconfig
95406 +++ b/mm/Kconfig
95407 @@ -333,10 +333,11 @@ config KSM
95408 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
95409
95410 config DEFAULT_MMAP_MIN_ADDR
95411 - int "Low address space to protect from user allocation"
95412 + int "Low address space to protect from user allocation"
95413 depends on MMU
95414 - default 4096
95415 - help
95416 + default 32768 if ALPHA || ARM || PARISC || SPARC32
95417 + default 65536
95418 + help
95419 This is the portion of low virtual memory which should be protected
95420 from userspace allocation. Keeping a user from writing to low pages
95421 can help reduce the impact of kernel NULL pointer bugs.
95422 @@ -367,7 +368,7 @@ config MEMORY_FAILURE
95423
95424 config HWPOISON_INJECT
95425 tristate "HWPoison pages injector"
95426 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
95427 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
95428 select PROC_PAGE_MONITOR
95429
95430 config NOMMU_INITIAL_TRIM_EXCESS
95431 diff --git a/mm/backing-dev.c b/mm/backing-dev.c
95432 index 1706cbb..f89dbca 100644
95433 --- a/mm/backing-dev.c
95434 +++ b/mm/backing-dev.c
95435 @@ -12,7 +12,7 @@
95436 #include <linux/device.h>
95437 #include <trace/events/writeback.h>
95438
95439 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
95440 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
95441
95442 struct backing_dev_info default_backing_dev_info = {
95443 .name = "default",
95444 @@ -533,7 +533,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
95445 return err;
95446
95447 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
95448 - atomic_long_inc_return(&bdi_seq));
95449 + atomic_long_inc_return_unchecked(&bdi_seq));
95450 if (err) {
95451 bdi_destroy(bdi);
95452 return err;
95453 diff --git a/mm/filemap.c b/mm/filemap.c
95454 index 90effcd..539aa64 100644
95455 --- a/mm/filemap.c
95456 +++ b/mm/filemap.c
95457 @@ -2092,7 +2092,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
95458 struct address_space *mapping = file->f_mapping;
95459
95460 if (!mapping->a_ops->readpage)
95461 - return -ENOEXEC;
95462 + return -ENODEV;
95463 file_accessed(file);
95464 vma->vm_ops = &generic_file_vm_ops;
95465 return 0;
95466 @@ -2270,6 +2270,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
95467 *pos = i_size_read(inode);
95468
95469 if (limit != RLIM_INFINITY) {
95470 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
95471 if (*pos >= limit) {
95472 send_sig(SIGXFSZ, current, 0);
95473 return -EFBIG;
95474 diff --git a/mm/fremap.c b/mm/fremap.c
95475 index 72b8fa3..c5b39f1 100644
95476 --- a/mm/fremap.c
95477 +++ b/mm/fremap.c
95478 @@ -180,6 +180,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
95479 retry:
95480 vma = find_vma(mm, start);
95481
95482 +#ifdef CONFIG_PAX_SEGMEXEC
95483 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
95484 + goto out;
95485 +#endif
95486 +
95487 /*
95488 * Make sure the vma is shared, that it supports prefaulting,
95489 * and that the remapped range is valid and fully within
95490 diff --git a/mm/gup.c b/mm/gup.c
95491 index 91d044b..a58ecf6 100644
95492 --- a/mm/gup.c
95493 +++ b/mm/gup.c
95494 @@ -270,11 +270,6 @@ static int faultin_page(struct task_struct *tsk, struct vm_area_struct *vma,
95495 unsigned int fault_flags = 0;
95496 int ret;
95497
95498 - /* For mlock, just skip the stack guard page. */
95499 - if ((*flags & FOLL_MLOCK) &&
95500 - (stack_guard_page_start(vma, address) ||
95501 - stack_guard_page_end(vma, address + PAGE_SIZE)))
95502 - return -ENOENT;
95503 if (*flags & FOLL_WRITE)
95504 fault_flags |= FAULT_FLAG_WRITE;
95505 if (nonblocking)
95506 @@ -436,14 +431,14 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
95507 if (!(gup_flags & FOLL_FORCE))
95508 gup_flags |= FOLL_NUMA;
95509
95510 - do {
95511 + while (nr_pages) {
95512 struct page *page;
95513 unsigned int foll_flags = gup_flags;
95514 unsigned int page_increm;
95515
95516 /* first iteration or cross vma bound */
95517 if (!vma || start >= vma->vm_end) {
95518 - vma = find_extend_vma(mm, start);
95519 + vma = find_vma(mm, start);
95520 if (!vma && in_gate_area(mm, start)) {
95521 int ret;
95522 ret = get_gate_page(mm, start & PAGE_MASK,
95523 @@ -455,7 +450,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
95524 goto next_page;
95525 }
95526
95527 - if (!vma || check_vma_flags(vma, gup_flags))
95528 + if (!vma || start < vma->vm_start || check_vma_flags(vma, gup_flags))
95529 return i ? : -EFAULT;
95530 if (is_vm_hugetlb_page(vma)) {
95531 i = follow_hugetlb_page(mm, vma, pages, vmas,
95532 @@ -510,7 +505,7 @@ next_page:
95533 i += page_increm;
95534 start += page_increm * PAGE_SIZE;
95535 nr_pages -= page_increm;
95536 - } while (nr_pages);
95537 + }
95538 return i;
95539 }
95540 EXPORT_SYMBOL(__get_user_pages);
95541 diff --git a/mm/highmem.c b/mm/highmem.c
95542 index 123bcd3..0de52ba 100644
95543 --- a/mm/highmem.c
95544 +++ b/mm/highmem.c
95545 @@ -195,8 +195,9 @@ static void flush_all_zero_pkmaps(void)
95546 * So no dangers, even with speculative execution.
95547 */
95548 page = pte_page(pkmap_page_table[i]);
95549 + pax_open_kernel();
95550 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
95551 -
95552 + pax_close_kernel();
95553 set_page_address(page, NULL);
95554 need_flush = 1;
95555 }
95556 @@ -259,9 +260,11 @@ start:
95557 }
95558 }
95559 vaddr = PKMAP_ADDR(last_pkmap_nr);
95560 +
95561 + pax_open_kernel();
95562 set_pte_at(&init_mm, vaddr,
95563 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
95564 -
95565 + pax_close_kernel();
95566 pkmap_count[last_pkmap_nr] = 1;
95567 set_page_address(page, (void *)vaddr);
95568
95569 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
95570 index eeceeeb..a209d58 100644
95571 --- a/mm/hugetlb.c
95572 +++ b/mm/hugetlb.c
95573 @@ -2258,6 +2258,7 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
95574 struct ctl_table *table, int write,
95575 void __user *buffer, size_t *length, loff_t *ppos)
95576 {
95577 + ctl_table_no_const t;
95578 struct hstate *h = &default_hstate;
95579 unsigned long tmp = h->max_huge_pages;
95580 int ret;
95581 @@ -2265,9 +2266,10 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
95582 if (!hugepages_supported())
95583 return -ENOTSUPP;
95584
95585 - table->data = &tmp;
95586 - table->maxlen = sizeof(unsigned long);
95587 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
95588 + t = *table;
95589 + t.data = &tmp;
95590 + t.maxlen = sizeof(unsigned long);
95591 + ret = proc_doulongvec_minmax(&t, write, buffer, length, ppos);
95592 if (ret)
95593 goto out;
95594
95595 @@ -2302,6 +2304,7 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
95596 struct hstate *h = &default_hstate;
95597 unsigned long tmp;
95598 int ret;
95599 + ctl_table_no_const hugetlb_table;
95600
95601 if (!hugepages_supported())
95602 return -ENOTSUPP;
95603 @@ -2311,9 +2314,10 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
95604 if (write && hstate_is_gigantic(h))
95605 return -EINVAL;
95606
95607 - table->data = &tmp;
95608 - table->maxlen = sizeof(unsigned long);
95609 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
95610 + hugetlb_table = *table;
95611 + hugetlb_table.data = &tmp;
95612 + hugetlb_table.maxlen = sizeof(unsigned long);
95613 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
95614 if (ret)
95615 goto out;
95616
95617 @@ -2792,6 +2796,27 @@ static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
95618 mutex_unlock(&mapping->i_mmap_mutex);
95619 }
95620
95621 +#ifdef CONFIG_PAX_SEGMEXEC
95622 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
95623 +{
95624 + struct mm_struct *mm = vma->vm_mm;
95625 + struct vm_area_struct *vma_m;
95626 + unsigned long address_m;
95627 + pte_t *ptep_m;
95628 +
95629 + vma_m = pax_find_mirror_vma(vma);
95630 + if (!vma_m)
95631 + return;
95632 +
95633 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
95634 + address_m = address + SEGMEXEC_TASK_SIZE;
95635 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
95636 + get_page(page_m);
95637 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
95638 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
95639 +}
95640 +#endif
95641 +
95642 /*
95643 * Hugetlb_cow() should be called with page lock of the original hugepage held.
95644 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
95645 @@ -2903,6 +2928,11 @@ retry_avoidcopy:
95646 make_huge_pte(vma, new_page, 1));
95647 page_remove_rmap(old_page);
95648 hugepage_add_new_anon_rmap(new_page, vma, address);
95649 +
95650 +#ifdef CONFIG_PAX_SEGMEXEC
95651 + pax_mirror_huge_pte(vma, address, new_page);
95652 +#endif
95653 +
95654 /* Make the old page be freed below */
95655 new_page = old_page;
95656 }
95657 @@ -3063,6 +3093,10 @@ retry:
95658 && (vma->vm_flags & VM_SHARED)));
95659 set_huge_pte_at(mm, address, ptep, new_pte);
95660
95661 +#ifdef CONFIG_PAX_SEGMEXEC
95662 + pax_mirror_huge_pte(vma, address, page);
95663 +#endif
95664 +
95665 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
95666 /* Optimization, do the COW without a second fault */
95667 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
95668 @@ -3129,6 +3163,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
95669 struct hstate *h = hstate_vma(vma);
95670 struct address_space *mapping;
95671
95672 +#ifdef CONFIG_PAX_SEGMEXEC
95673 + struct vm_area_struct *vma_m;
95674 +#endif
95675 +
95676 address &= huge_page_mask(h);
95677
95678 ptep = huge_pte_offset(mm, address);
95679 @@ -3142,6 +3180,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
95680 VM_FAULT_SET_HINDEX(hstate_index(h));
95681 }
95682
95683 +#ifdef CONFIG_PAX_SEGMEXEC
95684 + vma_m = pax_find_mirror_vma(vma);
95685 + if (vma_m) {
95686 + unsigned long address_m;
95687 +
95688 + if (vma->vm_start > vma_m->vm_start) {
95689 + address_m = address;
95690 + address -= SEGMEXEC_TASK_SIZE;
95691 + vma = vma_m;
95692 + h = hstate_vma(vma);
95693 + } else
95694 + address_m = address + SEGMEXEC_TASK_SIZE;
95695 +
95696 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
95697 + return VM_FAULT_OOM;
95698 + address_m &= HPAGE_MASK;
95699 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
95700 + }
95701 +#endif
95702 +
95703 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
95704 if (!ptep)
95705 return VM_FAULT_OOM;
95706 diff --git a/mm/internal.h b/mm/internal.h
95707 index 5f2772f..4c3882c 100644
95708 --- a/mm/internal.h
95709 +++ b/mm/internal.h
95710 @@ -134,6 +134,7 @@ __find_buddy_index(unsigned long page_idx, unsigned int order)
95711
95712 extern int __isolate_free_page(struct page *page, unsigned int order);
95713 extern void __free_pages_bootmem(struct page *page, unsigned int order);
95714 +extern void free_compound_page(struct page *page);
95715 extern void prep_compound_page(struct page *page, unsigned long order);
95716 #ifdef CONFIG_MEMORY_FAILURE
95717 extern bool is_free_buddy_page(struct page *page);
95718 @@ -376,7 +377,7 @@ extern u32 hwpoison_filter_enable;
95719
95720 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
95721 unsigned long, unsigned long,
95722 - unsigned long, unsigned long);
95723 + unsigned long, unsigned long) __intentional_overflow(-1);
95724
95725 extern void set_pageblock_order(void);
95726 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
95727 diff --git a/mm/iov_iter.c b/mm/iov_iter.c
95728 index 141dcf7..7327fd3 100644
95729 --- a/mm/iov_iter.c
95730 +++ b/mm/iov_iter.c
95731 @@ -173,7 +173,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
95732
95733 while (bytes) {
95734 char __user *buf = iov->iov_base + base;
95735 - int copy = min(bytes, iov->iov_len - base);
95736 + size_t copy = min(bytes, iov->iov_len - base);
95737
95738 base = 0;
95739 left = __copy_from_user_inatomic(vaddr, buf, copy);
95740 @@ -201,7 +201,7 @@ static size_t copy_from_user_atomic_iovec(struct page *page,
95741
95742 kaddr = kmap_atomic(page);
95743 if (likely(i->nr_segs == 1)) {
95744 - int left;
95745 + size_t left;
95746 char __user *buf = i->iov->iov_base + i->iov_offset;
95747 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
95748 copied = bytes - left;
95749 @@ -231,7 +231,7 @@ static void advance_iovec(struct iov_iter *i, size_t bytes)
95750 * zero-length segments (without overruning the iovec).
95751 */
95752 while (bytes || unlikely(i->count && !iov->iov_len)) {
95753 - int copy;
95754 + size_t copy;
95755
95756 copy = min(bytes, iov->iov_len - base);
95757 BUG_ON(!i->count || i->count < copy);
95758 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
95759 index 3cda50c..032ba634 100644
95760 --- a/mm/kmemleak.c
95761 +++ b/mm/kmemleak.c
95762 @@ -364,7 +364,7 @@ static void print_unreferenced(struct seq_file *seq,
95763
95764 for (i = 0; i < object->trace_len; i++) {
95765 void *ptr = (void *)object->trace[i];
95766 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
95767 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
95768 }
95769 }
95770
95771 @@ -1905,7 +1905,7 @@ static int __init kmemleak_late_init(void)
95772 return -ENOMEM;
95773 }
95774
95775 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
95776 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
95777 &kmemleak_fops);
95778 if (!dentry)
95779 pr_warning("Failed to create the debugfs kmemleak file\n");
95780 diff --git a/mm/maccess.c b/mm/maccess.c
95781 index d53adf9..03a24bf 100644
95782 --- a/mm/maccess.c
95783 +++ b/mm/maccess.c
95784 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
95785 set_fs(KERNEL_DS);
95786 pagefault_disable();
95787 ret = __copy_from_user_inatomic(dst,
95788 - (__force const void __user *)src, size);
95789 + (const void __force_user *)src, size);
95790 pagefault_enable();
95791 set_fs(old_fs);
95792
95793 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
95794
95795 set_fs(KERNEL_DS);
95796 pagefault_disable();
95797 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
95798 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
95799 pagefault_enable();
95800 set_fs(old_fs);
95801
95802 diff --git a/mm/madvise.c b/mm/madvise.c
95803 index 0938b30..199abe8 100644
95804 --- a/mm/madvise.c
95805 +++ b/mm/madvise.c
95806 @@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
95807 pgoff_t pgoff;
95808 unsigned long new_flags = vma->vm_flags;
95809
95810 +#ifdef CONFIG_PAX_SEGMEXEC
95811 + struct vm_area_struct *vma_m;
95812 +#endif
95813 +
95814 switch (behavior) {
95815 case MADV_NORMAL:
95816 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
95817 @@ -126,6 +130,13 @@ success:
95818 /*
95819 * vm_flags is protected by the mmap_sem held in write mode.
95820 */
95821 +
95822 +#ifdef CONFIG_PAX_SEGMEXEC
95823 + vma_m = pax_find_mirror_vma(vma);
95824 + if (vma_m)
95825 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
95826 +#endif
95827 +
95828 vma->vm_flags = new_flags;
95829
95830 out:
95831 @@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
95832 struct vm_area_struct **prev,
95833 unsigned long start, unsigned long end)
95834 {
95835 +
95836 +#ifdef CONFIG_PAX_SEGMEXEC
95837 + struct vm_area_struct *vma_m;
95838 +#endif
95839 +
95840 *prev = vma;
95841 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
95842 return -EINVAL;
95843 @@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
95844 zap_page_range(vma, start, end - start, &details);
95845 } else
95846 zap_page_range(vma, start, end - start, NULL);
95847 +
95848 +#ifdef CONFIG_PAX_SEGMEXEC
95849 + vma_m = pax_find_mirror_vma(vma);
95850 + if (vma_m) {
95851 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
95852 + struct zap_details details = {
95853 + .nonlinear_vma = vma_m,
95854 + .last_index = ULONG_MAX,
95855 + };
95856 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
95857 + } else
95858 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
95859 + }
95860 +#endif
95861 +
95862 return 0;
95863 }
95864
95865 @@ -488,6 +519,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
95866 if (end < start)
95867 return error;
95868
95869 +#ifdef CONFIG_PAX_SEGMEXEC
95870 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
95871 + if (end > SEGMEXEC_TASK_SIZE)
95872 + return error;
95873 + } else
95874 +#endif
95875 +
95876 + if (end > TASK_SIZE)
95877 + return error;
95878 +
95879 error = 0;
95880 if (end == start)
95881 return error;
95882 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
95883 index 44c6bd2..60369dc3 100644
95884 --- a/mm/memory-failure.c
95885 +++ b/mm/memory-failure.c
95886 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
95887
95888 int sysctl_memory_failure_recovery __read_mostly = 1;
95889
95890 -atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
95891 +atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
95892
95893 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
95894
95895 @@ -198,7 +198,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
95896 pfn, t->comm, t->pid);
95897 si.si_signo = SIGBUS;
95898 si.si_errno = 0;
95899 - si.si_addr = (void *)addr;
95900 + si.si_addr = (void __user *)addr;
95901 #ifdef __ARCH_SI_TRAPNO
95902 si.si_trapno = trapno;
95903 #endif
95904 @@ -791,7 +791,7 @@ static struct page_state {
95905 unsigned long res;
95906 char *msg;
95907 int (*action)(struct page *p, unsigned long pfn);
95908 -} error_states[] = {
95909 +} __do_const error_states[] = {
95910 { reserved, reserved, "reserved kernel", me_kernel },
95911 /*
95912 * free pages are specially detected outside this table:
95913 @@ -1099,7 +1099,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
95914 nr_pages = 1 << compound_order(hpage);
95915 else /* normal page or thp */
95916 nr_pages = 1;
95917 - atomic_long_add(nr_pages, &num_poisoned_pages);
95918 + atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
95919
95920 /*
95921 * We need/can do nothing about count=0 pages.
95922 @@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
95923 if (PageHWPoison(hpage)) {
95924 if ((hwpoison_filter(p) && TestClearPageHWPoison(p))
95925 || (p != hpage && TestSetPageHWPoison(hpage))) {
95926 - atomic_long_sub(nr_pages, &num_poisoned_pages);
95927 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
95928 unlock_page(hpage);
95929 return 0;
95930 }
95931 @@ -1196,14 +1196,14 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
95932 */
95933 if (!PageHWPoison(p)) {
95934 printk(KERN_ERR "MCE %#lx: just unpoisoned\n", pfn);
95935 - atomic_long_sub(nr_pages, &num_poisoned_pages);
95936 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
95937 put_page(hpage);
95938 res = 0;
95939 goto out;
95940 }
95941 if (hwpoison_filter(p)) {
95942 if (TestClearPageHWPoison(p))
95943 - atomic_long_sub(nr_pages, &num_poisoned_pages);
95944 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
95945 unlock_page(hpage);
95946 put_page(hpage);
95947 return 0;
95948 @@ -1433,7 +1433,7 @@ int unpoison_memory(unsigned long pfn)
95949 return 0;
95950 }
95951 if (TestClearPageHWPoison(p))
95952 - atomic_long_dec(&num_poisoned_pages);
95953 + atomic_long_dec_unchecked(&num_poisoned_pages);
95954 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
95955 return 0;
95956 }
95957 @@ -1447,7 +1447,7 @@ int unpoison_memory(unsigned long pfn)
95958 */
95959 if (TestClearPageHWPoison(page)) {
95960 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
95961 - atomic_long_sub(nr_pages, &num_poisoned_pages);
95962 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
95963 freeit = 1;
95964 if (PageHuge(page))
95965 clear_page_hwpoison_huge_page(page);
95966 @@ -1572,11 +1572,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
95967 if (PageHuge(page)) {
95968 set_page_hwpoison_huge_page(hpage);
95969 dequeue_hwpoisoned_huge_page(hpage);
95970 - atomic_long_add(1 << compound_order(hpage),
95971 + atomic_long_add_unchecked(1 << compound_order(hpage),
95972 &num_poisoned_pages);
95973 } else {
95974 SetPageHWPoison(page);
95975 - atomic_long_inc(&num_poisoned_pages);
95976 + atomic_long_inc_unchecked(&num_poisoned_pages);
95977 }
95978 }
95979 return ret;
95980 @@ -1615,7 +1615,7 @@ static int __soft_offline_page(struct page *page, int flags)
95981 put_page(page);
95982 pr_info("soft_offline: %#lx: invalidated\n", pfn);
95983 SetPageHWPoison(page);
95984 - atomic_long_inc(&num_poisoned_pages);
95985 + atomic_long_inc_unchecked(&num_poisoned_pages);
95986 return 0;
95987 }
95988
95989 @@ -1666,7 +1666,7 @@ static int __soft_offline_page(struct page *page, int flags)
95990 if (!is_free_buddy_page(page))
95991 pr_info("soft offline: %#lx: page leaked\n",
95992 pfn);
95993 - atomic_long_inc(&num_poisoned_pages);
95994 + atomic_long_inc_unchecked(&num_poisoned_pages);
95995 }
95996 } else {
95997 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
95998 @@ -1736,11 +1736,11 @@ int soft_offline_page(struct page *page, int flags)
95999 if (PageHuge(page)) {
96000 set_page_hwpoison_huge_page(hpage);
96001 dequeue_hwpoisoned_huge_page(hpage);
96002 - atomic_long_add(1 << compound_order(hpage),
96003 + atomic_long_add_unchecked(1 << compound_order(hpage),
96004 &num_poisoned_pages);
96005 } else {
96006 SetPageHWPoison(page);
96007 - atomic_long_inc(&num_poisoned_pages);
96008 + atomic_long_inc_unchecked(&num_poisoned_pages);
96009 }
96010 }
96011 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
96012 diff --git a/mm/memory.c b/mm/memory.c
96013 index 37b80fc..9cdef79 100644
96014 --- a/mm/memory.c
96015 +++ b/mm/memory.c
96016 @@ -415,6 +415,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
96017 free_pte_range(tlb, pmd, addr);
96018 } while (pmd++, addr = next, addr != end);
96019
96020 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
96021 start &= PUD_MASK;
96022 if (start < floor)
96023 return;
96024 @@ -429,6 +430,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
96025 pmd = pmd_offset(pud, start);
96026 pud_clear(pud);
96027 pmd_free_tlb(tlb, pmd, start);
96028 +#endif
96029 +
96030 }
96031
96032 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
96033 @@ -448,6 +451,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
96034 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
96035 } while (pud++, addr = next, addr != end);
96036
96037 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
96038 start &= PGDIR_MASK;
96039 if (start < floor)
96040 return;
96041 @@ -462,6 +466,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
96042 pud = pud_offset(pgd, start);
96043 pgd_clear(pgd);
96044 pud_free_tlb(tlb, pud, start);
96045 +#endif
96046 +
96047 }
96048
96049 /*
96050 @@ -691,10 +697,10 @@ static void print_bad_pte(struct vm_area_struct *vma, unsigned long addr,
96051 * Choose text because data symbols depend on CONFIG_KALLSYMS_ALL=y
96052 */
96053 if (vma->vm_ops)
96054 - printk(KERN_ALERT "vma->vm_ops->fault: %pSR\n",
96055 + printk(KERN_ALERT "vma->vm_ops->fault: %pAR\n",
96056 vma->vm_ops->fault);
96057 if (vma->vm_file)
96058 - printk(KERN_ALERT "vma->vm_file->f_op->mmap: %pSR\n",
96059 + printk(KERN_ALERT "vma->vm_file->f_op->mmap: %pAR\n",
96060 vma->vm_file->f_op->mmap);
96061 dump_stack();
96062 add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
96063 @@ -815,20 +821,20 @@ copy_one_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,
96064 if (!pte_file(pte)) {
96065 swp_entry_t entry = pte_to_swp_entry(pte);
96066
96067 - if (swap_duplicate(entry) < 0)
96068 - return entry.val;
96069 + if (likely(!non_swap_entry(entry))) {
96070 + if (swap_duplicate(entry) < 0)
96071 + return entry.val;
96072
96073 - /* make sure dst_mm is on swapoff's mmlist. */
96074 - if (unlikely(list_empty(&dst_mm->mmlist))) {
96075 - spin_lock(&mmlist_lock);
96076 - if (list_empty(&dst_mm->mmlist))
96077 - list_add(&dst_mm->mmlist,
96078 - &src_mm->mmlist);
96079 - spin_unlock(&mmlist_lock);
96080 - }
96081 - if (likely(!non_swap_entry(entry)))
96082 + /* make sure dst_mm is on swapoff's mmlist. */
96083 + if (unlikely(list_empty(&dst_mm->mmlist))) {
96084 + spin_lock(&mmlist_lock);
96085 + if (list_empty(&dst_mm->mmlist))
96086 + list_add(&dst_mm->mmlist,
96087 + &src_mm->mmlist);
96088 + spin_unlock(&mmlist_lock);
96089 + }
96090 rss[MM_SWAPENTS]++;
96091 - else if (is_migration_entry(entry)) {
96092 + } else if (is_migration_entry(entry)) {
96093 page = migration_entry_to_page(entry);
96094
96095 if (PageAnon(page))
96096 @@ -1501,6 +1507,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
96097 page_add_file_rmap(page);
96098 set_pte_at(mm, addr, pte, mk_pte(page, prot));
96099
96100 +#ifdef CONFIG_PAX_SEGMEXEC
96101 + pax_mirror_file_pte(vma, addr, page, ptl);
96102 +#endif
96103 +
96104 retval = 0;
96105 pte_unmap_unlock(pte, ptl);
96106 return retval;
96107 @@ -1545,9 +1555,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
96108 if (!page_count(page))
96109 return -EINVAL;
96110 if (!(vma->vm_flags & VM_MIXEDMAP)) {
96111 +
96112 +#ifdef CONFIG_PAX_SEGMEXEC
96113 + struct vm_area_struct *vma_m;
96114 +#endif
96115 +
96116 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
96117 BUG_ON(vma->vm_flags & VM_PFNMAP);
96118 vma->vm_flags |= VM_MIXEDMAP;
96119 +
96120 +#ifdef CONFIG_PAX_SEGMEXEC
96121 + vma_m = pax_find_mirror_vma(vma);
96122 + if (vma_m)
96123 + vma_m->vm_flags |= VM_MIXEDMAP;
96124 +#endif
96125 +
96126 }
96127 return insert_page(vma, addr, page, vma->vm_page_prot);
96128 }
96129 @@ -1630,6 +1652,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
96130 unsigned long pfn)
96131 {
96132 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
96133 + BUG_ON(vma->vm_mirror);
96134
96135 if (addr < vma->vm_start || addr >= vma->vm_end)
96136 return -EFAULT;
96137 @@ -1877,7 +1900,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
96138
96139 BUG_ON(pud_huge(*pud));
96140
96141 - pmd = pmd_alloc(mm, pud, addr);
96142 + pmd = (mm == &init_mm) ?
96143 + pmd_alloc_kernel(mm, pud, addr) :
96144 + pmd_alloc(mm, pud, addr);
96145 if (!pmd)
96146 return -ENOMEM;
96147 do {
96148 @@ -1897,7 +1922,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
96149 unsigned long next;
96150 int err;
96151
96152 - pud = pud_alloc(mm, pgd, addr);
96153 + pud = (mm == &init_mm) ?
96154 + pud_alloc_kernel(mm, pgd, addr) :
96155 + pud_alloc(mm, pgd, addr);
96156 if (!pud)
96157 return -ENOMEM;
96158 do {
96159 @@ -2019,6 +2046,186 @@ static int do_page_mkwrite(struct vm_area_struct *vma, struct page *page,
96160 return ret;
96161 }
96162
96163 +#ifdef CONFIG_PAX_SEGMEXEC
96164 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
96165 +{
96166 + struct mm_struct *mm = vma->vm_mm;
96167 + spinlock_t *ptl;
96168 + pte_t *pte, entry;
96169 +
96170 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
96171 + entry = *pte;
96172 + if (!pte_present(entry)) {
96173 + if (!pte_none(entry)) {
96174 + BUG_ON(pte_file(entry));
96175 + free_swap_and_cache(pte_to_swp_entry(entry));
96176 + pte_clear_not_present_full(mm, address, pte, 0);
96177 + }
96178 + } else {
96179 + struct page *page;
96180 +
96181 + flush_cache_page(vma, address, pte_pfn(entry));
96182 + entry = ptep_clear_flush(vma, address, pte);
96183 + BUG_ON(pte_dirty(entry));
96184 + page = vm_normal_page(vma, address, entry);
96185 + if (page) {
96186 + update_hiwater_rss(mm);
96187 + if (PageAnon(page))
96188 + dec_mm_counter_fast(mm, MM_ANONPAGES);
96189 + else
96190 + dec_mm_counter_fast(mm, MM_FILEPAGES);
96191 + page_remove_rmap(page);
96192 + page_cache_release(page);
96193 + }
96194 + }
96195 + pte_unmap_unlock(pte, ptl);
96196 +}
96197 +
96198 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
96199 + *
96200 + * the ptl of the lower mapped page is held on entry and is not released on exit
96201 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
96202 + */
96203 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
96204 +{
96205 + struct mm_struct *mm = vma->vm_mm;
96206 + unsigned long address_m;
96207 + spinlock_t *ptl_m;
96208 + struct vm_area_struct *vma_m;
96209 + pmd_t *pmd_m;
96210 + pte_t *pte_m, entry_m;
96211 +
96212 + BUG_ON(!page_m || !PageAnon(page_m));
96213 +
96214 + vma_m = pax_find_mirror_vma(vma);
96215 + if (!vma_m)
96216 + return;
96217 +
96218 + BUG_ON(!PageLocked(page_m));
96219 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
96220 + address_m = address + SEGMEXEC_TASK_SIZE;
96221 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
96222 + pte_m = pte_offset_map(pmd_m, address_m);
96223 + ptl_m = pte_lockptr(mm, pmd_m);
96224 + if (ptl != ptl_m) {
96225 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
96226 + if (!pte_none(*pte_m))
96227 + goto out;
96228 + }
96229 +
96230 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
96231 + page_cache_get(page_m);
96232 + page_add_anon_rmap(page_m, vma_m, address_m);
96233 + inc_mm_counter_fast(mm, MM_ANONPAGES);
96234 + set_pte_at(mm, address_m, pte_m, entry_m);
96235 + update_mmu_cache(vma_m, address_m, pte_m);
96236 +out:
96237 + if (ptl != ptl_m)
96238 + spin_unlock(ptl_m);
96239 + pte_unmap(pte_m);
96240 + unlock_page(page_m);
96241 +}
96242 +
96243 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
96244 +{
96245 + struct mm_struct *mm = vma->vm_mm;
96246 + unsigned long address_m;
96247 + spinlock_t *ptl_m;
96248 + struct vm_area_struct *vma_m;
96249 + pmd_t *pmd_m;
96250 + pte_t *pte_m, entry_m;
96251 +
96252 + BUG_ON(!page_m || PageAnon(page_m));
96253 +
96254 + vma_m = pax_find_mirror_vma(vma);
96255 + if (!vma_m)
96256 + return;
96257 +
96258 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
96259 + address_m = address + SEGMEXEC_TASK_SIZE;
96260 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
96261 + pte_m = pte_offset_map(pmd_m, address_m);
96262 + ptl_m = pte_lockptr(mm, pmd_m);
96263 + if (ptl != ptl_m) {
96264 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
96265 + if (!pte_none(*pte_m))
96266 + goto out;
96267 + }
96268 +
96269 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
96270 + page_cache_get(page_m);
96271 + page_add_file_rmap(page_m);
96272 + inc_mm_counter_fast(mm, MM_FILEPAGES);
96273 + set_pte_at(mm, address_m, pte_m, entry_m);
96274 + update_mmu_cache(vma_m, address_m, pte_m);
96275 +out:
96276 + if (ptl != ptl_m)
96277 + spin_unlock(ptl_m);
96278 + pte_unmap(pte_m);
96279 +}
96280 +
96281 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
96282 +{
96283 + struct mm_struct *mm = vma->vm_mm;
96284 + unsigned long address_m;
96285 + spinlock_t *ptl_m;
96286 + struct vm_area_struct *vma_m;
96287 + pmd_t *pmd_m;
96288 + pte_t *pte_m, entry_m;
96289 +
96290 + vma_m = pax_find_mirror_vma(vma);
96291 + if (!vma_m)
96292 + return;
96293 +
96294 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
96295 + address_m = address + SEGMEXEC_TASK_SIZE;
96296 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
96297 + pte_m = pte_offset_map(pmd_m, address_m);
96298 + ptl_m = pte_lockptr(mm, pmd_m);
96299 + if (ptl != ptl_m) {
96300 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
96301 + if (!pte_none(*pte_m))
96302 + goto out;
96303 + }
96304 +
96305 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
96306 + set_pte_at(mm, address_m, pte_m, entry_m);
96307 +out:
96308 + if (ptl != ptl_m)
96309 + spin_unlock(ptl_m);
96310 + pte_unmap(pte_m);
96311 +}
96312 +
96313 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
96314 +{
96315 + struct page *page_m;
96316 + pte_t entry;
96317 +
96318 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
96319 + goto out;
96320 +
96321 + entry = *pte;
96322 + page_m = vm_normal_page(vma, address, entry);
96323 + if (!page_m)
96324 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
96325 + else if (PageAnon(page_m)) {
96326 + if (pax_find_mirror_vma(vma)) {
96327 + pte_unmap_unlock(pte, ptl);
96328 + lock_page(page_m);
96329 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
96330 + if (pte_same(entry, *pte))
96331 + pax_mirror_anon_pte(vma, address, page_m, ptl);
96332 + else
96333 + unlock_page(page_m);
96334 + }
96335 + } else
96336 + pax_mirror_file_pte(vma, address, page_m, ptl);
96337 +
96338 +out:
96339 + pte_unmap_unlock(pte, ptl);
96340 +}
96341 +#endif
96342 +
96343 /*
96344 * This routine handles present pages, when users try to write
96345 * to a shared page. It is done by copying the page to a new address
96346 @@ -2217,6 +2424,12 @@ gotten:
96347 */
96348 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
96349 if (likely(pte_same(*page_table, orig_pte))) {
96350 +
96351 +#ifdef CONFIG_PAX_SEGMEXEC
96352 + if (pax_find_mirror_vma(vma))
96353 + BUG_ON(!trylock_page(new_page));
96354 +#endif
96355 +
96356 if (old_page) {
96357 if (!PageAnon(old_page)) {
96358 dec_mm_counter_fast(mm, MM_FILEPAGES);
96359 @@ -2270,6 +2483,10 @@ gotten:
96360 page_remove_rmap(old_page);
96361 }
96362
96363 +#ifdef CONFIG_PAX_SEGMEXEC
96364 + pax_mirror_anon_pte(vma, address, new_page, ptl);
96365 +#endif
96366 +
96367 /* Free the old page.. */
96368 new_page = old_page;
96369 ret |= VM_FAULT_WRITE;
96370 @@ -2544,6 +2761,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
96371 swap_free(entry);
96372 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
96373 try_to_free_swap(page);
96374 +
96375 +#ifdef CONFIG_PAX_SEGMEXEC
96376 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
96377 +#endif
96378 +
96379 unlock_page(page);
96380 if (page != swapcache) {
96381 /*
96382 @@ -2567,6 +2789,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
96383
96384 /* No need to invalidate - it was non-present before */
96385 update_mmu_cache(vma, address, page_table);
96386 +
96387 +#ifdef CONFIG_PAX_SEGMEXEC
96388 + pax_mirror_anon_pte(vma, address, page, ptl);
96389 +#endif
96390 +
96391 unlock:
96392 pte_unmap_unlock(page_table, ptl);
96393 out:
96394 @@ -2586,40 +2813,6 @@ out_release:
96395 }
96396
96397 /*
96398 - * This is like a special single-page "expand_{down|up}wards()",
96399 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
96400 - * doesn't hit another vma.
96401 - */
96402 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
96403 -{
96404 - address &= PAGE_MASK;
96405 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
96406 - struct vm_area_struct *prev = vma->vm_prev;
96407 -
96408 - /*
96409 - * Is there a mapping abutting this one below?
96410 - *
96411 - * That's only ok if it's the same stack mapping
96412 - * that has gotten split..
96413 - */
96414 - if (prev && prev->vm_end == address)
96415 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
96416 -
96417 - expand_downwards(vma, address - PAGE_SIZE);
96418 - }
96419 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
96420 - struct vm_area_struct *next = vma->vm_next;
96421 -
96422 - /* As VM_GROWSDOWN but s/below/above/ */
96423 - if (next && next->vm_start == address + PAGE_SIZE)
96424 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
96425 -
96426 - expand_upwards(vma, address + PAGE_SIZE);
96427 - }
96428 - return 0;
96429 -}
96430 -
96431 -/*
96432 * We enter with non-exclusive mmap_sem (to exclude vma changes,
96433 * but allow concurrent faults), and pte mapped but not yet locked.
96434 * We return with mmap_sem still held, but pte unmapped and unlocked.
96435 @@ -2629,27 +2822,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
96436 unsigned int flags)
96437 {
96438 struct mem_cgroup *memcg;
96439 - struct page *page;
96440 + struct page *page = NULL;
96441 spinlock_t *ptl;
96442 pte_t entry;
96443
96444 - pte_unmap(page_table);
96445 -
96446 - /* Check if we need to add a guard page to the stack */
96447 - if (check_stack_guard_page(vma, address) < 0)
96448 - return VM_FAULT_SIGBUS;
96449 -
96450 - /* Use the zero-page for reads */
96451 if (!(flags & FAULT_FLAG_WRITE)) {
96452 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
96453 vma->vm_page_prot));
96454 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
96455 + ptl = pte_lockptr(mm, pmd);
96456 + spin_lock(ptl);
96457 if (!pte_none(*page_table))
96458 goto unlock;
96459 goto setpte;
96460 }
96461
96462 /* Allocate our own private page. */
96463 + pte_unmap(page_table);
96464 +
96465 if (unlikely(anon_vma_prepare(vma)))
96466 goto oom;
96467 page = alloc_zeroed_user_highpage_movable(vma, address);
96468 @@ -2673,6 +2862,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
96469 if (!pte_none(*page_table))
96470 goto release;
96471
96472 +#ifdef CONFIG_PAX_SEGMEXEC
96473 + if (pax_find_mirror_vma(vma))
96474 + BUG_ON(!trylock_page(page));
96475 +#endif
96476 +
96477 inc_mm_counter_fast(mm, MM_ANONPAGES);
96478 page_add_new_anon_rmap(page, vma, address);
96479 mem_cgroup_commit_charge(page, memcg, false);
96480 @@ -2682,6 +2876,12 @@ setpte:
96481
96482 /* No need to invalidate - it was non-present before */
96483 update_mmu_cache(vma, address, page_table);
96484 +
96485 +#ifdef CONFIG_PAX_SEGMEXEC
96486 + if (page)
96487 + pax_mirror_anon_pte(vma, address, page, ptl);
96488 +#endif
96489 +
96490 unlock:
96491 pte_unmap_unlock(page_table, ptl);
96492 return 0;
96493 @@ -2912,6 +3112,11 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96494 return ret;
96495 }
96496 do_set_pte(vma, address, fault_page, pte, false, false);
96497 +
96498 +#ifdef CONFIG_PAX_SEGMEXEC
96499 + pax_mirror_file_pte(vma, address, fault_page, ptl);
96500 +#endif
96501 +
96502 unlock_page(fault_page);
96503 unlock_out:
96504 pte_unmap_unlock(pte, ptl);
96505 @@ -2954,7 +3159,18 @@ static int do_cow_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96506 page_cache_release(fault_page);
96507 goto uncharge_out;
96508 }
96509 +
96510 +#ifdef CONFIG_PAX_SEGMEXEC
96511 + if (pax_find_mirror_vma(vma))
96512 + BUG_ON(!trylock_page(new_page));
96513 +#endif
96514 +
96515 do_set_pte(vma, address, new_page, pte, true, true);
96516 +
96517 +#ifdef CONFIG_PAX_SEGMEXEC
96518 + pax_mirror_anon_pte(vma, address, new_page, ptl);
96519 +#endif
96520 +
96521 mem_cgroup_commit_charge(new_page, memcg, false);
96522 lru_cache_add_active_or_unevictable(new_page, vma);
96523 pte_unmap_unlock(pte, ptl);
96524 @@ -3004,6 +3220,11 @@ static int do_shared_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96525 return ret;
96526 }
96527 do_set_pte(vma, address, fault_page, pte, true, false);
96528 +
96529 +#ifdef CONFIG_PAX_SEGMEXEC
96530 + pax_mirror_file_pte(vma, address, fault_page, ptl);
96531 +#endif
96532 +
96533 pte_unmap_unlock(pte, ptl);
96534
96535 if (set_page_dirty(fault_page))
96536 @@ -3245,6 +3466,12 @@ static int handle_pte_fault(struct mm_struct *mm,
96537 if (flags & FAULT_FLAG_WRITE)
96538 flush_tlb_fix_spurious_fault(vma, address);
96539 }
96540 +
96541 +#ifdef CONFIG_PAX_SEGMEXEC
96542 + pax_mirror_pte(vma, address, pte, pmd, ptl);
96543 + return 0;
96544 +#endif
96545 +
96546 unlock:
96547 pte_unmap_unlock(pte, ptl);
96548 return 0;
96549 @@ -3264,9 +3491,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96550 pmd_t *pmd;
96551 pte_t *pte;
96552
96553 +#ifdef CONFIG_PAX_SEGMEXEC
96554 + struct vm_area_struct *vma_m;
96555 +#endif
96556 +
96557 if (unlikely(is_vm_hugetlb_page(vma)))
96558 return hugetlb_fault(mm, vma, address, flags);
96559
96560 +#ifdef CONFIG_PAX_SEGMEXEC
96561 + vma_m = pax_find_mirror_vma(vma);
96562 + if (vma_m) {
96563 + unsigned long address_m;
96564 + pgd_t *pgd_m;
96565 + pud_t *pud_m;
96566 + pmd_t *pmd_m;
96567 +
96568 + if (vma->vm_start > vma_m->vm_start) {
96569 + address_m = address;
96570 + address -= SEGMEXEC_TASK_SIZE;
96571 + vma = vma_m;
96572 + } else
96573 + address_m = address + SEGMEXEC_TASK_SIZE;
96574 +
96575 + pgd_m = pgd_offset(mm, address_m);
96576 + pud_m = pud_alloc(mm, pgd_m, address_m);
96577 + if (!pud_m)
96578 + return VM_FAULT_OOM;
96579 + pmd_m = pmd_alloc(mm, pud_m, address_m);
96580 + if (!pmd_m)
96581 + return VM_FAULT_OOM;
96582 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
96583 + return VM_FAULT_OOM;
96584 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
96585 + }
96586 +#endif
96587 +
96588 pgd = pgd_offset(mm, address);
96589 pud = pud_alloc(mm, pgd, address);
96590 if (!pud)
96591 @@ -3400,6 +3659,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
96592 spin_unlock(&mm->page_table_lock);
96593 return 0;
96594 }
96595 +
96596 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
96597 +{
96598 + pud_t *new = pud_alloc_one(mm, address);
96599 + if (!new)
96600 + return -ENOMEM;
96601 +
96602 + smp_wmb(); /* See comment in __pte_alloc */
96603 +
96604 + spin_lock(&mm->page_table_lock);
96605 + if (pgd_present(*pgd)) /* Another has populated it */
96606 + pud_free(mm, new);
96607 + else
96608 + pgd_populate_kernel(mm, pgd, new);
96609 + spin_unlock(&mm->page_table_lock);
96610 + return 0;
96611 +}
96612 #endif /* __PAGETABLE_PUD_FOLDED */
96613
96614 #ifndef __PAGETABLE_PMD_FOLDED
96615 @@ -3430,6 +3706,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
96616 spin_unlock(&mm->page_table_lock);
96617 return 0;
96618 }
96619 +
96620 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
96621 +{
96622 + pmd_t *new = pmd_alloc_one(mm, address);
96623 + if (!new)
96624 + return -ENOMEM;
96625 +
96626 + smp_wmb(); /* See comment in __pte_alloc */
96627 +
96628 + spin_lock(&mm->page_table_lock);
96629 +#ifndef __ARCH_HAS_4LEVEL_HACK
96630 + if (pud_present(*pud)) /* Another has populated it */
96631 + pmd_free(mm, new);
96632 + else
96633 + pud_populate_kernel(mm, pud, new);
96634 +#else
96635 + if (pgd_present(*pud)) /* Another has populated it */
96636 + pmd_free(mm, new);
96637 + else
96638 + pgd_populate_kernel(mm, pud, new);
96639 +#endif /* __ARCH_HAS_4LEVEL_HACK */
96640 + spin_unlock(&mm->page_table_lock);
96641 + return 0;
96642 +}
96643 #endif /* __PAGETABLE_PMD_FOLDED */
96644
96645 static int __follow_pte(struct mm_struct *mm, unsigned long address,
96646 @@ -3539,8 +3839,8 @@ out:
96647 return ret;
96648 }
96649
96650 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
96651 - void *buf, int len, int write)
96652 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
96653 + void *buf, size_t len, int write)
96654 {
96655 resource_size_t phys_addr;
96656 unsigned long prot = 0;
96657 @@ -3566,8 +3866,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
96658 * Access another process' address space as given in mm. If non-NULL, use the
96659 * given task for page fault accounting.
96660 */
96661 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96662 - unsigned long addr, void *buf, int len, int write)
96663 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96664 + unsigned long addr, void *buf, size_t len, int write)
96665 {
96666 struct vm_area_struct *vma;
96667 void *old_buf = buf;
96668 @@ -3575,7 +3875,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96669 down_read(&mm->mmap_sem);
96670 /* ignore errors, just check how much was successfully transferred */
96671 while (len) {
96672 - int bytes, ret, offset;
96673 + ssize_t bytes, ret, offset;
96674 void *maddr;
96675 struct page *page = NULL;
96676
96677 @@ -3636,8 +3936,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96678 *
96679 * The caller must hold a reference on @mm.
96680 */
96681 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
96682 - void *buf, int len, int write)
96683 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
96684 + void *buf, size_t len, int write)
96685 {
96686 return __access_remote_vm(NULL, mm, addr, buf, len, write);
96687 }
96688 @@ -3647,11 +3947,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
96689 * Source/target buffer must be kernel space,
96690 * Do not walk the page table directly, use get_user_pages
96691 */
96692 -int access_process_vm(struct task_struct *tsk, unsigned long addr,
96693 - void *buf, int len, int write)
96694 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
96695 + void *buf, size_t len, int write)
96696 {
96697 struct mm_struct *mm;
96698 - int ret;
96699 + ssize_t ret;
96700
96701 mm = get_task_mm(tsk);
96702 if (!mm)
96703 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
96704 index 8f5330d..b41914b 100644
96705 --- a/mm/mempolicy.c
96706 +++ b/mm/mempolicy.c
96707 @@ -750,6 +750,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
96708 unsigned long vmstart;
96709 unsigned long vmend;
96710
96711 +#ifdef CONFIG_PAX_SEGMEXEC
96712 + struct vm_area_struct *vma_m;
96713 +#endif
96714 +
96715 vma = find_vma(mm, start);
96716 if (!vma || vma->vm_start > start)
96717 return -EFAULT;
96718 @@ -793,6 +797,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
96719 err = vma_replace_policy(vma, new_pol);
96720 if (err)
96721 goto out;
96722 +
96723 +#ifdef CONFIG_PAX_SEGMEXEC
96724 + vma_m = pax_find_mirror_vma(vma);
96725 + if (vma_m) {
96726 + err = vma_replace_policy(vma_m, new_pol);
96727 + if (err)
96728 + goto out;
96729 + }
96730 +#endif
96731 +
96732 }
96733
96734 out:
96735 @@ -1225,6 +1239,17 @@ static long do_mbind(unsigned long start, unsigned long len,
96736
96737 if (end < start)
96738 return -EINVAL;
96739 +
96740 +#ifdef CONFIG_PAX_SEGMEXEC
96741 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
96742 + if (end > SEGMEXEC_TASK_SIZE)
96743 + return -EINVAL;
96744 + } else
96745 +#endif
96746 +
96747 + if (end > TASK_SIZE)
96748 + return -EINVAL;
96749 +
96750 if (end == start)
96751 return 0;
96752
96753 @@ -1450,8 +1475,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
96754 */
96755 tcred = __task_cred(task);
96756 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
96757 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
96758 - !capable(CAP_SYS_NICE)) {
96759 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
96760 rcu_read_unlock();
96761 err = -EPERM;
96762 goto out_put;
96763 @@ -1482,6 +1506,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
96764 goto out;
96765 }
96766
96767 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
96768 + if (mm != current->mm &&
96769 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
96770 + mmput(mm);
96771 + err = -EPERM;
96772 + goto out;
96773 + }
96774 +#endif
96775 +
96776 err = do_migrate_pages(mm, old, new,
96777 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
96778
96779 diff --git a/mm/migrate.c b/mm/migrate.c
96780 index 0143995..b294728 100644
96781 --- a/mm/migrate.c
96782 +++ b/mm/migrate.c
96783 @@ -1495,8 +1495,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
96784 */
96785 tcred = __task_cred(task);
96786 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
96787 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
96788 - !capable(CAP_SYS_NICE)) {
96789 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
96790 rcu_read_unlock();
96791 err = -EPERM;
96792 goto out;
96793 diff --git a/mm/mlock.c b/mm/mlock.c
96794 index ce84cb0..6d5a9aa 100644
96795 --- a/mm/mlock.c
96796 +++ b/mm/mlock.c
96797 @@ -14,6 +14,7 @@
96798 #include <linux/pagevec.h>
96799 #include <linux/mempolicy.h>
96800 #include <linux/syscalls.h>
96801 +#include <linux/security.h>
96802 #include <linux/sched.h>
96803 #include <linux/export.h>
96804 #include <linux/rmap.h>
96805 @@ -613,7 +614,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
96806 {
96807 unsigned long nstart, end, tmp;
96808 struct vm_area_struct * vma, * prev;
96809 - int error;
96810 + int error = 0;
96811
96812 VM_BUG_ON(start & ~PAGE_MASK);
96813 VM_BUG_ON(len != PAGE_ALIGN(len));
96814 @@ -622,6 +623,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
96815 return -EINVAL;
96816 if (end == start)
96817 return 0;
96818 + if (end > TASK_SIZE)
96819 + return -EINVAL;
96820 +
96821 vma = find_vma(current->mm, start);
96822 if (!vma || vma->vm_start > start)
96823 return -ENOMEM;
96824 @@ -633,6 +637,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
96825 for (nstart = start ; ; ) {
96826 vm_flags_t newflags;
96827
96828 +#ifdef CONFIG_PAX_SEGMEXEC
96829 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
96830 + break;
96831 +#endif
96832 +
96833 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
96834
96835 newflags = vma->vm_flags & ~VM_LOCKED;
96836 @@ -746,6 +755,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
96837 locked += current->mm->locked_vm;
96838
96839 /* check against resource limits */
96840 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
96841 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
96842 error = do_mlock(start, len, 1);
96843
96844 @@ -783,6 +793,11 @@ static int do_mlockall(int flags)
96845 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
96846 vm_flags_t newflags;
96847
96848 +#ifdef CONFIG_PAX_SEGMEXEC
96849 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
96850 + break;
96851 +#endif
96852 +
96853 newflags = vma->vm_flags & ~VM_LOCKED;
96854 if (flags & MCL_CURRENT)
96855 newflags |= VM_LOCKED;
96856 @@ -814,8 +829,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
96857 lock_limit >>= PAGE_SHIFT;
96858
96859 ret = -ENOMEM;
96860 +
96861 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
96862 +
96863 down_write(&current->mm->mmap_sem);
96864 -
96865 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
96866 capable(CAP_IPC_LOCK))
96867 ret = do_mlockall(flags);
96868 diff --git a/mm/mmap.c b/mm/mmap.c
96869 index ebc25fa..9135e65 100644
96870 --- a/mm/mmap.c
96871 +++ b/mm/mmap.c
96872 @@ -41,6 +41,7 @@
96873 #include <linux/notifier.h>
96874 #include <linux/memory.h>
96875 #include <linux/printk.h>
96876 +#include <linux/random.h>
96877
96878 #include <asm/uaccess.h>
96879 #include <asm/cacheflush.h>
96880 @@ -57,6 +58,16 @@
96881 #define arch_rebalance_pgtables(addr, len) (addr)
96882 #endif
96883
96884 +static inline void verify_mm_writelocked(struct mm_struct *mm)
96885 +{
96886 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
96887 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
96888 + up_read(&mm->mmap_sem);
96889 + BUG();
96890 + }
96891 +#endif
96892 +}
96893 +
96894 static void unmap_region(struct mm_struct *mm,
96895 struct vm_area_struct *vma, struct vm_area_struct *prev,
96896 unsigned long start, unsigned long end);
96897 @@ -76,16 +87,25 @@ static void unmap_region(struct mm_struct *mm,
96898 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
96899 *
96900 */
96901 -pgprot_t protection_map[16] = {
96902 +pgprot_t protection_map[16] __read_only = {
96903 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
96904 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
96905 };
96906
96907 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
96908 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
96909 {
96910 - return __pgprot(pgprot_val(protection_map[vm_flags &
96911 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
96912 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
96913 pgprot_val(arch_vm_get_page_prot(vm_flags)));
96914 +
96915 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
96916 + if (!(__supported_pte_mask & _PAGE_NX) &&
96917 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
96918 + (vm_flags & (VM_READ | VM_WRITE)))
96919 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
96920 +#endif
96921 +
96922 + return prot;
96923 }
96924 EXPORT_SYMBOL(vm_get_page_prot);
96925
96926 @@ -95,6 +115,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
96927 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
96928 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
96929 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
96930 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
96931 /*
96932 * Make sure vm_committed_as in one cacheline and not cacheline shared with
96933 * other variables. It can be updated by several CPUs frequently.
96934 @@ -255,6 +276,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
96935 struct vm_area_struct *next = vma->vm_next;
96936
96937 might_sleep();
96938 + BUG_ON(vma->vm_mirror);
96939 if (vma->vm_ops && vma->vm_ops->close)
96940 vma->vm_ops->close(vma);
96941 if (vma->vm_file)
96942 @@ -299,6 +321,12 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
96943 * not page aligned -Ram Gupta
96944 */
96945 rlim = rlimit(RLIMIT_DATA);
96946 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
96947 + /* force a minimum 16MB brk heap on setuid/setgid binaries */
96948 + if (rlim < PAGE_SIZE && (get_dumpable(mm) != SUID_DUMP_USER) && gr_is_global_nonroot(current_uid()))
96949 + rlim = 4096 * PAGE_SIZE;
96950 +#endif
96951 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
96952 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
96953 (mm->end_data - mm->start_data) > rlim)
96954 goto out;
96955 @@ -752,8 +780,11 @@ again: remove_next = 1 + (end > next->vm_end);
96956 * shrinking vma had, to cover any anon pages imported.
96957 */
96958 if (exporter && exporter->anon_vma && !importer->anon_vma) {
96959 - if (anon_vma_clone(importer, exporter))
96960 - return -ENOMEM;
96961 + int error;
96962 +
96963 + error = anon_vma_clone(importer, exporter);
96964 + if (error)
96965 + return error;
96966 importer->anon_vma = exporter->anon_vma;
96967 }
96968 }
96969 @@ -949,6 +980,12 @@ static int
96970 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
96971 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
96972 {
96973 +
96974 +#ifdef CONFIG_PAX_SEGMEXEC
96975 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
96976 + return 0;
96977 +#endif
96978 +
96979 if (is_mergeable_vma(vma, file, vm_flags) &&
96980 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
96981 if (vma->vm_pgoff == vm_pgoff)
96982 @@ -968,6 +1005,12 @@ static int
96983 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
96984 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
96985 {
96986 +
96987 +#ifdef CONFIG_PAX_SEGMEXEC
96988 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
96989 + return 0;
96990 +#endif
96991 +
96992 if (is_mergeable_vma(vma, file, vm_flags) &&
96993 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
96994 pgoff_t vm_pglen;
96995 @@ -1010,13 +1053,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
96996 struct vm_area_struct *vma_merge(struct mm_struct *mm,
96997 struct vm_area_struct *prev, unsigned long addr,
96998 unsigned long end, unsigned long vm_flags,
96999 - struct anon_vma *anon_vma, struct file *file,
97000 + struct anon_vma *anon_vma, struct file *file,
97001 pgoff_t pgoff, struct mempolicy *policy)
97002 {
97003 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
97004 struct vm_area_struct *area, *next;
97005 int err;
97006
97007 +#ifdef CONFIG_PAX_SEGMEXEC
97008 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
97009 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
97010 +
97011 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
97012 +#endif
97013 +
97014 /*
97015 * We later require that vma->vm_flags == vm_flags,
97016 * so this tests vma->vm_flags & VM_SPECIAL, too.
97017 @@ -1032,6 +1082,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
97018 if (next && next->vm_end == end) /* cases 6, 7, 8 */
97019 next = next->vm_next;
97020
97021 +#ifdef CONFIG_PAX_SEGMEXEC
97022 + if (prev)
97023 + prev_m = pax_find_mirror_vma(prev);
97024 + if (area)
97025 + area_m = pax_find_mirror_vma(area);
97026 + if (next)
97027 + next_m = pax_find_mirror_vma(next);
97028 +#endif
97029 +
97030 /*
97031 * Can it merge with the predecessor?
97032 */
97033 @@ -1051,9 +1110,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
97034 /* cases 1, 6 */
97035 err = vma_adjust(prev, prev->vm_start,
97036 next->vm_end, prev->vm_pgoff, NULL);
97037 - } else /* cases 2, 5, 7 */
97038 +
97039 +#ifdef CONFIG_PAX_SEGMEXEC
97040 + if (!err && prev_m)
97041 + err = vma_adjust(prev_m, prev_m->vm_start,
97042 + next_m->vm_end, prev_m->vm_pgoff, NULL);
97043 +#endif
97044 +
97045 + } else { /* cases 2, 5, 7 */
97046 err = vma_adjust(prev, prev->vm_start,
97047 end, prev->vm_pgoff, NULL);
97048 +
97049 +#ifdef CONFIG_PAX_SEGMEXEC
97050 + if (!err && prev_m)
97051 + err = vma_adjust(prev_m, prev_m->vm_start,
97052 + end_m, prev_m->vm_pgoff, NULL);
97053 +#endif
97054 +
97055 + }
97056 if (err)
97057 return NULL;
97058 khugepaged_enter_vma_merge(prev, vm_flags);
97059 @@ -1067,12 +1141,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
97060 mpol_equal(policy, vma_policy(next)) &&
97061 can_vma_merge_before(next, vm_flags,
97062 anon_vma, file, pgoff+pglen)) {
97063 - if (prev && addr < prev->vm_end) /* case 4 */
97064 + if (prev && addr < prev->vm_end) { /* case 4 */
97065 err = vma_adjust(prev, prev->vm_start,
97066 addr, prev->vm_pgoff, NULL);
97067 - else /* cases 3, 8 */
97068 +
97069 +#ifdef CONFIG_PAX_SEGMEXEC
97070 + if (!err && prev_m)
97071 + err = vma_adjust(prev_m, prev_m->vm_start,
97072 + addr_m, prev_m->vm_pgoff, NULL);
97073 +#endif
97074 +
97075 + } else { /* cases 3, 8 */
97076 err = vma_adjust(area, addr, next->vm_end,
97077 next->vm_pgoff - pglen, NULL);
97078 +
97079 +#ifdef CONFIG_PAX_SEGMEXEC
97080 + if (!err && area_m)
97081 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
97082 + next_m->vm_pgoff - pglen, NULL);
97083 +#endif
97084 +
97085 + }
97086 if (err)
97087 return NULL;
97088 khugepaged_enter_vma_merge(area, vm_flags);
97089 @@ -1181,8 +1270,10 @@ none:
97090 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
97091 struct file *file, long pages)
97092 {
97093 - const unsigned long stack_flags
97094 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
97095 +
97096 +#ifdef CONFIG_PAX_RANDMMAP
97097 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
97098 +#endif
97099
97100 mm->total_vm += pages;
97101
97102 @@ -1190,7 +1281,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
97103 mm->shared_vm += pages;
97104 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
97105 mm->exec_vm += pages;
97106 - } else if (flags & stack_flags)
97107 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
97108 mm->stack_vm += pages;
97109 }
97110 #endif /* CONFIG_PROC_FS */
97111 @@ -1220,6 +1311,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
97112 locked += mm->locked_vm;
97113 lock_limit = rlimit(RLIMIT_MEMLOCK);
97114 lock_limit >>= PAGE_SHIFT;
97115 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
97116 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
97117 return -EAGAIN;
97118 }
97119 @@ -1246,7 +1338,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
97120 * (the exception is when the underlying filesystem is noexec
97121 * mounted, in which case we dont add PROT_EXEC.)
97122 */
97123 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
97124 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
97125 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
97126 prot |= PROT_EXEC;
97127
97128 @@ -1272,7 +1364,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
97129 /* Obtain the address to map to. we verify (or select) it and ensure
97130 * that it represents a valid section of the address space.
97131 */
97132 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
97133 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
97134 if (addr & ~PAGE_MASK)
97135 return addr;
97136
97137 @@ -1283,6 +1375,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
97138 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
97139 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
97140
97141 +#ifdef CONFIG_PAX_MPROTECT
97142 + if (mm->pax_flags & MF_PAX_MPROTECT) {
97143 +
97144 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
97145 + if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
97146 + mm->binfmt->handle_mmap)
97147 + mm->binfmt->handle_mmap(file);
97148 +#endif
97149 +
97150 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
97151 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
97152 + gr_log_rwxmmap(file);
97153 +
97154 +#ifdef CONFIG_PAX_EMUPLT
97155 + vm_flags &= ~VM_EXEC;
97156 +#else
97157 + return -EPERM;
97158 +#endif
97159 +
97160 + }
97161 +
97162 + if (!(vm_flags & VM_EXEC))
97163 + vm_flags &= ~VM_MAYEXEC;
97164 +#else
97165 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
97166 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
97167 +#endif
97168 + else
97169 + vm_flags &= ~VM_MAYWRITE;
97170 + }
97171 +#endif
97172 +
97173 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
97174 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
97175 + vm_flags &= ~VM_PAGEEXEC;
97176 +#endif
97177 +
97178 if (flags & MAP_LOCKED)
97179 if (!can_do_mlock())
97180 return -EPERM;
97181 @@ -1370,6 +1499,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
97182 vm_flags |= VM_NORESERVE;
97183 }
97184
97185 + if (!gr_acl_handle_mmap(file, prot))
97186 + return -EACCES;
97187 +
97188 addr = mmap_region(file, addr, len, vm_flags, pgoff);
97189 if (!IS_ERR_VALUE(addr) &&
97190 ((vm_flags & VM_LOCKED) ||
97191 @@ -1463,7 +1595,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
97192 vm_flags_t vm_flags = vma->vm_flags;
97193
97194 /* If it was private or non-writable, the write bit is already clear */
97195 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
97196 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
97197 return 0;
97198
97199 /* The backer wishes to know when pages are first written to? */
97200 @@ -1509,7 +1641,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
97201 struct rb_node **rb_link, *rb_parent;
97202 unsigned long charged = 0;
97203
97204 +#ifdef CONFIG_PAX_SEGMEXEC
97205 + struct vm_area_struct *vma_m = NULL;
97206 +#endif
97207 +
97208 + /*
97209 + * mm->mmap_sem is required to protect against another thread
97210 + * changing the mappings in case we sleep.
97211 + */
97212 + verify_mm_writelocked(mm);
97213 +
97214 /* Check against address space limit. */
97215 +
97216 +#ifdef CONFIG_PAX_RANDMMAP
97217 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
97218 +#endif
97219 +
97220 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
97221 unsigned long nr_pages;
97222
97223 @@ -1528,11 +1675,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
97224
97225 /* Clear old maps */
97226 error = -ENOMEM;
97227 -munmap_back:
97228 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
97229 if (do_munmap(mm, addr, len))
97230 return -ENOMEM;
97231 - goto munmap_back;
97232 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
97233 }
97234
97235 /*
97236 @@ -1563,6 +1709,16 @@ munmap_back:
97237 goto unacct_error;
97238 }
97239
97240 +#ifdef CONFIG_PAX_SEGMEXEC
97241 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
97242 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
97243 + if (!vma_m) {
97244 + error = -ENOMEM;
97245 + goto free_vma;
97246 + }
97247 + }
97248 +#endif
97249 +
97250 vma->vm_mm = mm;
97251 vma->vm_start = addr;
97252 vma->vm_end = addr + len;
97253 @@ -1593,6 +1749,13 @@ munmap_back:
97254 if (error)
97255 goto unmap_and_free_vma;
97256
97257 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
97258 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
97259 + vma->vm_flags |= VM_PAGEEXEC;
97260 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
97261 + }
97262 +#endif
97263 +
97264 /* Can addr have changed??
97265 *
97266 * Answer: Yes, several device drivers can do it in their
97267 @@ -1626,6 +1789,12 @@ munmap_back:
97268 }
97269
97270 vma_link(mm, vma, prev, rb_link, rb_parent);
97271 +
97272 +#ifdef CONFIG_PAX_SEGMEXEC
97273 + if (vma_m)
97274 + BUG_ON(pax_mirror_vma(vma_m, vma));
97275 +#endif
97276 +
97277 /* Once vma denies write, undo our temporary denial count */
97278 if (file) {
97279 if (vm_flags & VM_SHARED)
97280 @@ -1638,6 +1807,7 @@ out:
97281 perf_event_mmap(vma);
97282
97283 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
97284 + track_exec_limit(mm, addr, addr + len, vm_flags);
97285 if (vm_flags & VM_LOCKED) {
97286 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
97287 vma == get_gate_vma(current->mm)))
97288 @@ -1673,6 +1843,12 @@ allow_write_and_free_vma:
97289 if (vm_flags & VM_DENYWRITE)
97290 allow_write_access(file);
97291 free_vma:
97292 +
97293 +#ifdef CONFIG_PAX_SEGMEXEC
97294 + if (vma_m)
97295 + kmem_cache_free(vm_area_cachep, vma_m);
97296 +#endif
97297 +
97298 kmem_cache_free(vm_area_cachep, vma);
97299 unacct_error:
97300 if (charged)
97301 @@ -1680,7 +1856,63 @@ unacct_error:
97302 return error;
97303 }
97304
97305 -unsigned long unmapped_area(struct vm_unmapped_area_info *info)
97306 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
97307 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
97308 +{
97309 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
97310 + return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
97311 +
97312 + return 0;
97313 +}
97314 +#endif
97315 +
97316 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
97317 +{
97318 + if (!vma) {
97319 +#ifdef CONFIG_STACK_GROWSUP
97320 + if (addr > sysctl_heap_stack_gap)
97321 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
97322 + else
97323 + vma = find_vma(current->mm, 0);
97324 + if (vma && (vma->vm_flags & VM_GROWSUP))
97325 + return false;
97326 +#endif
97327 + return true;
97328 + }
97329 +
97330 + if (addr + len > vma->vm_start)
97331 + return false;
97332 +
97333 + if (vma->vm_flags & VM_GROWSDOWN)
97334 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
97335 +#ifdef CONFIG_STACK_GROWSUP
97336 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
97337 + return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
97338 +#endif
97339 + else if (offset)
97340 + return offset <= vma->vm_start - addr - len;
97341 +
97342 + return true;
97343 +}
97344 +
97345 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
97346 +{
97347 + if (vma->vm_start < len)
97348 + return -ENOMEM;
97349 +
97350 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
97351 + if (offset <= vma->vm_start - len)
97352 + return vma->vm_start - len - offset;
97353 + else
97354 + return -ENOMEM;
97355 + }
97356 +
97357 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
97358 + return vma->vm_start - len - sysctl_heap_stack_gap;
97359 + return -ENOMEM;
97360 +}
97361 +
97362 +unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
97363 {
97364 /*
97365 * We implement the search by looking for an rbtree node that
97366 @@ -1728,11 +1960,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
97367 }
97368 }
97369
97370 - gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
97371 + gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
97372 check_current:
97373 /* Check if current node has a suitable gap */
97374 if (gap_start > high_limit)
97375 return -ENOMEM;
97376 +
97377 + if (gap_end - gap_start > info->threadstack_offset)
97378 + gap_start += info->threadstack_offset;
97379 + else
97380 + gap_start = gap_end;
97381 +
97382 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
97383 + if (gap_end - gap_start > sysctl_heap_stack_gap)
97384 + gap_start += sysctl_heap_stack_gap;
97385 + else
97386 + gap_start = gap_end;
97387 + }
97388 + if (vma->vm_flags & VM_GROWSDOWN) {
97389 + if (gap_end - gap_start > sysctl_heap_stack_gap)
97390 + gap_end -= sysctl_heap_stack_gap;
97391 + else
97392 + gap_end = gap_start;
97393 + }
97394 if (gap_end >= low_limit && gap_end - gap_start >= length)
97395 goto found;
97396
97397 @@ -1782,7 +2032,7 @@ found:
97398 return gap_start;
97399 }
97400
97401 -unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
97402 +unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
97403 {
97404 struct mm_struct *mm = current->mm;
97405 struct vm_area_struct *vma;
97406 @@ -1836,6 +2086,24 @@ check_current:
97407 gap_end = vma->vm_start;
97408 if (gap_end < low_limit)
97409 return -ENOMEM;
97410 +
97411 + if (gap_end - gap_start > info->threadstack_offset)
97412 + gap_end -= info->threadstack_offset;
97413 + else
97414 + gap_end = gap_start;
97415 +
97416 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
97417 + if (gap_end - gap_start > sysctl_heap_stack_gap)
97418 + gap_start += sysctl_heap_stack_gap;
97419 + else
97420 + gap_start = gap_end;
97421 + }
97422 + if (vma->vm_flags & VM_GROWSDOWN) {
97423 + if (gap_end - gap_start > sysctl_heap_stack_gap)
97424 + gap_end -= sysctl_heap_stack_gap;
97425 + else
97426 + gap_end = gap_start;
97427 + }
97428 if (gap_start <= high_limit && gap_end - gap_start >= length)
97429 goto found;
97430
97431 @@ -1899,6 +2167,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
97432 struct mm_struct *mm = current->mm;
97433 struct vm_area_struct *vma;
97434 struct vm_unmapped_area_info info;
97435 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
97436
97437 if (len > TASK_SIZE - mmap_min_addr)
97438 return -ENOMEM;
97439 @@ -1906,11 +2175,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
97440 if (flags & MAP_FIXED)
97441 return addr;
97442
97443 +#ifdef CONFIG_PAX_RANDMMAP
97444 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
97445 +#endif
97446 +
97447 if (addr) {
97448 addr = PAGE_ALIGN(addr);
97449 vma = find_vma(mm, addr);
97450 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
97451 - (!vma || addr + len <= vma->vm_start))
97452 + check_heap_stack_gap(vma, addr, len, offset))
97453 return addr;
97454 }
97455
97456 @@ -1919,6 +2192,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
97457 info.low_limit = mm->mmap_base;
97458 info.high_limit = TASK_SIZE;
97459 info.align_mask = 0;
97460 + info.threadstack_offset = offset;
97461 return vm_unmapped_area(&info);
97462 }
97463 #endif
97464 @@ -1937,6 +2211,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97465 struct mm_struct *mm = current->mm;
97466 unsigned long addr = addr0;
97467 struct vm_unmapped_area_info info;
97468 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
97469
97470 /* requested length too big for entire address space */
97471 if (len > TASK_SIZE - mmap_min_addr)
97472 @@ -1945,12 +2220,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97473 if (flags & MAP_FIXED)
97474 return addr;
97475
97476 +#ifdef CONFIG_PAX_RANDMMAP
97477 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
97478 +#endif
97479 +
97480 /* requesting a specific address */
97481 if (addr) {
97482 addr = PAGE_ALIGN(addr);
97483 vma = find_vma(mm, addr);
97484 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
97485 - (!vma || addr + len <= vma->vm_start))
97486 + check_heap_stack_gap(vma, addr, len, offset))
97487 return addr;
97488 }
97489
97490 @@ -1959,6 +2238,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97491 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
97492 info.high_limit = mm->mmap_base;
97493 info.align_mask = 0;
97494 + info.threadstack_offset = offset;
97495 addr = vm_unmapped_area(&info);
97496
97497 /*
97498 @@ -1971,6 +2251,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97499 VM_BUG_ON(addr != -ENOMEM);
97500 info.flags = 0;
97501 info.low_limit = TASK_UNMAPPED_BASE;
97502 +
97503 +#ifdef CONFIG_PAX_RANDMMAP
97504 + if (mm->pax_flags & MF_PAX_RANDMMAP)
97505 + info.low_limit += mm->delta_mmap;
97506 +#endif
97507 +
97508 info.high_limit = TASK_SIZE;
97509 addr = vm_unmapped_area(&info);
97510 }
97511 @@ -2071,6 +2357,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
97512 return vma;
97513 }
97514
97515 +#ifdef CONFIG_PAX_SEGMEXEC
97516 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
97517 +{
97518 + struct vm_area_struct *vma_m;
97519 +
97520 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
97521 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
97522 + BUG_ON(vma->vm_mirror);
97523 + return NULL;
97524 + }
97525 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
97526 + vma_m = vma->vm_mirror;
97527 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
97528 + BUG_ON(vma->vm_file != vma_m->vm_file);
97529 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
97530 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
97531 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
97532 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
97533 + return vma_m;
97534 +}
97535 +#endif
97536 +
97537 /*
97538 * Verify that the stack growth is acceptable and
97539 * update accounting. This is shared with both the
97540 @@ -2087,6 +2395,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97541 return -ENOMEM;
97542
97543 /* Stack limit test */
97544 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
97545 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
97546 return -ENOMEM;
97547
97548 @@ -2097,6 +2406,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97549 locked = mm->locked_vm + grow;
97550 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
97551 limit >>= PAGE_SHIFT;
97552 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
97553 if (locked > limit && !capable(CAP_IPC_LOCK))
97554 return -ENOMEM;
97555 }
97556 @@ -2126,37 +2436,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97557 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
97558 * vma is the last one with address > vma->vm_end. Have to extend vma.
97559 */
97560 +#ifndef CONFIG_IA64
97561 +static
97562 +#endif
97563 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
97564 {
97565 int error;
97566 + bool locknext;
97567
97568 if (!(vma->vm_flags & VM_GROWSUP))
97569 return -EFAULT;
97570
97571 + /* Also guard against wrapping around to address 0. */
97572 + if (address < PAGE_ALIGN(address+1))
97573 + address = PAGE_ALIGN(address+1);
97574 + else
97575 + return -ENOMEM;
97576 +
97577 /*
97578 * We must make sure the anon_vma is allocated
97579 * so that the anon_vma locking is not a noop.
97580 */
97581 if (unlikely(anon_vma_prepare(vma)))
97582 return -ENOMEM;
97583 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
97584 + if (locknext && anon_vma_prepare(vma->vm_next))
97585 + return -ENOMEM;
97586 vma_lock_anon_vma(vma);
97587 + if (locknext)
97588 + vma_lock_anon_vma(vma->vm_next);
97589
97590 /*
97591 * vma->vm_start/vm_end cannot change under us because the caller
97592 * is required to hold the mmap_sem in read mode. We need the
97593 - * anon_vma lock to serialize against concurrent expand_stacks.
97594 - * Also guard against wrapping around to address 0.
97595 + * anon_vma locks to serialize against concurrent expand_stacks
97596 + * and expand_upwards.
97597 */
97598 - if (address < PAGE_ALIGN(address+4))
97599 - address = PAGE_ALIGN(address+4);
97600 - else {
97601 - vma_unlock_anon_vma(vma);
97602 - return -ENOMEM;
97603 - }
97604 error = 0;
97605
97606 /* Somebody else might have raced and expanded it already */
97607 - if (address > vma->vm_end) {
97608 + 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)
97609 + error = -ENOMEM;
97610 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
97611 unsigned long size, grow;
97612
97613 size = address - vma->vm_start;
97614 @@ -2191,6 +2512,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
97615 }
97616 }
97617 }
97618 + if (locknext)
97619 + vma_unlock_anon_vma(vma->vm_next);
97620 vma_unlock_anon_vma(vma);
97621 khugepaged_enter_vma_merge(vma, vma->vm_flags);
97622 validate_mm(vma->vm_mm);
97623 @@ -2205,6 +2528,8 @@ int expand_downwards(struct vm_area_struct *vma,
97624 unsigned long address)
97625 {
97626 int error;
97627 + bool lockprev = false;
97628 + struct vm_area_struct *prev;
97629
97630 /*
97631 * We must make sure the anon_vma is allocated
97632 @@ -2218,6 +2543,15 @@ int expand_downwards(struct vm_area_struct *vma,
97633 if (error)
97634 return error;
97635
97636 + prev = vma->vm_prev;
97637 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
97638 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
97639 +#endif
97640 + if (lockprev && anon_vma_prepare(prev))
97641 + return -ENOMEM;
97642 + if (lockprev)
97643 + vma_lock_anon_vma(prev);
97644 +
97645 vma_lock_anon_vma(vma);
97646
97647 /*
97648 @@ -2227,9 +2561,17 @@ int expand_downwards(struct vm_area_struct *vma,
97649 */
97650
97651 /* Somebody else might have raced and expanded it already */
97652 - if (address < vma->vm_start) {
97653 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
97654 + error = -ENOMEM;
97655 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
97656 unsigned long size, grow;
97657
97658 +#ifdef CONFIG_PAX_SEGMEXEC
97659 + struct vm_area_struct *vma_m;
97660 +
97661 + vma_m = pax_find_mirror_vma(vma);
97662 +#endif
97663 +
97664 size = vma->vm_end - address;
97665 grow = (vma->vm_start - address) >> PAGE_SHIFT;
97666
97667 @@ -2254,13 +2596,27 @@ int expand_downwards(struct vm_area_struct *vma,
97668 vma->vm_pgoff -= grow;
97669 anon_vma_interval_tree_post_update_vma(vma);
97670 vma_gap_update(vma);
97671 +
97672 +#ifdef CONFIG_PAX_SEGMEXEC
97673 + if (vma_m) {
97674 + anon_vma_interval_tree_pre_update_vma(vma_m);
97675 + vma_m->vm_start -= grow << PAGE_SHIFT;
97676 + vma_m->vm_pgoff -= grow;
97677 + anon_vma_interval_tree_post_update_vma(vma_m);
97678 + vma_gap_update(vma_m);
97679 + }
97680 +#endif
97681 +
97682 spin_unlock(&vma->vm_mm->page_table_lock);
97683
97684 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
97685 perf_event_mmap(vma);
97686 }
97687 }
97688 }
97689 vma_unlock_anon_vma(vma);
97690 + if (lockprev)
97691 + vma_unlock_anon_vma(prev);
97692 khugepaged_enter_vma_merge(vma, vma->vm_flags);
97693 validate_mm(vma->vm_mm);
97694 return error;
97695 @@ -2358,6 +2714,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
97696 do {
97697 long nrpages = vma_pages(vma);
97698
97699 +#ifdef CONFIG_PAX_SEGMEXEC
97700 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
97701 + vma = remove_vma(vma);
97702 + continue;
97703 + }
97704 +#endif
97705 +
97706 if (vma->vm_flags & VM_ACCOUNT)
97707 nr_accounted += nrpages;
97708 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
97709 @@ -2402,6 +2765,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
97710 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
97711 vma->vm_prev = NULL;
97712 do {
97713 +
97714 +#ifdef CONFIG_PAX_SEGMEXEC
97715 + if (vma->vm_mirror) {
97716 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
97717 + vma->vm_mirror->vm_mirror = NULL;
97718 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
97719 + vma->vm_mirror = NULL;
97720 + }
97721 +#endif
97722 +
97723 vma_rb_erase(vma, &mm->mm_rb);
97724 mm->map_count--;
97725 tail_vma = vma;
97726 @@ -2429,14 +2802,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
97727 struct vm_area_struct *new;
97728 int err = -ENOMEM;
97729
97730 +#ifdef CONFIG_PAX_SEGMEXEC
97731 + struct vm_area_struct *vma_m, *new_m = NULL;
97732 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
97733 +#endif
97734 +
97735 if (is_vm_hugetlb_page(vma) && (addr &
97736 ~(huge_page_mask(hstate_vma(vma)))))
97737 return -EINVAL;
97738
97739 +#ifdef CONFIG_PAX_SEGMEXEC
97740 + vma_m = pax_find_mirror_vma(vma);
97741 +#endif
97742 +
97743 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
97744 if (!new)
97745 goto out_err;
97746
97747 +#ifdef CONFIG_PAX_SEGMEXEC
97748 + if (vma_m) {
97749 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
97750 + if (!new_m) {
97751 + kmem_cache_free(vm_area_cachep, new);
97752 + goto out_err;
97753 + }
97754 + }
97755 +#endif
97756 +
97757 /* most fields are the same, copy all, and then fixup */
97758 *new = *vma;
97759
97760 @@ -2449,11 +2841,28 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
97761 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
97762 }
97763
97764 +#ifdef CONFIG_PAX_SEGMEXEC
97765 + if (vma_m) {
97766 + *new_m = *vma_m;
97767 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
97768 + new_m->vm_mirror = new;
97769 + new->vm_mirror = new_m;
97770 +
97771 + if (new_below)
97772 + new_m->vm_end = addr_m;
97773 + else {
97774 + new_m->vm_start = addr_m;
97775 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
97776 + }
97777 + }
97778 +#endif
97779 +
97780 err = vma_dup_policy(vma, new);
97781 if (err)
97782 goto out_free_vma;
97783
97784 - if (anon_vma_clone(new, vma))
97785 + err = anon_vma_clone(new, vma);
97786 + if (err)
97787 goto out_free_mpol;
97788
97789 if (new->vm_file)
97790 @@ -2468,6 +2877,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
97791 else
97792 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
97793
97794 +#ifdef CONFIG_PAX_SEGMEXEC
97795 + if (!err && vma_m) {
97796 + struct mempolicy *pol = vma_policy(new);
97797 +
97798 + if (anon_vma_clone(new_m, vma_m))
97799 + goto out_free_mpol;
97800 +
97801 + mpol_get(pol);
97802 + set_vma_policy(new_m, pol);
97803 +
97804 + if (new_m->vm_file)
97805 + get_file(new_m->vm_file);
97806 +
97807 + if (new_m->vm_ops && new_m->vm_ops->open)
97808 + new_m->vm_ops->open(new_m);
97809 +
97810 + if (new_below)
97811 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
97812 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
97813 + else
97814 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
97815 +
97816 + if (err) {
97817 + if (new_m->vm_ops && new_m->vm_ops->close)
97818 + new_m->vm_ops->close(new_m);
97819 + if (new_m->vm_file)
97820 + fput(new_m->vm_file);
97821 + mpol_put(pol);
97822 + }
97823 + }
97824 +#endif
97825 +
97826 /* Success. */
97827 if (!err)
97828 return 0;
97829 @@ -2477,10 +2918,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
97830 new->vm_ops->close(new);
97831 if (new->vm_file)
97832 fput(new->vm_file);
97833 - unlink_anon_vmas(new);
97834 out_free_mpol:
97835 mpol_put(vma_policy(new));
97836 out_free_vma:
97837 +
97838 +#ifdef CONFIG_PAX_SEGMEXEC
97839 + if (new_m) {
97840 + unlink_anon_vmas(new_m);
97841 + kmem_cache_free(vm_area_cachep, new_m);
97842 + }
97843 +#endif
97844 +
97845 + unlink_anon_vmas(new);
97846 kmem_cache_free(vm_area_cachep, new);
97847 out_err:
97848 return err;
97849 @@ -2493,6 +2942,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
97850 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97851 unsigned long addr, int new_below)
97852 {
97853 +
97854 +#ifdef CONFIG_PAX_SEGMEXEC
97855 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
97856 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
97857 + if (mm->map_count >= sysctl_max_map_count-1)
97858 + return -ENOMEM;
97859 + } else
97860 +#endif
97861 +
97862 if (mm->map_count >= sysctl_max_map_count)
97863 return -ENOMEM;
97864
97865 @@ -2504,11 +2962,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97866 * work. This now handles partial unmappings.
97867 * Jeremy Fitzhardinge <jeremy@goop.org>
97868 */
97869 +#ifdef CONFIG_PAX_SEGMEXEC
97870 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97871 {
97872 + int ret = __do_munmap(mm, start, len);
97873 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
97874 + return ret;
97875 +
97876 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
97877 +}
97878 +
97879 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97880 +#else
97881 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97882 +#endif
97883 +{
97884 unsigned long end;
97885 struct vm_area_struct *vma, *prev, *last;
97886
97887 + /*
97888 + * mm->mmap_sem is required to protect against another thread
97889 + * changing the mappings in case we sleep.
97890 + */
97891 + verify_mm_writelocked(mm);
97892 +
97893 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
97894 return -EINVAL;
97895
97896 @@ -2583,6 +3060,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97897 /* Fix up all other VM information */
97898 remove_vma_list(mm, vma);
97899
97900 + track_exec_limit(mm, start, end, 0UL);
97901 +
97902 return 0;
97903 }
97904
97905 @@ -2591,6 +3070,13 @@ int vm_munmap(unsigned long start, size_t len)
97906 int ret;
97907 struct mm_struct *mm = current->mm;
97908
97909 +
97910 +#ifdef CONFIG_PAX_SEGMEXEC
97911 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
97912 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
97913 + return -EINVAL;
97914 +#endif
97915 +
97916 down_write(&mm->mmap_sem);
97917 ret = do_munmap(mm, start, len);
97918 up_write(&mm->mmap_sem);
97919 @@ -2604,16 +3090,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
97920 return vm_munmap(addr, len);
97921 }
97922
97923 -static inline void verify_mm_writelocked(struct mm_struct *mm)
97924 -{
97925 -#ifdef CONFIG_DEBUG_VM
97926 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
97927 - WARN_ON(1);
97928 - up_read(&mm->mmap_sem);
97929 - }
97930 -#endif
97931 -}
97932 -
97933 /*
97934 * this is really a simplified "do_mmap". it only handles
97935 * anonymous maps. eventually we may be able to do some
97936 @@ -2627,6 +3103,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
97937 struct rb_node ** rb_link, * rb_parent;
97938 pgoff_t pgoff = addr >> PAGE_SHIFT;
97939 int error;
97940 + unsigned long charged;
97941
97942 len = PAGE_ALIGN(len);
97943 if (!len)
97944 @@ -2634,10 +3111,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
97945
97946 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
97947
97948 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
97949 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
97950 + flags &= ~VM_EXEC;
97951 +
97952 +#ifdef CONFIG_PAX_MPROTECT
97953 + if (mm->pax_flags & MF_PAX_MPROTECT)
97954 + flags &= ~VM_MAYEXEC;
97955 +#endif
97956 +
97957 + }
97958 +#endif
97959 +
97960 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
97961 if (error & ~PAGE_MASK)
97962 return error;
97963
97964 + charged = len >> PAGE_SHIFT;
97965 +
97966 error = mlock_future_check(mm, mm->def_flags, len);
97967 if (error)
97968 return error;
97969 @@ -2651,21 +3142,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
97970 /*
97971 * Clear old maps. this also does some error checking for us
97972 */
97973 - munmap_back:
97974 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
97975 if (do_munmap(mm, addr, len))
97976 return -ENOMEM;
97977 - goto munmap_back;
97978 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
97979 }
97980
97981 /* Check against address space limits *after* clearing old maps... */
97982 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
97983 + if (!may_expand_vm(mm, charged))
97984 return -ENOMEM;
97985
97986 if (mm->map_count > sysctl_max_map_count)
97987 return -ENOMEM;
97988
97989 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
97990 + if (security_vm_enough_memory_mm(mm, charged))
97991 return -ENOMEM;
97992
97993 /* Can we just expand an old private anonymous mapping? */
97994 @@ -2679,7 +3169,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
97995 */
97996 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
97997 if (!vma) {
97998 - vm_unacct_memory(len >> PAGE_SHIFT);
97999 + vm_unacct_memory(charged);
98000 return -ENOMEM;
98001 }
98002
98003 @@ -2693,10 +3183,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98004 vma_link(mm, vma, prev, rb_link, rb_parent);
98005 out:
98006 perf_event_mmap(vma);
98007 - mm->total_vm += len >> PAGE_SHIFT;
98008 + mm->total_vm += charged;
98009 if (flags & VM_LOCKED)
98010 - mm->locked_vm += (len >> PAGE_SHIFT);
98011 + mm->locked_vm += charged;
98012 vma->vm_flags |= VM_SOFTDIRTY;
98013 + track_exec_limit(mm, addr, addr + len, flags);
98014 return addr;
98015 }
98016
98017 @@ -2758,6 +3249,7 @@ void exit_mmap(struct mm_struct *mm)
98018 while (vma) {
98019 if (vma->vm_flags & VM_ACCOUNT)
98020 nr_accounted += vma_pages(vma);
98021 + vma->vm_mirror = NULL;
98022 vma = remove_vma(vma);
98023 }
98024 vm_unacct_memory(nr_accounted);
98025 @@ -2775,6 +3267,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
98026 struct vm_area_struct *prev;
98027 struct rb_node **rb_link, *rb_parent;
98028
98029 +#ifdef CONFIG_PAX_SEGMEXEC
98030 + struct vm_area_struct *vma_m = NULL;
98031 +#endif
98032 +
98033 + if (security_mmap_addr(vma->vm_start))
98034 + return -EPERM;
98035 +
98036 /*
98037 * The vm_pgoff of a purely anonymous vma should be irrelevant
98038 * until its first write fault, when page's anon_vma and index
98039 @@ -2798,7 +3297,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
98040 security_vm_enough_memory_mm(mm, vma_pages(vma)))
98041 return -ENOMEM;
98042
98043 +#ifdef CONFIG_PAX_SEGMEXEC
98044 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
98045 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
98046 + if (!vma_m)
98047 + return -ENOMEM;
98048 + }
98049 +#endif
98050 +
98051 vma_link(mm, vma, prev, rb_link, rb_parent);
98052 +
98053 +#ifdef CONFIG_PAX_SEGMEXEC
98054 + if (vma_m)
98055 + BUG_ON(pax_mirror_vma(vma_m, vma));
98056 +#endif
98057 +
98058 return 0;
98059 }
98060
98061 @@ -2817,6 +3330,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
98062 struct rb_node **rb_link, *rb_parent;
98063 bool faulted_in_anon_vma = true;
98064
98065 + BUG_ON(vma->vm_mirror);
98066 +
98067 /*
98068 * If anonymous vma has not yet been faulted, update new pgoff
98069 * to match new location, to increase its chance of merging.
98070 @@ -2881,6 +3396,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
98071 return NULL;
98072 }
98073
98074 +#ifdef CONFIG_PAX_SEGMEXEC
98075 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
98076 +{
98077 + struct vm_area_struct *prev_m;
98078 + struct rb_node **rb_link_m, *rb_parent_m;
98079 + struct mempolicy *pol_m;
98080 +
98081 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
98082 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
98083 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
98084 + *vma_m = *vma;
98085 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
98086 + if (anon_vma_clone(vma_m, vma))
98087 + return -ENOMEM;
98088 + pol_m = vma_policy(vma_m);
98089 + mpol_get(pol_m);
98090 + set_vma_policy(vma_m, pol_m);
98091 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
98092 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
98093 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
98094 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
98095 + if (vma_m->vm_file)
98096 + get_file(vma_m->vm_file);
98097 + if (vma_m->vm_ops && vma_m->vm_ops->open)
98098 + vma_m->vm_ops->open(vma_m);
98099 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
98100 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
98101 + vma_m->vm_mirror = vma;
98102 + vma->vm_mirror = vma_m;
98103 + return 0;
98104 +}
98105 +#endif
98106 +
98107 /*
98108 * Return true if the calling process may expand its vm space by the passed
98109 * number of pages
98110 @@ -2892,6 +3440,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
98111
98112 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
98113
98114 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
98115 if (cur + npages > lim)
98116 return 0;
98117 return 1;
98118 @@ -2974,6 +3523,22 @@ static struct vm_area_struct *__install_special_mapping(
98119 vma->vm_start = addr;
98120 vma->vm_end = addr + len;
98121
98122 +#ifdef CONFIG_PAX_MPROTECT
98123 + if (mm->pax_flags & MF_PAX_MPROTECT) {
98124 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
98125 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
98126 + return ERR_PTR(-EPERM);
98127 + if (!(vm_flags & VM_EXEC))
98128 + vm_flags &= ~VM_MAYEXEC;
98129 +#else
98130 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
98131 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
98132 +#endif
98133 + else
98134 + vm_flags &= ~VM_MAYWRITE;
98135 + }
98136 +#endif
98137 +
98138 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
98139 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
98140
98141 diff --git a/mm/mprotect.c b/mm/mprotect.c
98142 index c43d557..0b7ccd2 100644
98143 --- a/mm/mprotect.c
98144 +++ b/mm/mprotect.c
98145 @@ -24,10 +24,18 @@
98146 #include <linux/migrate.h>
98147 #include <linux/perf_event.h>
98148 #include <linux/ksm.h>
98149 +#include <linux/sched/sysctl.h>
98150 +
98151 +#ifdef CONFIG_PAX_MPROTECT
98152 +#include <linux/elf.h>
98153 +#include <linux/binfmts.h>
98154 +#endif
98155 +
98156 #include <asm/uaccess.h>
98157 #include <asm/pgtable.h>
98158 #include <asm/cacheflush.h>
98159 #include <asm/tlbflush.h>
98160 +#include <asm/mmu_context.h>
98161
98162 #ifndef pgprot_modify
98163 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
98164 @@ -256,6 +264,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
98165 return pages;
98166 }
98167
98168 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
98169 +/* called while holding the mmap semaphor for writing except stack expansion */
98170 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
98171 +{
98172 + unsigned long oldlimit, newlimit = 0UL;
98173 +
98174 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
98175 + return;
98176 +
98177 + spin_lock(&mm->page_table_lock);
98178 + oldlimit = mm->context.user_cs_limit;
98179 + if ((prot & VM_EXEC) && oldlimit < end)
98180 + /* USER_CS limit moved up */
98181 + newlimit = end;
98182 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
98183 + /* USER_CS limit moved down */
98184 + newlimit = start;
98185 +
98186 + if (newlimit) {
98187 + mm->context.user_cs_limit = newlimit;
98188 +
98189 +#ifdef CONFIG_SMP
98190 + wmb();
98191 + cpus_clear(mm->context.cpu_user_cs_mask);
98192 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
98193 +#endif
98194 +
98195 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
98196 + }
98197 + spin_unlock(&mm->page_table_lock);
98198 + if (newlimit == end) {
98199 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
98200 +
98201 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
98202 + if (is_vm_hugetlb_page(vma))
98203 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
98204 + else
98205 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
98206 + }
98207 +}
98208 +#endif
98209 +
98210 int
98211 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
98212 unsigned long start, unsigned long end, unsigned long newflags)
98213 @@ -268,11 +318,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
98214 int error;
98215 int dirty_accountable = 0;
98216
98217 +#ifdef CONFIG_PAX_SEGMEXEC
98218 + struct vm_area_struct *vma_m = NULL;
98219 + unsigned long start_m, end_m;
98220 +
98221 + start_m = start + SEGMEXEC_TASK_SIZE;
98222 + end_m = end + SEGMEXEC_TASK_SIZE;
98223 +#endif
98224 +
98225 if (newflags == oldflags) {
98226 *pprev = vma;
98227 return 0;
98228 }
98229
98230 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
98231 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
98232 +
98233 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
98234 + return -ENOMEM;
98235 +
98236 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
98237 + return -ENOMEM;
98238 + }
98239 +
98240 /*
98241 * If we make a private mapping writable we increase our commit;
98242 * but (without finer accounting) cannot reduce our commit if we
98243 @@ -289,6 +357,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
98244 }
98245 }
98246
98247 +#ifdef CONFIG_PAX_SEGMEXEC
98248 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
98249 + if (start != vma->vm_start) {
98250 + error = split_vma(mm, vma, start, 1);
98251 + if (error)
98252 + goto fail;
98253 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
98254 + *pprev = (*pprev)->vm_next;
98255 + }
98256 +
98257 + if (end != vma->vm_end) {
98258 + error = split_vma(mm, vma, end, 0);
98259 + if (error)
98260 + goto fail;
98261 + }
98262 +
98263 + if (pax_find_mirror_vma(vma)) {
98264 + error = __do_munmap(mm, start_m, end_m - start_m);
98265 + if (error)
98266 + goto fail;
98267 + } else {
98268 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
98269 + if (!vma_m) {
98270 + error = -ENOMEM;
98271 + goto fail;
98272 + }
98273 + vma->vm_flags = newflags;
98274 + error = pax_mirror_vma(vma_m, vma);
98275 + if (error) {
98276 + vma->vm_flags = oldflags;
98277 + goto fail;
98278 + }
98279 + }
98280 + }
98281 +#endif
98282 +
98283 /*
98284 * First try to merge with previous and/or next vma.
98285 */
98286 @@ -319,9 +423,21 @@ success:
98287 * vm_flags and vm_page_prot are protected by the mmap_sem
98288 * held in write mode.
98289 */
98290 +
98291 +#ifdef CONFIG_PAX_SEGMEXEC
98292 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
98293 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
98294 +#endif
98295 +
98296 vma->vm_flags = newflags;
98297 +
98298 +#ifdef CONFIG_PAX_MPROTECT
98299 + if (mm->binfmt && mm->binfmt->handle_mprotect)
98300 + mm->binfmt->handle_mprotect(vma, newflags);
98301 +#endif
98302 +
98303 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
98304 - vm_get_page_prot(newflags));
98305 + vm_get_page_prot(vma->vm_flags));
98306
98307 if (vma_wants_writenotify(vma)) {
98308 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
98309 @@ -360,6 +476,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98310 end = start + len;
98311 if (end <= start)
98312 return -ENOMEM;
98313 +
98314 +#ifdef CONFIG_PAX_SEGMEXEC
98315 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
98316 + if (end > SEGMEXEC_TASK_SIZE)
98317 + return -EINVAL;
98318 + } else
98319 +#endif
98320 +
98321 + if (end > TASK_SIZE)
98322 + return -EINVAL;
98323 +
98324 if (!arch_validate_prot(prot))
98325 return -EINVAL;
98326
98327 @@ -367,7 +494,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98328 /*
98329 * Does the application expect PROT_READ to imply PROT_EXEC:
98330 */
98331 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
98332 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
98333 prot |= PROT_EXEC;
98334
98335 vm_flags = calc_vm_prot_bits(prot);
98336 @@ -399,6 +526,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98337 if (start > vma->vm_start)
98338 prev = vma;
98339
98340 +#ifdef CONFIG_PAX_MPROTECT
98341 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
98342 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
98343 +#endif
98344 +
98345 for (nstart = start ; ; ) {
98346 unsigned long newflags;
98347
98348 @@ -409,6 +541,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98349
98350 /* newflags >> 4 shift VM_MAY% in place of VM_% */
98351 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
98352 + if (prot & (PROT_WRITE | PROT_EXEC))
98353 + gr_log_rwxmprotect(vma);
98354 +
98355 + error = -EACCES;
98356 + goto out;
98357 + }
98358 +
98359 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
98360 error = -EACCES;
98361 goto out;
98362 }
98363 @@ -423,6 +563,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98364 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
98365 if (error)
98366 goto out;
98367 +
98368 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
98369 +
98370 nstart = tmp;
98371
98372 if (nstart < prev->vm_end)
98373 diff --git a/mm/mremap.c b/mm/mremap.c
98374 index 05f1180..c3cde48 100644
98375 --- a/mm/mremap.c
98376 +++ b/mm/mremap.c
98377 @@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
98378 continue;
98379 pte = ptep_get_and_clear(mm, old_addr, old_pte);
98380 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
98381 +
98382 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
98383 + if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
98384 + pte = pte_exprotect(pte);
98385 +#endif
98386 +
98387 pte = move_soft_dirty_pte(pte);
98388 set_pte_at(mm, new_addr, new_pte, pte);
98389 }
98390 @@ -344,6 +350,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
98391 if (is_vm_hugetlb_page(vma))
98392 goto Einval;
98393
98394 +#ifdef CONFIG_PAX_SEGMEXEC
98395 + if (pax_find_mirror_vma(vma))
98396 + goto Einval;
98397 +#endif
98398 +
98399 /* We can't remap across vm area boundaries */
98400 if (old_len > vma->vm_end - addr)
98401 goto Efault;
98402 @@ -399,20 +410,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
98403 unsigned long ret = -EINVAL;
98404 unsigned long charged = 0;
98405 unsigned long map_flags;
98406 + unsigned long pax_task_size = TASK_SIZE;
98407
98408 if (new_addr & ~PAGE_MASK)
98409 goto out;
98410
98411 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
98412 +#ifdef CONFIG_PAX_SEGMEXEC
98413 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
98414 + pax_task_size = SEGMEXEC_TASK_SIZE;
98415 +#endif
98416 +
98417 + pax_task_size -= PAGE_SIZE;
98418 +
98419 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
98420 goto out;
98421
98422 /* Check if the location we're moving into overlaps the
98423 * old location at all, and fail if it does.
98424 */
98425 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
98426 - goto out;
98427 -
98428 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
98429 + if (addr + old_len > new_addr && new_addr + new_len > addr)
98430 goto out;
98431
98432 ret = do_munmap(mm, new_addr, new_len);
98433 @@ -481,6 +497,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98434 unsigned long ret = -EINVAL;
98435 unsigned long charged = 0;
98436 bool locked = false;
98437 + unsigned long pax_task_size = TASK_SIZE;
98438
98439 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
98440 return ret;
98441 @@ -502,6 +519,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98442 if (!new_len)
98443 return ret;
98444
98445 +#ifdef CONFIG_PAX_SEGMEXEC
98446 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
98447 + pax_task_size = SEGMEXEC_TASK_SIZE;
98448 +#endif
98449 +
98450 + pax_task_size -= PAGE_SIZE;
98451 +
98452 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
98453 + old_len > pax_task_size || addr > pax_task_size-old_len)
98454 + return ret;
98455 +
98456 down_write(&current->mm->mmap_sem);
98457
98458 if (flags & MREMAP_FIXED) {
98459 @@ -552,6 +580,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98460 new_addr = addr;
98461 }
98462 ret = addr;
98463 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
98464 goto out;
98465 }
98466 }
98467 @@ -575,7 +604,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98468 goto out;
98469 }
98470
98471 + map_flags = vma->vm_flags;
98472 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
98473 + if (!(ret & ~PAGE_MASK)) {
98474 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
98475 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
98476 + }
98477 }
98478 out:
98479 if (ret & ~PAGE_MASK)
98480 diff --git a/mm/nommu.c b/mm/nommu.c
98481 index a881d96..e5932cd 100644
98482 --- a/mm/nommu.c
98483 +++ b/mm/nommu.c
98484 @@ -70,7 +70,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
98485 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
98486 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
98487 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
98488 -int heap_stack_gap = 0;
98489
98490 atomic_long_t mmap_pages_allocated;
98491
98492 @@ -857,15 +856,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
98493 EXPORT_SYMBOL(find_vma);
98494
98495 /*
98496 - * find a VMA
98497 - * - we don't extend stack VMAs under NOMMU conditions
98498 - */
98499 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
98500 -{
98501 - return find_vma(mm, addr);
98502 -}
98503 -
98504 -/*
98505 * expand a stack to a given address
98506 * - not supported under NOMMU conditions
98507 */
98508 @@ -1572,6 +1562,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
98509
98510 /* most fields are the same, copy all, and then fixup */
98511 *new = *vma;
98512 + INIT_LIST_HEAD(&new->anon_vma_chain);
98513 *region = *vma->vm_region;
98514 new->vm_region = region;
98515
98516 @@ -2002,8 +1993,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
98517 }
98518 EXPORT_SYMBOL(generic_file_remap_pages);
98519
98520 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
98521 - unsigned long addr, void *buf, int len, int write)
98522 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
98523 + unsigned long addr, void *buf, size_t len, int write)
98524 {
98525 struct vm_area_struct *vma;
98526
98527 @@ -2044,8 +2035,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
98528 *
98529 * The caller must hold a reference on @mm.
98530 */
98531 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
98532 - void *buf, int len, int write)
98533 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
98534 + void *buf, size_t len, int write)
98535 {
98536 return __access_remote_vm(NULL, mm, addr, buf, len, write);
98537 }
98538 @@ -2054,7 +2045,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
98539 * Access another process' address space.
98540 * - source/target buffer must be kernel space
98541 */
98542 -int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
98543 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
98544 {
98545 struct mm_struct *mm;
98546
98547 diff --git a/mm/page-writeback.c b/mm/page-writeback.c
98548 index ba5fd97..5a95869 100644
98549 --- a/mm/page-writeback.c
98550 +++ b/mm/page-writeback.c
98551 @@ -664,7 +664,7 @@ static long long pos_ratio_polynom(unsigned long setpoint,
98552 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
98553 * - the bdi dirty thresh drops quickly due to change of JBOD workload
98554 */
98555 -static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
98556 +static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
98557 unsigned long thresh,
98558 unsigned long bg_thresh,
98559 unsigned long dirty,
98560 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
98561 index c5fe124..2cf7f17 100644
98562 --- a/mm/page_alloc.c
98563 +++ b/mm/page_alloc.c
98564 @@ -61,6 +61,7 @@
98565 #include <linux/page-debug-flags.h>
98566 #include <linux/hugetlb.h>
98567 #include <linux/sched/rt.h>
98568 +#include <linux/random.h>
98569
98570 #include <asm/sections.h>
98571 #include <asm/tlbflush.h>
98572 @@ -357,7 +358,7 @@ out:
98573 * This usage means that zero-order pages may not be compound.
98574 */
98575
98576 -static void free_compound_page(struct page *page)
98577 +void free_compound_page(struct page *page)
98578 {
98579 __free_pages_ok(page, compound_order(page));
98580 }
98581 @@ -740,6 +741,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
98582 int i;
98583 int bad = 0;
98584
98585 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
98586 + unsigned long index = 1UL << order;
98587 +#endif
98588 +
98589 trace_mm_page_free(page, order);
98590 kmemcheck_free_shadow(page, order);
98591
98592 @@ -756,6 +761,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
98593 debug_check_no_obj_freed(page_address(page),
98594 PAGE_SIZE << order);
98595 }
98596 +
98597 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
98598 + for (; index; --index)
98599 + sanitize_highpage(page + index - 1);
98600 +#endif
98601 +
98602 arch_free_page(page, order);
98603 kernel_map_pages(page, 1 << order, 0);
98604
98605 @@ -779,6 +790,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
98606 local_irq_restore(flags);
98607 }
98608
98609 +#ifdef CONFIG_PAX_LATENT_ENTROPY
98610 +bool __meminitdata extra_latent_entropy;
98611 +
98612 +static int __init setup_pax_extra_latent_entropy(char *str)
98613 +{
98614 + extra_latent_entropy = true;
98615 + return 0;
98616 +}
98617 +early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
98618 +
98619 +volatile u64 latent_entropy __latent_entropy;
98620 +EXPORT_SYMBOL(latent_entropy);
98621 +#endif
98622 +
98623 void __init __free_pages_bootmem(struct page *page, unsigned int order)
98624 {
98625 unsigned int nr_pages = 1 << order;
98626 @@ -794,6 +819,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
98627 __ClearPageReserved(p);
98628 set_page_count(p, 0);
98629
98630 +#ifdef CONFIG_PAX_LATENT_ENTROPY
98631 + if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
98632 + u64 hash = 0;
98633 + size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
98634 + const u64 *data = lowmem_page_address(page);
98635 +
98636 + for (index = 0; index < end; index++)
98637 + hash ^= hash + data[index];
98638 + latent_entropy ^= hash;
98639 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
98640 + }
98641 +#endif
98642 +
98643 page_zone(page)->managed_pages += nr_pages;
98644 set_page_refcounted(page);
98645 __free_pages(page, order);
98646 @@ -922,8 +960,10 @@ static int prep_new_page(struct page *page, unsigned int order, gfp_t gfp_flags)
98647 arch_alloc_page(page, order);
98648 kernel_map_pages(page, 1 << order, 1);
98649
98650 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
98651 if (gfp_flags & __GFP_ZERO)
98652 prep_zero_page(page, order, gfp_flags);
98653 +#endif
98654
98655 if (order && (gfp_flags & __GFP_COMP))
98656 prep_compound_page(page, order);
98657 @@ -1601,7 +1641,7 @@ again:
98658 }
98659
98660 __mod_zone_page_state(zone, NR_ALLOC_BATCH, -(1 << order));
98661 - if (atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]) <= 0 &&
98662 + if (atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]) <= 0 &&
98663 !zone_is_fair_depleted(zone))
98664 zone_set_flag(zone, ZONE_FAIR_DEPLETED);
98665
98666 @@ -1922,7 +1962,7 @@ static void reset_alloc_batches(struct zone *preferred_zone)
98667 do {
98668 mod_zone_page_state(zone, NR_ALLOC_BATCH,
98669 high_wmark_pages(zone) - low_wmark_pages(zone) -
98670 - atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
98671 + atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
98672 zone_clear_flag(zone, ZONE_FAIR_DEPLETED);
98673 } while (zone++ != preferred_zone);
98674 }
98675 @@ -5699,7 +5739,7 @@ static void __setup_per_zone_wmarks(void)
98676
98677 __mod_zone_page_state(zone, NR_ALLOC_BATCH,
98678 high_wmark_pages(zone) - low_wmark_pages(zone) -
98679 - atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
98680 + atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
98681
98682 setup_zone_migrate_reserve(zone);
98683 spin_unlock_irqrestore(&zone->lock, flags);
98684 diff --git a/mm/percpu.c b/mm/percpu.c
98685 index 2139e30..1d45bce 100644
98686 --- a/mm/percpu.c
98687 +++ b/mm/percpu.c
98688 @@ -123,7 +123,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
98689 static unsigned int pcpu_high_unit_cpu __read_mostly;
98690
98691 /* the address of the first chunk which starts with the kernel static area */
98692 -void *pcpu_base_addr __read_mostly;
98693 +void *pcpu_base_addr __read_only;
98694 EXPORT_SYMBOL_GPL(pcpu_base_addr);
98695
98696 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
98697 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
98698 index 5077afc..846c9ef 100644
98699 --- a/mm/process_vm_access.c
98700 +++ b/mm/process_vm_access.c
98701 @@ -13,6 +13,7 @@
98702 #include <linux/uio.h>
98703 #include <linux/sched.h>
98704 #include <linux/highmem.h>
98705 +#include <linux/security.h>
98706 #include <linux/ptrace.h>
98707 #include <linux/slab.h>
98708 #include <linux/syscalls.h>
98709 @@ -157,19 +158,19 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
98710 ssize_t iov_len;
98711 size_t total_len = iov_iter_count(iter);
98712
98713 + return -ENOSYS; // PaX: until properly audited
98714 +
98715 /*
98716 * Work out how many pages of struct pages we're going to need
98717 * when eventually calling get_user_pages
98718 */
98719 for (i = 0; i < riovcnt; i++) {
98720 iov_len = rvec[i].iov_len;
98721 - if (iov_len > 0) {
98722 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
98723 - + iov_len)
98724 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
98725 - / PAGE_SIZE + 1;
98726 - nr_pages = max(nr_pages, nr_pages_iov);
98727 - }
98728 + if (iov_len <= 0)
98729 + continue;
98730 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
98731 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
98732 + nr_pages = max(nr_pages, nr_pages_iov);
98733 }
98734
98735 if (nr_pages == 0)
98736 @@ -197,6 +198,11 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
98737 goto free_proc_pages;
98738 }
98739
98740 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
98741 + rc = -EPERM;
98742 + goto put_task_struct;
98743 + }
98744 +
98745 mm = mm_access(task, PTRACE_MODE_ATTACH);
98746 if (!mm || IS_ERR(mm)) {
98747 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
98748 diff --git a/mm/rmap.c b/mm/rmap.c
98749 index e01318d..7a532bd 100644
98750 --- a/mm/rmap.c
98751 +++ b/mm/rmap.c
98752 @@ -164,6 +164,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98753 struct anon_vma *anon_vma = vma->anon_vma;
98754 struct anon_vma_chain *avc;
98755
98756 +#ifdef CONFIG_PAX_SEGMEXEC
98757 + struct anon_vma_chain *avc_m = NULL;
98758 +#endif
98759 +
98760 might_sleep();
98761 if (unlikely(!anon_vma)) {
98762 struct mm_struct *mm = vma->vm_mm;
98763 @@ -173,6 +177,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98764 if (!avc)
98765 goto out_enomem;
98766
98767 +#ifdef CONFIG_PAX_SEGMEXEC
98768 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
98769 + if (!avc_m)
98770 + goto out_enomem_free_avc;
98771 +#endif
98772 +
98773 anon_vma = find_mergeable_anon_vma(vma);
98774 allocated = NULL;
98775 if (!anon_vma) {
98776 @@ -186,6 +196,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98777 /* page_table_lock to protect against threads */
98778 spin_lock(&mm->page_table_lock);
98779 if (likely(!vma->anon_vma)) {
98780 +
98781 +#ifdef CONFIG_PAX_SEGMEXEC
98782 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
98783 +
98784 + if (vma_m) {
98785 + BUG_ON(vma_m->anon_vma);
98786 + vma_m->anon_vma = anon_vma;
98787 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
98788 + avc_m = NULL;
98789 + }
98790 +#endif
98791 +
98792 vma->anon_vma = anon_vma;
98793 anon_vma_chain_link(vma, avc, anon_vma);
98794 allocated = NULL;
98795 @@ -196,12 +218,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98796
98797 if (unlikely(allocated))
98798 put_anon_vma(allocated);
98799 +
98800 +#ifdef CONFIG_PAX_SEGMEXEC
98801 + if (unlikely(avc_m))
98802 + anon_vma_chain_free(avc_m);
98803 +#endif
98804 +
98805 if (unlikely(avc))
98806 anon_vma_chain_free(avc);
98807 }
98808 return 0;
98809
98810 out_enomem_free_avc:
98811 +
98812 +#ifdef CONFIG_PAX_SEGMEXEC
98813 + if (avc_m)
98814 + anon_vma_chain_free(avc_m);
98815 +#endif
98816 +
98817 anon_vma_chain_free(avc);
98818 out_enomem:
98819 return -ENOMEM;
98820 @@ -237,7 +271,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
98821 * Attach the anon_vmas from src to dst.
98822 * Returns 0 on success, -ENOMEM on failure.
98823 */
98824 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
98825 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
98826 {
98827 struct anon_vma_chain *avc, *pavc;
98828 struct anon_vma *root = NULL;
98829 @@ -270,10 +304,11 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
98830 * the corresponding VMA in the parent process is attached to.
98831 * Returns 0 on success, non-zero on failure.
98832 */
98833 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
98834 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
98835 {
98836 struct anon_vma_chain *avc;
98837 struct anon_vma *anon_vma;
98838 + int error;
98839
98840 /* Don't bother if the parent process has no anon_vma here. */
98841 if (!pvma->anon_vma)
98842 @@ -283,8 +318,9 @@ int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
98843 * First, attach the new VMA to the parent VMA's anon_vmas,
98844 * so rmap can find non-COWed pages in child processes.
98845 */
98846 - if (anon_vma_clone(vma, pvma))
98847 - return -ENOMEM;
98848 + error = anon_vma_clone(vma, pvma);
98849 + if (error)
98850 + return error;
98851
98852 /* Then add our own anon_vma. */
98853 anon_vma = anon_vma_alloc();
98854 @@ -374,8 +410,10 @@ static void anon_vma_ctor(void *data)
98855 void __init anon_vma_init(void)
98856 {
98857 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
98858 - 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
98859 - anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
98860 + 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
98861 + anon_vma_ctor);
98862 + anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
98863 + SLAB_PANIC|SLAB_NO_SANITIZE);
98864 }
98865
98866 /*
98867 diff --git a/mm/shmem.c b/mm/shmem.c
98868 index 469f90d..34a09ee 100644
98869 --- a/mm/shmem.c
98870 +++ b/mm/shmem.c
98871 @@ -33,7 +33,7 @@
98872 #include <linux/swap.h>
98873 #include <linux/aio.h>
98874
98875 -static struct vfsmount *shm_mnt;
98876 +struct vfsmount *shm_mnt;
98877
98878 #ifdef CONFIG_SHMEM
98879 /*
98880 @@ -80,7 +80,7 @@ static struct vfsmount *shm_mnt;
98881 #define BOGO_DIRENT_SIZE 20
98882
98883 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
98884 -#define SHORT_SYMLINK_LEN 128
98885 +#define SHORT_SYMLINK_LEN 64
98886
98887 /*
98888 * shmem_fallocate communicates with shmem_fault or shmem_writepage via
98889 @@ -2524,6 +2524,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
98890 static int shmem_xattr_validate(const char *name)
98891 {
98892 struct { const char *prefix; size_t len; } arr[] = {
98893 +
98894 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
98895 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
98896 +#endif
98897 +
98898 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
98899 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
98900 };
98901 @@ -2579,6 +2584,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
98902 if (err)
98903 return err;
98904
98905 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
98906 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
98907 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
98908 + return -EOPNOTSUPP;
98909 + if (size > 8)
98910 + return -EINVAL;
98911 + }
98912 +#endif
98913 +
98914 return simple_xattr_set(&info->xattrs, name, value, size, flags);
98915 }
98916
98917 @@ -2962,8 +2976,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
98918 int err = -ENOMEM;
98919
98920 /* Round up to L1_CACHE_BYTES to resist false sharing */
98921 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
98922 - L1_CACHE_BYTES), GFP_KERNEL);
98923 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
98924 if (!sbinfo)
98925 return -ENOMEM;
98926
98927 diff --git a/mm/slab.c b/mm/slab.c
98928 index 7c52b38..3ccc17e 100644
98929 --- a/mm/slab.c
98930 +++ b/mm/slab.c
98931 @@ -316,10 +316,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
98932 if ((x)->max_freeable < i) \
98933 (x)->max_freeable = i; \
98934 } while (0)
98935 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
98936 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
98937 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
98938 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
98939 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
98940 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
98941 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
98942 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
98943 +#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
98944 +#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
98945 #else
98946 #define STATS_INC_ACTIVE(x) do { } while (0)
98947 #define STATS_DEC_ACTIVE(x) do { } while (0)
98948 @@ -336,6 +338,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
98949 #define STATS_INC_ALLOCMISS(x) do { } while (0)
98950 #define STATS_INC_FREEHIT(x) do { } while (0)
98951 #define STATS_INC_FREEMISS(x) do { } while (0)
98952 +#define STATS_INC_SANITIZED(x) do { } while (0)
98953 +#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
98954 #endif
98955
98956 #if DEBUG
98957 @@ -452,7 +456,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
98958 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
98959 */
98960 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
98961 - const struct page *page, void *obj)
98962 + const struct page *page, const void *obj)
98963 {
98964 u32 offset = (obj - page->s_mem);
98965 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
98966 @@ -1462,12 +1466,12 @@ void __init kmem_cache_init(void)
98967 */
98968
98969 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
98970 - kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
98971 + kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
98972
98973 if (INDEX_AC != INDEX_NODE)
98974 kmalloc_caches[INDEX_NODE] =
98975 create_kmalloc_cache("kmalloc-node",
98976 - kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
98977 + kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
98978
98979 slab_early_init = 0;
98980
98981 @@ -3384,6 +3388,20 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
98982 struct array_cache *ac = cpu_cache_get(cachep);
98983
98984 check_irq_off();
98985 +
98986 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
98987 + if (cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))
98988 + STATS_INC_NOT_SANITIZED(cachep);
98989 + else {
98990 + memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
98991 +
98992 + if (cachep->ctor)
98993 + cachep->ctor(objp);
98994 +
98995 + STATS_INC_SANITIZED(cachep);
98996 + }
98997 +#endif
98998 +
98999 kmemleak_free_recursive(objp, cachep->flags);
99000 objp = cache_free_debugcheck(cachep, objp, caller);
99001
99002 @@ -3607,6 +3625,7 @@ void kfree(const void *objp)
99003
99004 if (unlikely(ZERO_OR_NULL_PTR(objp)))
99005 return;
99006 + VM_BUG_ON(!virt_addr_valid(objp));
99007 local_irq_save(flags);
99008 kfree_debugcheck(objp);
99009 c = virt_to_cache(objp);
99010 @@ -4056,14 +4075,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
99011 }
99012 /* cpu stats */
99013 {
99014 - unsigned long allochit = atomic_read(&cachep->allochit);
99015 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
99016 - unsigned long freehit = atomic_read(&cachep->freehit);
99017 - unsigned long freemiss = atomic_read(&cachep->freemiss);
99018 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
99019 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
99020 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
99021 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
99022
99023 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
99024 allochit, allocmiss, freehit, freemiss);
99025 }
99026 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99027 + {
99028 + unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
99029 + unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
99030 +
99031 + seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
99032 + }
99033 +#endif
99034 #endif
99035 }
99036
99037 @@ -4281,13 +4308,69 @@ static const struct file_operations proc_slabstats_operations = {
99038 static int __init slab_proc_init(void)
99039 {
99040 #ifdef CONFIG_DEBUG_SLAB_LEAK
99041 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
99042 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
99043 #endif
99044 return 0;
99045 }
99046 module_init(slab_proc_init);
99047 #endif
99048
99049 +bool is_usercopy_object(const void *ptr)
99050 +{
99051 + struct page *page;
99052 + struct kmem_cache *cachep;
99053 +
99054 + if (ZERO_OR_NULL_PTR(ptr))
99055 + return false;
99056 +
99057 + if (!slab_is_available())
99058 + return false;
99059 +
99060 + if (!virt_addr_valid(ptr))
99061 + return false;
99062 +
99063 + page = virt_to_head_page(ptr);
99064 +
99065 + if (!PageSlab(page))
99066 + return false;
99067 +
99068 + cachep = page->slab_cache;
99069 + return cachep->flags & SLAB_USERCOPY;
99070 +}
99071 +
99072 +#ifdef CONFIG_PAX_USERCOPY
99073 +const char *check_heap_object(const void *ptr, unsigned long n)
99074 +{
99075 + struct page *page;
99076 + struct kmem_cache *cachep;
99077 + unsigned int objnr;
99078 + unsigned long offset;
99079 +
99080 + if (ZERO_OR_NULL_PTR(ptr))
99081 + return "<null>";
99082 +
99083 + if (!virt_addr_valid(ptr))
99084 + return NULL;
99085 +
99086 + page = virt_to_head_page(ptr);
99087 +
99088 + if (!PageSlab(page))
99089 + return NULL;
99090 +
99091 + cachep = page->slab_cache;
99092 + if (!(cachep->flags & SLAB_USERCOPY))
99093 + return cachep->name;
99094 +
99095 + objnr = obj_to_index(cachep, page, ptr);
99096 + BUG_ON(objnr >= cachep->num);
99097 + offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
99098 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
99099 + return NULL;
99100 +
99101 + return cachep->name;
99102 +}
99103 +#endif
99104 +
99105 /**
99106 * ksize - get the actual amount of memory allocated for a given object
99107 * @objp: Pointer to the object
99108 diff --git a/mm/slab.h b/mm/slab.h
99109 index 0e0fdd3..d0fd761 100644
99110 --- a/mm/slab.h
99111 +++ b/mm/slab.h
99112 @@ -32,6 +32,20 @@ extern struct list_head slab_caches;
99113 /* The slab cache that manages slab cache information */
99114 extern struct kmem_cache *kmem_cache;
99115
99116 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99117 +#ifdef CONFIG_X86_64
99118 +#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
99119 +#else
99120 +#define PAX_MEMORY_SANITIZE_VALUE '\xff'
99121 +#endif
99122 +enum pax_sanitize_mode {
99123 + PAX_SANITIZE_SLAB_OFF = 0,
99124 + PAX_SANITIZE_SLAB_FAST,
99125 + PAX_SANITIZE_SLAB_FULL,
99126 +};
99127 +extern enum pax_sanitize_mode pax_sanitize_slab;
99128 +#endif
99129 +
99130 unsigned long calculate_alignment(unsigned long flags,
99131 unsigned long align, unsigned long size);
99132
99133 @@ -67,7 +81,8 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
99134
99135 /* Legal flag mask for kmem_cache_create(), for various configurations */
99136 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
99137 - SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
99138 + SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
99139 + SLAB_USERCOPY | SLAB_NO_SANITIZE)
99140
99141 #if defined(CONFIG_DEBUG_SLAB)
99142 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
99143 @@ -251,6 +266,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
99144 return s;
99145
99146 page = virt_to_head_page(x);
99147 +
99148 + BUG_ON(!PageSlab(page));
99149 +
99150 cachep = page->slab_cache;
99151 if (slab_equal_or_root(cachep, s))
99152 return cachep;
99153 diff --git a/mm/slab_common.c b/mm/slab_common.c
99154 index d319502..da7714e 100644
99155 --- a/mm/slab_common.c
99156 +++ b/mm/slab_common.c
99157 @@ -25,11 +25,35 @@
99158
99159 #include "slab.h"
99160
99161 -enum slab_state slab_state;
99162 +enum slab_state slab_state __read_only;
99163 LIST_HEAD(slab_caches);
99164 DEFINE_MUTEX(slab_mutex);
99165 struct kmem_cache *kmem_cache;
99166
99167 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99168 +enum pax_sanitize_mode pax_sanitize_slab __read_only = PAX_SANITIZE_SLAB_FAST;
99169 +static int __init pax_sanitize_slab_setup(char *str)
99170 +{
99171 + if (!str)
99172 + return 0;
99173 +
99174 + if (!strcmp(str, "0") || !strcmp(str, "off")) {
99175 + pr_info("PaX slab sanitization: %s\n", "disabled");
99176 + pax_sanitize_slab = PAX_SANITIZE_SLAB_OFF;
99177 + } else if (!strcmp(str, "1") || !strcmp(str, "fast")) {
99178 + pr_info("PaX slab sanitization: %s\n", "fast");
99179 + pax_sanitize_slab = PAX_SANITIZE_SLAB_FAST;
99180 + } else if (!strcmp(str, "full")) {
99181 + pr_info("PaX slab sanitization: %s\n", "full");
99182 + pax_sanitize_slab = PAX_SANITIZE_SLAB_FULL;
99183 + } else
99184 + pr_err("PaX slab sanitization: unsupported option '%s'\n", str);
99185 +
99186 + return 0;
99187 +}
99188 +early_param("pax_sanitize_slab", pax_sanitize_slab_setup);
99189 +#endif
99190 +
99191 #ifdef CONFIG_DEBUG_VM
99192 static int kmem_cache_sanity_check(const char *name, size_t size)
99193 {
99194 @@ -160,7 +184,7 @@ do_kmem_cache_create(char *name, size_t object_size, size_t size, size_t align,
99195 if (err)
99196 goto out_free_cache;
99197
99198 - s->refcount = 1;
99199 + atomic_set(&s->refcount, 1);
99200 list_add(&s->list, &slab_caches);
99201 out:
99202 if (err)
99203 @@ -222,6 +246,13 @@ kmem_cache_create(const char *name, size_t size, size_t align,
99204 */
99205 flags &= CACHE_CREATE_MASK;
99206
99207 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99208 + if (pax_sanitize_slab == PAX_SANITIZE_SLAB_OFF || (flags & SLAB_DESTROY_BY_RCU))
99209 + flags |= SLAB_NO_SANITIZE;
99210 + else if (pax_sanitize_slab == PAX_SANITIZE_SLAB_FULL)
99211 + flags &= ~SLAB_NO_SANITIZE;
99212 +#endif
99213 +
99214 s = __kmem_cache_alias(name, size, align, flags, ctor);
99215 if (s)
99216 goto out_unlock;
99217 @@ -341,8 +372,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
99218
99219 mutex_lock(&slab_mutex);
99220
99221 - s->refcount--;
99222 - if (s->refcount)
99223 + if (!atomic_dec_and_test(&s->refcount))
99224 goto out_unlock;
99225
99226 if (memcg_cleanup_cache_params(s) != 0)
99227 @@ -362,7 +392,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
99228 rcu_barrier();
99229
99230 memcg_free_cache_params(s);
99231 -#ifdef SLAB_SUPPORTS_SYSFS
99232 +#if defined(SLAB_SUPPORTS_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99233 sysfs_slab_remove(s);
99234 #else
99235 slab_kmem_cache_release(s);
99236 @@ -418,7 +448,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
99237 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
99238 name, size, err);
99239
99240 - s->refcount = -1; /* Exempt from merging for now */
99241 + atomic_set(&s->refcount, -1); /* Exempt from merging for now */
99242 }
99243
99244 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
99245 @@ -431,7 +461,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
99246
99247 create_boot_cache(s, name, size, flags);
99248 list_add(&s->list, &slab_caches);
99249 - s->refcount = 1;
99250 + atomic_set(&s->refcount, 1);
99251 return s;
99252 }
99253
99254 @@ -443,6 +473,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
99255 EXPORT_SYMBOL(kmalloc_dma_caches);
99256 #endif
99257
99258 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99259 +struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
99260 +EXPORT_SYMBOL(kmalloc_usercopy_caches);
99261 +#endif
99262 +
99263 /*
99264 * Conversion table for small slabs sizes / 8 to the index in the
99265 * kmalloc array. This is necessary for slabs < 192 since we have non power
99266 @@ -507,6 +542,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
99267 return kmalloc_dma_caches[index];
99268
99269 #endif
99270 +
99271 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99272 + if (unlikely((flags & GFP_USERCOPY)))
99273 + return kmalloc_usercopy_caches[index];
99274 +
99275 +#endif
99276 +
99277 return kmalloc_caches[index];
99278 }
99279
99280 @@ -563,7 +605,7 @@ void __init create_kmalloc_caches(unsigned long flags)
99281 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
99282 if (!kmalloc_caches[i]) {
99283 kmalloc_caches[i] = create_kmalloc_cache(NULL,
99284 - 1 << i, flags);
99285 + 1 << i, SLAB_USERCOPY | flags);
99286 }
99287
99288 /*
99289 @@ -572,10 +614,10 @@ void __init create_kmalloc_caches(unsigned long flags)
99290 * earlier power of two caches
99291 */
99292 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
99293 - kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
99294 + kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
99295
99296 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
99297 - kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
99298 + kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
99299 }
99300
99301 /* Kmalloc array is now usable */
99302 @@ -608,6 +650,23 @@ void __init create_kmalloc_caches(unsigned long flags)
99303 }
99304 }
99305 #endif
99306 +
99307 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99308 + for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
99309 + struct kmem_cache *s = kmalloc_caches[i];
99310 +
99311 + if (s) {
99312 + int size = kmalloc_size(i);
99313 + char *n = kasprintf(GFP_NOWAIT,
99314 + "usercopy-kmalloc-%d", size);
99315 +
99316 + BUG_ON(!n);
99317 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
99318 + size, SLAB_USERCOPY | flags);
99319 + }
99320 + }
99321 +#endif
99322 +
99323 }
99324 #endif /* !CONFIG_SLOB */
99325
99326 @@ -666,6 +725,9 @@ void print_slabinfo_header(struct seq_file *m)
99327 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
99328 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
99329 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
99330 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99331 + seq_puts(m, " : pax <sanitized> <not_sanitized>");
99332 +#endif
99333 #endif
99334 seq_putc(m, '\n');
99335 }
99336 diff --git a/mm/slob.c b/mm/slob.c
99337 index 21980e0..975f1bf 100644
99338 --- a/mm/slob.c
99339 +++ b/mm/slob.c
99340 @@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
99341 /*
99342 * Return the size of a slob block.
99343 */
99344 -static slobidx_t slob_units(slob_t *s)
99345 +static slobidx_t slob_units(const slob_t *s)
99346 {
99347 if (s->units > 0)
99348 return s->units;
99349 @@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
99350 /*
99351 * Return the next free slob block pointer after this one.
99352 */
99353 -static slob_t *slob_next(slob_t *s)
99354 +static slob_t *slob_next(const slob_t *s)
99355 {
99356 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
99357 slobidx_t next;
99358 @@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
99359 /*
99360 * Returns true if s is the last free block in its page.
99361 */
99362 -static int slob_last(slob_t *s)
99363 +static int slob_last(const slob_t *s)
99364 {
99365 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
99366 }
99367
99368 -static void *slob_new_pages(gfp_t gfp, int order, int node)
99369 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
99370 {
99371 - void *page;
99372 + struct page *page;
99373
99374 #ifdef CONFIG_NUMA
99375 if (node != NUMA_NO_NODE)
99376 @@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
99377 if (!page)
99378 return NULL;
99379
99380 - return page_address(page);
99381 + __SetPageSlab(page);
99382 + return page;
99383 }
99384
99385 -static void slob_free_pages(void *b, int order)
99386 +static void slob_free_pages(struct page *sp, int order)
99387 {
99388 if (current->reclaim_state)
99389 current->reclaim_state->reclaimed_slab += 1 << order;
99390 - free_pages((unsigned long)b, order);
99391 + __ClearPageSlab(sp);
99392 + page_mapcount_reset(sp);
99393 + sp->private = 0;
99394 + __free_pages(sp, order);
99395 }
99396
99397 /*
99398 @@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
99399
99400 /* Not enough space: must allocate a new page */
99401 if (!b) {
99402 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
99403 - if (!b)
99404 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
99405 + if (!sp)
99406 return NULL;
99407 - sp = virt_to_page(b);
99408 - __SetPageSlab(sp);
99409 + b = page_address(sp);
99410
99411 spin_lock_irqsave(&slob_lock, flags);
99412 sp->units = SLOB_UNITS(PAGE_SIZE);
99413 sp->freelist = b;
99414 + sp->private = 0;
99415 INIT_LIST_HEAD(&sp->lru);
99416 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
99417 set_slob_page_free(sp, slob_list);
99418 @@ -337,7 +341,7 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
99419 /*
99420 * slob_free: entry point into the slob allocator.
99421 */
99422 -static void slob_free(void *block, int size)
99423 +static void slob_free(struct kmem_cache *c, void *block, int size)
99424 {
99425 struct page *sp;
99426 slob_t *prev, *next, *b = (slob_t *)block;
99427 @@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
99428 if (slob_page_free(sp))
99429 clear_slob_page_free(sp);
99430 spin_unlock_irqrestore(&slob_lock, flags);
99431 - __ClearPageSlab(sp);
99432 - page_mapcount_reset(sp);
99433 - slob_free_pages(b, 0);
99434 + slob_free_pages(sp, 0);
99435 return;
99436 }
99437
99438 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99439 + if (pax_sanitize_slab && !(c && (c->flags & SLAB_NO_SANITIZE)))
99440 + memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
99441 +#endif
99442 +
99443 if (!slob_page_free(sp)) {
99444 /* This slob page is about to become partially free. Easy! */
99445 sp->units = units;
99446 @@ -424,11 +431,10 @@ out:
99447 */
99448
99449 static __always_inline void *
99450 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
99451 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
99452 {
99453 - unsigned int *m;
99454 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99455 - void *ret;
99456 + slob_t *m;
99457 + void *ret = NULL;
99458
99459 gfp &= gfp_allowed_mask;
99460
99461 @@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
99462
99463 if (!m)
99464 return NULL;
99465 - *m = size;
99466 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
99467 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
99468 + m[0].units = size;
99469 + m[1].units = align;
99470 ret = (void *)m + align;
99471
99472 trace_kmalloc_node(caller, ret,
99473 size, size + align, gfp, node);
99474 } else {
99475 unsigned int order = get_order(size);
99476 + struct page *page;
99477
99478 if (likely(order))
99479 gfp |= __GFP_COMP;
99480 - ret = slob_new_pages(gfp, order, node);
99481 + page = slob_new_pages(gfp, order, node);
99482 + if (page) {
99483 + ret = page_address(page);
99484 + page->private = size;
99485 + }
99486
99487 trace_kmalloc_node(caller, ret,
99488 size, PAGE_SIZE << order, gfp, node);
99489 }
99490
99491 - kmemleak_alloc(ret, size, 1, gfp);
99492 + return ret;
99493 +}
99494 +
99495 +static __always_inline void *
99496 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
99497 +{
99498 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99499 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
99500 +
99501 + if (!ZERO_OR_NULL_PTR(ret))
99502 + kmemleak_alloc(ret, size, 1, gfp);
99503 return ret;
99504 }
99505
99506 @@ -493,34 +517,112 @@ void kfree(const void *block)
99507 return;
99508 kmemleak_free(block);
99509
99510 + VM_BUG_ON(!virt_addr_valid(block));
99511 sp = virt_to_page(block);
99512 - if (PageSlab(sp)) {
99513 + VM_BUG_ON(!PageSlab(sp));
99514 + if (!sp->private) {
99515 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99516 - unsigned int *m = (unsigned int *)(block - align);
99517 - slob_free(m, *m + align);
99518 - } else
99519 + slob_t *m = (slob_t *)(block - align);
99520 + slob_free(NULL, m, m[0].units + align);
99521 + } else {
99522 + __ClearPageSlab(sp);
99523 + page_mapcount_reset(sp);
99524 + sp->private = 0;
99525 __free_pages(sp, compound_order(sp));
99526 + }
99527 }
99528 EXPORT_SYMBOL(kfree);
99529
99530 +bool is_usercopy_object(const void *ptr)
99531 +{
99532 + if (!slab_is_available())
99533 + return false;
99534 +
99535 + // PAX: TODO
99536 +
99537 + return false;
99538 +}
99539 +
99540 +#ifdef CONFIG_PAX_USERCOPY
99541 +const char *check_heap_object(const void *ptr, unsigned long n)
99542 +{
99543 + struct page *page;
99544 + const slob_t *free;
99545 + const void *base;
99546 + unsigned long flags;
99547 +
99548 + if (ZERO_OR_NULL_PTR(ptr))
99549 + return "<null>";
99550 +
99551 + if (!virt_addr_valid(ptr))
99552 + return NULL;
99553 +
99554 + page = virt_to_head_page(ptr);
99555 + if (!PageSlab(page))
99556 + return NULL;
99557 +
99558 + if (page->private) {
99559 + base = page;
99560 + if (base <= ptr && n <= page->private - (ptr - base))
99561 + return NULL;
99562 + return "<slob>";
99563 + }
99564 +
99565 + /* some tricky double walking to find the chunk */
99566 + spin_lock_irqsave(&slob_lock, flags);
99567 + base = (void *)((unsigned long)ptr & PAGE_MASK);
99568 + free = page->freelist;
99569 +
99570 + while (!slob_last(free) && (void *)free <= ptr) {
99571 + base = free + slob_units(free);
99572 + free = slob_next(free);
99573 + }
99574 +
99575 + while (base < (void *)free) {
99576 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
99577 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
99578 + int offset;
99579 +
99580 + if (ptr < base + align)
99581 + break;
99582 +
99583 + offset = ptr - base - align;
99584 + if (offset >= m) {
99585 + base += size;
99586 + continue;
99587 + }
99588 +
99589 + if (n > m - offset)
99590 + break;
99591 +
99592 + spin_unlock_irqrestore(&slob_lock, flags);
99593 + return NULL;
99594 + }
99595 +
99596 + spin_unlock_irqrestore(&slob_lock, flags);
99597 + return "<slob>";
99598 +}
99599 +#endif
99600 +
99601 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
99602 size_t ksize(const void *block)
99603 {
99604 struct page *sp;
99605 int align;
99606 - unsigned int *m;
99607 + slob_t *m;
99608
99609 BUG_ON(!block);
99610 if (unlikely(block == ZERO_SIZE_PTR))
99611 return 0;
99612
99613 sp = virt_to_page(block);
99614 - if (unlikely(!PageSlab(sp)))
99615 - return PAGE_SIZE << compound_order(sp);
99616 + VM_BUG_ON(!PageSlab(sp));
99617 + if (sp->private)
99618 + return sp->private;
99619
99620 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99621 - m = (unsigned int *)(block - align);
99622 - return SLOB_UNITS(*m) * SLOB_UNIT;
99623 + m = (slob_t *)(block - align);
99624 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
99625 }
99626 EXPORT_SYMBOL(ksize);
99627
99628 @@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
99629
99630 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
99631 {
99632 - void *b;
99633 + void *b = NULL;
99634
99635 flags &= gfp_allowed_mask;
99636
99637 lockdep_trace_alloc(flags);
99638
99639 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99640 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
99641 +#else
99642 if (c->size < PAGE_SIZE) {
99643 b = slob_alloc(c->size, flags, c->align, node);
99644 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
99645 SLOB_UNITS(c->size) * SLOB_UNIT,
99646 flags, node);
99647 } else {
99648 - b = slob_new_pages(flags, get_order(c->size), node);
99649 + struct page *sp;
99650 +
99651 + sp = slob_new_pages(flags, get_order(c->size), node);
99652 + if (sp) {
99653 + b = page_address(sp);
99654 + sp->private = c->size;
99655 + }
99656 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
99657 PAGE_SIZE << get_order(c->size),
99658 flags, node);
99659 }
99660 +#endif
99661
99662 if (b && c->ctor)
99663 c->ctor(b);
99664 @@ -582,12 +694,16 @@ void *kmem_cache_alloc_node(struct kmem_cache *cachep, gfp_t gfp, int node)
99665 EXPORT_SYMBOL(kmem_cache_alloc_node);
99666 #endif
99667
99668 -static void __kmem_cache_free(void *b, int size)
99669 +static void __kmem_cache_free(struct kmem_cache *c, void *b, int size)
99670 {
99671 - if (size < PAGE_SIZE)
99672 - slob_free(b, size);
99673 + struct page *sp;
99674 +
99675 + sp = virt_to_page(b);
99676 + BUG_ON(!PageSlab(sp));
99677 + if (!sp->private)
99678 + slob_free(c, b, size);
99679 else
99680 - slob_free_pages(b, get_order(size));
99681 + slob_free_pages(sp, get_order(size));
99682 }
99683
99684 static void kmem_rcu_free(struct rcu_head *head)
99685 @@ -595,22 +711,36 @@ static void kmem_rcu_free(struct rcu_head *head)
99686 struct slob_rcu *slob_rcu = (struct slob_rcu *)head;
99687 void *b = (void *)slob_rcu - (slob_rcu->size - sizeof(struct slob_rcu));
99688
99689 - __kmem_cache_free(b, slob_rcu->size);
99690 + __kmem_cache_free(NULL, b, slob_rcu->size);
99691 }
99692
99693 void kmem_cache_free(struct kmem_cache *c, void *b)
99694 {
99695 + int size = c->size;
99696 +
99697 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99698 + if (size + c->align < PAGE_SIZE) {
99699 + size += c->align;
99700 + b -= c->align;
99701 + }
99702 +#endif
99703 +
99704 kmemleak_free_recursive(b, c->flags);
99705 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
99706 struct slob_rcu *slob_rcu;
99707 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
99708 - slob_rcu->size = c->size;
99709 + slob_rcu = b + (size - sizeof(struct slob_rcu));
99710 + slob_rcu->size = size;
99711 call_rcu(&slob_rcu->head, kmem_rcu_free);
99712 } else {
99713 - __kmem_cache_free(b, c->size);
99714 + __kmem_cache_free(c, b, size);
99715 }
99716
99717 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99718 + trace_kfree(_RET_IP_, b);
99719 +#else
99720 trace_kmem_cache_free(_RET_IP_, b);
99721 +#endif
99722 +
99723 }
99724 EXPORT_SYMBOL(kmem_cache_free);
99725
99726 diff --git a/mm/slub.c b/mm/slub.c
99727 index 3e8afcc..d6e2c89 100644
99728 --- a/mm/slub.c
99729 +++ b/mm/slub.c
99730 @@ -207,7 +207,7 @@ struct track {
99731
99732 enum track_item { TRACK_ALLOC, TRACK_FREE };
99733
99734 -#ifdef CONFIG_SYSFS
99735 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99736 static int sysfs_slab_add(struct kmem_cache *);
99737 static int sysfs_slab_alias(struct kmem_cache *, const char *);
99738 static void memcg_propagate_slab_attrs(struct kmem_cache *s);
99739 @@ -545,7 +545,7 @@ static void print_track(const char *s, struct track *t)
99740 if (!t->addr)
99741 return;
99742
99743 - pr_err("INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
99744 + pr_err("INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
99745 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
99746 #ifdef CONFIG_STACKTRACE
99747 {
99748 @@ -2643,6 +2643,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
99749
99750 slab_free_hook(s, x);
99751
99752 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99753 + if (!(s->flags & SLAB_NO_SANITIZE)) {
99754 + memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
99755 + if (s->ctor)
99756 + s->ctor(x);
99757 + }
99758 +#endif
99759 +
99760 redo:
99761 /*
99762 * Determine the currently cpus per cpu slab.
99763 @@ -2710,7 +2718,7 @@ static int slub_min_objects;
99764 * Merge control. If this is set then no merging of slab caches will occur.
99765 * (Could be removed. This was introduced to pacify the merge skeptics.)
99766 */
99767 -static int slub_nomerge;
99768 +static int slub_nomerge = 1;
99769
99770 /*
99771 * Calculate the order of allocation given an slab object size.
99772 @@ -2986,6 +2994,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
99773 s->inuse = size;
99774
99775 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
99776 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99777 + (!(flags & SLAB_NO_SANITIZE)) ||
99778 +#endif
99779 s->ctor)) {
99780 /*
99781 * Relocate free pointer after the object if it is not
99782 @@ -3313,6 +3324,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
99783 EXPORT_SYMBOL(__kmalloc_node);
99784 #endif
99785
99786 +bool is_usercopy_object(const void *ptr)
99787 +{
99788 + struct page *page;
99789 + struct kmem_cache *s;
99790 +
99791 + if (ZERO_OR_NULL_PTR(ptr))
99792 + return false;
99793 +
99794 + if (!slab_is_available())
99795 + return false;
99796 +
99797 + if (!virt_addr_valid(ptr))
99798 + return false;
99799 +
99800 + page = virt_to_head_page(ptr);
99801 +
99802 + if (!PageSlab(page))
99803 + return false;
99804 +
99805 + s = page->slab_cache;
99806 + return s->flags & SLAB_USERCOPY;
99807 +}
99808 +
99809 +#ifdef CONFIG_PAX_USERCOPY
99810 +const char *check_heap_object(const void *ptr, unsigned long n)
99811 +{
99812 + struct page *page;
99813 + struct kmem_cache *s;
99814 + unsigned long offset;
99815 +
99816 + if (ZERO_OR_NULL_PTR(ptr))
99817 + return "<null>";
99818 +
99819 + if (!virt_addr_valid(ptr))
99820 + return NULL;
99821 +
99822 + page = virt_to_head_page(ptr);
99823 +
99824 + if (!PageSlab(page))
99825 + return NULL;
99826 +
99827 + s = page->slab_cache;
99828 + if (!(s->flags & SLAB_USERCOPY))
99829 + return s->name;
99830 +
99831 + offset = (ptr - page_address(page)) % s->size;
99832 + if (offset <= s->object_size && n <= s->object_size - offset)
99833 + return NULL;
99834 +
99835 + return s->name;
99836 +}
99837 +#endif
99838 +
99839 size_t ksize(const void *object)
99840 {
99841 struct page *page;
99842 @@ -3341,6 +3405,7 @@ void kfree(const void *x)
99843 if (unlikely(ZERO_OR_NULL_PTR(x)))
99844 return;
99845
99846 + VM_BUG_ON(!virt_addr_valid(x));
99847 page = virt_to_head_page(x);
99848 if (unlikely(!PageSlab(page))) {
99849 BUG_ON(!PageCompound(page));
99850 @@ -3642,7 +3707,7 @@ static int slab_unmergeable(struct kmem_cache *s)
99851 /*
99852 * We may have set a slab to be unmergeable during bootstrap.
99853 */
99854 - if (s->refcount < 0)
99855 + if (atomic_read(&s->refcount) < 0)
99856 return 1;
99857
99858 return 0;
99859 @@ -3699,7 +3764,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
99860 int i;
99861 struct kmem_cache *c;
99862
99863 - s->refcount++;
99864 + atomic_inc(&s->refcount);
99865
99866 /*
99867 * Adjust the object sizes so that we clear
99868 @@ -3718,7 +3783,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
99869 }
99870
99871 if (sysfs_slab_alias(s, name)) {
99872 - s->refcount--;
99873 + atomic_dec(&s->refcount);
99874 s = NULL;
99875 }
99876 }
99877 @@ -3835,7 +3900,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
99878 }
99879 #endif
99880
99881 -#ifdef CONFIG_SYSFS
99882 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99883 static int count_inuse(struct page *page)
99884 {
99885 return page->inuse;
99886 @@ -4116,7 +4181,11 @@ static int list_locations(struct kmem_cache *s, char *buf,
99887 len += sprintf(buf + len, "%7ld ", l->count);
99888
99889 if (l->addr)
99890 +#ifdef CONFIG_GRKERNSEC_HIDESYM
99891 + len += sprintf(buf + len, "%pS", NULL);
99892 +#else
99893 len += sprintf(buf + len, "%pS", (void *)l->addr);
99894 +#endif
99895 else
99896 len += sprintf(buf + len, "<not-available>");
99897
99898 @@ -4218,12 +4287,12 @@ static void __init resiliency_test(void)
99899 validate_slab_cache(kmalloc_caches[9]);
99900 }
99901 #else
99902 -#ifdef CONFIG_SYSFS
99903 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99904 static void resiliency_test(void) {};
99905 #endif
99906 #endif
99907
99908 -#ifdef CONFIG_SYSFS
99909 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99910 enum slab_stat_type {
99911 SL_ALL, /* All slabs */
99912 SL_PARTIAL, /* Only partially allocated slabs */
99913 @@ -4460,13 +4529,17 @@ static ssize_t ctor_show(struct kmem_cache *s, char *buf)
99914 {
99915 if (!s->ctor)
99916 return 0;
99917 +#ifdef CONFIG_GRKERNSEC_HIDESYM
99918 + return sprintf(buf, "%pS\n", NULL);
99919 +#else
99920 return sprintf(buf, "%pS\n", s->ctor);
99921 +#endif
99922 }
99923 SLAB_ATTR_RO(ctor);
99924
99925 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
99926 {
99927 - return sprintf(buf, "%d\n", s->refcount < 0 ? 0 : s->refcount - 1);
99928 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) < 0 ? 0 : atomic_read(&s->refcount) - 1);
99929 }
99930 SLAB_ATTR_RO(aliases);
99931
99932 @@ -4554,6 +4627,22 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
99933 SLAB_ATTR_RO(cache_dma);
99934 #endif
99935
99936 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99937 +static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
99938 +{
99939 + return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
99940 +}
99941 +SLAB_ATTR_RO(usercopy);
99942 +#endif
99943 +
99944 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99945 +static ssize_t sanitize_show(struct kmem_cache *s, char *buf)
99946 +{
99947 + return sprintf(buf, "%d\n", !(s->flags & SLAB_NO_SANITIZE));
99948 +}
99949 +SLAB_ATTR_RO(sanitize);
99950 +#endif
99951 +
99952 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
99953 {
99954 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
99955 @@ -4888,6 +4977,12 @@ static struct attribute *slab_attrs[] = {
99956 #ifdef CONFIG_ZONE_DMA
99957 &cache_dma_attr.attr,
99958 #endif
99959 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99960 + &usercopy_attr.attr,
99961 +#endif
99962 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99963 + &sanitize_attr.attr,
99964 +#endif
99965 #ifdef CONFIG_NUMA
99966 &remote_node_defrag_ratio_attr.attr,
99967 #endif
99968 @@ -5132,6 +5227,7 @@ static char *create_unique_id(struct kmem_cache *s)
99969 return name;
99970 }
99971
99972 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99973 static int sysfs_slab_add(struct kmem_cache *s)
99974 {
99975 int err;
99976 @@ -5205,6 +5301,7 @@ void sysfs_slab_remove(struct kmem_cache *s)
99977 kobject_del(&s->kobj);
99978 kobject_put(&s->kobj);
99979 }
99980 +#endif
99981
99982 /*
99983 * Need to buffer aliases during bootup until sysfs becomes
99984 @@ -5218,6 +5315,7 @@ struct saved_alias {
99985
99986 static struct saved_alias *alias_list;
99987
99988 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99989 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
99990 {
99991 struct saved_alias *al;
99992 @@ -5240,6 +5338,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
99993 alias_list = al;
99994 return 0;
99995 }
99996 +#endif
99997
99998 static int __init slab_sysfs_init(void)
99999 {
100000 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
100001 index 4cba9c2..b4f9fcc 100644
100002 --- a/mm/sparse-vmemmap.c
100003 +++ b/mm/sparse-vmemmap.c
100004 @@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
100005 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
100006 if (!p)
100007 return NULL;
100008 - pud_populate(&init_mm, pud, p);
100009 + pud_populate_kernel(&init_mm, pud, p);
100010 }
100011 return pud;
100012 }
100013 @@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
100014 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
100015 if (!p)
100016 return NULL;
100017 - pgd_populate(&init_mm, pgd, p);
100018 + pgd_populate_kernel(&init_mm, pgd, p);
100019 }
100020 return pgd;
100021 }
100022 diff --git a/mm/sparse.c b/mm/sparse.c
100023 index d1b48b6..6e8590e 100644
100024 --- a/mm/sparse.c
100025 +++ b/mm/sparse.c
100026 @@ -750,7 +750,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
100027
100028 for (i = 0; i < PAGES_PER_SECTION; i++) {
100029 if (PageHWPoison(&memmap[i])) {
100030 - atomic_long_sub(1, &num_poisoned_pages);
100031 + atomic_long_sub_unchecked(1, &num_poisoned_pages);
100032 ClearPageHWPoison(&memmap[i]);
100033 }
100034 }
100035 diff --git a/mm/swap.c b/mm/swap.c
100036 index 6b2dc38..46b79ba 100644
100037 --- a/mm/swap.c
100038 +++ b/mm/swap.c
100039 @@ -31,6 +31,7 @@
100040 #include <linux/memcontrol.h>
100041 #include <linux/gfp.h>
100042 #include <linux/uio.h>
100043 +#include <linux/hugetlb.h>
100044
100045 #include "internal.h"
100046
100047 @@ -77,6 +78,8 @@ static void __put_compound_page(struct page *page)
100048
100049 __page_cache_release(page);
100050 dtor = get_compound_page_dtor(page);
100051 + if (!PageHuge(page))
100052 + BUG_ON(dtor != free_compound_page);
100053 (*dtor)(page);
100054 }
100055
100056 diff --git a/mm/swapfile.c b/mm/swapfile.c
100057 index 8798b2e..348f9dd 100644
100058 --- a/mm/swapfile.c
100059 +++ b/mm/swapfile.c
100060 @@ -84,7 +84,7 @@ static DEFINE_MUTEX(swapon_mutex);
100061
100062 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
100063 /* Activity counter to indicate that a swapon or swapoff has occurred */
100064 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
100065 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
100066
100067 static inline unsigned char swap_count(unsigned char ent)
100068 {
100069 @@ -1944,7 +1944,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
100070 spin_unlock(&swap_lock);
100071
100072 err = 0;
100073 - atomic_inc(&proc_poll_event);
100074 + atomic_inc_unchecked(&proc_poll_event);
100075 wake_up_interruptible(&proc_poll_wait);
100076
100077 out_dput:
100078 @@ -1961,8 +1961,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
100079
100080 poll_wait(file, &proc_poll_wait, wait);
100081
100082 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
100083 - seq->poll_event = atomic_read(&proc_poll_event);
100084 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
100085 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
100086 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
100087 }
100088
100089 @@ -2060,7 +2060,7 @@ static int swaps_open(struct inode *inode, struct file *file)
100090 return ret;
100091
100092 seq = file->private_data;
100093 - seq->poll_event = atomic_read(&proc_poll_event);
100094 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
100095 return 0;
100096 }
100097
100098 @@ -2520,7 +2520,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
100099 (frontswap_map) ? "FS" : "");
100100
100101 mutex_unlock(&swapon_mutex);
100102 - atomic_inc(&proc_poll_event);
100103 + atomic_inc_unchecked(&proc_poll_event);
100104 wake_up_interruptible(&proc_poll_wait);
100105
100106 if (S_ISREG(inode->i_mode))
100107 diff --git a/mm/util.c b/mm/util.c
100108 index 093c973..b70a268 100644
100109 --- a/mm/util.c
100110 +++ b/mm/util.c
100111 @@ -202,6 +202,12 @@ done:
100112 void arch_pick_mmap_layout(struct mm_struct *mm)
100113 {
100114 mm->mmap_base = TASK_UNMAPPED_BASE;
100115 +
100116 +#ifdef CONFIG_PAX_RANDMMAP
100117 + if (mm->pax_flags & MF_PAX_RANDMMAP)
100118 + mm->mmap_base += mm->delta_mmap;
100119 +#endif
100120 +
100121 mm->get_unmapped_area = arch_get_unmapped_area;
100122 }
100123 #endif
100124 @@ -378,6 +384,9 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
100125 if (!mm->arg_end)
100126 goto out_mm; /* Shh! No looking before we're done */
100127
100128 + if (gr_acl_handle_procpidmem(task))
100129 + goto out_mm;
100130 +
100131 len = mm->arg_end - mm->arg_start;
100132
100133 if (len > buflen)
100134 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
100135 index 2b0aa54..b451f74 100644
100136 --- a/mm/vmalloc.c
100137 +++ b/mm/vmalloc.c
100138 @@ -40,6 +40,21 @@ struct vfree_deferred {
100139 };
100140 static DEFINE_PER_CPU(struct vfree_deferred, vfree_deferred);
100141
100142 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100143 +struct stack_deferred_llist {
100144 + struct llist_head list;
100145 + void *stack;
100146 + void *lowmem_stack;
100147 +};
100148 +
100149 +struct stack_deferred {
100150 + struct stack_deferred_llist list;
100151 + struct work_struct wq;
100152 +};
100153 +
100154 +static DEFINE_PER_CPU(struct stack_deferred, stack_deferred);
100155 +#endif
100156 +
100157 static void __vunmap(const void *, int);
100158
100159 static void free_work(struct work_struct *w)
100160 @@ -47,12 +62,30 @@ static void free_work(struct work_struct *w)
100161 struct vfree_deferred *p = container_of(w, struct vfree_deferred, wq);
100162 struct llist_node *llnode = llist_del_all(&p->list);
100163 while (llnode) {
100164 - void *p = llnode;
100165 + void *x = llnode;
100166 llnode = llist_next(llnode);
100167 - __vunmap(p, 1);
100168 + __vunmap(x, 1);
100169 }
100170 }
100171
100172 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100173 +static void unmap_work(struct work_struct *w)
100174 +{
100175 + struct stack_deferred *p = container_of(w, struct stack_deferred, wq);
100176 + struct llist_node *llnode = llist_del_all(&p->list.list);
100177 + while (llnode) {
100178 + struct stack_deferred_llist *x =
100179 + llist_entry((struct llist_head *)llnode,
100180 + struct stack_deferred_llist, list);
100181 + void *stack = ACCESS_ONCE(x->stack);
100182 + void *lowmem_stack = ACCESS_ONCE(x->lowmem_stack);
100183 + llnode = llist_next(llnode);
100184 + __vunmap(stack, 0);
100185 + free_kmem_pages((unsigned long)lowmem_stack, THREAD_SIZE_ORDER);
100186 + }
100187 +}
100188 +#endif
100189 +
100190 /*** Page table manipulation functions ***/
100191
100192 static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
100193 @@ -61,8 +94,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
100194
100195 pte = pte_offset_kernel(pmd, addr);
100196 do {
100197 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
100198 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
100199 +
100200 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
100201 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
100202 + BUG_ON(!pte_exec(*pte));
100203 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
100204 + continue;
100205 + }
100206 +#endif
100207 +
100208 + {
100209 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
100210 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
100211 + }
100212 } while (pte++, addr += PAGE_SIZE, addr != end);
100213 }
100214
100215 @@ -122,16 +166,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
100216 pte = pte_alloc_kernel(pmd, addr);
100217 if (!pte)
100218 return -ENOMEM;
100219 +
100220 + pax_open_kernel();
100221 do {
100222 struct page *page = pages[*nr];
100223
100224 - if (WARN_ON(!pte_none(*pte)))
100225 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
100226 + if (pgprot_val(prot) & _PAGE_NX)
100227 +#endif
100228 +
100229 + if (!pte_none(*pte)) {
100230 + pax_close_kernel();
100231 + WARN_ON(1);
100232 return -EBUSY;
100233 - if (WARN_ON(!page))
100234 + }
100235 + if (!page) {
100236 + pax_close_kernel();
100237 + WARN_ON(1);
100238 return -ENOMEM;
100239 + }
100240 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
100241 (*nr)++;
100242 } while (pte++, addr += PAGE_SIZE, addr != end);
100243 + pax_close_kernel();
100244 return 0;
100245 }
100246
100247 @@ -141,7 +198,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
100248 pmd_t *pmd;
100249 unsigned long next;
100250
100251 - pmd = pmd_alloc(&init_mm, pud, addr);
100252 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
100253 if (!pmd)
100254 return -ENOMEM;
100255 do {
100256 @@ -158,7 +215,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
100257 pud_t *pud;
100258 unsigned long next;
100259
100260 - pud = pud_alloc(&init_mm, pgd, addr);
100261 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
100262 if (!pud)
100263 return -ENOMEM;
100264 do {
100265 @@ -218,6 +275,12 @@ int is_vmalloc_or_module_addr(const void *x)
100266 if (addr >= MODULES_VADDR && addr < MODULES_END)
100267 return 1;
100268 #endif
100269 +
100270 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
100271 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
100272 + return 1;
100273 +#endif
100274 +
100275 return is_vmalloc_addr(x);
100276 }
100277
100278 @@ -238,8 +301,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
100279
100280 if (!pgd_none(*pgd)) {
100281 pud_t *pud = pud_offset(pgd, addr);
100282 +#ifdef CONFIG_X86
100283 + if (!pud_large(*pud))
100284 +#endif
100285 if (!pud_none(*pud)) {
100286 pmd_t *pmd = pmd_offset(pud, addr);
100287 +#ifdef CONFIG_X86
100288 + if (!pmd_large(*pmd))
100289 +#endif
100290 if (!pmd_none(*pmd)) {
100291 pte_t *ptep, pte;
100292
100293 @@ -1183,13 +1252,23 @@ void __init vmalloc_init(void)
100294 for_each_possible_cpu(i) {
100295 struct vmap_block_queue *vbq;
100296 struct vfree_deferred *p;
100297 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100298 + struct stack_deferred *p2;
100299 +#endif
100300
100301 vbq = &per_cpu(vmap_block_queue, i);
100302 spin_lock_init(&vbq->lock);
100303 INIT_LIST_HEAD(&vbq->free);
100304 +
100305 p = &per_cpu(vfree_deferred, i);
100306 init_llist_head(&p->list);
100307 INIT_WORK(&p->wq, free_work);
100308 +
100309 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100310 + p2 = &per_cpu(stack_deferred, i);
100311 + init_llist_head(&p2->list.list);
100312 + INIT_WORK(&p2->wq, unmap_work);
100313 +#endif
100314 }
100315
100316 /* Import existing vmlist entries. */
100317 @@ -1314,6 +1393,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
100318 struct vm_struct *area;
100319
100320 BUG_ON(in_interrupt());
100321 +
100322 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
100323 + if (flags & VM_KERNEXEC) {
100324 + if (start != VMALLOC_START || end != VMALLOC_END)
100325 + return NULL;
100326 + start = (unsigned long)MODULES_EXEC_VADDR;
100327 + end = (unsigned long)MODULES_EXEC_END;
100328 + }
100329 +#endif
100330 +
100331 if (flags & VM_IOREMAP)
100332 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
100333
100334 @@ -1519,6 +1608,23 @@ void vunmap(const void *addr)
100335 }
100336 EXPORT_SYMBOL(vunmap);
100337
100338 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100339 +void unmap_process_stacks(struct task_struct *task)
100340 +{
100341 + if (unlikely(in_interrupt())) {
100342 + struct stack_deferred *p = &__get_cpu_var(stack_deferred);
100343 + struct stack_deferred_llist *list = task->stack;
100344 + list->stack = task->stack;
100345 + list->lowmem_stack = task->lowmem_stack;
100346 + if (llist_add((struct llist_node *)&list->list, &p->list.list))
100347 + schedule_work(&p->wq);
100348 + } else {
100349 + __vunmap(task->stack, 0);
100350 + free_kmem_pages((unsigned long)task->lowmem_stack, THREAD_SIZE_ORDER);
100351 + }
100352 +}
100353 +#endif
100354 +
100355 /**
100356 * vmap - map an array of pages into virtually contiguous space
100357 * @pages: array of page pointers
100358 @@ -1539,6 +1645,11 @@ void *vmap(struct page **pages, unsigned int count,
100359 if (count > totalram_pages)
100360 return NULL;
100361
100362 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
100363 + if (!(pgprot_val(prot) & _PAGE_NX))
100364 + flags |= VM_KERNEXEC;
100365 +#endif
100366 +
100367 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
100368 __builtin_return_address(0));
100369 if (!area)
100370 @@ -1641,6 +1752,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
100371 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
100372 goto fail;
100373
100374 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
100375 + if (!(pgprot_val(prot) & _PAGE_NX))
100376 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
100377 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
100378 + else
100379 +#endif
100380 +
100381 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
100382 start, end, node, gfp_mask, caller);
100383 if (!area)
100384 @@ -1817,10 +1935,9 @@ EXPORT_SYMBOL(vzalloc_node);
100385 * For tight control over page level allocator and protection flags
100386 * use __vmalloc() instead.
100387 */
100388 -
100389 void *vmalloc_exec(unsigned long size)
100390 {
100391 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
100392 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
100393 NUMA_NO_NODE, __builtin_return_address(0));
100394 }
100395
100396 @@ -2127,6 +2244,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
100397 {
100398 struct vm_struct *area;
100399
100400 + BUG_ON(vma->vm_mirror);
100401 +
100402 size = PAGE_ALIGN(size);
100403
100404 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
100405 @@ -2609,7 +2728,11 @@ static int s_show(struct seq_file *m, void *p)
100406 v->addr, v->addr + v->size, v->size);
100407
100408 if (v->caller)
100409 +#ifdef CONFIG_GRKERNSEC_HIDESYM
100410 + seq_printf(m, " %pK", v->caller);
100411 +#else
100412 seq_printf(m, " %pS", v->caller);
100413 +#endif
100414
100415 if (v->nr_pages)
100416 seq_printf(m, " pages=%d", v->nr_pages);
100417 diff --git a/mm/vmpressure.c b/mm/vmpressure.c
100418 index d4042e7..c5afd57 100644
100419 --- a/mm/vmpressure.c
100420 +++ b/mm/vmpressure.c
100421 @@ -165,6 +165,7 @@ static void vmpressure_work_fn(struct work_struct *work)
100422 unsigned long scanned;
100423 unsigned long reclaimed;
100424
100425 + spin_lock(&vmpr->sr_lock);
100426 /*
100427 * Several contexts might be calling vmpressure(), so it is
100428 * possible that the work was rescheduled again before the old
100429 @@ -173,11 +174,12 @@ static void vmpressure_work_fn(struct work_struct *work)
100430 * here. No need for any locks here since we don't care if
100431 * vmpr->reclaimed is in sync.
100432 */
100433 - if (!vmpr->scanned)
100434 + scanned = vmpr->scanned;
100435 + if (!scanned) {
100436 + spin_unlock(&vmpr->sr_lock);
100437 return;
100438 + }
100439
100440 - spin_lock(&vmpr->sr_lock);
100441 - scanned = vmpr->scanned;
100442 reclaimed = vmpr->reclaimed;
100443 vmpr->scanned = 0;
100444 vmpr->reclaimed = 0;
100445 diff --git a/mm/vmstat.c b/mm/vmstat.c
100446 index e9ab104..de275bd 100644
100447 --- a/mm/vmstat.c
100448 +++ b/mm/vmstat.c
100449 @@ -20,6 +20,7 @@
100450 #include <linux/writeback.h>
100451 #include <linux/compaction.h>
100452 #include <linux/mm_inline.h>
100453 +#include <linux/grsecurity.h>
100454
100455 #include "internal.h"
100456
100457 @@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
100458 *
100459 * vm_stat contains the global counters
100460 */
100461 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
100462 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
100463 EXPORT_SYMBOL(vm_stat);
100464
100465 #ifdef CONFIG_SMP
100466 @@ -425,7 +426,7 @@ static inline void fold_diff(int *diff)
100467
100468 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
100469 if (diff[i])
100470 - atomic_long_add(diff[i], &vm_stat[i]);
100471 + atomic_long_add_unchecked(diff[i], &vm_stat[i]);
100472 }
100473
100474 /*
100475 @@ -457,7 +458,7 @@ static void refresh_cpu_vm_stats(void)
100476 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
100477 if (v) {
100478
100479 - atomic_long_add(v, &zone->vm_stat[i]);
100480 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
100481 global_diff[i] += v;
100482 #ifdef CONFIG_NUMA
100483 /* 3 seconds idle till flush */
100484 @@ -519,7 +520,7 @@ void cpu_vm_stats_fold(int cpu)
100485
100486 v = p->vm_stat_diff[i];
100487 p->vm_stat_diff[i] = 0;
100488 - atomic_long_add(v, &zone->vm_stat[i]);
100489 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
100490 global_diff[i] += v;
100491 }
100492 }
100493 @@ -539,8 +540,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
100494 if (pset->vm_stat_diff[i]) {
100495 int v = pset->vm_stat_diff[i];
100496 pset->vm_stat_diff[i] = 0;
100497 - atomic_long_add(v, &zone->vm_stat[i]);
100498 - atomic_long_add(v, &vm_stat[i]);
100499 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
100500 + atomic_long_add_unchecked(v, &vm_stat[i]);
100501 }
100502 }
100503 #endif
100504 @@ -1163,10 +1164,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
100505 stat_items_size += sizeof(struct vm_event_state);
100506 #endif
100507
100508 - v = kmalloc(stat_items_size, GFP_KERNEL);
100509 + v = kzalloc(stat_items_size, GFP_KERNEL);
100510 m->private = v;
100511 if (!v)
100512 return ERR_PTR(-ENOMEM);
100513 +
100514 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
100515 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
100516 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
100517 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
100518 + && !in_group_p(grsec_proc_gid)
100519 +#endif
100520 + )
100521 + return (unsigned long *)m->private + *pos;
100522 +#endif
100523 +#endif
100524 +
100525 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
100526 v[i] = global_page_state(i);
100527 v += NR_VM_ZONE_STAT_ITEMS;
100528 @@ -1315,10 +1328,16 @@ static int __init setup_vmstat(void)
100529 cpu_notifier_register_done();
100530 #endif
100531 #ifdef CONFIG_PROC_FS
100532 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
100533 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
100534 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
100535 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
100536 + {
100537 + mode_t gr_mode = S_IRUGO;
100538 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
100539 + gr_mode = S_IRUSR;
100540 +#endif
100541 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
100542 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
100543 + proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
100544 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
100545 + }
100546 #endif
100547 return 0;
100548 }
100549 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
100550 index 64c6bed..b79a5de 100644
100551 --- a/net/8021q/vlan.c
100552 +++ b/net/8021q/vlan.c
100553 @@ -481,7 +481,7 @@ out:
100554 return NOTIFY_DONE;
100555 }
100556
100557 -static struct notifier_block vlan_notifier_block __read_mostly = {
100558 +static struct notifier_block vlan_notifier_block = {
100559 .notifier_call = vlan_device_event,
100560 };
100561
100562 @@ -556,8 +556,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
100563 err = -EPERM;
100564 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
100565 break;
100566 - if ((args.u.name_type >= 0) &&
100567 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
100568 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
100569 struct vlan_net *vn;
100570
100571 vn = net_generic(net, vlan_net_id);
100572 diff --git a/net/9p/client.c b/net/9p/client.c
100573 index e86a9bea..e91f70e 100644
100574 --- a/net/9p/client.c
100575 +++ b/net/9p/client.c
100576 @@ -596,7 +596,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
100577 len - inline_len);
100578 } else {
100579 err = copy_from_user(ename + inline_len,
100580 - uidata, len - inline_len);
100581 + (char __force_user *)uidata, len - inline_len);
100582 if (err) {
100583 err = -EFAULT;
100584 goto out_err;
100585 @@ -1570,7 +1570,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
100586 kernel_buf = 1;
100587 indata = data;
100588 } else
100589 - indata = (__force char *)udata;
100590 + indata = (__force_kernel char *)udata;
100591 /*
100592 * response header len is 11
100593 * PDU Header(7) + IO Size (4)
100594 @@ -1645,7 +1645,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
100595 kernel_buf = 1;
100596 odata = data;
100597 } else
100598 - odata = (char *)udata;
100599 + odata = (char __force_kernel *)udata;
100600 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
100601 P9_ZC_HDR_SZ, kernel_buf, "dqd",
100602 fid->fid, offset, rsize);
100603 diff --git a/net/9p/mod.c b/net/9p/mod.c
100604 index 6ab36ae..6f1841b 100644
100605 --- a/net/9p/mod.c
100606 +++ b/net/9p/mod.c
100607 @@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
100608 void v9fs_register_trans(struct p9_trans_module *m)
100609 {
100610 spin_lock(&v9fs_trans_lock);
100611 - list_add_tail(&m->list, &v9fs_trans_list);
100612 + pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
100613 spin_unlock(&v9fs_trans_lock);
100614 }
100615 EXPORT_SYMBOL(v9fs_register_trans);
100616 @@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
100617 void v9fs_unregister_trans(struct p9_trans_module *m)
100618 {
100619 spin_lock(&v9fs_trans_lock);
100620 - list_del_init(&m->list);
100621 + pax_list_del_init((struct list_head *)&m->list);
100622 spin_unlock(&v9fs_trans_lock);
100623 }
100624 EXPORT_SYMBOL(v9fs_unregister_trans);
100625 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
100626 index 80d08f6..de63fd1 100644
100627 --- a/net/9p/trans_fd.c
100628 +++ b/net/9p/trans_fd.c
100629 @@ -428,7 +428,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
100630 oldfs = get_fs();
100631 set_fs(get_ds());
100632 /* The cast to a user pointer is valid due to the set_fs() */
100633 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
100634 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
100635 set_fs(oldfs);
100636
100637 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
100638 diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
100639 index af46bc4..f9adfcd 100644
100640 --- a/net/appletalk/atalk_proc.c
100641 +++ b/net/appletalk/atalk_proc.c
100642 @@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
100643 struct proc_dir_entry *p;
100644 int rc = -ENOMEM;
100645
100646 - atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
100647 + atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
100648 if (!atalk_proc_dir)
100649 goto out;
100650
100651 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
100652 index 876fbe8..8bbea9f 100644
100653 --- a/net/atm/atm_misc.c
100654 +++ b/net/atm/atm_misc.c
100655 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
100656 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
100657 return 1;
100658 atm_return(vcc, truesize);
100659 - atomic_inc(&vcc->stats->rx_drop);
100660 + atomic_inc_unchecked(&vcc->stats->rx_drop);
100661 return 0;
100662 }
100663 EXPORT_SYMBOL(atm_charge);
100664 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
100665 }
100666 }
100667 atm_return(vcc, guess);
100668 - atomic_inc(&vcc->stats->rx_drop);
100669 + atomic_inc_unchecked(&vcc->stats->rx_drop);
100670 return NULL;
100671 }
100672 EXPORT_SYMBOL(atm_alloc_charge);
100673 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
100674
100675 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
100676 {
100677 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
100678 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
100679 __SONET_ITEMS
100680 #undef __HANDLE_ITEM
100681 }
100682 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
100683
100684 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
100685 {
100686 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
100687 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
100688 __SONET_ITEMS
100689 #undef __HANDLE_ITEM
100690 }
100691 diff --git a/net/atm/lec.c b/net/atm/lec.c
100692 index 4b98f89..5a2f6cb 100644
100693 --- a/net/atm/lec.c
100694 +++ b/net/atm/lec.c
100695 @@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
100696 }
100697
100698 static struct lane2_ops lane2_ops = {
100699 - lane2_resolve, /* resolve, spec 3.1.3 */
100700 - lane2_associate_req, /* associate_req, spec 3.1.4 */
100701 - NULL /* associate indicator, spec 3.1.5 */
100702 + .resolve = lane2_resolve,
100703 + .associate_req = lane2_associate_req,
100704 + .associate_indicator = NULL
100705 };
100706
100707 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
100708 diff --git a/net/atm/lec.h b/net/atm/lec.h
100709 index 4149db1..f2ab682 100644
100710 --- a/net/atm/lec.h
100711 +++ b/net/atm/lec.h
100712 @@ -48,7 +48,7 @@ struct lane2_ops {
100713 const u8 *tlvs, u32 sizeoftlvs);
100714 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
100715 const u8 *tlvs, u32 sizeoftlvs);
100716 -};
100717 +} __no_const;
100718
100719 /*
100720 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
100721 diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
100722 index d1b2d9a..d549f7f 100644
100723 --- a/net/atm/mpoa_caches.c
100724 +++ b/net/atm/mpoa_caches.c
100725 @@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
100726
100727
100728 static struct in_cache_ops ingress_ops = {
100729 - in_cache_add_entry, /* add_entry */
100730 - in_cache_get, /* get */
100731 - in_cache_get_with_mask, /* get_with_mask */
100732 - in_cache_get_by_vcc, /* get_by_vcc */
100733 - in_cache_put, /* put */
100734 - in_cache_remove_entry, /* remove_entry */
100735 - cache_hit, /* cache_hit */
100736 - clear_count_and_expired, /* clear_count */
100737 - check_resolving_entries, /* check_resolving */
100738 - refresh_entries, /* refresh */
100739 - in_destroy_cache /* destroy_cache */
100740 + .add_entry = in_cache_add_entry,
100741 + .get = in_cache_get,
100742 + .get_with_mask = in_cache_get_with_mask,
100743 + .get_by_vcc = in_cache_get_by_vcc,
100744 + .put = in_cache_put,
100745 + .remove_entry = in_cache_remove_entry,
100746 + .cache_hit = cache_hit,
100747 + .clear_count = clear_count_and_expired,
100748 + .check_resolving = check_resolving_entries,
100749 + .refresh = refresh_entries,
100750 + .destroy_cache = in_destroy_cache
100751 };
100752
100753 static struct eg_cache_ops egress_ops = {
100754 - eg_cache_add_entry, /* add_entry */
100755 - eg_cache_get_by_cache_id, /* get_by_cache_id */
100756 - eg_cache_get_by_tag, /* get_by_tag */
100757 - eg_cache_get_by_vcc, /* get_by_vcc */
100758 - eg_cache_get_by_src_ip, /* get_by_src_ip */
100759 - eg_cache_put, /* put */
100760 - eg_cache_remove_entry, /* remove_entry */
100761 - update_eg_cache_entry, /* update */
100762 - clear_expired, /* clear_expired */
100763 - eg_destroy_cache /* destroy_cache */
100764 + .add_entry = eg_cache_add_entry,
100765 + .get_by_cache_id = eg_cache_get_by_cache_id,
100766 + .get_by_tag = eg_cache_get_by_tag,
100767 + .get_by_vcc = eg_cache_get_by_vcc,
100768 + .get_by_src_ip = eg_cache_get_by_src_ip,
100769 + .put = eg_cache_put,
100770 + .remove_entry = eg_cache_remove_entry,
100771 + .update = update_eg_cache_entry,
100772 + .clear_expired = clear_expired,
100773 + .destroy_cache = eg_destroy_cache
100774 };
100775
100776
100777 diff --git a/net/atm/proc.c b/net/atm/proc.c
100778 index bbb6461..cf04016 100644
100779 --- a/net/atm/proc.c
100780 +++ b/net/atm/proc.c
100781 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
100782 const struct k_atm_aal_stats *stats)
100783 {
100784 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
100785 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
100786 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
100787 - atomic_read(&stats->rx_drop));
100788 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
100789 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
100790 + atomic_read_unchecked(&stats->rx_drop));
100791 }
100792
100793 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
100794 diff --git a/net/atm/resources.c b/net/atm/resources.c
100795 index 0447d5d..3cf4728 100644
100796 --- a/net/atm/resources.c
100797 +++ b/net/atm/resources.c
100798 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
100799 static void copy_aal_stats(struct k_atm_aal_stats *from,
100800 struct atm_aal_stats *to)
100801 {
100802 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
100803 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
100804 __AAL_STAT_ITEMS
100805 #undef __HANDLE_ITEM
100806 }
100807 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
100808 static void subtract_aal_stats(struct k_atm_aal_stats *from,
100809 struct atm_aal_stats *to)
100810 {
100811 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
100812 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
100813 __AAL_STAT_ITEMS
100814 #undef __HANDLE_ITEM
100815 }
100816 diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
100817 index 919a5ce..cc6b444 100644
100818 --- a/net/ax25/sysctl_net_ax25.c
100819 +++ b/net/ax25/sysctl_net_ax25.c
100820 @@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
100821 {
100822 char path[sizeof("net/ax25/") + IFNAMSIZ];
100823 int k;
100824 - struct ctl_table *table;
100825 + ctl_table_no_const *table;
100826
100827 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
100828 if (!table)
100829 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
100830 index 1e80539..676c37a 100644
100831 --- a/net/batman-adv/bat_iv_ogm.c
100832 +++ b/net/batman-adv/bat_iv_ogm.c
100833 @@ -313,7 +313,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
100834
100835 /* randomize initial seqno to avoid collision */
100836 get_random_bytes(&random_seqno, sizeof(random_seqno));
100837 - atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
100838 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
100839
100840 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
100841 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
100842 @@ -918,9 +918,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
100843 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
100844
100845 /* change sequence number to network order */
100846 - seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
100847 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
100848 batadv_ogm_packet->seqno = htonl(seqno);
100849 - atomic_inc(&hard_iface->bat_iv.ogm_seqno);
100850 + atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
100851
100852 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
100853
100854 @@ -1597,7 +1597,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
100855 return;
100856
100857 /* could be changed by schedule_own_packet() */
100858 - if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
100859 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
100860
100861 if (ogm_packet->flags & BATADV_DIRECTLINK)
100862 has_directlink_flag = true;
100863 diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
100864 index fc1835c..eead856 100644
100865 --- a/net/batman-adv/fragmentation.c
100866 +++ b/net/batman-adv/fragmentation.c
100867 @@ -450,7 +450,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
100868 frag_header.packet_type = BATADV_UNICAST_FRAG;
100869 frag_header.version = BATADV_COMPAT_VERSION;
100870 frag_header.ttl = BATADV_TTL;
100871 - frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
100872 + frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
100873 frag_header.reserved = 0;
100874 frag_header.no = 0;
100875 frag_header.total_size = htons(skb->len);
100876 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
100877 index 5467955..30cc771 100644
100878 --- a/net/batman-adv/soft-interface.c
100879 +++ b/net/batman-adv/soft-interface.c
100880 @@ -296,7 +296,7 @@ send:
100881 primary_if->net_dev->dev_addr);
100882
100883 /* set broadcast sequence number */
100884 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
100885 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
100886 bcast_packet->seqno = htonl(seqno);
100887
100888 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
100889 @@ -761,7 +761,7 @@ static int batadv_softif_init_late(struct net_device *dev)
100890 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
100891
100892 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
100893 - atomic_set(&bat_priv->bcast_seqno, 1);
100894 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
100895 atomic_set(&bat_priv->tt.vn, 0);
100896 atomic_set(&bat_priv->tt.local_changes, 0);
100897 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
100898 @@ -775,7 +775,7 @@ static int batadv_softif_init_late(struct net_device *dev)
100899
100900 /* randomize initial seqno to avoid collision */
100901 get_random_bytes(&random_seqno, sizeof(random_seqno));
100902 - atomic_set(&bat_priv->frag_seqno, random_seqno);
100903 + atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
100904
100905 bat_priv->primary_if = NULL;
100906 bat_priv->num_ifaces = 0;
100907 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
100908 index 8854c05..ee5d5497 100644
100909 --- a/net/batman-adv/types.h
100910 +++ b/net/batman-adv/types.h
100911 @@ -67,7 +67,7 @@ enum batadv_dhcp_recipient {
100912 struct batadv_hard_iface_bat_iv {
100913 unsigned char *ogm_buff;
100914 int ogm_buff_len;
100915 - atomic_t ogm_seqno;
100916 + atomic_unchecked_t ogm_seqno;
100917 };
100918
100919 /**
100920 @@ -768,7 +768,7 @@ struct batadv_priv {
100921 atomic_t bonding;
100922 atomic_t fragmentation;
100923 atomic_t packet_size_max;
100924 - atomic_t frag_seqno;
100925 + atomic_unchecked_t frag_seqno;
100926 #ifdef CONFIG_BATMAN_ADV_BLA
100927 atomic_t bridge_loop_avoidance;
100928 #endif
100929 @@ -787,7 +787,7 @@ struct batadv_priv {
100930 #endif
100931 uint32_t isolation_mark;
100932 uint32_t isolation_mark_mask;
100933 - atomic_t bcast_seqno;
100934 + atomic_unchecked_t bcast_seqno;
100935 atomic_t bcast_queue_left;
100936 atomic_t batman_queue_left;
100937 char num_ifaces;
100938 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
100939 index 115f149..f0ba286 100644
100940 --- a/net/bluetooth/hci_sock.c
100941 +++ b/net/bluetooth/hci_sock.c
100942 @@ -1067,7 +1067,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
100943 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
100944 }
100945
100946 - len = min_t(unsigned int, len, sizeof(uf));
100947 + len = min((size_t)len, sizeof(uf));
100948 if (copy_from_user(&uf, optval, len)) {
100949 err = -EFAULT;
100950 break;
100951 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
100952 index 14ca8ae..262d49a 100644
100953 --- a/net/bluetooth/l2cap_core.c
100954 +++ b/net/bluetooth/l2cap_core.c
100955 @@ -3565,8 +3565,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
100956 break;
100957
100958 case L2CAP_CONF_RFC:
100959 - if (olen == sizeof(rfc))
100960 - memcpy(&rfc, (void *)val, olen);
100961 + if (olen != sizeof(rfc))
100962 + break;
100963 +
100964 + memcpy(&rfc, (void *)val, olen);
100965
100966 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
100967 rfc.mode != chan->mode)
100968 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
100969 index 1884f72..b3b71f9 100644
100970 --- a/net/bluetooth/l2cap_sock.c
100971 +++ b/net/bluetooth/l2cap_sock.c
100972 @@ -629,7 +629,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
100973 struct sock *sk = sock->sk;
100974 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
100975 struct l2cap_options opts;
100976 - int len, err = 0;
100977 + int err = 0;
100978 + size_t len = optlen;
100979 u32 opt;
100980
100981 BT_DBG("sk %p", sk);
100982 @@ -656,7 +657,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
100983 opts.max_tx = chan->max_tx;
100984 opts.txwin_size = chan->tx_win;
100985
100986 - len = min_t(unsigned int, sizeof(opts), optlen);
100987 + len = min(sizeof(opts), len);
100988 if (copy_from_user((char *) &opts, optval, len)) {
100989 err = -EFAULT;
100990 break;
100991 @@ -743,7 +744,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
100992 struct bt_security sec;
100993 struct bt_power pwr;
100994 struct l2cap_conn *conn;
100995 - int len, err = 0;
100996 + int err = 0;
100997 + size_t len = optlen;
100998 u32 opt;
100999
101000 BT_DBG("sk %p", sk);
101001 @@ -767,7 +769,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
101002
101003 sec.level = BT_SECURITY_LOW;
101004
101005 - len = min_t(unsigned int, sizeof(sec), optlen);
101006 + len = min(sizeof(sec), len);
101007 if (copy_from_user((char *) &sec, optval, len)) {
101008 err = -EFAULT;
101009 break;
101010 @@ -862,7 +864,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
101011
101012 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
101013
101014 - len = min_t(unsigned int, sizeof(pwr), optlen);
101015 + len = min(sizeof(pwr), len);
101016 if (copy_from_user((char *) &pwr, optval, len)) {
101017 err = -EFAULT;
101018 break;
101019 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
101020 index 8bbbb5e..6fc0950 100644
101021 --- a/net/bluetooth/rfcomm/sock.c
101022 +++ b/net/bluetooth/rfcomm/sock.c
101023 @@ -687,7 +687,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
101024 struct sock *sk = sock->sk;
101025 struct bt_security sec;
101026 int err = 0;
101027 - size_t len;
101028 + size_t len = optlen;
101029 u32 opt;
101030
101031 BT_DBG("sk %p", sk);
101032 @@ -709,7 +709,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
101033
101034 sec.level = BT_SECURITY_LOW;
101035
101036 - len = min_t(unsigned int, sizeof(sec), optlen);
101037 + len = min(sizeof(sec), len);
101038 if (copy_from_user((char *) &sec, optval, len)) {
101039 err = -EFAULT;
101040 break;
101041 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
101042 index 8e385a0..a5bdd8e 100644
101043 --- a/net/bluetooth/rfcomm/tty.c
101044 +++ b/net/bluetooth/rfcomm/tty.c
101045 @@ -752,7 +752,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
101046 BT_DBG("tty %p id %d", tty, tty->index);
101047
101048 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
101049 - dev->channel, dev->port.count);
101050 + dev->channel, atomic_read(&dev->port.count));
101051
101052 err = tty_port_open(&dev->port, tty, filp);
101053 if (err)
101054 @@ -775,7 +775,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
101055 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
101056
101057 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
101058 - dev->port.count);
101059 + atomic_read(&dev->port.count));
101060
101061 tty_port_close(&dev->port, tty, filp);
101062 }
101063 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
101064 index 6d69631..b8fdc85 100644
101065 --- a/net/bridge/netfilter/ebtables.c
101066 +++ b/net/bridge/netfilter/ebtables.c
101067 @@ -1518,7 +1518,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
101068 tmp.valid_hooks = t->table->valid_hooks;
101069 }
101070 mutex_unlock(&ebt_mutex);
101071 - if (copy_to_user(user, &tmp, *len) != 0) {
101072 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
101073 BUGPRINT("c2u Didn't work\n");
101074 ret = -EFAULT;
101075 break;
101076 @@ -2324,7 +2324,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
101077 goto out;
101078 tmp.valid_hooks = t->valid_hooks;
101079
101080 - if (copy_to_user(user, &tmp, *len) != 0) {
101081 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
101082 ret = -EFAULT;
101083 break;
101084 }
101085 @@ -2335,7 +2335,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
101086 tmp.entries_size = t->table->entries_size;
101087 tmp.valid_hooks = t->table->valid_hooks;
101088
101089 - if (copy_to_user(user, &tmp, *len) != 0) {
101090 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
101091 ret = -EFAULT;
101092 break;
101093 }
101094 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
101095 index f5afda1..dcf770a 100644
101096 --- a/net/caif/cfctrl.c
101097 +++ b/net/caif/cfctrl.c
101098 @@ -10,6 +10,7 @@
101099 #include <linux/spinlock.h>
101100 #include <linux/slab.h>
101101 #include <linux/pkt_sched.h>
101102 +#include <linux/sched.h>
101103 #include <net/caif/caif_layer.h>
101104 #include <net/caif/cfpkt.h>
101105 #include <net/caif/cfctrl.h>
101106 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
101107 memset(&dev_info, 0, sizeof(dev_info));
101108 dev_info.id = 0xff;
101109 cfsrvl_init(&this->serv, 0, &dev_info, false);
101110 - atomic_set(&this->req_seq_no, 1);
101111 - atomic_set(&this->rsp_seq_no, 1);
101112 + atomic_set_unchecked(&this->req_seq_no, 1);
101113 + atomic_set_unchecked(&this->rsp_seq_no, 1);
101114 this->serv.layer.receive = cfctrl_recv;
101115 sprintf(this->serv.layer.name, "ctrl");
101116 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
101117 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
101118 struct cfctrl_request_info *req)
101119 {
101120 spin_lock_bh(&ctrl->info_list_lock);
101121 - atomic_inc(&ctrl->req_seq_no);
101122 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
101123 + atomic_inc_unchecked(&ctrl->req_seq_no);
101124 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
101125 list_add_tail(&req->list, &ctrl->list);
101126 spin_unlock_bh(&ctrl->info_list_lock);
101127 }
101128 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
101129 if (p != first)
101130 pr_warn("Requests are not received in order\n");
101131
101132 - atomic_set(&ctrl->rsp_seq_no,
101133 + atomic_set_unchecked(&ctrl->rsp_seq_no,
101134 p->sequence_no);
101135 list_del(&p->list);
101136 goto out;
101137 diff --git a/net/can/af_can.c b/net/can/af_can.c
101138 index ce82337..5d17b4d 100644
101139 --- a/net/can/af_can.c
101140 +++ b/net/can/af_can.c
101141 @@ -884,7 +884,7 @@ static const struct net_proto_family can_family_ops = {
101142 };
101143
101144 /* notifier block for netdevice event */
101145 -static struct notifier_block can_netdev_notifier __read_mostly = {
101146 +static struct notifier_block can_netdev_notifier = {
101147 .notifier_call = can_notifier,
101148 };
101149
101150 diff --git a/net/can/bcm.c b/net/can/bcm.c
101151 index dcb75c0..24b1b43 100644
101152 --- a/net/can/bcm.c
101153 +++ b/net/can/bcm.c
101154 @@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
101155 }
101156
101157 /* create /proc/net/can-bcm directory */
101158 - proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
101159 + proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
101160 return 0;
101161 }
101162
101163 diff --git a/net/can/gw.c b/net/can/gw.c
101164 index 050a211..bb9fe33 100644
101165 --- a/net/can/gw.c
101166 +++ b/net/can/gw.c
101167 @@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
101168 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
101169
101170 static HLIST_HEAD(cgw_list);
101171 -static struct notifier_block notifier;
101172
101173 static struct kmem_cache *cgw_cache __read_mostly;
101174
101175 @@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
101176 return err;
101177 }
101178
101179 +static struct notifier_block notifier = {
101180 + .notifier_call = cgw_notifier
101181 +};
101182 +
101183 static __init int cgw_module_init(void)
101184 {
101185 /* sanitize given module parameter */
101186 @@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
101187 return -ENOMEM;
101188
101189 /* set notifier */
101190 - notifier.notifier_call = cgw_notifier;
101191 register_netdevice_notifier(&notifier);
101192
101193 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
101194 diff --git a/net/can/proc.c b/net/can/proc.c
101195 index 1a19b98..df2b4ec 100644
101196 --- a/net/can/proc.c
101197 +++ b/net/can/proc.c
101198 @@ -514,7 +514,7 @@ static void can_remove_proc_readentry(const char *name)
101199 void can_init_proc(void)
101200 {
101201 /* create /proc/net/can directory */
101202 - can_dir = proc_mkdir("can", init_net.proc_net);
101203 + can_dir = proc_mkdir_restrict("can", init_net.proc_net);
101204
101205 if (!can_dir) {
101206 printk(KERN_INFO "can: failed to create /proc/net/can . "
101207 diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
101208 index 9f02369..e6160e9 100644
101209 --- a/net/ceph/messenger.c
101210 +++ b/net/ceph/messenger.c
101211 @@ -188,7 +188,7 @@ static void con_fault(struct ceph_connection *con);
101212 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
101213
101214 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
101215 -static atomic_t addr_str_seq = ATOMIC_INIT(0);
101216 +static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
101217
101218 static struct page *zero_page; /* used in certain error cases */
101219
101220 @@ -199,7 +199,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
101221 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
101222 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
101223
101224 - i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
101225 + i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
101226 s = addr_str[i];
101227
101228 switch (ss->ss_family) {
101229 diff --git a/net/compat.c b/net/compat.c
101230 index bc8aeef..f9c070c 100644
101231 --- a/net/compat.c
101232 +++ b/net/compat.c
101233 @@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
101234 return -EFAULT;
101235 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
101236 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
101237 - kmsg->msg_name = compat_ptr(tmp1);
101238 - kmsg->msg_iov = compat_ptr(tmp2);
101239 - kmsg->msg_control = compat_ptr(tmp3);
101240 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
101241 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
101242 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
101243 return 0;
101244 }
101245
101246 @@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
101247
101248 if (kern_msg->msg_name && kern_msg->msg_namelen) {
101249 if (mode == VERIFY_READ) {
101250 - int err = move_addr_to_kernel(kern_msg->msg_name,
101251 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
101252 kern_msg->msg_namelen,
101253 kern_address);
101254 if (err < 0)
101255 @@ -100,7 +100,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
101256 }
101257
101258 tot_len = iov_from_user_compat_to_kern(kern_iov,
101259 - (struct compat_iovec __user *)kern_msg->msg_iov,
101260 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
101261 kern_msg->msg_iovlen);
101262 if (tot_len >= 0)
101263 kern_msg->msg_iov = kern_iov;
101264 @@ -120,20 +120,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
101265
101266 #define CMSG_COMPAT_FIRSTHDR(msg) \
101267 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
101268 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
101269 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
101270 (struct compat_cmsghdr __user *)NULL)
101271
101272 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
101273 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
101274 (ucmlen) <= (unsigned long) \
101275 ((mhdr)->msg_controllen - \
101276 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
101277 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
101278
101279 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
101280 struct compat_cmsghdr __user *cmsg, int cmsg_len)
101281 {
101282 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
101283 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
101284 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
101285 msg->msg_controllen)
101286 return NULL;
101287 return (struct compat_cmsghdr __user *)ptr;
101288 @@ -223,7 +223,7 @@ Efault:
101289
101290 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
101291 {
101292 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
101293 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
101294 struct compat_cmsghdr cmhdr;
101295 struct compat_timeval ctv;
101296 struct compat_timespec cts[3];
101297 @@ -279,7 +279,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
101298
101299 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
101300 {
101301 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
101302 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
101303 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
101304 int fdnum = scm->fp->count;
101305 struct file **fp = scm->fp->fp;
101306 @@ -367,7 +367,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
101307 return -EFAULT;
101308 old_fs = get_fs();
101309 set_fs(KERNEL_DS);
101310 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
101311 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
101312 set_fs(old_fs);
101313
101314 return err;
101315 @@ -428,7 +428,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
101316 len = sizeof(ktime);
101317 old_fs = get_fs();
101318 set_fs(KERNEL_DS);
101319 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
101320 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
101321 set_fs(old_fs);
101322
101323 if (!err) {
101324 @@ -571,7 +571,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
101325 case MCAST_JOIN_GROUP:
101326 case MCAST_LEAVE_GROUP:
101327 {
101328 - struct compat_group_req __user *gr32 = (void *)optval;
101329 + struct compat_group_req __user *gr32 = (void __user *)optval;
101330 struct group_req __user *kgr =
101331 compat_alloc_user_space(sizeof(struct group_req));
101332 u32 interface;
101333 @@ -592,7 +592,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
101334 case MCAST_BLOCK_SOURCE:
101335 case MCAST_UNBLOCK_SOURCE:
101336 {
101337 - struct compat_group_source_req __user *gsr32 = (void *)optval;
101338 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
101339 struct group_source_req __user *kgsr = compat_alloc_user_space(
101340 sizeof(struct group_source_req));
101341 u32 interface;
101342 @@ -613,7 +613,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
101343 }
101344 case MCAST_MSFILTER:
101345 {
101346 - struct compat_group_filter __user *gf32 = (void *)optval;
101347 + struct compat_group_filter __user *gf32 = (void __user *)optval;
101348 struct group_filter __user *kgf;
101349 u32 interface, fmode, numsrc;
101350
101351 @@ -651,7 +651,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
101352 char __user *optval, int __user *optlen,
101353 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
101354 {
101355 - struct compat_group_filter __user *gf32 = (void *)optval;
101356 + struct compat_group_filter __user *gf32 = (void __user *)optval;
101357 struct group_filter __user *kgf;
101358 int __user *koptlen;
101359 u32 interface, fmode, numsrc;
101360 @@ -804,7 +804,7 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args)
101361
101362 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
101363 return -EINVAL;
101364 - if (copy_from_user(a, args, nas[call]))
101365 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
101366 return -EFAULT;
101367 a0 = a[0];
101368 a1 = a[1];
101369 diff --git a/net/core/datagram.c b/net/core/datagram.c
101370 index fdbc9a8..cd6972c 100644
101371 --- a/net/core/datagram.c
101372 +++ b/net/core/datagram.c
101373 @@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
101374 }
101375
101376 kfree_skb(skb);
101377 - atomic_inc(&sk->sk_drops);
101378 + atomic_inc_unchecked(&sk->sk_drops);
101379 sk_mem_reclaim_partial(sk);
101380
101381 return err;
101382 diff --git a/net/core/dev.c b/net/core/dev.c
101383 index cf8a95f..2837211 100644
101384 --- a/net/core/dev.c
101385 +++ b/net/core/dev.c
101386 @@ -1683,14 +1683,14 @@ int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
101387 {
101388 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
101389 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
101390 - atomic_long_inc(&dev->rx_dropped);
101391 + atomic_long_inc_unchecked(&dev->rx_dropped);
101392 kfree_skb(skb);
101393 return NET_RX_DROP;
101394 }
101395 }
101396
101397 if (unlikely(!is_skb_forwardable(dev, skb))) {
101398 - atomic_long_inc(&dev->rx_dropped);
101399 + atomic_long_inc_unchecked(&dev->rx_dropped);
101400 kfree_skb(skb);
101401 return NET_RX_DROP;
101402 }
101403 @@ -2487,7 +2487,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
101404
101405 struct dev_gso_cb {
101406 void (*destructor)(struct sk_buff *skb);
101407 -};
101408 +} __no_const;
101409
101410 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
101411
101412 @@ -2952,7 +2952,7 @@ recursion_alert:
101413 rc = -ENETDOWN;
101414 rcu_read_unlock_bh();
101415
101416 - atomic_long_inc(&dev->tx_dropped);
101417 + atomic_long_inc_unchecked(&dev->tx_dropped);
101418 kfree_skb(skb);
101419 return rc;
101420 out:
101421 @@ -3296,7 +3296,7 @@ enqueue:
101422
101423 local_irq_restore(flags);
101424
101425 - atomic_long_inc(&skb->dev->rx_dropped);
101426 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
101427 kfree_skb(skb);
101428 return NET_RX_DROP;
101429 }
101430 @@ -3373,7 +3373,7 @@ int netif_rx_ni(struct sk_buff *skb)
101431 }
101432 EXPORT_SYMBOL(netif_rx_ni);
101433
101434 -static void net_tx_action(struct softirq_action *h)
101435 +static __latent_entropy void net_tx_action(void)
101436 {
101437 struct softnet_data *sd = &__get_cpu_var(softnet_data);
101438
101439 @@ -3706,7 +3706,7 @@ ncls:
101440 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
101441 } else {
101442 drop:
101443 - atomic_long_inc(&skb->dev->rx_dropped);
101444 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
101445 kfree_skb(skb);
101446 /* Jamal, now you will not able to escape explaining
101447 * me how you were going to use this. :-)
101448 @@ -4426,7 +4426,7 @@ void netif_napi_del(struct napi_struct *napi)
101449 }
101450 EXPORT_SYMBOL(netif_napi_del);
101451
101452 -static void net_rx_action(struct softirq_action *h)
101453 +static __latent_entropy void net_rx_action(void)
101454 {
101455 struct softnet_data *sd = &__get_cpu_var(softnet_data);
101456 unsigned long time_limit = jiffies + 2;
101457 @@ -6480,8 +6480,8 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
101458 } else {
101459 netdev_stats_to_stats64(storage, &dev->stats);
101460 }
101461 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
101462 - storage->tx_dropped += atomic_long_read(&dev->tx_dropped);
101463 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
101464 + storage->tx_dropped += atomic_long_read_unchecked(&dev->tx_dropped);
101465 return storage;
101466 }
101467 EXPORT_SYMBOL(dev_get_stats);
101468 diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
101469 index cf999e0..c59a9754 100644
101470 --- a/net/core/dev_ioctl.c
101471 +++ b/net/core/dev_ioctl.c
101472 @@ -366,9 +366,13 @@ void dev_load(struct net *net, const char *name)
101473 if (no_module && capable(CAP_NET_ADMIN))
101474 no_module = request_module("netdev-%s", name);
101475 if (no_module && capable(CAP_SYS_MODULE)) {
101476 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
101477 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
101478 +#else
101479 if (!request_module("%s", name))
101480 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
101481 name);
101482 +#endif
101483 }
101484 }
101485 EXPORT_SYMBOL(dev_load);
101486 diff --git a/net/core/filter.c b/net/core/filter.c
101487 index d814b8a..b5ab778 100644
101488 --- a/net/core/filter.c
101489 +++ b/net/core/filter.c
101490 @@ -559,7 +559,11 @@ do_pass:
101491
101492 /* Unkown instruction. */
101493 default:
101494 - goto err;
101495 + WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
101496 + fp->code, fp->jt, fp->jf, fp->k);
101497 + kfree(addrs);
101498 + BUG();
101499 + return -EINVAL;
101500 }
101501
101502 insn++;
101503 @@ -606,7 +610,7 @@ static int check_load_and_stores(const struct sock_filter *filter, int flen)
101504 u16 *masks, memvalid = 0; /* One bit per cell, 16 cells */
101505 int pc, ret = 0;
101506
101507 - BUILD_BUG_ON(BPF_MEMWORDS > 16);
101508 + BUILD_BUG_ON(BPF_MEMWORDS != 16);
101509
101510 masks = kmalloc_array(flen, sizeof(*masks), GFP_KERNEL);
101511 if (!masks)
101512 @@ -933,7 +937,7 @@ static struct bpf_prog *bpf_migrate_filter(struct bpf_prog *fp)
101513
101514 /* Expand fp for appending the new filter representation. */
101515 old_fp = fp;
101516 - fp = krealloc(old_fp, bpf_prog_size(new_len), GFP_KERNEL);
101517 + fp = bpf_prog_realloc(old_fp, bpf_prog_size(new_len), 0);
101518 if (!fp) {
101519 /* The old_fp is still around in case we couldn't
101520 * allocate new memory, so uncharge on that one.
101521 @@ -1013,11 +1017,11 @@ int bpf_prog_create(struct bpf_prog **pfp, struct sock_fprog_kern *fprog)
101522 if (fprog->filter == NULL)
101523 return -EINVAL;
101524
101525 - fp = kmalloc(bpf_prog_size(fprog->len), GFP_KERNEL);
101526 + fp = bpf_prog_alloc(bpf_prog_size(fprog->len), 0);
101527 if (!fp)
101528 return -ENOMEM;
101529
101530 - memcpy(fp->insns, fprog->filter, fsize);
101531 + memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
101532
101533 fp->len = fprog->len;
101534 /* Since unattached filters are not copied back to user
101535 @@ -1069,12 +1073,12 @@ int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk)
101536 if (fprog->filter == NULL)
101537 return -EINVAL;
101538
101539 - prog = kmalloc(bpf_fsize, GFP_KERNEL);
101540 + prog = bpf_prog_alloc(bpf_fsize, 0);
101541 if (!prog)
101542 return -ENOMEM;
101543
101544 if (copy_from_user(prog->insns, fprog->filter, fsize)) {
101545 - kfree(prog);
101546 + __bpf_prog_free(prog);
101547 return -EFAULT;
101548 }
101549
101550 @@ -1082,7 +1086,7 @@ int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk)
101551
101552 err = bpf_prog_store_orig_filter(prog, fprog);
101553 if (err) {
101554 - kfree(prog);
101555 + __bpf_prog_free(prog);
101556 return -ENOMEM;
101557 }
101558
101559 diff --git a/net/core/flow.c b/net/core/flow.c
101560 index a0348fd..6951c76 100644
101561 --- a/net/core/flow.c
101562 +++ b/net/core/flow.c
101563 @@ -65,7 +65,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
101564 static int flow_entry_valid(struct flow_cache_entry *fle,
101565 struct netns_xfrm *xfrm)
101566 {
101567 - if (atomic_read(&xfrm->flow_cache_genid) != fle->genid)
101568 + if (atomic_read_unchecked(&xfrm->flow_cache_genid) != fle->genid)
101569 return 0;
101570 if (fle->object && !fle->object->ops->check(fle->object))
101571 return 0;
101572 @@ -242,7 +242,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
101573 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
101574 fcp->hash_count++;
101575 }
101576 - } else if (likely(fle->genid == atomic_read(&net->xfrm.flow_cache_genid))) {
101577 + } else if (likely(fle->genid == atomic_read_unchecked(&net->xfrm.flow_cache_genid))) {
101578 flo = fle->object;
101579 if (!flo)
101580 goto ret_object;
101581 @@ -263,7 +263,7 @@ nocache:
101582 }
101583 flo = resolver(net, key, family, dir, flo, ctx);
101584 if (fle) {
101585 - fle->genid = atomic_read(&net->xfrm.flow_cache_genid);
101586 + fle->genid = atomic_read_unchecked(&net->xfrm.flow_cache_genid);
101587 if (!IS_ERR(flo))
101588 fle->object = flo;
101589 else
101590 diff --git a/net/core/iovec.c b/net/core/iovec.c
101591 index e1ec45a..e5c6f16 100644
101592 --- a/net/core/iovec.c
101593 +++ b/net/core/iovec.c
101594 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
101595 if (m->msg_name && m->msg_namelen) {
101596 if (mode == VERIFY_READ) {
101597 void __user *namep;
101598 - namep = (void __user __force *) m->msg_name;
101599 + namep = (void __force_user *) m->msg_name;
101600 err = move_addr_to_kernel(namep, m->msg_namelen,
101601 address);
101602 if (err < 0)
101603 @@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
101604 }
101605
101606 size = m->msg_iovlen * sizeof(struct iovec);
101607 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
101608 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
101609 return -EFAULT;
101610
101611 m->msg_iov = iov;
101612 diff --git a/net/core/neighbour.c b/net/core/neighbour.c
101613 index ef31fef..8be66d9 100644
101614 --- a/net/core/neighbour.c
101615 +++ b/net/core/neighbour.c
101616 @@ -2825,7 +2825,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
101617 void __user *buffer, size_t *lenp, loff_t *ppos)
101618 {
101619 int size, ret;
101620 - struct ctl_table tmp = *ctl;
101621 + ctl_table_no_const tmp = *ctl;
101622
101623 tmp.extra1 = &zero;
101624 tmp.extra2 = &unres_qlen_max;
101625 @@ -2887,7 +2887,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
101626 void __user *buffer,
101627 size_t *lenp, loff_t *ppos)
101628 {
101629 - struct ctl_table tmp = *ctl;
101630 + ctl_table_no_const tmp = *ctl;
101631 int ret;
101632
101633 tmp.extra1 = &zero;
101634 diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
101635 index 2bf8329..2eb1423 100644
101636 --- a/net/core/net-procfs.c
101637 +++ b/net/core/net-procfs.c
101638 @@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
101639 struct rtnl_link_stats64 temp;
101640 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
101641
101642 - seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101643 + if (gr_proc_is_restricted())
101644 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101645 + "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
101646 + dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
101647 + 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
101648 + else
101649 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101650 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
101651 dev->name, stats->rx_bytes, stats->rx_packets,
101652 stats->rx_errors,
101653 @@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
101654 return 0;
101655 }
101656
101657 -static const struct seq_operations dev_seq_ops = {
101658 +const struct seq_operations dev_seq_ops = {
101659 .start = dev_seq_start,
101660 .next = dev_seq_next,
101661 .stop = dev_seq_stop,
101662 @@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
101663
101664 static int softnet_seq_open(struct inode *inode, struct file *file)
101665 {
101666 - return seq_open(file, &softnet_seq_ops);
101667 + return seq_open_restrict(file, &softnet_seq_ops);
101668 }
101669
101670 static const struct file_operations softnet_seq_fops = {
101671 @@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
101672 else
101673 seq_printf(seq, "%04x", ntohs(pt->type));
101674
101675 +#ifdef CONFIG_GRKERNSEC_HIDESYM
101676 + seq_printf(seq, " %-8s %pf\n",
101677 + pt->dev ? pt->dev->name : "", NULL);
101678 +#else
101679 seq_printf(seq, " %-8s %pf\n",
101680 pt->dev ? pt->dev->name : "", pt->func);
101681 +#endif
101682 }
101683
101684 return 0;
101685 diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
101686 index 9dd0669..c52fb1b 100644
101687 --- a/net/core/net-sysfs.c
101688 +++ b/net/core/net-sysfs.c
101689 @@ -278,7 +278,7 @@ static ssize_t carrier_changes_show(struct device *dev,
101690 {
101691 struct net_device *netdev = to_net_dev(dev);
101692 return sprintf(buf, fmt_dec,
101693 - atomic_read(&netdev->carrier_changes));
101694 + atomic_read_unchecked(&netdev->carrier_changes));
101695 }
101696 static DEVICE_ATTR_RO(carrier_changes);
101697
101698 diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
101699 index 7c6b51a..e9dd57f 100644
101700 --- a/net/core/net_namespace.c
101701 +++ b/net/core/net_namespace.c
101702 @@ -445,7 +445,7 @@ static int __register_pernet_operations(struct list_head *list,
101703 int error;
101704 LIST_HEAD(net_exit_list);
101705
101706 - list_add_tail(&ops->list, list);
101707 + pax_list_add_tail((struct list_head *)&ops->list, list);
101708 if (ops->init || (ops->id && ops->size)) {
101709 for_each_net(net) {
101710 error = ops_init(ops, net);
101711 @@ -458,7 +458,7 @@ static int __register_pernet_operations(struct list_head *list,
101712
101713 out_undo:
101714 /* If I have an error cleanup all namespaces I initialized */
101715 - list_del(&ops->list);
101716 + pax_list_del((struct list_head *)&ops->list);
101717 ops_exit_list(ops, &net_exit_list);
101718 ops_free_list(ops, &net_exit_list);
101719 return error;
101720 @@ -469,7 +469,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
101721 struct net *net;
101722 LIST_HEAD(net_exit_list);
101723
101724 - list_del(&ops->list);
101725 + pax_list_del((struct list_head *)&ops->list);
101726 for_each_net(net)
101727 list_add_tail(&net->exit_list, &net_exit_list);
101728 ops_exit_list(ops, &net_exit_list);
101729 @@ -603,7 +603,7 @@ int register_pernet_device(struct pernet_operations *ops)
101730 mutex_lock(&net_mutex);
101731 error = register_pernet_operations(&pernet_list, ops);
101732 if (!error && (first_device == &pernet_list))
101733 - first_device = &ops->list;
101734 + first_device = (struct list_head *)&ops->list;
101735 mutex_unlock(&net_mutex);
101736 return error;
101737 }
101738 diff --git a/net/core/netpoll.c b/net/core/netpoll.c
101739 index 907fb5e..8260f040b 100644
101740 --- a/net/core/netpoll.c
101741 +++ b/net/core/netpoll.c
101742 @@ -382,7 +382,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
101743 struct udphdr *udph;
101744 struct iphdr *iph;
101745 struct ethhdr *eth;
101746 - static atomic_t ip_ident;
101747 + static atomic_unchecked_t ip_ident;
101748 struct ipv6hdr *ip6h;
101749
101750 udp_len = len + sizeof(*udph);
101751 @@ -453,7 +453,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
101752 put_unaligned(0x45, (unsigned char *)iph);
101753 iph->tos = 0;
101754 put_unaligned(htons(ip_len), &(iph->tot_len));
101755 - iph->id = htons(atomic_inc_return(&ip_ident));
101756 + iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
101757 iph->frag_off = 0;
101758 iph->ttl = 64;
101759 iph->protocol = IPPROTO_UDP;
101760 diff --git a/net/core/pktgen.c b/net/core/pktgen.c
101761 index 8b849dd..cd88bfc 100644
101762 --- a/net/core/pktgen.c
101763 +++ b/net/core/pktgen.c
101764 @@ -3723,7 +3723,7 @@ static int __net_init pg_net_init(struct net *net)
101765 pn->net = net;
101766 INIT_LIST_HEAD(&pn->pktgen_threads);
101767 pn->pktgen_exiting = false;
101768 - pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
101769 + pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
101770 if (!pn->proc_dir) {
101771 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
101772 return -ENODEV;
101773 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
101774 index f0493e3..c3ffd7f 100644
101775 --- a/net/core/rtnetlink.c
101776 +++ b/net/core/rtnetlink.c
101777 @@ -58,7 +58,7 @@ struct rtnl_link {
101778 rtnl_doit_func doit;
101779 rtnl_dumpit_func dumpit;
101780 rtnl_calcit_func calcit;
101781 -};
101782 +} __no_const;
101783
101784 static DEFINE_MUTEX(rtnl_mutex);
101785
101786 @@ -304,10 +304,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
101787 * to use the ops for creating device. So do not
101788 * fill up dellink as well. That disables rtnl_dellink.
101789 */
101790 - if (ops->setup && !ops->dellink)
101791 - ops->dellink = unregister_netdevice_queue;
101792 + if (ops->setup && !ops->dellink) {
101793 + pax_open_kernel();
101794 + *(void **)&ops->dellink = unregister_netdevice_queue;
101795 + pax_close_kernel();
101796 + }
101797
101798 - list_add_tail(&ops->list, &link_ops);
101799 + pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
101800 return 0;
101801 }
101802 EXPORT_SYMBOL_GPL(__rtnl_link_register);
101803 @@ -354,7 +357,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
101804 for_each_net(net) {
101805 __rtnl_kill_links(net, ops);
101806 }
101807 - list_del(&ops->list);
101808 + pax_list_del((struct list_head *)&ops->list);
101809 }
101810 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
101811
101812 @@ -1014,7 +1017,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
101813 (dev->ifalias &&
101814 nla_put_string(skb, IFLA_IFALIAS, dev->ifalias)) ||
101815 nla_put_u32(skb, IFLA_CARRIER_CHANGES,
101816 - atomic_read(&dev->carrier_changes)))
101817 + atomic_read_unchecked(&dev->carrier_changes)))
101818 goto nla_put_failure;
101819
101820 if (1) {
101821 @@ -2780,6 +2783,9 @@ static int rtnl_bridge_setlink(struct sk_buff *skb, struct nlmsghdr *nlh)
101822 if (br_spec) {
101823 nla_for_each_nested(attr, br_spec, rem) {
101824 if (nla_type(attr) == IFLA_BRIDGE_FLAGS) {
101825 + if (nla_len(attr) < sizeof(flags))
101826 + return -EINVAL;
101827 +
101828 have_flags = true;
101829 flags = nla_get_u16(attr);
101830 break;
101831 @@ -2850,6 +2856,9 @@ static int rtnl_bridge_dellink(struct sk_buff *skb, struct nlmsghdr *nlh)
101832 if (br_spec) {
101833 nla_for_each_nested(attr, br_spec, rem) {
101834 if (nla_type(attr) == IFLA_BRIDGE_FLAGS) {
101835 + if (nla_len(attr) < sizeof(flags))
101836 + return -EINVAL;
101837 +
101838 have_flags = true;
101839 flags = nla_get_u16(attr);
101840 break;
101841 diff --git a/net/core/scm.c b/net/core/scm.c
101842 index b442e7e..6f5b5a2 100644
101843 --- a/net/core/scm.c
101844 +++ b/net/core/scm.c
101845 @@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
101846 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
101847 {
101848 struct cmsghdr __user *cm
101849 - = (__force struct cmsghdr __user *)msg->msg_control;
101850 + = (struct cmsghdr __force_user *)msg->msg_control;
101851 struct cmsghdr cmhdr;
101852 int cmlen = CMSG_LEN(len);
101853 int err;
101854 @@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
101855 err = -EFAULT;
101856 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
101857 goto out;
101858 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
101859 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
101860 goto out;
101861 cmlen = CMSG_SPACE(len);
101862 if (msg->msg_controllen < cmlen)
101863 @@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
101864 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
101865 {
101866 struct cmsghdr __user *cm
101867 - = (__force struct cmsghdr __user*)msg->msg_control;
101868 + = (struct cmsghdr __force_user *)msg->msg_control;
101869
101870 int fdmax = 0;
101871 int fdnum = scm->fp->count;
101872 @@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
101873 if (fdnum < fdmax)
101874 fdmax = fdnum;
101875
101876 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
101877 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
101878 i++, cmfptr++)
101879 {
101880 struct socket *sock;
101881 diff --git a/net/core/skbuff.c b/net/core/skbuff.c
101882 index 8d28969..4d36260 100644
101883 --- a/net/core/skbuff.c
101884 +++ b/net/core/skbuff.c
101885 @@ -360,18 +360,29 @@ refill:
101886 goto end;
101887 }
101888 nc->frag.size = PAGE_SIZE << order;
101889 -recycle:
101890 - atomic_set(&nc->frag.page->_count, NETDEV_PAGECNT_MAX_BIAS);
101891 + /* Even if we own the page, we do not use atomic_set().
101892 + * This would break get_page_unless_zero() users.
101893 + */
101894 + atomic_add(NETDEV_PAGECNT_MAX_BIAS - 1,
101895 + &nc->frag.page->_count);
101896 nc->pagecnt_bias = NETDEV_PAGECNT_MAX_BIAS;
101897 nc->frag.offset = 0;
101898 }
101899
101900 if (nc->frag.offset + fragsz > nc->frag.size) {
101901 - /* avoid unnecessary locked operations if possible */
101902 - if ((atomic_read(&nc->frag.page->_count) == nc->pagecnt_bias) ||
101903 - atomic_sub_and_test(nc->pagecnt_bias, &nc->frag.page->_count))
101904 - goto recycle;
101905 - goto refill;
101906 + if (atomic_read(&nc->frag.page->_count) != nc->pagecnt_bias) {
101907 + if (!atomic_sub_and_test(nc->pagecnt_bias,
101908 + &nc->frag.page->_count))
101909 + goto refill;
101910 + /* OK, page count is 0, we can safely set it */
101911 + atomic_set(&nc->frag.page->_count,
101912 + NETDEV_PAGECNT_MAX_BIAS);
101913 + } else {
101914 + atomic_add(NETDEV_PAGECNT_MAX_BIAS - nc->pagecnt_bias,
101915 + &nc->frag.page->_count);
101916 + }
101917 + nc->pagecnt_bias = NETDEV_PAGECNT_MAX_BIAS;
101918 + nc->frag.offset = 0;
101919 }
101920
101921 data = page_address(nc->frag.page) + nc->frag.offset;
101922 @@ -2011,7 +2022,7 @@ EXPORT_SYMBOL(__skb_checksum);
101923 __wsum skb_checksum(const struct sk_buff *skb, int offset,
101924 int len, __wsum csum)
101925 {
101926 - const struct skb_checksum_ops ops = {
101927 + static const struct skb_checksum_ops ops = {
101928 .update = csum_partial_ext,
101929 .combine = csum_block_add_ext,
101930 };
101931 @@ -3237,13 +3248,15 @@ void __init skb_init(void)
101932 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
101933 sizeof(struct sk_buff),
101934 0,
101935 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
101936 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
101937 + SLAB_NO_SANITIZE,
101938 NULL);
101939 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
101940 (2*sizeof(struct sk_buff)) +
101941 sizeof(atomic_t),
101942 0,
101943 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
101944 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
101945 + SLAB_NO_SANITIZE,
101946 NULL);
101947 }
101948
101949 diff --git a/net/core/sock.c b/net/core/sock.c
101950 index 9c3f823..bd8c884 100644
101951 --- a/net/core/sock.c
101952 +++ b/net/core/sock.c
101953 @@ -442,7 +442,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
101954 struct sk_buff_head *list = &sk->sk_receive_queue;
101955
101956 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
101957 - atomic_inc(&sk->sk_drops);
101958 + atomic_inc_unchecked(&sk->sk_drops);
101959 trace_sock_rcvqueue_full(sk, skb);
101960 return -ENOMEM;
101961 }
101962 @@ -452,7 +452,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
101963 return err;
101964
101965 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
101966 - atomic_inc(&sk->sk_drops);
101967 + atomic_inc_unchecked(&sk->sk_drops);
101968 return -ENOBUFS;
101969 }
101970
101971 @@ -472,7 +472,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
101972 skb_dst_force(skb);
101973
101974 spin_lock_irqsave(&list->lock, flags);
101975 - skb->dropcount = atomic_read(&sk->sk_drops);
101976 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
101977 __skb_queue_tail(list, skb);
101978 spin_unlock_irqrestore(&list->lock, flags);
101979
101980 @@ -492,7 +492,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
101981 skb->dev = NULL;
101982
101983 if (sk_rcvqueues_full(sk, sk->sk_rcvbuf)) {
101984 - atomic_inc(&sk->sk_drops);
101985 + atomic_inc_unchecked(&sk->sk_drops);
101986 goto discard_and_relse;
101987 }
101988 if (nested)
101989 @@ -510,7 +510,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
101990 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
101991 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
101992 bh_unlock_sock(sk);
101993 - atomic_inc(&sk->sk_drops);
101994 + atomic_inc_unchecked(&sk->sk_drops);
101995 goto discard_and_relse;
101996 }
101997
101998 @@ -999,12 +999,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
101999 struct timeval tm;
102000 } v;
102001
102002 - int lv = sizeof(int);
102003 - int len;
102004 + unsigned int lv = sizeof(int);
102005 + unsigned int len;
102006
102007 if (get_user(len, optlen))
102008 return -EFAULT;
102009 - if (len < 0)
102010 + if (len > INT_MAX)
102011 return -EINVAL;
102012
102013 memset(&v, 0, sizeof(v));
102014 @@ -1142,11 +1142,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
102015
102016 case SO_PEERNAME:
102017 {
102018 - char address[128];
102019 + char address[_K_SS_MAXSIZE];
102020
102021 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
102022 return -ENOTCONN;
102023 - if (lv < len)
102024 + if (lv < len || sizeof address < len)
102025 return -EINVAL;
102026 if (copy_to_user(optval, address, len))
102027 return -EFAULT;
102028 @@ -1227,7 +1227,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
102029
102030 if (len > lv)
102031 len = lv;
102032 - if (copy_to_user(optval, &v, len))
102033 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
102034 return -EFAULT;
102035 lenout:
102036 if (put_user(len, optlen))
102037 @@ -1723,6 +1723,8 @@ EXPORT_SYMBOL(sock_kmalloc);
102038 */
102039 void sock_kfree_s(struct sock *sk, void *mem, int size)
102040 {
102041 + if (WARN_ON_ONCE(!mem))
102042 + return;
102043 kfree(mem);
102044 atomic_sub(size, &sk->sk_omem_alloc);
102045 }
102046 @@ -2369,7 +2371,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
102047 */
102048 smp_wmb();
102049 atomic_set(&sk->sk_refcnt, 1);
102050 - atomic_set(&sk->sk_drops, 0);
102051 + atomic_set_unchecked(&sk->sk_drops, 0);
102052 }
102053 EXPORT_SYMBOL(sock_init_data);
102054
102055 @@ -2497,6 +2499,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
102056 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
102057 int level, int type)
102058 {
102059 + struct sock_extended_err ee;
102060 struct sock_exterr_skb *serr;
102061 struct sk_buff *skb, *skb2;
102062 int copied, err;
102063 @@ -2518,7 +2521,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
102064 sock_recv_timestamp(msg, sk, skb);
102065
102066 serr = SKB_EXT_ERR(skb);
102067 - put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
102068 + ee = serr->ee;
102069 + put_cmsg(msg, level, type, sizeof ee, &ee);
102070
102071 msg->msg_flags |= MSG_ERRQUEUE;
102072 err = copied;
102073 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
102074 index ad704c7..ca48aff 100644
102075 --- a/net/core/sock_diag.c
102076 +++ b/net/core/sock_diag.c
102077 @@ -9,26 +9,33 @@
102078 #include <linux/inet_diag.h>
102079 #include <linux/sock_diag.h>
102080
102081 -static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
102082 +static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
102083 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
102084 static DEFINE_MUTEX(sock_diag_table_mutex);
102085
102086 int sock_diag_check_cookie(void *sk, __u32 *cookie)
102087 {
102088 +#ifndef CONFIG_GRKERNSEC_HIDESYM
102089 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
102090 cookie[1] != INET_DIAG_NOCOOKIE) &&
102091 ((u32)(unsigned long)sk != cookie[0] ||
102092 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
102093 return -ESTALE;
102094 else
102095 +#endif
102096 return 0;
102097 }
102098 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
102099
102100 void sock_diag_save_cookie(void *sk, __u32 *cookie)
102101 {
102102 +#ifdef CONFIG_GRKERNSEC_HIDESYM
102103 + cookie[0] = 0;
102104 + cookie[1] = 0;
102105 +#else
102106 cookie[0] = (u32)(unsigned long)sk;
102107 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
102108 +#endif
102109 }
102110 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
102111
102112 @@ -110,8 +117,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
102113 mutex_lock(&sock_diag_table_mutex);
102114 if (sock_diag_handlers[hndl->family])
102115 err = -EBUSY;
102116 - else
102117 + else {
102118 + pax_open_kernel();
102119 sock_diag_handlers[hndl->family] = hndl;
102120 + pax_close_kernel();
102121 + }
102122 mutex_unlock(&sock_diag_table_mutex);
102123
102124 return err;
102125 @@ -127,7 +137,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
102126
102127 mutex_lock(&sock_diag_table_mutex);
102128 BUG_ON(sock_diag_handlers[family] != hnld);
102129 + pax_open_kernel();
102130 sock_diag_handlers[family] = NULL;
102131 + pax_close_kernel();
102132 mutex_unlock(&sock_diag_table_mutex);
102133 }
102134 EXPORT_SYMBOL_GPL(sock_diag_unregister);
102135 diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
102136 index cf9cd13..50683950 100644
102137 --- a/net/core/sysctl_net_core.c
102138 +++ b/net/core/sysctl_net_core.c
102139 @@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
102140 {
102141 unsigned int orig_size, size;
102142 int ret, i;
102143 - struct ctl_table tmp = {
102144 + ctl_table_no_const tmp = {
102145 .data = &size,
102146 .maxlen = sizeof(size),
102147 .mode = table->mode
102148 @@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
102149 void __user *buffer, size_t *lenp, loff_t *ppos)
102150 {
102151 char id[IFNAMSIZ];
102152 - struct ctl_table tbl = {
102153 + ctl_table_no_const tbl = {
102154 .data = id,
102155 .maxlen = IFNAMSIZ,
102156 };
102157 @@ -263,7 +263,7 @@ static struct ctl_table net_core_table[] = {
102158 .mode = 0644,
102159 .proc_handler = proc_dointvec
102160 },
102161 -#ifdef CONFIG_BPF_JIT
102162 +#if defined(CONFIG_BPF_JIT) && !defined(CONFIG_GRKERNSEC_BPF_HARDEN)
102163 {
102164 .procname = "bpf_jit_enable",
102165 .data = &bpf_jit_enable,
102166 @@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
102167
102168 static __net_init int sysctl_core_net_init(struct net *net)
102169 {
102170 - struct ctl_table *tbl;
102171 + ctl_table_no_const *tbl = NULL;
102172
102173 net->core.sysctl_somaxconn = SOMAXCONN;
102174
102175 - tbl = netns_core_table;
102176 if (!net_eq(net, &init_net)) {
102177 - tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
102178 + tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
102179 if (tbl == NULL)
102180 goto err_dup;
102181
102182 @@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
102183 if (net->user_ns != &init_user_ns) {
102184 tbl[0].procname = NULL;
102185 }
102186 - }
102187 -
102188 - net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
102189 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
102190 + } else
102191 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
102192 if (net->core.sysctl_hdr == NULL)
102193 goto err_reg;
102194
102195 return 0;
102196
102197 err_reg:
102198 - if (tbl != netns_core_table)
102199 - kfree(tbl);
102200 + kfree(tbl);
102201 err_dup:
102202 return -ENOMEM;
102203 }
102204 @@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
102205 kfree(tbl);
102206 }
102207
102208 -static __net_initdata struct pernet_operations sysctl_core_ops = {
102209 +static __net_initconst struct pernet_operations sysctl_core_ops = {
102210 .init = sysctl_core_net_init,
102211 .exit = sysctl_core_net_exit,
102212 };
102213 diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
102214 index ae011b4..d2d18bf 100644
102215 --- a/net/decnet/af_decnet.c
102216 +++ b/net/decnet/af_decnet.c
102217 @@ -465,6 +465,7 @@ static struct proto dn_proto = {
102218 .sysctl_rmem = sysctl_decnet_rmem,
102219 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
102220 .obj_size = sizeof(struct dn_sock),
102221 + .slab_flags = SLAB_USERCOPY,
102222 };
102223
102224 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
102225 diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
102226 index 3b726f3..1af6368 100644
102227 --- a/net/decnet/dn_dev.c
102228 +++ b/net/decnet/dn_dev.c
102229 @@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
102230 .extra1 = &min_t3,
102231 .extra2 = &max_t3
102232 },
102233 - {0}
102234 + { }
102235 },
102236 };
102237
102238 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
102239 index 5325b54..a0d4d69 100644
102240 --- a/net/decnet/sysctl_net_decnet.c
102241 +++ b/net/decnet/sysctl_net_decnet.c
102242 @@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
102243
102244 if (len > *lenp) len = *lenp;
102245
102246 - if (copy_to_user(buffer, addr, len))
102247 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
102248 return -EFAULT;
102249
102250 *lenp = len;
102251 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
102252
102253 if (len > *lenp) len = *lenp;
102254
102255 - if (copy_to_user(buffer, devname, len))
102256 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
102257 return -EFAULT;
102258
102259 *lenp = len;
102260 diff --git a/net/ieee802154/reassembly.c b/net/ieee802154/reassembly.c
102261 index 32755cb..236d827 100644
102262 --- a/net/ieee802154/reassembly.c
102263 +++ b/net/ieee802154/reassembly.c
102264 @@ -433,14 +433,13 @@ static struct ctl_table lowpan_frags_ctl_table[] = {
102265
102266 static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
102267 {
102268 - struct ctl_table *table;
102269 + ctl_table_no_const *table = NULL;
102270 struct ctl_table_header *hdr;
102271 struct netns_ieee802154_lowpan *ieee802154_lowpan =
102272 net_ieee802154_lowpan(net);
102273
102274 - table = lowpan_frags_ns_ctl_table;
102275 if (!net_eq(net, &init_net)) {
102276 - table = kmemdup(table, sizeof(lowpan_frags_ns_ctl_table),
102277 + table = kmemdup(lowpan_frags_ns_ctl_table, sizeof(lowpan_frags_ns_ctl_table),
102278 GFP_KERNEL);
102279 if (table == NULL)
102280 goto err_alloc;
102281 @@ -455,9 +454,9 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
102282 /* Don't export sysctls to unprivileged users */
102283 if (net->user_ns != &init_user_ns)
102284 table[0].procname = NULL;
102285 - }
102286 -
102287 - hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
102288 + hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
102289 + } else
102290 + hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", lowpan_frags_ns_ctl_table);
102291 if (hdr == NULL)
102292 goto err_reg;
102293
102294 @@ -465,8 +464,7 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
102295 return 0;
102296
102297 err_reg:
102298 - if (!net_eq(net, &init_net))
102299 - kfree(table);
102300 + kfree(table);
102301 err_alloc:
102302 return -ENOMEM;
102303 }
102304 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
102305 index 214882e..ec032f6 100644
102306 --- a/net/ipv4/devinet.c
102307 +++ b/net/ipv4/devinet.c
102308 @@ -69,7 +69,8 @@
102309
102310 static struct ipv4_devconf ipv4_devconf = {
102311 .data = {
102312 - [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 1,
102313 + [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 0,
102314 + [IPV4_DEVCONF_RP_FILTER - 1] = 1,
102315 [IPV4_DEVCONF_SEND_REDIRECTS - 1] = 1,
102316 [IPV4_DEVCONF_SECURE_REDIRECTS - 1] = 1,
102317 [IPV4_DEVCONF_SHARED_MEDIA - 1] = 1,
102318 @@ -80,7 +81,8 @@ static struct ipv4_devconf ipv4_devconf = {
102319
102320 static struct ipv4_devconf ipv4_devconf_dflt = {
102321 .data = {
102322 - [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 1,
102323 + [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 0,
102324 + [IPV4_DEVCONF_RP_FILTER - 1] = 1,
102325 [IPV4_DEVCONF_SEND_REDIRECTS - 1] = 1,
102326 [IPV4_DEVCONF_SECURE_REDIRECTS - 1] = 1,
102327 [IPV4_DEVCONF_SHARED_MEDIA - 1] = 1,
102328 @@ -1548,7 +1550,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
102329 idx = 0;
102330 head = &net->dev_index_head[h];
102331 rcu_read_lock();
102332 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
102333 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
102334 net->dev_base_seq;
102335 hlist_for_each_entry_rcu(dev, head, index_hlist) {
102336 if (idx < s_idx)
102337 @@ -1866,7 +1868,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
102338 idx = 0;
102339 head = &net->dev_index_head[h];
102340 rcu_read_lock();
102341 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
102342 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
102343 net->dev_base_seq;
102344 hlist_for_each_entry_rcu(dev, head, index_hlist) {
102345 if (idx < s_idx)
102346 @@ -2101,7 +2103,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
102347 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
102348 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
102349
102350 -static struct devinet_sysctl_table {
102351 +static const struct devinet_sysctl_table {
102352 struct ctl_table_header *sysctl_header;
102353 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
102354 } devinet_sysctl = {
102355 @@ -2233,7 +2235,7 @@ static __net_init int devinet_init_net(struct net *net)
102356 int err;
102357 struct ipv4_devconf *all, *dflt;
102358 #ifdef CONFIG_SYSCTL
102359 - struct ctl_table *tbl = ctl_forward_entry;
102360 + ctl_table_no_const *tbl = NULL;
102361 struct ctl_table_header *forw_hdr;
102362 #endif
102363
102364 @@ -2251,7 +2253,7 @@ static __net_init int devinet_init_net(struct net *net)
102365 goto err_alloc_dflt;
102366
102367 #ifdef CONFIG_SYSCTL
102368 - tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
102369 + tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
102370 if (tbl == NULL)
102371 goto err_alloc_ctl;
102372
102373 @@ -2271,7 +2273,10 @@ static __net_init int devinet_init_net(struct net *net)
102374 goto err_reg_dflt;
102375
102376 err = -ENOMEM;
102377 - forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
102378 + if (!net_eq(net, &init_net))
102379 + forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
102380 + else
102381 + forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
102382 if (forw_hdr == NULL)
102383 goto err_reg_ctl;
102384 net->ipv4.forw_hdr = forw_hdr;
102385 @@ -2287,8 +2292,7 @@ err_reg_ctl:
102386 err_reg_dflt:
102387 __devinet_sysctl_unregister(all);
102388 err_reg_all:
102389 - if (tbl != ctl_forward_entry)
102390 - kfree(tbl);
102391 + kfree(tbl);
102392 err_alloc_ctl:
102393 #endif
102394 if (dflt != &ipv4_devconf_dflt)
102395 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
102396 index 255aa99..45c78f8 100644
102397 --- a/net/ipv4/fib_frontend.c
102398 +++ b/net/ipv4/fib_frontend.c
102399 @@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
102400 #ifdef CONFIG_IP_ROUTE_MULTIPATH
102401 fib_sync_up(dev);
102402 #endif
102403 - atomic_inc(&net->ipv4.dev_addr_genid);
102404 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
102405 rt_cache_flush(dev_net(dev));
102406 break;
102407 case NETDEV_DOWN:
102408 fib_del_ifaddr(ifa, NULL);
102409 - atomic_inc(&net->ipv4.dev_addr_genid);
102410 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
102411 if (ifa->ifa_dev->ifa_list == NULL) {
102412 /* Last address was deleted from this interface.
102413 * Disable IP.
102414 @@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
102415 #ifdef CONFIG_IP_ROUTE_MULTIPATH
102416 fib_sync_up(dev);
102417 #endif
102418 - atomic_inc(&net->ipv4.dev_addr_genid);
102419 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
102420 rt_cache_flush(net);
102421 break;
102422 case NETDEV_DOWN:
102423 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
102424 index 4a74ea8..32335a7 100644
102425 --- a/net/ipv4/fib_semantics.c
102426 +++ b/net/ipv4/fib_semantics.c
102427 @@ -768,7 +768,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
102428 nh->nh_saddr = inet_select_addr(nh->nh_dev,
102429 nh->nh_gw,
102430 nh->nh_parent->fib_scope);
102431 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
102432 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
102433
102434 return nh->nh_saddr;
102435 }
102436 diff --git a/net/ipv4/gre_offload.c b/net/ipv4/gre_offload.c
102437 index dd73bea..a2eec02 100644
102438 --- a/net/ipv4/gre_offload.c
102439 +++ b/net/ipv4/gre_offload.c
102440 @@ -59,13 +59,13 @@ static struct sk_buff *gre_gso_segment(struct sk_buff *skb,
102441 if (csum)
102442 skb->encap_hdr_csum = 1;
102443
102444 - if (unlikely(!pskb_may_pull(skb, ghl)))
102445 - goto out;
102446 -
102447 /* setup inner skb. */
102448 skb->protocol = greh->protocol;
102449 skb->encapsulation = 0;
102450
102451 + if (unlikely(!pskb_may_pull(skb, ghl)))
102452 + goto out;
102453 +
102454 __skb_pull(skb, ghl);
102455 skb_reset_mac_header(skb);
102456 skb_set_network_header(skb, skb_inner_network_offset(skb));
102457 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
102458 index 43116e8..ba0916a8 100644
102459 --- a/net/ipv4/inet_hashtables.c
102460 +++ b/net/ipv4/inet_hashtables.c
102461 @@ -18,6 +18,7 @@
102462 #include <linux/sched.h>
102463 #include <linux/slab.h>
102464 #include <linux/wait.h>
102465 +#include <linux/security.h>
102466
102467 #include <net/inet_connection_sock.h>
102468 #include <net/inet_hashtables.h>
102469 @@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
102470 return inet_ehashfn(net, laddr, lport, faddr, fport);
102471 }
102472
102473 +extern void gr_update_task_in_ip_table(const struct inet_sock *inet);
102474 +
102475 /*
102476 * Allocate and initialize a new local port bind bucket.
102477 * The bindhash mutex for snum's hash chain must be held here.
102478 @@ -554,6 +557,8 @@ ok:
102479 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
102480 spin_unlock(&head->lock);
102481
102482 + gr_update_task_in_ip_table(inet_sk(sk));
102483 +
102484 if (tw) {
102485 inet_twsk_deschedule(tw, death_row);
102486 while (twrefcnt) {
102487 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
102488 index bd5f592..e80e605 100644
102489 --- a/net/ipv4/inetpeer.c
102490 +++ b/net/ipv4/inetpeer.c
102491 @@ -482,7 +482,7 @@ relookup:
102492 if (p) {
102493 p->daddr = *daddr;
102494 atomic_set(&p->refcnt, 1);
102495 - atomic_set(&p->rid, 0);
102496 + atomic_set_unchecked(&p->rid, 0);
102497 p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
102498 p->rate_tokens = 0;
102499 /* 60*HZ is arbitrary, but chosen enough high so that the first
102500 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
102501 index 15f0e2b..8cf8177 100644
102502 --- a/net/ipv4/ip_fragment.c
102503 +++ b/net/ipv4/ip_fragment.c
102504 @@ -268,7 +268,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
102505 return 0;
102506
102507 start = qp->rid;
102508 - end = atomic_inc_return(&peer->rid);
102509 + end = atomic_inc_return_unchecked(&peer->rid);
102510 qp->rid = end;
102511
102512 rc = qp->q.fragments && (end - start) > max;
102513 @@ -746,12 +746,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
102514
102515 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
102516 {
102517 - struct ctl_table *table;
102518 + ctl_table_no_const *table = NULL;
102519 struct ctl_table_header *hdr;
102520
102521 - table = ip4_frags_ns_ctl_table;
102522 if (!net_eq(net, &init_net)) {
102523 - table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
102524 + table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
102525 if (table == NULL)
102526 goto err_alloc;
102527
102528 @@ -765,9 +764,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
102529 /* Don't export sysctls to unprivileged users */
102530 if (net->user_ns != &init_user_ns)
102531 table[0].procname = NULL;
102532 - }
102533 + hdr = register_net_sysctl(net, "net/ipv4", table);
102534 + } else
102535 + hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
102536
102537 - hdr = register_net_sysctl(net, "net/ipv4", table);
102538 if (hdr == NULL)
102539 goto err_reg;
102540
102541 @@ -775,8 +775,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
102542 return 0;
102543
102544 err_reg:
102545 - if (!net_eq(net, &init_net))
102546 - kfree(table);
102547 + kfree(table);
102548 err_alloc:
102549 return -ENOMEM;
102550 }
102551 diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
102552 index 9b84254..c776611 100644
102553 --- a/net/ipv4/ip_gre.c
102554 +++ b/net/ipv4/ip_gre.c
102555 @@ -115,7 +115,7 @@ static bool log_ecn_error = true;
102556 module_param(log_ecn_error, bool, 0644);
102557 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
102558
102559 -static struct rtnl_link_ops ipgre_link_ops __read_mostly;
102560 +static struct rtnl_link_ops ipgre_link_ops;
102561 static int ipgre_tunnel_init(struct net_device *dev);
102562
102563 static int ipgre_net_id __read_mostly;
102564 @@ -733,7 +733,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
102565 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
102566 };
102567
102568 -static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
102569 +static struct rtnl_link_ops ipgre_link_ops = {
102570 .kind = "gre",
102571 .maxtype = IFLA_GRE_MAX,
102572 .policy = ipgre_policy,
102573 @@ -747,7 +747,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
102574 .fill_info = ipgre_fill_info,
102575 };
102576
102577 -static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
102578 +static struct rtnl_link_ops ipgre_tap_ops = {
102579 .kind = "gretap",
102580 .maxtype = IFLA_GRE_MAX,
102581 .policy = ipgre_policy,
102582 diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c
102583 index 3d4da2c..40f9c29 100644
102584 --- a/net/ipv4/ip_input.c
102585 +++ b/net/ipv4/ip_input.c
102586 @@ -147,6 +147,10 @@
102587 #include <linux/mroute.h>
102588 #include <linux/netlink.h>
102589
102590 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102591 +extern int grsec_enable_blackhole;
102592 +#endif
102593 +
102594 /*
102595 * Process Router Attention IP option (RFC 2113)
102596 */
102597 @@ -223,6 +227,9 @@ static int ip_local_deliver_finish(struct sk_buff *skb)
102598 if (!raw) {
102599 if (xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) {
102600 IP_INC_STATS_BH(net, IPSTATS_MIB_INUNKNOWNPROTOS);
102601 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102602 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
102603 +#endif
102604 icmp_send(skb, ICMP_DEST_UNREACH,
102605 ICMP_PROT_UNREACH, 0);
102606 }
102607 diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
102608 index c43a1e2..73cbbe1 100644
102609 --- a/net/ipv4/ip_output.c
102610 +++ b/net/ipv4/ip_output.c
102611 @@ -231,7 +231,7 @@ static int ip_finish_output_gso(struct sk_buff *skb)
102612 */
102613 features = netif_skb_features(skb);
102614 segs = skb_gso_segment(skb, features & ~NETIF_F_GSO_MASK);
102615 - if (IS_ERR(segs)) {
102616 + if (IS_ERR_OR_NULL(segs)) {
102617 kfree_skb(skb);
102618 return -ENOMEM;
102619 }
102620 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
102621 index 2407e5d..edc2f1a 100644
102622 --- a/net/ipv4/ip_sockglue.c
102623 +++ b/net/ipv4/ip_sockglue.c
102624 @@ -1188,7 +1188,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
102625 len = min_t(unsigned int, len, opt->optlen);
102626 if (put_user(len, optlen))
102627 return -EFAULT;
102628 - if (copy_to_user(optval, opt->__data, len))
102629 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
102630 + copy_to_user(optval, opt->__data, len))
102631 return -EFAULT;
102632 return 0;
102633 }
102634 @@ -1319,7 +1320,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
102635 if (sk->sk_type != SOCK_STREAM)
102636 return -ENOPROTOOPT;
102637
102638 - msg.msg_control = (__force void *) optval;
102639 + msg.msg_control = (__force_kernel void *) optval;
102640 msg.msg_controllen = len;
102641 msg.msg_flags = flags;
102642
102643 diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
102644 index e453cb7..3c8d952 100644
102645 --- a/net/ipv4/ip_vti.c
102646 +++ b/net/ipv4/ip_vti.c
102647 @@ -45,7 +45,7 @@
102648 #include <net/net_namespace.h>
102649 #include <net/netns/generic.h>
102650
102651 -static struct rtnl_link_ops vti_link_ops __read_mostly;
102652 +static struct rtnl_link_ops vti_link_ops;
102653
102654 static int vti_net_id __read_mostly;
102655 static int vti_tunnel_init(struct net_device *dev);
102656 @@ -519,7 +519,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
102657 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
102658 };
102659
102660 -static struct rtnl_link_ops vti_link_ops __read_mostly = {
102661 +static struct rtnl_link_ops vti_link_ops = {
102662 .kind = "vti",
102663 .maxtype = IFLA_VTI_MAX,
102664 .policy = vti_policy,
102665 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
102666 index 5bbef4f..5bc4fb6 100644
102667 --- a/net/ipv4/ipconfig.c
102668 +++ b/net/ipv4/ipconfig.c
102669 @@ -332,7 +332,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
102670
102671 mm_segment_t oldfs = get_fs();
102672 set_fs(get_ds());
102673 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
102674 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
102675 set_fs(oldfs);
102676 return res;
102677 }
102678 @@ -343,7 +343,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
102679
102680 mm_segment_t oldfs = get_fs();
102681 set_fs(get_ds());
102682 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
102683 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
102684 set_fs(oldfs);
102685 return res;
102686 }
102687 @@ -354,7 +354,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
102688
102689 mm_segment_t oldfs = get_fs();
102690 set_fs(get_ds());
102691 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
102692 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
102693 set_fs(oldfs);
102694 return res;
102695 }
102696 diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
102697 index 62eaa00..29b2dc2 100644
102698 --- a/net/ipv4/ipip.c
102699 +++ b/net/ipv4/ipip.c
102700 @@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
102701 static int ipip_net_id __read_mostly;
102702
102703 static int ipip_tunnel_init(struct net_device *dev);
102704 -static struct rtnl_link_ops ipip_link_ops __read_mostly;
102705 +static struct rtnl_link_ops ipip_link_ops;
102706
102707 static int ipip_err(struct sk_buff *skb, u32 info)
102708 {
102709 @@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
102710 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
102711 };
102712
102713 -static struct rtnl_link_ops ipip_link_ops __read_mostly = {
102714 +static struct rtnl_link_ops ipip_link_ops = {
102715 .kind = "ipip",
102716 .maxtype = IFLA_IPTUN_MAX,
102717 .policy = ipip_policy,
102718 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
102719 index f95b6f9..2ee2097 100644
102720 --- a/net/ipv4/netfilter/arp_tables.c
102721 +++ b/net/ipv4/netfilter/arp_tables.c
102722 @@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
102723 #endif
102724
102725 static int get_info(struct net *net, void __user *user,
102726 - const int *len, int compat)
102727 + int len, int compat)
102728 {
102729 char name[XT_TABLE_MAXNAMELEN];
102730 struct xt_table *t;
102731 int ret;
102732
102733 - if (*len != sizeof(struct arpt_getinfo)) {
102734 - duprintf("length %u != %Zu\n", *len,
102735 + if (len != sizeof(struct arpt_getinfo)) {
102736 + duprintf("length %u != %Zu\n", len,
102737 sizeof(struct arpt_getinfo));
102738 return -EINVAL;
102739 }
102740 @@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
102741 info.size = private->size;
102742 strcpy(info.name, name);
102743
102744 - if (copy_to_user(user, &info, *len) != 0)
102745 + if (copy_to_user(user, &info, len) != 0)
102746 ret = -EFAULT;
102747 else
102748 ret = 0;
102749 @@ -1690,7 +1690,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
102750
102751 switch (cmd) {
102752 case ARPT_SO_GET_INFO:
102753 - ret = get_info(sock_net(sk), user, len, 1);
102754 + ret = get_info(sock_net(sk), user, *len, 1);
102755 break;
102756 case ARPT_SO_GET_ENTRIES:
102757 ret = compat_get_entries(sock_net(sk), user, len);
102758 @@ -1735,7 +1735,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
102759
102760 switch (cmd) {
102761 case ARPT_SO_GET_INFO:
102762 - ret = get_info(sock_net(sk), user, len, 0);
102763 + ret = get_info(sock_net(sk), user, *len, 0);
102764 break;
102765
102766 case ARPT_SO_GET_ENTRIES:
102767 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
102768 index 99e810f..3711b81 100644
102769 --- a/net/ipv4/netfilter/ip_tables.c
102770 +++ b/net/ipv4/netfilter/ip_tables.c
102771 @@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
102772 #endif
102773
102774 static int get_info(struct net *net, void __user *user,
102775 - const int *len, int compat)
102776 + int len, int compat)
102777 {
102778 char name[XT_TABLE_MAXNAMELEN];
102779 struct xt_table *t;
102780 int ret;
102781
102782 - if (*len != sizeof(struct ipt_getinfo)) {
102783 - duprintf("length %u != %zu\n", *len,
102784 + if (len != sizeof(struct ipt_getinfo)) {
102785 + duprintf("length %u != %zu\n", len,
102786 sizeof(struct ipt_getinfo));
102787 return -EINVAL;
102788 }
102789 @@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
102790 info.size = private->size;
102791 strcpy(info.name, name);
102792
102793 - if (copy_to_user(user, &info, *len) != 0)
102794 + if (copy_to_user(user, &info, len) != 0)
102795 ret = -EFAULT;
102796 else
102797 ret = 0;
102798 @@ -1973,7 +1973,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
102799
102800 switch (cmd) {
102801 case IPT_SO_GET_INFO:
102802 - ret = get_info(sock_net(sk), user, len, 1);
102803 + ret = get_info(sock_net(sk), user, *len, 1);
102804 break;
102805 case IPT_SO_GET_ENTRIES:
102806 ret = compat_get_entries(sock_net(sk), user, len);
102807 @@ -2020,7 +2020,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
102808
102809 switch (cmd) {
102810 case IPT_SO_GET_INFO:
102811 - ret = get_info(sock_net(sk), user, len, 0);
102812 + ret = get_info(sock_net(sk), user, *len, 0);
102813 break;
102814
102815 case IPT_SO_GET_ENTRIES:
102816 diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
102817 index 2510c02..cfb34fa 100644
102818 --- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
102819 +++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
102820 @@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
102821 spin_lock_init(&cn->lock);
102822
102823 #ifdef CONFIG_PROC_FS
102824 - cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
102825 + cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
102826 if (!cn->procdir) {
102827 pr_err("Unable to proc dir entry\n");
102828 return -ENOMEM;
102829 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
102830 index a3c59a0..2e88bfd 100644
102831 --- a/net/ipv4/ping.c
102832 +++ b/net/ipv4/ping.c
102833 @@ -59,7 +59,7 @@ struct ping_table {
102834 };
102835
102836 static struct ping_table ping_table;
102837 -struct pingv6_ops pingv6_ops;
102838 +struct pingv6_ops *pingv6_ops;
102839 EXPORT_SYMBOL_GPL(pingv6_ops);
102840
102841 static u16 ping_port_rover;
102842 @@ -217,6 +217,8 @@ static struct sock *ping_lookup(struct net *net, struct sk_buff *skb, u16 ident)
102843 &ipv6_hdr(skb)->daddr))
102844 continue;
102845 #endif
102846 + } else {
102847 + continue;
102848 }
102849
102850 if (sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif)
102851 @@ -348,7 +350,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
102852 return -ENODEV;
102853 }
102854 }
102855 - has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
102856 + has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
102857 scoped);
102858 rcu_read_unlock();
102859
102860 @@ -556,7 +558,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
102861 }
102862 #if IS_ENABLED(CONFIG_IPV6)
102863 } else if (skb->protocol == htons(ETH_P_IPV6)) {
102864 - harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
102865 + harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
102866 #endif
102867 }
102868
102869 @@ -574,7 +576,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
102870 info, (u8 *)icmph);
102871 #if IS_ENABLED(CONFIG_IPV6)
102872 } else if (family == AF_INET6) {
102873 - pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
102874 + pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
102875 info, (u8 *)icmph);
102876 #endif
102877 }
102878 @@ -858,7 +860,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
102879 return ip_recv_error(sk, msg, len, addr_len);
102880 #if IS_ENABLED(CONFIG_IPV6)
102881 } else if (family == AF_INET6) {
102882 - return pingv6_ops.ipv6_recv_error(sk, msg, len,
102883 + return pingv6_ops->ipv6_recv_error(sk, msg, len,
102884 addr_len);
102885 #endif
102886 }
102887 @@ -916,10 +918,10 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
102888 }
102889
102890 if (inet6_sk(sk)->rxopt.all)
102891 - pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
102892 + pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
102893 if (skb->protocol == htons(ETH_P_IPV6) &&
102894 inet6_sk(sk)->rxopt.all)
102895 - pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
102896 + pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
102897 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
102898 ip_cmsg_recv(msg, skb);
102899 #endif
102900 @@ -1111,7 +1113,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
102901 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
102902 0, sock_i_ino(sp),
102903 atomic_read(&sp->sk_refcnt), sp,
102904 - atomic_read(&sp->sk_drops));
102905 + atomic_read_unchecked(&sp->sk_drops));
102906 }
102907
102908 static int ping_v4_seq_show(struct seq_file *seq, void *v)
102909 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
102910 index 739db31..74f0210 100644
102911 --- a/net/ipv4/raw.c
102912 +++ b/net/ipv4/raw.c
102913 @@ -314,7 +314,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
102914 int raw_rcv(struct sock *sk, struct sk_buff *skb)
102915 {
102916 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
102917 - atomic_inc(&sk->sk_drops);
102918 + atomic_inc_unchecked(&sk->sk_drops);
102919 kfree_skb(skb);
102920 return NET_RX_DROP;
102921 }
102922 @@ -755,16 +755,20 @@ static int raw_init(struct sock *sk)
102923
102924 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
102925 {
102926 + struct icmp_filter filter;
102927 +
102928 if (optlen > sizeof(struct icmp_filter))
102929 optlen = sizeof(struct icmp_filter);
102930 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
102931 + if (copy_from_user(&filter, optval, optlen))
102932 return -EFAULT;
102933 + raw_sk(sk)->filter = filter;
102934 return 0;
102935 }
102936
102937 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
102938 {
102939 int len, ret = -EFAULT;
102940 + struct icmp_filter filter;
102941
102942 if (get_user(len, optlen))
102943 goto out;
102944 @@ -774,8 +778,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
102945 if (len > sizeof(struct icmp_filter))
102946 len = sizeof(struct icmp_filter);
102947 ret = -EFAULT;
102948 - if (put_user(len, optlen) ||
102949 - copy_to_user(optval, &raw_sk(sk)->filter, len))
102950 + filter = raw_sk(sk)->filter;
102951 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
102952 goto out;
102953 ret = 0;
102954 out: return ret;
102955 @@ -1004,7 +1008,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
102956 0, 0L, 0,
102957 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
102958 0, sock_i_ino(sp),
102959 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
102960 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
102961 }
102962
102963 static int raw_seq_show(struct seq_file *seq, void *v)
102964 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
102965 index 29836f8..bd1e2ba 100644
102966 --- a/net/ipv4/route.c
102967 +++ b/net/ipv4/route.c
102968 @@ -228,7 +228,7 @@ static const struct seq_operations rt_cache_seq_ops = {
102969
102970 static int rt_cache_seq_open(struct inode *inode, struct file *file)
102971 {
102972 - return seq_open(file, &rt_cache_seq_ops);
102973 + return seq_open_restrict(file, &rt_cache_seq_ops);
102974 }
102975
102976 static const struct file_operations rt_cache_seq_fops = {
102977 @@ -319,7 +319,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
102978
102979 static int rt_cpu_seq_open(struct inode *inode, struct file *file)
102980 {
102981 - return seq_open(file, &rt_cpu_seq_ops);
102982 + return seq_open_restrict(file, &rt_cpu_seq_ops);
102983 }
102984
102985 static const struct file_operations rt_cpu_seq_fops = {
102986 @@ -357,7 +357,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
102987
102988 static int rt_acct_proc_open(struct inode *inode, struct file *file)
102989 {
102990 - return single_open(file, rt_acct_proc_show, NULL);
102991 + return single_open_restrict(file, rt_acct_proc_show, NULL);
102992 }
102993
102994 static const struct file_operations rt_acct_proc_fops = {
102995 @@ -459,11 +459,11 @@ static struct neighbour *ipv4_neigh_lookup(const struct dst_entry *dst,
102996
102997 #define IP_IDENTS_SZ 2048u
102998 struct ip_ident_bucket {
102999 - atomic_t id;
103000 + atomic_unchecked_t id;
103001 u32 stamp32;
103002 };
103003
103004 -static struct ip_ident_bucket *ip_idents __read_mostly;
103005 +static struct ip_ident_bucket ip_idents[IP_IDENTS_SZ] __read_mostly;
103006
103007 /* In order to protect privacy, we add a perturbation to identifiers
103008 * if one generator is seldom used. This makes hard for an attacker
103009 @@ -479,7 +479,7 @@ u32 ip_idents_reserve(u32 hash, int segs)
103010 if (old != now && cmpxchg(&bucket->stamp32, old, now) == old)
103011 delta = prandom_u32_max(now - old);
103012
103013 - return atomic_add_return(segs + delta, &bucket->id) - segs;
103014 + return atomic_add_return_unchecked(segs + delta, &bucket->id) - segs;
103015 }
103016 EXPORT_SYMBOL(ip_idents_reserve);
103017
103018 @@ -2624,34 +2624,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
103019 .maxlen = sizeof(int),
103020 .mode = 0200,
103021 .proc_handler = ipv4_sysctl_rtcache_flush,
103022 + .extra1 = &init_net,
103023 },
103024 { },
103025 };
103026
103027 static __net_init int sysctl_route_net_init(struct net *net)
103028 {
103029 - struct ctl_table *tbl;
103030 + ctl_table_no_const *tbl = NULL;
103031
103032 - tbl = ipv4_route_flush_table;
103033 if (!net_eq(net, &init_net)) {
103034 - tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
103035 + tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
103036 if (tbl == NULL)
103037 goto err_dup;
103038
103039 /* Don't export sysctls to unprivileged users */
103040 if (net->user_ns != &init_user_ns)
103041 tbl[0].procname = NULL;
103042 - }
103043 - tbl[0].extra1 = net;
103044 + tbl[0].extra1 = net;
103045 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
103046 + } else
103047 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
103048
103049 - net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
103050 if (net->ipv4.route_hdr == NULL)
103051 goto err_reg;
103052 return 0;
103053
103054 err_reg:
103055 - if (tbl != ipv4_route_flush_table)
103056 - kfree(tbl);
103057 + kfree(tbl);
103058 err_dup:
103059 return -ENOMEM;
103060 }
103061 @@ -2674,8 +2674,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
103062
103063 static __net_init int rt_genid_init(struct net *net)
103064 {
103065 - atomic_set(&net->ipv4.rt_genid, 0);
103066 - atomic_set(&net->fnhe_genid, 0);
103067 + atomic_set_unchecked(&net->ipv4.rt_genid, 0);
103068 + atomic_set_unchecked(&net->fnhe_genid, 0);
103069 get_random_bytes(&net->ipv4.dev_addr_genid,
103070 sizeof(net->ipv4.dev_addr_genid));
103071 return 0;
103072 @@ -2718,11 +2718,7 @@ int __init ip_rt_init(void)
103073 {
103074 int rc = 0;
103075
103076 - ip_idents = kmalloc(IP_IDENTS_SZ * sizeof(*ip_idents), GFP_KERNEL);
103077 - if (!ip_idents)
103078 - panic("IP: failed to allocate ip_idents\n");
103079 -
103080 - prandom_bytes(ip_idents, IP_IDENTS_SZ * sizeof(*ip_idents));
103081 + prandom_bytes(ip_idents, sizeof(ip_idents));
103082
103083 #ifdef CONFIG_IP_ROUTE_CLASSID
103084 ip_rt_acct = __alloc_percpu(256 * sizeof(struct ip_rt_acct), __alignof__(struct ip_rt_acct));
103085 diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
103086 index 79a007c..5023029 100644
103087 --- a/net/ipv4/sysctl_net_ipv4.c
103088 +++ b/net/ipv4/sysctl_net_ipv4.c
103089 @@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
103090 container_of(table->data, struct net, ipv4.ip_local_ports.range);
103091 int ret;
103092 int range[2];
103093 - struct ctl_table tmp = {
103094 + ctl_table_no_const tmp = {
103095 .data = &range,
103096 .maxlen = sizeof(range),
103097 .mode = table->mode,
103098 @@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
103099 int ret;
103100 gid_t urange[2];
103101 kgid_t low, high;
103102 - struct ctl_table tmp = {
103103 + ctl_table_no_const tmp = {
103104 .data = &urange,
103105 .maxlen = sizeof(urange),
103106 .mode = table->mode,
103107 @@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
103108 void __user *buffer, size_t *lenp, loff_t *ppos)
103109 {
103110 char val[TCP_CA_NAME_MAX];
103111 - struct ctl_table tbl = {
103112 + ctl_table_no_const tbl = {
103113 .data = val,
103114 .maxlen = TCP_CA_NAME_MAX,
103115 };
103116 @@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
103117 void __user *buffer, size_t *lenp,
103118 loff_t *ppos)
103119 {
103120 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
103121 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
103122 int ret;
103123
103124 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
103125 @@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
103126 void __user *buffer, size_t *lenp,
103127 loff_t *ppos)
103128 {
103129 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
103130 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
103131 int ret;
103132
103133 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
103134 @@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
103135 void __user *buffer, size_t *lenp,
103136 loff_t *ppos)
103137 {
103138 - struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
103139 + ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
103140 struct tcp_fastopen_context *ctxt;
103141 int ret;
103142 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
103143 @@ -857,13 +857,12 @@ static struct ctl_table ipv4_net_table[] = {
103144
103145 static __net_init int ipv4_sysctl_init_net(struct net *net)
103146 {
103147 - struct ctl_table *table;
103148 + ctl_table_no_const *table = NULL;
103149
103150 - table = ipv4_net_table;
103151 if (!net_eq(net, &init_net)) {
103152 int i;
103153
103154 - table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
103155 + table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
103156 if (table == NULL)
103157 goto err_alloc;
103158
103159 @@ -872,7 +871,10 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
103160 table[i].data += (void *)net - (void *)&init_net;
103161 }
103162
103163 - net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
103164 + if (!net_eq(net, &init_net))
103165 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
103166 + else
103167 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
103168 if (net->ipv4.ipv4_hdr == NULL)
103169 goto err_reg;
103170
103171 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
103172 index a906e02..f3b6a0f 100644
103173 --- a/net/ipv4/tcp_input.c
103174 +++ b/net/ipv4/tcp_input.c
103175 @@ -755,7 +755,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
103176 * without any lock. We want to make sure compiler wont store
103177 * intermediate values in this location.
103178 */
103179 - ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
103180 + ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
103181 sk->sk_max_pacing_rate);
103182 }
103183
103184 @@ -4488,7 +4488,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
103185 * simplifies code)
103186 */
103187 static void
103188 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
103189 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
103190 struct sk_buff *head, struct sk_buff *tail,
103191 u32 start, u32 end)
103192 {
103193 @@ -5546,6 +5546,7 @@ discard:
103194 tcp_paws_reject(&tp->rx_opt, 0))
103195 goto discard_and_undo;
103196
103197 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
103198 if (th->syn) {
103199 /* We see SYN without ACK. It is attempt of
103200 * simultaneous connect with crossed SYNs.
103201 @@ -5596,6 +5597,7 @@ discard:
103202 goto discard;
103203 #endif
103204 }
103205 +#endif
103206 /* "fifth, if neither of the SYN or RST bits is set then
103207 * drop the segment and return."
103208 */
103209 @@ -5642,7 +5644,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
103210 goto discard;
103211
103212 if (th->syn) {
103213 - if (th->fin)
103214 + if (th->fin || th->urg || th->psh)
103215 goto discard;
103216 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
103217 return 1;
103218 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
103219 index 3f49eae..bde687a 100644
103220 --- a/net/ipv4/tcp_ipv4.c
103221 +++ b/net/ipv4/tcp_ipv4.c
103222 @@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
103223 EXPORT_SYMBOL(sysctl_tcp_low_latency);
103224
103225
103226 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103227 +extern int grsec_enable_blackhole;
103228 +#endif
103229 +
103230 #ifdef CONFIG_TCP_MD5SIG
103231 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
103232 __be32 daddr, __be32 saddr, const struct tcphdr *th);
103233 @@ -1487,6 +1491,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
103234 return 0;
103235
103236 reset:
103237 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103238 + if (!grsec_enable_blackhole)
103239 +#endif
103240 tcp_v4_send_reset(rsk, skb);
103241 discard:
103242 kfree_skb(skb);
103243 @@ -1633,12 +1640,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
103244 TCP_SKB_CB(skb)->sacked = 0;
103245
103246 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
103247 - if (!sk)
103248 + if (!sk) {
103249 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103250 + ret = 1;
103251 +#endif
103252 goto no_tcp_socket;
103253 -
103254 + }
103255 process:
103256 - if (sk->sk_state == TCP_TIME_WAIT)
103257 + if (sk->sk_state == TCP_TIME_WAIT) {
103258 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103259 + ret = 2;
103260 +#endif
103261 goto do_time_wait;
103262 + }
103263
103264 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
103265 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
103266 @@ -1704,6 +1718,10 @@ csum_error:
103267 bad_packet:
103268 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
103269 } else {
103270 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103271 + if (!grsec_enable_blackhole || (ret == 1 &&
103272 + (skb->dev->flags & IFF_LOOPBACK)))
103273 +#endif
103274 tcp_v4_send_reset(NULL, skb);
103275 }
103276
103277 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
103278 index 1649988..6251843 100644
103279 --- a/net/ipv4/tcp_minisocks.c
103280 +++ b/net/ipv4/tcp_minisocks.c
103281 @@ -27,6 +27,10 @@
103282 #include <net/inet_common.h>
103283 #include <net/xfrm.h>
103284
103285 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103286 +extern int grsec_enable_blackhole;
103287 +#endif
103288 +
103289 int sysctl_tcp_syncookies __read_mostly = 1;
103290 EXPORT_SYMBOL(sysctl_tcp_syncookies);
103291
103292 @@ -740,7 +744,10 @@ embryonic_reset:
103293 * avoid becoming vulnerable to outside attack aiming at
103294 * resetting legit local connections.
103295 */
103296 - req->rsk_ops->send_reset(sk, skb);
103297 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103298 + if (!grsec_enable_blackhole)
103299 +#endif
103300 + req->rsk_ops->send_reset(sk, skb);
103301 } else if (fastopen) { /* received a valid RST pkt */
103302 reqsk_fastopen_remove(sk, req, true);
103303 tcp_reset(sk);
103304 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
103305 index 3b66610..bfbe23a 100644
103306 --- a/net/ipv4/tcp_probe.c
103307 +++ b/net/ipv4/tcp_probe.c
103308 @@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
103309 if (cnt + width >= len)
103310 break;
103311
103312 - if (copy_to_user(buf + cnt, tbuf, width))
103313 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
103314 return -EFAULT;
103315 cnt += width;
103316 }
103317 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
103318 index df90cd1..9ab2c9b 100644
103319 --- a/net/ipv4/tcp_timer.c
103320 +++ b/net/ipv4/tcp_timer.c
103321 @@ -22,6 +22,10 @@
103322 #include <linux/gfp.h>
103323 #include <net/tcp.h>
103324
103325 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103326 +extern int grsec_lastack_retries;
103327 +#endif
103328 +
103329 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
103330 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
103331 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
103332 @@ -192,6 +196,13 @@ static int tcp_write_timeout(struct sock *sk)
103333 }
103334 }
103335
103336 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103337 + if ((sk->sk_state == TCP_LAST_ACK) &&
103338 + (grsec_lastack_retries > 0) &&
103339 + (grsec_lastack_retries < retry_until))
103340 + retry_until = grsec_lastack_retries;
103341 +#endif
103342 +
103343 if (retransmits_timed_out(sk, retry_until,
103344 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
103345 /* Has it gone just too far? */
103346 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
103347 index f57c0e4..cf24bd0 100644
103348 --- a/net/ipv4/udp.c
103349 +++ b/net/ipv4/udp.c
103350 @@ -87,6 +87,7 @@
103351 #include <linux/types.h>
103352 #include <linux/fcntl.h>
103353 #include <linux/module.h>
103354 +#include <linux/security.h>
103355 #include <linux/socket.h>
103356 #include <linux/sockios.h>
103357 #include <linux/igmp.h>
103358 @@ -113,6 +114,10 @@
103359 #include <net/busy_poll.h>
103360 #include "udp_impl.h"
103361
103362 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103363 +extern int grsec_enable_blackhole;
103364 +#endif
103365 +
103366 struct udp_table udp_table __read_mostly;
103367 EXPORT_SYMBOL(udp_table);
103368
103369 @@ -594,6 +599,9 @@ static inline bool __udp_is_mcast_sock(struct net *net, struct sock *sk,
103370 return true;
103371 }
103372
103373 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
103374 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
103375 +
103376 /*
103377 * This routine is called by the ICMP module when it gets some
103378 * sort of error condition. If err < 0 then the socket should
103379 @@ -931,9 +939,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
103380 dport = usin->sin_port;
103381 if (dport == 0)
103382 return -EINVAL;
103383 +
103384 + err = gr_search_udp_sendmsg(sk, usin);
103385 + if (err)
103386 + return err;
103387 } else {
103388 if (sk->sk_state != TCP_ESTABLISHED)
103389 return -EDESTADDRREQ;
103390 +
103391 + err = gr_search_udp_sendmsg(sk, NULL);
103392 + if (err)
103393 + return err;
103394 +
103395 daddr = inet->inet_daddr;
103396 dport = inet->inet_dport;
103397 /* Open fast path for connected socket.
103398 @@ -1181,7 +1198,7 @@ static unsigned int first_packet_length(struct sock *sk)
103399 IS_UDPLITE(sk));
103400 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
103401 IS_UDPLITE(sk));
103402 - atomic_inc(&sk->sk_drops);
103403 + atomic_inc_unchecked(&sk->sk_drops);
103404 __skb_unlink(skb, rcvq);
103405 __skb_queue_tail(&list_kill, skb);
103406 }
103407 @@ -1261,6 +1278,10 @@ try_again:
103408 if (!skb)
103409 goto out;
103410
103411 + err = gr_search_udp_recvmsg(sk, skb);
103412 + if (err)
103413 + goto out_free;
103414 +
103415 ulen = skb->len - sizeof(struct udphdr);
103416 copied = len;
103417 if (copied > ulen)
103418 @@ -1294,7 +1315,7 @@ try_again:
103419 if (unlikely(err)) {
103420 trace_kfree_skb(skb, udp_recvmsg);
103421 if (!peeked) {
103422 - atomic_inc(&sk->sk_drops);
103423 + atomic_inc_unchecked(&sk->sk_drops);
103424 UDP_INC_STATS_USER(sock_net(sk),
103425 UDP_MIB_INERRORS, is_udplite);
103426 }
103427 @@ -1591,7 +1612,7 @@ csum_error:
103428 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
103429 drop:
103430 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
103431 - atomic_inc(&sk->sk_drops);
103432 + atomic_inc_unchecked(&sk->sk_drops);
103433 kfree_skb(skb);
103434 return -1;
103435 }
103436 @@ -1610,7 +1631,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
103437 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
103438
103439 if (!skb1) {
103440 - atomic_inc(&sk->sk_drops);
103441 + atomic_inc_unchecked(&sk->sk_drops);
103442 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
103443 IS_UDPLITE(sk));
103444 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
103445 @@ -1807,6 +1828,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
103446 goto csum_error;
103447
103448 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
103449 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103450 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
103451 +#endif
103452 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
103453
103454 /*
103455 @@ -2393,7 +2417,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
103456 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
103457 0, sock_i_ino(sp),
103458 atomic_read(&sp->sk_refcnt), sp,
103459 - atomic_read(&sp->sk_drops));
103460 + atomic_read_unchecked(&sp->sk_drops));
103461 }
103462
103463 int udp4_seq_show(struct seq_file *seq, void *v)
103464 diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
103465 index 6156f68..d6ab46d 100644
103466 --- a/net/ipv4/xfrm4_policy.c
103467 +++ b/net/ipv4/xfrm4_policy.c
103468 @@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
103469 fl4->flowi4_tos = iph->tos;
103470 }
103471
103472 -static inline int xfrm4_garbage_collect(struct dst_ops *ops)
103473 +static int xfrm4_garbage_collect(struct dst_ops *ops)
103474 {
103475 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
103476
103477 - xfrm4_policy_afinfo.garbage_collect(net);
103478 + xfrm_garbage_collect_deferred(net);
103479 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
103480 }
103481
103482 @@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
103483
103484 static int __net_init xfrm4_net_init(struct net *net)
103485 {
103486 - struct ctl_table *table;
103487 + ctl_table_no_const *table = NULL;
103488 struct ctl_table_header *hdr;
103489
103490 - table = xfrm4_policy_table;
103491 if (!net_eq(net, &init_net)) {
103492 - table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
103493 + table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
103494 if (!table)
103495 goto err_alloc;
103496
103497 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
103498 - }
103499 -
103500 - hdr = register_net_sysctl(net, "net/ipv4", table);
103501 + hdr = register_net_sysctl(net, "net/ipv4", table);
103502 + } else
103503 + hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
103504 if (!hdr)
103505 goto err_reg;
103506
103507 @@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
103508 return 0;
103509
103510 err_reg:
103511 - if (!net_eq(net, &init_net))
103512 - kfree(table);
103513 + kfree(table);
103514 err_alloc:
103515 return -ENOMEM;
103516 }
103517 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
103518 index 3e118df..288a0d1 100644
103519 --- a/net/ipv6/addrconf.c
103520 +++ b/net/ipv6/addrconf.c
103521 @@ -171,7 +171,7 @@ static struct ipv6_devconf ipv6_devconf __read_mostly = {
103522 .hop_limit = IPV6_DEFAULT_HOPLIMIT,
103523 .mtu6 = IPV6_MIN_MTU,
103524 .accept_ra = 1,
103525 - .accept_redirects = 1,
103526 + .accept_redirects = 0,
103527 .autoconf = 1,
103528 .force_mld_version = 0,
103529 .mldv1_unsolicited_report_interval = 10 * HZ,
103530 @@ -208,7 +208,7 @@ static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = {
103531 .hop_limit = IPV6_DEFAULT_HOPLIMIT,
103532 .mtu6 = IPV6_MIN_MTU,
103533 .accept_ra = 1,
103534 - .accept_redirects = 1,
103535 + .accept_redirects = 0,
103536 .autoconf = 1,
103537 .force_mld_version = 0,
103538 .mldv1_unsolicited_report_interval = 10 * HZ,
103539 @@ -604,7 +604,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
103540 idx = 0;
103541 head = &net->dev_index_head[h];
103542 rcu_read_lock();
103543 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
103544 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
103545 net->dev_base_seq;
103546 hlist_for_each_entry_rcu(dev, head, index_hlist) {
103547 if (idx < s_idx)
103548 @@ -2396,7 +2396,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
103549 p.iph.ihl = 5;
103550 p.iph.protocol = IPPROTO_IPV6;
103551 p.iph.ttl = 64;
103552 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
103553 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
103554
103555 if (ops->ndo_do_ioctl) {
103556 mm_segment_t oldfs = get_fs();
103557 @@ -3531,16 +3531,23 @@ static const struct file_operations if6_fops = {
103558 .release = seq_release_net,
103559 };
103560
103561 +extern void register_ipv6_seq_ops_addr(struct seq_operations *addr);
103562 +extern void unregister_ipv6_seq_ops_addr(void);
103563 +
103564 static int __net_init if6_proc_net_init(struct net *net)
103565 {
103566 - if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops))
103567 + register_ipv6_seq_ops_addr(&if6_seq_ops);
103568 + if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops)) {
103569 + unregister_ipv6_seq_ops_addr();
103570 return -ENOMEM;
103571 + }
103572 return 0;
103573 }
103574
103575 static void __net_exit if6_proc_net_exit(struct net *net)
103576 {
103577 remove_proc_entry("if_inet6", net->proc_net);
103578 + unregister_ipv6_seq_ops_addr();
103579 }
103580
103581 static struct pernet_operations if6_proc_net_ops = {
103582 @@ -4156,7 +4163,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
103583 s_ip_idx = ip_idx = cb->args[2];
103584
103585 rcu_read_lock();
103586 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
103587 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
103588 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
103589 idx = 0;
103590 head = &net->dev_index_head[h];
103591 @@ -4784,7 +4791,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
103592 rt_genid_bump_ipv6(net);
103593 break;
103594 }
103595 - atomic_inc(&net->ipv6.dev_addr_genid);
103596 + atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
103597 }
103598
103599 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
103600 @@ -4804,7 +4811,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
103601 int *valp = ctl->data;
103602 int val = *valp;
103603 loff_t pos = *ppos;
103604 - struct ctl_table lctl;
103605 + ctl_table_no_const lctl;
103606 int ret;
103607
103608 /*
103609 @@ -4889,7 +4896,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
103610 int *valp = ctl->data;
103611 int val = *valp;
103612 loff_t pos = *ppos;
103613 - struct ctl_table lctl;
103614 + ctl_table_no_const lctl;
103615 int ret;
103616
103617 /*
103618 diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
103619 index 2daa3a1..341066c 100644
103620 --- a/net/ipv6/af_inet6.c
103621 +++ b/net/ipv6/af_inet6.c
103622 @@ -766,7 +766,7 @@ static int __net_init inet6_net_init(struct net *net)
103623 net->ipv6.sysctl.icmpv6_time = 1*HZ;
103624 net->ipv6.sysctl.flowlabel_consistency = 1;
103625 net->ipv6.sysctl.auto_flowlabels = 0;
103626 - atomic_set(&net->ipv6.rt_genid, 0);
103627 + atomic_set_unchecked(&net->ipv6.rt_genid, 0);
103628
103629 err = ipv6_init_mibs(net);
103630 if (err)
103631 diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
103632 index 2753319..b7e625c 100644
103633 --- a/net/ipv6/datagram.c
103634 +++ b/net/ipv6/datagram.c
103635 @@ -939,5 +939,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
103636 0,
103637 sock_i_ino(sp),
103638 atomic_read(&sp->sk_refcnt), sp,
103639 - atomic_read(&sp->sk_drops));
103640 + atomic_read_unchecked(&sp->sk_drops));
103641 }
103642 diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
103643 index 06ba3e5..5c08d38 100644
103644 --- a/net/ipv6/icmp.c
103645 +++ b/net/ipv6/icmp.c
103646 @@ -993,7 +993,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
103647
103648 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
103649 {
103650 - struct ctl_table *table;
103651 + ctl_table_no_const *table;
103652
103653 table = kmemdup(ipv6_icmp_table_template,
103654 sizeof(ipv6_icmp_table_template),
103655 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
103656 index cacb493..3cae894 100644
103657 --- a/net/ipv6/ip6_gre.c
103658 +++ b/net/ipv6/ip6_gre.c
103659 @@ -71,8 +71,8 @@ struct ip6gre_net {
103660 struct net_device *fb_tunnel_dev;
103661 };
103662
103663 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
103664 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly;
103665 +static struct rtnl_link_ops ip6gre_link_ops;
103666 +static struct rtnl_link_ops ip6gre_tap_ops;
103667 static int ip6gre_tunnel_init(struct net_device *dev);
103668 static void ip6gre_tunnel_setup(struct net_device *dev);
103669 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
103670 @@ -1285,7 +1285,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
103671 }
103672
103673
103674 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
103675 +static struct inet6_protocol ip6gre_protocol = {
103676 .handler = ip6gre_rcv,
103677 .err_handler = ip6gre_err,
103678 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
103679 @@ -1646,7 +1646,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
103680 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
103681 };
103682
103683 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
103684 +static struct rtnl_link_ops ip6gre_link_ops = {
103685 .kind = "ip6gre",
103686 .maxtype = IFLA_GRE_MAX,
103687 .policy = ip6gre_policy,
103688 @@ -1660,7 +1660,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
103689 .fill_info = ip6gre_fill_info,
103690 };
103691
103692 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
103693 +static struct rtnl_link_ops ip6gre_tap_ops = {
103694 .kind = "ip6gretap",
103695 .maxtype = IFLA_GRE_MAX,
103696 .policy = ip6gre_policy,
103697 diff --git a/net/ipv6/ip6_offload.c b/net/ipv6/ip6_offload.c
103698 index 65eda2a..620a102 100644
103699 --- a/net/ipv6/ip6_offload.c
103700 +++ b/net/ipv6/ip6_offload.c
103701 @@ -46,6 +46,7 @@ static int ipv6_gso_pull_exthdrs(struct sk_buff *skb, int proto)
103702 if (unlikely(!pskb_may_pull(skb, len)))
103703 break;
103704
103705 + opth = (void *)skb->data;
103706 proto = opth->nexthdr;
103707 __skb_pull(skb, len);
103708 }
103709 diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
103710 index d2eeb3b..c186e9a 100644
103711 --- a/net/ipv6/ip6_tunnel.c
103712 +++ b/net/ipv6/ip6_tunnel.c
103713 @@ -86,7 +86,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
103714
103715 static int ip6_tnl_dev_init(struct net_device *dev);
103716 static void ip6_tnl_dev_setup(struct net_device *dev);
103717 -static struct rtnl_link_ops ip6_link_ops __read_mostly;
103718 +static struct rtnl_link_ops ip6_link_ops;
103719
103720 static int ip6_tnl_net_id __read_mostly;
103721 struct ip6_tnl_net {
103722 @@ -1706,7 +1706,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
103723 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
103724 };
103725
103726 -static struct rtnl_link_ops ip6_link_ops __read_mostly = {
103727 +static struct rtnl_link_ops ip6_link_ops = {
103728 .kind = "ip6tnl",
103729 .maxtype = IFLA_IPTUN_MAX,
103730 .policy = ip6_tnl_policy,
103731 diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
103732 index 99c9487..63f4d92 100644
103733 --- a/net/ipv6/ip6_vti.c
103734 +++ b/net/ipv6/ip6_vti.c
103735 @@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
103736
103737 static int vti6_dev_init(struct net_device *dev);
103738 static void vti6_dev_setup(struct net_device *dev);
103739 -static struct rtnl_link_ops vti6_link_ops __read_mostly;
103740 +static struct rtnl_link_ops vti6_link_ops;
103741
103742 static int vti6_net_id __read_mostly;
103743 struct vti6_net {
103744 @@ -972,7 +972,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
103745 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
103746 };
103747
103748 -static struct rtnl_link_ops vti6_link_ops __read_mostly = {
103749 +static struct rtnl_link_ops vti6_link_ops = {
103750 .kind = "vti6",
103751 .maxtype = IFLA_VTI_MAX,
103752 .policy = vti6_policy,
103753 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
103754 index 0c28998..d0a2ecd 100644
103755 --- a/net/ipv6/ipv6_sockglue.c
103756 +++ b/net/ipv6/ipv6_sockglue.c
103757 @@ -995,7 +995,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
103758 if (sk->sk_type != SOCK_STREAM)
103759 return -ENOPROTOOPT;
103760
103761 - msg.msg_control = optval;
103762 + msg.msg_control = (void __force_kernel *)optval;
103763 msg.msg_controllen = len;
103764 msg.msg_flags = flags;
103765
103766 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
103767 index e080fbb..412b3cf 100644
103768 --- a/net/ipv6/netfilter/ip6_tables.c
103769 +++ b/net/ipv6/netfilter/ip6_tables.c
103770 @@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
103771 #endif
103772
103773 static int get_info(struct net *net, void __user *user,
103774 - const int *len, int compat)
103775 + int len, int compat)
103776 {
103777 char name[XT_TABLE_MAXNAMELEN];
103778 struct xt_table *t;
103779 int ret;
103780
103781 - if (*len != sizeof(struct ip6t_getinfo)) {
103782 - duprintf("length %u != %zu\n", *len,
103783 + if (len != sizeof(struct ip6t_getinfo)) {
103784 + duprintf("length %u != %zu\n", len,
103785 sizeof(struct ip6t_getinfo));
103786 return -EINVAL;
103787 }
103788 @@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
103789 info.size = private->size;
103790 strcpy(info.name, name);
103791
103792 - if (copy_to_user(user, &info, *len) != 0)
103793 + if (copy_to_user(user, &info, len) != 0)
103794 ret = -EFAULT;
103795 else
103796 ret = 0;
103797 @@ -1983,7 +1983,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
103798
103799 switch (cmd) {
103800 case IP6T_SO_GET_INFO:
103801 - ret = get_info(sock_net(sk), user, len, 1);
103802 + ret = get_info(sock_net(sk), user, *len, 1);
103803 break;
103804 case IP6T_SO_GET_ENTRIES:
103805 ret = compat_get_entries(sock_net(sk), user, len);
103806 @@ -2030,7 +2030,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
103807
103808 switch (cmd) {
103809 case IP6T_SO_GET_INFO:
103810 - ret = get_info(sock_net(sk), user, len, 0);
103811 + ret = get_info(sock_net(sk), user, *len, 0);
103812 break;
103813
103814 case IP6T_SO_GET_ENTRIES:
103815 diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
103816 index 6f187c8..34b367f 100644
103817 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c
103818 +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
103819 @@ -96,12 +96,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
103820
103821 static int nf_ct_frag6_sysctl_register(struct net *net)
103822 {
103823 - struct ctl_table *table;
103824 + ctl_table_no_const *table = NULL;
103825 struct ctl_table_header *hdr;
103826
103827 - table = nf_ct_frag6_sysctl_table;
103828 if (!net_eq(net, &init_net)) {
103829 - table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
103830 + table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
103831 GFP_KERNEL);
103832 if (table == NULL)
103833 goto err_alloc;
103834 @@ -112,9 +111,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
103835 table[2].data = &net->nf_frag.frags.high_thresh;
103836 table[2].extra1 = &net->nf_frag.frags.low_thresh;
103837 table[2].extra2 = &init_net.nf_frag.frags.high_thresh;
103838 - }
103839 -
103840 - hdr = register_net_sysctl(net, "net/netfilter", table);
103841 + hdr = register_net_sysctl(net, "net/netfilter", table);
103842 + } else
103843 + hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
103844 if (hdr == NULL)
103845 goto err_reg;
103846
103847 @@ -122,8 +121,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
103848 return 0;
103849
103850 err_reg:
103851 - if (!net_eq(net, &init_net))
103852 - kfree(table);
103853 + kfree(table);
103854 err_alloc:
103855 return -ENOMEM;
103856 }
103857 diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
103858 index 5b7a1ed..d9da205 100644
103859 --- a/net/ipv6/ping.c
103860 +++ b/net/ipv6/ping.c
103861 @@ -240,6 +240,24 @@ static struct pernet_operations ping_v6_net_ops = {
103862 };
103863 #endif
103864
103865 +static struct pingv6_ops real_pingv6_ops = {
103866 + .ipv6_recv_error = ipv6_recv_error,
103867 + .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
103868 + .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
103869 + .icmpv6_err_convert = icmpv6_err_convert,
103870 + .ipv6_icmp_error = ipv6_icmp_error,
103871 + .ipv6_chk_addr = ipv6_chk_addr,
103872 +};
103873 +
103874 +static struct pingv6_ops dummy_pingv6_ops = {
103875 + .ipv6_recv_error = dummy_ipv6_recv_error,
103876 + .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
103877 + .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
103878 + .icmpv6_err_convert = dummy_icmpv6_err_convert,
103879 + .ipv6_icmp_error = dummy_ipv6_icmp_error,
103880 + .ipv6_chk_addr = dummy_ipv6_chk_addr,
103881 +};
103882 +
103883 int __init pingv6_init(void)
103884 {
103885 #ifdef CONFIG_PROC_FS
103886 @@ -247,13 +265,7 @@ int __init pingv6_init(void)
103887 if (ret)
103888 return ret;
103889 #endif
103890 - pingv6_ops.ipv6_recv_error = ipv6_recv_error;
103891 - pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
103892 - pingv6_ops.ip6_datagram_recv_specific_ctl =
103893 - ip6_datagram_recv_specific_ctl;
103894 - pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
103895 - pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
103896 - pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
103897 + pingv6_ops = &real_pingv6_ops;
103898 return inet6_register_protosw(&pingv6_protosw);
103899 }
103900
103901 @@ -262,14 +274,9 @@ int __init pingv6_init(void)
103902 */
103903 void pingv6_exit(void)
103904 {
103905 - pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
103906 - pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
103907 - pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
103908 - pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
103909 - pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
103910 - pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
103911 #ifdef CONFIG_PROC_FS
103912 unregister_pernet_subsys(&ping_v6_net_ops);
103913 #endif
103914 + pingv6_ops = &dummy_pingv6_ops;
103915 inet6_unregister_protosw(&pingv6_protosw);
103916 }
103917 diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
103918 index 2d6f860..b0165f5 100644
103919 --- a/net/ipv6/proc.c
103920 +++ b/net/ipv6/proc.c
103921 @@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
103922 if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
103923 goto proc_snmp6_fail;
103924
103925 - net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
103926 + net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
103927 if (!net->mib.proc_net_devsnmp6)
103928 goto proc_dev_snmp6_fail;
103929 return 0;
103930 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
103931 index 39d4422..b0979547 100644
103932 --- a/net/ipv6/raw.c
103933 +++ b/net/ipv6/raw.c
103934 @@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
103935 {
103936 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
103937 skb_checksum_complete(skb)) {
103938 - atomic_inc(&sk->sk_drops);
103939 + atomic_inc_unchecked(&sk->sk_drops);
103940 kfree_skb(skb);
103941 return NET_RX_DROP;
103942 }
103943 @@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
103944 struct raw6_sock *rp = raw6_sk(sk);
103945
103946 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
103947 - atomic_inc(&sk->sk_drops);
103948 + atomic_inc_unchecked(&sk->sk_drops);
103949 kfree_skb(skb);
103950 return NET_RX_DROP;
103951 }
103952 @@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
103953
103954 if (inet->hdrincl) {
103955 if (skb_checksum_complete(skb)) {
103956 - atomic_inc(&sk->sk_drops);
103957 + atomic_inc_unchecked(&sk->sk_drops);
103958 kfree_skb(skb);
103959 return NET_RX_DROP;
103960 }
103961 @@ -608,7 +608,7 @@ out:
103962 return err;
103963 }
103964
103965 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
103966 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
103967 struct flowi6 *fl6, struct dst_entry **dstp,
103968 unsigned int flags)
103969 {
103970 @@ -914,12 +914,15 @@ do_confirm:
103971 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
103972 char __user *optval, int optlen)
103973 {
103974 + struct icmp6_filter filter;
103975 +
103976 switch (optname) {
103977 case ICMPV6_FILTER:
103978 if (optlen > sizeof(struct icmp6_filter))
103979 optlen = sizeof(struct icmp6_filter);
103980 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
103981 + if (copy_from_user(&filter, optval, optlen))
103982 return -EFAULT;
103983 + raw6_sk(sk)->filter = filter;
103984 return 0;
103985 default:
103986 return -ENOPROTOOPT;
103987 @@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
103988 char __user *optval, int __user *optlen)
103989 {
103990 int len;
103991 + struct icmp6_filter filter;
103992
103993 switch (optname) {
103994 case ICMPV6_FILTER:
103995 @@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
103996 len = sizeof(struct icmp6_filter);
103997 if (put_user(len, optlen))
103998 return -EFAULT;
103999 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
104000 + filter = raw6_sk(sk)->filter;
104001 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
104002 return -EFAULT;
104003 return 0;
104004 default:
104005 diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
104006 index c6557d9..173e728 100644
104007 --- a/net/ipv6/reassembly.c
104008 +++ b/net/ipv6/reassembly.c
104009 @@ -627,12 +627,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
104010
104011 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
104012 {
104013 - struct ctl_table *table;
104014 + ctl_table_no_const *table = NULL;
104015 struct ctl_table_header *hdr;
104016
104017 - table = ip6_frags_ns_ctl_table;
104018 if (!net_eq(net, &init_net)) {
104019 - table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
104020 + table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
104021 if (table == NULL)
104022 goto err_alloc;
104023
104024 @@ -646,9 +645,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
104025 /* Don't export sysctls to unprivileged users */
104026 if (net->user_ns != &init_user_ns)
104027 table[0].procname = NULL;
104028 - }
104029 + hdr = register_net_sysctl(net, "net/ipv6", table);
104030 + } else
104031 + hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
104032
104033 - hdr = register_net_sysctl(net, "net/ipv6", table);
104034 if (hdr == NULL)
104035 goto err_reg;
104036
104037 @@ -656,8 +656,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
104038 return 0;
104039
104040 err_reg:
104041 - if (!net_eq(net, &init_net))
104042 - kfree(table);
104043 + kfree(table);
104044 err_alloc:
104045 return -ENOMEM;
104046 }
104047 diff --git a/net/ipv6/route.c b/net/ipv6/route.c
104048 index bafde82..af2c91f 100644
104049 --- a/net/ipv6/route.c
104050 +++ b/net/ipv6/route.c
104051 @@ -2967,7 +2967,7 @@ struct ctl_table ipv6_route_table_template[] = {
104052
104053 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
104054 {
104055 - struct ctl_table *table;
104056 + ctl_table_no_const *table;
104057
104058 table = kmemdup(ipv6_route_table_template,
104059 sizeof(ipv6_route_table_template),
104060 diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
104061 index ca1c7c4..37fba59 100644
104062 --- a/net/ipv6/sit.c
104063 +++ b/net/ipv6/sit.c
104064 @@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
104065 static void ipip6_dev_free(struct net_device *dev);
104066 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
104067 __be32 *v4dst);
104068 -static struct rtnl_link_ops sit_link_ops __read_mostly;
104069 +static struct rtnl_link_ops sit_link_ops;
104070
104071 static int sit_net_id __read_mostly;
104072 struct sit_net {
104073 @@ -484,11 +484,11 @@ static void ipip6_tunnel_uninit(struct net_device *dev)
104074 */
104075 static int ipip6_err_gen_icmpv6_unreach(struct sk_buff *skb)
104076 {
104077 - const struct iphdr *iph = (const struct iphdr *) skb->data;
104078 + int ihl = ((const struct iphdr *)skb->data)->ihl*4;
104079 struct rt6_info *rt;
104080 struct sk_buff *skb2;
104081
104082 - if (!pskb_may_pull(skb, iph->ihl * 4 + sizeof(struct ipv6hdr) + 8))
104083 + if (!pskb_may_pull(skb, ihl + sizeof(struct ipv6hdr) + 8))
104084 return 1;
104085
104086 skb2 = skb_clone(skb, GFP_ATOMIC);
104087 @@ -497,7 +497,7 @@ static int ipip6_err_gen_icmpv6_unreach(struct sk_buff *skb)
104088 return 1;
104089
104090 skb_dst_drop(skb2);
104091 - skb_pull(skb2, iph->ihl * 4);
104092 + skb_pull(skb2, ihl);
104093 skb_reset_network_header(skb2);
104094
104095 rt = rt6_lookup(dev_net(skb->dev), &ipv6_hdr(skb2)->saddr, NULL, 0, 0);
104096 @@ -1659,7 +1659,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
104097 unregister_netdevice_queue(dev, head);
104098 }
104099
104100 -static struct rtnl_link_ops sit_link_ops __read_mostly = {
104101 +static struct rtnl_link_ops sit_link_ops = {
104102 .kind = "sit",
104103 .maxtype = IFLA_IPTUN_MAX,
104104 .policy = ipip6_policy,
104105 diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
104106 index 0c56c93..ece50df 100644
104107 --- a/net/ipv6/sysctl_net_ipv6.c
104108 +++ b/net/ipv6/sysctl_net_ipv6.c
104109 @@ -68,7 +68,7 @@ static struct ctl_table ipv6_rotable[] = {
104110
104111 static int __net_init ipv6_sysctl_net_init(struct net *net)
104112 {
104113 - struct ctl_table *ipv6_table;
104114 + ctl_table_no_const *ipv6_table;
104115 struct ctl_table *ipv6_route_table;
104116 struct ctl_table *ipv6_icmp_table;
104117 int err;
104118 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
104119 index 264c0f2..b6512c6 100644
104120 --- a/net/ipv6/tcp_ipv6.c
104121 +++ b/net/ipv6/tcp_ipv6.c
104122 @@ -102,6 +102,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
104123 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
104124 }
104125
104126 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104127 +extern int grsec_enable_blackhole;
104128 +#endif
104129 +
104130 static void tcp_v6_hash(struct sock *sk)
104131 {
104132 if (sk->sk_state != TCP_CLOSE) {
104133 @@ -1333,6 +1337,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
104134 return 0;
104135
104136 reset:
104137 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104138 + if (!grsec_enable_blackhole)
104139 +#endif
104140 tcp_v6_send_reset(sk, skb);
104141 discard:
104142 if (opt_skb)
104143 @@ -1417,12 +1424,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
104144 TCP_SKB_CB(skb)->sacked = 0;
104145
104146 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
104147 - if (!sk)
104148 + if (!sk) {
104149 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104150 + ret = 1;
104151 +#endif
104152 goto no_tcp_socket;
104153 + }
104154
104155 process:
104156 - if (sk->sk_state == TCP_TIME_WAIT)
104157 + if (sk->sk_state == TCP_TIME_WAIT) {
104158 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104159 + ret = 2;
104160 +#endif
104161 goto do_time_wait;
104162 + }
104163
104164 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
104165 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
104166 @@ -1479,6 +1494,10 @@ csum_error:
104167 bad_packet:
104168 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
104169 } else {
104170 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104171 + if (!grsec_enable_blackhole || (ret == 1 &&
104172 + (skb->dev->flags & IFF_LOOPBACK)))
104173 +#endif
104174 tcp_v6_send_reset(NULL, skb);
104175 }
104176
104177 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
104178 index 4836af8..0e52bbd 100644
104179 --- a/net/ipv6/udp.c
104180 +++ b/net/ipv6/udp.c
104181 @@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
104182 udp_ipv6_hash_secret + net_hash_mix(net));
104183 }
104184
104185 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104186 +extern int grsec_enable_blackhole;
104187 +#endif
104188 +
104189 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
104190 {
104191 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
104192 @@ -434,7 +438,7 @@ try_again:
104193 if (unlikely(err)) {
104194 trace_kfree_skb(skb, udpv6_recvmsg);
104195 if (!peeked) {
104196 - atomic_inc(&sk->sk_drops);
104197 + atomic_inc_unchecked(&sk->sk_drops);
104198 if (is_udp4)
104199 UDP_INC_STATS_USER(sock_net(sk),
104200 UDP_MIB_INERRORS,
104201 @@ -701,7 +705,7 @@ csum_error:
104202 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
104203 drop:
104204 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
104205 - atomic_inc(&sk->sk_drops);
104206 + atomic_inc_unchecked(&sk->sk_drops);
104207 kfree_skb(skb);
104208 return -1;
104209 }
104210 @@ -740,7 +744,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
104211 if (likely(skb1 == NULL))
104212 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
104213 if (!skb1) {
104214 - atomic_inc(&sk->sk_drops);
104215 + atomic_inc_unchecked(&sk->sk_drops);
104216 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
104217 IS_UDPLITE(sk));
104218 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
104219 @@ -915,6 +919,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
104220 goto csum_error;
104221
104222 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
104223 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104224 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
104225 +#endif
104226 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
104227
104228 kfree_skb(skb);
104229 diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
104230 index 2a0bbda..442240d 100644
104231 --- a/net/ipv6/xfrm6_policy.c
104232 +++ b/net/ipv6/xfrm6_policy.c
104233 @@ -170,8 +170,10 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
104234 case IPPROTO_DCCP:
104235 if (!onlyproto && (nh + offset + 4 < skb->data ||
104236 pskb_may_pull(skb, nh + offset + 4 - skb->data))) {
104237 - __be16 *ports = (__be16 *)exthdr;
104238 + __be16 *ports;
104239
104240 + nh = skb_network_header(skb);
104241 + ports = (__be16 *)(nh + offset);
104242 fl6->fl6_sport = ports[!!reverse];
104243 fl6->fl6_dport = ports[!reverse];
104244 }
104245 @@ -180,8 +182,10 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
104246
104247 case IPPROTO_ICMPV6:
104248 if (!onlyproto && pskb_may_pull(skb, nh + offset + 2 - skb->data)) {
104249 - u8 *icmp = (u8 *)exthdr;
104250 + u8 *icmp;
104251
104252 + nh = skb_network_header(skb);
104253 + icmp = (u8 *)(nh + offset);
104254 fl6->fl6_icmp_type = icmp[0];
104255 fl6->fl6_icmp_code = icmp[1];
104256 }
104257 @@ -192,8 +196,9 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
104258 case IPPROTO_MH:
104259 if (!onlyproto && pskb_may_pull(skb, nh + offset + 3 - skb->data)) {
104260 struct ip6_mh *mh;
104261 - mh = (struct ip6_mh *)exthdr;
104262
104263 + nh = skb_network_header(skb);
104264 + mh = (struct ip6_mh *)(nh + offset);
104265 fl6->fl6_mh_type = mh->ip6mh_type;
104266 }
104267 fl6->flowi6_proto = nexthdr;
104268 @@ -212,11 +217,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
104269 }
104270 }
104271
104272 -static inline int xfrm6_garbage_collect(struct dst_ops *ops)
104273 +static int xfrm6_garbage_collect(struct dst_ops *ops)
104274 {
104275 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
104276
104277 - xfrm6_policy_afinfo.garbage_collect(net);
104278 + xfrm_garbage_collect_deferred(net);
104279 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
104280 }
104281
104282 @@ -329,19 +334,19 @@ static struct ctl_table xfrm6_policy_table[] = {
104283
104284 static int __net_init xfrm6_net_init(struct net *net)
104285 {
104286 - struct ctl_table *table;
104287 + ctl_table_no_const *table = NULL;
104288 struct ctl_table_header *hdr;
104289
104290 - table = xfrm6_policy_table;
104291 if (!net_eq(net, &init_net)) {
104292 - table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
104293 + table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
104294 if (!table)
104295 goto err_alloc;
104296
104297 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
104298 - }
104299 + hdr = register_net_sysctl(net, "net/ipv6", table);
104300 + } else
104301 + hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
104302
104303 - hdr = register_net_sysctl(net, "net/ipv6", table);
104304 if (!hdr)
104305 goto err_reg;
104306
104307 @@ -349,8 +354,7 @@ static int __net_init xfrm6_net_init(struct net *net)
104308 return 0;
104309
104310 err_reg:
104311 - if (!net_eq(net, &init_net))
104312 - kfree(table);
104313 + kfree(table);
104314 err_alloc:
104315 return -ENOMEM;
104316 }
104317 diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
104318 index e15c16a..7cf07aa 100644
104319 --- a/net/ipx/ipx_proc.c
104320 +++ b/net/ipx/ipx_proc.c
104321 @@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
104322 struct proc_dir_entry *p;
104323 int rc = -ENOMEM;
104324
104325 - ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
104326 + ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
104327
104328 if (!ipx_proc_dir)
104329 goto out;
104330 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
104331 index 61ceb4c..e788eb8 100644
104332 --- a/net/irda/ircomm/ircomm_tty.c
104333 +++ b/net/irda/ircomm/ircomm_tty.c
104334 @@ -317,10 +317,10 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
104335 add_wait_queue(&port->open_wait, &wait);
104336
104337 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
104338 - __FILE__, __LINE__, tty->driver->name, port->count);
104339 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
104340
104341 spin_lock_irqsave(&port->lock, flags);
104342 - port->count--;
104343 + atomic_dec(&port->count);
104344 port->blocked_open++;
104345 spin_unlock_irqrestore(&port->lock, flags);
104346
104347 @@ -355,7 +355,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
104348 }
104349
104350 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
104351 - __FILE__, __LINE__, tty->driver->name, port->count);
104352 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
104353
104354 schedule();
104355 }
104356 @@ -365,12 +365,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
104357
104358 spin_lock_irqsave(&port->lock, flags);
104359 if (!tty_hung_up_p(filp))
104360 - port->count++;
104361 + atomic_inc(&port->count);
104362 port->blocked_open--;
104363 spin_unlock_irqrestore(&port->lock, flags);
104364
104365 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
104366 - __FILE__, __LINE__, tty->driver->name, port->count);
104367 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
104368
104369 if (!retval)
104370 port->flags |= ASYNC_NORMAL_ACTIVE;
104371 @@ -444,12 +444,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
104372
104373 /* ++ is not atomic, so this should be protected - Jean II */
104374 spin_lock_irqsave(&self->port.lock, flags);
104375 - self->port.count++;
104376 + atomic_inc(&self->port.count);
104377 spin_unlock_irqrestore(&self->port.lock, flags);
104378 tty_port_tty_set(&self->port, tty);
104379
104380 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
104381 - self->line, self->port.count);
104382 + self->line, atomic_read(&self->port.count));
104383
104384 /* Not really used by us, but lets do it anyway */
104385 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
104386 @@ -985,7 +985,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
104387 tty_kref_put(port->tty);
104388 }
104389 port->tty = NULL;
104390 - port->count = 0;
104391 + atomic_set(&port->count, 0);
104392 spin_unlock_irqrestore(&port->lock, flags);
104393
104394 wake_up_interruptible(&port->open_wait);
104395 @@ -1342,7 +1342,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
104396 seq_putc(m, '\n');
104397
104398 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
104399 - seq_printf(m, "Open count: %d\n", self->port.count);
104400 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
104401 seq_printf(m, "Max data size: %d\n", self->max_data_size);
104402 seq_printf(m, "Max header size: %d\n", self->max_header_size);
104403
104404 diff --git a/net/irda/irproc.c b/net/irda/irproc.c
104405 index b9ac598..f88cc56 100644
104406 --- a/net/irda/irproc.c
104407 +++ b/net/irda/irproc.c
104408 @@ -66,7 +66,7 @@ void __init irda_proc_register(void)
104409 {
104410 int i;
104411
104412 - proc_irda = proc_mkdir("irda", init_net.proc_net);
104413 + proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
104414 if (proc_irda == NULL)
104415 return;
104416
104417 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
104418 index a089b6b..3ca3b60 100644
104419 --- a/net/iucv/af_iucv.c
104420 +++ b/net/iucv/af_iucv.c
104421 @@ -686,10 +686,10 @@ static void __iucv_auto_name(struct iucv_sock *iucv)
104422 {
104423 char name[12];
104424
104425 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
104426 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
104427 while (__iucv_get_sock_by_name(name)) {
104428 sprintf(name, "%08x",
104429 - atomic_inc_return(&iucv_sk_list.autobind_name));
104430 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
104431 }
104432 memcpy(iucv->src_name, name, 8);
104433 }
104434 diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
104435 index da78793..bdd78cf 100644
104436 --- a/net/iucv/iucv.c
104437 +++ b/net/iucv/iucv.c
104438 @@ -702,7 +702,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
104439 return NOTIFY_OK;
104440 }
104441
104442 -static struct notifier_block __refdata iucv_cpu_notifier = {
104443 +static struct notifier_block iucv_cpu_notifier = {
104444 .notifier_call = iucv_cpu_notify,
104445 };
104446
104447 diff --git a/net/key/af_key.c b/net/key/af_key.c
104448 index 1847ec4..26ef732 100644
104449 --- a/net/key/af_key.c
104450 +++ b/net/key/af_key.c
104451 @@ -3049,10 +3049,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
104452 static u32 get_acqseq(void)
104453 {
104454 u32 res;
104455 - static atomic_t acqseq;
104456 + static atomic_unchecked_t acqseq;
104457
104458 do {
104459 - res = atomic_inc_return(&acqseq);
104460 + res = atomic_inc_return_unchecked(&acqseq);
104461 } while (!res);
104462 return res;
104463 }
104464 diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
104465 index edb78e6..8dc654a 100644
104466 --- a/net/l2tp/l2tp_eth.c
104467 +++ b/net/l2tp/l2tp_eth.c
104468 @@ -42,12 +42,12 @@ struct l2tp_eth {
104469 struct sock *tunnel_sock;
104470 struct l2tp_session *session;
104471 struct list_head list;
104472 - atomic_long_t tx_bytes;
104473 - atomic_long_t tx_packets;
104474 - atomic_long_t tx_dropped;
104475 - atomic_long_t rx_bytes;
104476 - atomic_long_t rx_packets;
104477 - atomic_long_t rx_errors;
104478 + atomic_long_unchecked_t tx_bytes;
104479 + atomic_long_unchecked_t tx_packets;
104480 + atomic_long_unchecked_t tx_dropped;
104481 + atomic_long_unchecked_t rx_bytes;
104482 + atomic_long_unchecked_t rx_packets;
104483 + atomic_long_unchecked_t rx_errors;
104484 };
104485
104486 /* via l2tp_session_priv() */
104487 @@ -98,10 +98,10 @@ static int l2tp_eth_dev_xmit(struct sk_buff *skb, struct net_device *dev)
104488 int ret = l2tp_xmit_skb(session, skb, session->hdr_len);
104489
104490 if (likely(ret == NET_XMIT_SUCCESS)) {
104491 - atomic_long_add(len, &priv->tx_bytes);
104492 - atomic_long_inc(&priv->tx_packets);
104493 + atomic_long_add_unchecked(len, &priv->tx_bytes);
104494 + atomic_long_inc_unchecked(&priv->tx_packets);
104495 } else {
104496 - atomic_long_inc(&priv->tx_dropped);
104497 + atomic_long_inc_unchecked(&priv->tx_dropped);
104498 }
104499 return NETDEV_TX_OK;
104500 }
104501 @@ -111,12 +111,12 @@ static struct rtnl_link_stats64 *l2tp_eth_get_stats64(struct net_device *dev,
104502 {
104503 struct l2tp_eth *priv = netdev_priv(dev);
104504
104505 - stats->tx_bytes = atomic_long_read(&priv->tx_bytes);
104506 - stats->tx_packets = atomic_long_read(&priv->tx_packets);
104507 - stats->tx_dropped = atomic_long_read(&priv->tx_dropped);
104508 - stats->rx_bytes = atomic_long_read(&priv->rx_bytes);
104509 - stats->rx_packets = atomic_long_read(&priv->rx_packets);
104510 - stats->rx_errors = atomic_long_read(&priv->rx_errors);
104511 + stats->tx_bytes = atomic_long_read_unchecked(&priv->tx_bytes);
104512 + stats->tx_packets = atomic_long_read_unchecked(&priv->tx_packets);
104513 + stats->tx_dropped = atomic_long_read_unchecked(&priv->tx_dropped);
104514 + stats->rx_bytes = atomic_long_read_unchecked(&priv->rx_bytes);
104515 + stats->rx_packets = atomic_long_read_unchecked(&priv->rx_packets);
104516 + stats->rx_errors = atomic_long_read_unchecked(&priv->rx_errors);
104517 return stats;
104518 }
104519
104520 @@ -166,15 +166,15 @@ static void l2tp_eth_dev_recv(struct l2tp_session *session, struct sk_buff *skb,
104521 nf_reset(skb);
104522
104523 if (dev_forward_skb(dev, skb) == NET_RX_SUCCESS) {
104524 - atomic_long_inc(&priv->rx_packets);
104525 - atomic_long_add(data_len, &priv->rx_bytes);
104526 + atomic_long_inc_unchecked(&priv->rx_packets);
104527 + atomic_long_add_unchecked(data_len, &priv->rx_bytes);
104528 } else {
104529 - atomic_long_inc(&priv->rx_errors);
104530 + atomic_long_inc_unchecked(&priv->rx_errors);
104531 }
104532 return;
104533
104534 error:
104535 - atomic_long_inc(&priv->rx_errors);
104536 + atomic_long_inc_unchecked(&priv->rx_errors);
104537 kfree_skb(skb);
104538 }
104539
104540 diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
104541 index 1a3c7e0..80f8b0c 100644
104542 --- a/net/llc/llc_proc.c
104543 +++ b/net/llc/llc_proc.c
104544 @@ -247,7 +247,7 @@ int __init llc_proc_init(void)
104545 int rc = -ENOMEM;
104546 struct proc_dir_entry *p;
104547
104548 - llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
104549 + llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
104550 if (!llc_proc_dir)
104551 goto out;
104552
104553 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
104554 index 927b4ea..88a30e2 100644
104555 --- a/net/mac80211/cfg.c
104556 +++ b/net/mac80211/cfg.c
104557 @@ -540,7 +540,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
104558 ret = ieee80211_vif_use_channel(sdata, chandef,
104559 IEEE80211_CHANCTX_EXCLUSIVE);
104560 }
104561 - } else if (local->open_count == local->monitors) {
104562 + } else if (local_read(&local->open_count) == local->monitors) {
104563 local->_oper_chandef = *chandef;
104564 ieee80211_hw_config(local, 0);
104565 }
104566 @@ -3286,7 +3286,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
104567 else
104568 local->probe_req_reg--;
104569
104570 - if (!local->open_count)
104571 + if (!local_read(&local->open_count))
104572 break;
104573
104574 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
104575 @@ -3420,8 +3420,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
104576 if (chanctx_conf) {
104577 *chandef = chanctx_conf->def;
104578 ret = 0;
104579 - } else if (local->open_count > 0 &&
104580 - local->open_count == local->monitors &&
104581 + } else if (local_read(&local->open_count) > 0 &&
104582 + local_read(&local->open_count) == local->monitors &&
104583 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
104584 if (local->use_chanctx)
104585 *chandef = local->monitor_chandef;
104586 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
104587 index 5d102b5..6199fca 100644
104588 --- a/net/mac80211/ieee80211_i.h
104589 +++ b/net/mac80211/ieee80211_i.h
104590 @@ -28,6 +28,7 @@
104591 #include <net/ieee80211_radiotap.h>
104592 #include <net/cfg80211.h>
104593 #include <net/mac80211.h>
104594 +#include <asm/local.h>
104595 #include "key.h"
104596 #include "sta_info.h"
104597 #include "debug.h"
104598 @@ -1055,7 +1056,7 @@ struct ieee80211_local {
104599 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
104600 spinlock_t queue_stop_reason_lock;
104601
104602 - int open_count;
104603 + local_t open_count;
104604 int monitors, cooked_mntrs;
104605 /* number of interfaces with corresponding FIF_ flags */
104606 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
104607 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
104608 index 3538e5e..0aa7879 100644
104609 --- a/net/mac80211/iface.c
104610 +++ b/net/mac80211/iface.c
104611 @@ -531,7 +531,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104612 break;
104613 }
104614
104615 - if (local->open_count == 0) {
104616 + if (local_read(&local->open_count) == 0) {
104617 res = drv_start(local);
104618 if (res)
104619 goto err_del_bss;
104620 @@ -578,7 +578,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104621 res = drv_add_interface(local, sdata);
104622 if (res)
104623 goto err_stop;
104624 - } else if (local->monitors == 0 && local->open_count == 0) {
104625 + } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
104626 res = ieee80211_add_virtual_monitor(local);
104627 if (res)
104628 goto err_stop;
104629 @@ -687,7 +687,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104630 atomic_inc(&local->iff_promiscs);
104631
104632 if (coming_up)
104633 - local->open_count++;
104634 + local_inc(&local->open_count);
104635
104636 if (hw_reconf_flags)
104637 ieee80211_hw_config(local, hw_reconf_flags);
104638 @@ -725,7 +725,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104639 err_del_interface:
104640 drv_remove_interface(local, sdata);
104641 err_stop:
104642 - if (!local->open_count)
104643 + if (!local_read(&local->open_count))
104644 drv_stop(local);
104645 err_del_bss:
104646 sdata->bss = NULL;
104647 @@ -891,7 +891,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104648 }
104649
104650 if (going_down)
104651 - local->open_count--;
104652 + local_dec(&local->open_count);
104653
104654 switch (sdata->vif.type) {
104655 case NL80211_IFTYPE_AP_VLAN:
104656 @@ -952,7 +952,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104657 }
104658 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
104659
104660 - if (local->open_count == 0)
104661 + if (local_read(&local->open_count) == 0)
104662 ieee80211_clear_tx_pending(local);
104663
104664 /*
104665 @@ -995,7 +995,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104666 if (cancel_scan)
104667 flush_delayed_work(&local->scan_work);
104668
104669 - if (local->open_count == 0) {
104670 + if (local_read(&local->open_count) == 0) {
104671 ieee80211_stop_device(local);
104672
104673 /* no reconfiguring after stop! */
104674 @@ -1006,7 +1006,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104675 ieee80211_configure_filter(local);
104676 ieee80211_hw_config(local, hw_reconf_flags);
104677
104678 - if (local->monitors == local->open_count)
104679 + if (local->monitors == local_read(&local->open_count))
104680 ieee80211_add_virtual_monitor(local);
104681 }
104682
104683 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
104684 index e0ab432..36b7b94 100644
104685 --- a/net/mac80211/main.c
104686 +++ b/net/mac80211/main.c
104687 @@ -174,7 +174,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
104688 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
104689 IEEE80211_CONF_CHANGE_POWER);
104690
104691 - if (changed && local->open_count) {
104692 + if (changed && local_read(&local->open_count)) {
104693 ret = drv_config(local, changed);
104694 /*
104695 * Goal:
104696 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
104697 index 4c5192e..04cc0d8 100644
104698 --- a/net/mac80211/pm.c
104699 +++ b/net/mac80211/pm.c
104700 @@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
104701 struct ieee80211_sub_if_data *sdata;
104702 struct sta_info *sta;
104703
104704 - if (!local->open_count)
104705 + if (!local_read(&local->open_count))
104706 goto suspend;
104707
104708 ieee80211_scan_cancel(local);
104709 @@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
104710 cancel_work_sync(&local->dynamic_ps_enable_work);
104711 del_timer_sync(&local->dynamic_ps_timer);
104712
104713 - local->wowlan = wowlan && local->open_count;
104714 + local->wowlan = wowlan && local_read(&local->open_count);
104715 if (local->wowlan) {
104716 int err = drv_suspend(local, wowlan);
104717 if (err < 0) {
104718 @@ -125,7 +125,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
104719 WARN_ON(!list_empty(&local->chanctx_list));
104720
104721 /* stop hardware - this must stop RX */
104722 - if (local->open_count)
104723 + if (local_read(&local->open_count))
104724 ieee80211_stop_device(local);
104725
104726 suspend:
104727 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
104728 index 6081329..ab23834 100644
104729 --- a/net/mac80211/rate.c
104730 +++ b/net/mac80211/rate.c
104731 @@ -720,7 +720,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
104732
104733 ASSERT_RTNL();
104734
104735 - if (local->open_count)
104736 + if (local_read(&local->open_count))
104737 return -EBUSY;
104738
104739 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
104740 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
104741 index 725af7a..a21a20a 100644
104742 --- a/net/mac80211/util.c
104743 +++ b/net/mac80211/util.c
104744 @@ -1643,7 +1643,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
104745 }
104746 #endif
104747 /* everything else happens only if HW was up & running */
104748 - if (!local->open_count)
104749 + if (!local_read(&local->open_count))
104750 goto wake_up;
104751
104752 /*
104753 @@ -1869,7 +1869,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
104754 local->in_reconfig = false;
104755 barrier();
104756
104757 - if (local->monitors == local->open_count && local->monitors > 0)
104758 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
104759 ieee80211_add_virtual_monitor(local);
104760
104761 /*
104762 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
104763 index 6d77cce..36e2fc3 100644
104764 --- a/net/netfilter/Kconfig
104765 +++ b/net/netfilter/Kconfig
104766 @@ -1096,6 +1096,16 @@ config NETFILTER_XT_MATCH_ESP
104767
104768 To compile it as a module, choose M here. If unsure, say N.
104769
104770 +config NETFILTER_XT_MATCH_GRADM
104771 + tristate '"gradm" match support'
104772 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
104773 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
104774 + ---help---
104775 + The gradm match allows to match on grsecurity RBAC being enabled.
104776 + It is useful when iptables rules are applied early on bootup to
104777 + prevent connections to the machine (except from a trusted host)
104778 + while the RBAC system is disabled.
104779 +
104780 config NETFILTER_XT_MATCH_HASHLIMIT
104781 tristate '"hashlimit" match support'
104782 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
104783 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
104784 index fad5fdb..ba3672a 100644
104785 --- a/net/netfilter/Makefile
104786 +++ b/net/netfilter/Makefile
104787 @@ -136,6 +136,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
104788 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
104789 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
104790 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
104791 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
104792 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
104793 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
104794 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
104795 diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
104796 index 6582dce..a911da7 100644
104797 --- a/net/netfilter/ipset/ip_set_core.c
104798 +++ b/net/netfilter/ipset/ip_set_core.c
104799 @@ -1921,7 +1921,7 @@ done:
104800 return ret;
104801 }
104802
104803 -static struct nf_sockopt_ops so_set __read_mostly = {
104804 +static struct nf_sockopt_ops so_set = {
104805 .pf = PF_INET,
104806 .get_optmin = SO_IP_SET,
104807 .get_optmax = SO_IP_SET + 1,
104808 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
104809 index 610e19c..08d0c3f 100644
104810 --- a/net/netfilter/ipvs/ip_vs_conn.c
104811 +++ b/net/netfilter/ipvs/ip_vs_conn.c
104812 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
104813 /* Increase the refcnt counter of the dest */
104814 ip_vs_dest_hold(dest);
104815
104816 - conn_flags = atomic_read(&dest->conn_flags);
104817 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
104818 if (cp->protocol != IPPROTO_UDP)
104819 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
104820 flags = cp->flags;
104821 @@ -899,7 +899,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
104822
104823 cp->control = NULL;
104824 atomic_set(&cp->n_control, 0);
104825 - atomic_set(&cp->in_pkts, 0);
104826 + atomic_set_unchecked(&cp->in_pkts, 0);
104827
104828 cp->packet_xmit = NULL;
104829 cp->app = NULL;
104830 @@ -1187,7 +1187,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
104831
104832 /* Don't drop the entry if its number of incoming packets is not
104833 located in [0, 8] */
104834 - i = atomic_read(&cp->in_pkts);
104835 + i = atomic_read_unchecked(&cp->in_pkts);
104836 if (i > 8 || i < 0) return 0;
104837
104838 if (!todrop_rate[i]) return 0;
104839 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
104840 index 5c34e8d..0d8eb7f 100644
104841 --- a/net/netfilter/ipvs/ip_vs_core.c
104842 +++ b/net/netfilter/ipvs/ip_vs_core.c
104843 @@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
104844 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
104845 /* do not touch skb anymore */
104846
104847 - atomic_inc(&cp->in_pkts);
104848 + atomic_inc_unchecked(&cp->in_pkts);
104849 ip_vs_conn_put(cp);
104850 return ret;
104851 }
104852 @@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
104853 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
104854 pkts = sysctl_sync_threshold(ipvs);
104855 else
104856 - pkts = atomic_add_return(1, &cp->in_pkts);
104857 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
104858
104859 if (ipvs->sync_state & IP_VS_STATE_MASTER)
104860 ip_vs_sync_conn(net, cp, pkts);
104861 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
104862 index fd3f444..ab28fa24 100644
104863 --- a/net/netfilter/ipvs/ip_vs_ctl.c
104864 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
104865 @@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
104866 */
104867 ip_vs_rs_hash(ipvs, dest);
104868 }
104869 - atomic_set(&dest->conn_flags, conn_flags);
104870 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
104871
104872 /* bind the service */
104873 old_svc = rcu_dereference_protected(dest->svc, 1);
104874 @@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
104875 * align with netns init in ip_vs_control_net_init()
104876 */
104877
104878 -static struct ctl_table vs_vars[] = {
104879 +static ctl_table_no_const vs_vars[] __read_only = {
104880 {
104881 .procname = "amemthresh",
104882 .maxlen = sizeof(int),
104883 @@ -1989,7 +1989,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
104884 " %-7s %-6d %-10d %-10d\n",
104885 &dest->addr.in6,
104886 ntohs(dest->port),
104887 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
104888 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
104889 atomic_read(&dest->weight),
104890 atomic_read(&dest->activeconns),
104891 atomic_read(&dest->inactconns));
104892 @@ -2000,7 +2000,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
104893 "%-7s %-6d %-10d %-10d\n",
104894 ntohl(dest->addr.ip),
104895 ntohs(dest->port),
104896 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
104897 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
104898 atomic_read(&dest->weight),
104899 atomic_read(&dest->activeconns),
104900 atomic_read(&dest->inactconns));
104901 @@ -2471,7 +2471,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
104902
104903 entry.addr = dest->addr.ip;
104904 entry.port = dest->port;
104905 - entry.conn_flags = atomic_read(&dest->conn_flags);
104906 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
104907 entry.weight = atomic_read(&dest->weight);
104908 entry.u_threshold = dest->u_threshold;
104909 entry.l_threshold = dest->l_threshold;
104910 @@ -3010,7 +3010,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
104911 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
104912 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
104913 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
104914 - (atomic_read(&dest->conn_flags) &
104915 + (atomic_read_unchecked(&dest->conn_flags) &
104916 IP_VS_CONN_F_FWD_MASK)) ||
104917 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
104918 atomic_read(&dest->weight)) ||
104919 @@ -3600,7 +3600,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
104920 {
104921 int idx;
104922 struct netns_ipvs *ipvs = net_ipvs(net);
104923 - struct ctl_table *tbl;
104924 + ctl_table_no_const *tbl;
104925
104926 atomic_set(&ipvs->dropentry, 0);
104927 spin_lock_init(&ipvs->dropentry_lock);
104928 diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
104929 index 547ff33..c8c8117 100644
104930 --- a/net/netfilter/ipvs/ip_vs_lblc.c
104931 +++ b/net/netfilter/ipvs/ip_vs_lblc.c
104932 @@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
104933 * IPVS LBLC sysctl table
104934 */
104935 #ifdef CONFIG_SYSCTL
104936 -static struct ctl_table vs_vars_table[] = {
104937 +static ctl_table_no_const vs_vars_table[] __read_only = {
104938 {
104939 .procname = "lblc_expiration",
104940 .data = NULL,
104941 diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
104942 index 3f21a2f..a112e85 100644
104943 --- a/net/netfilter/ipvs/ip_vs_lblcr.c
104944 +++ b/net/netfilter/ipvs/ip_vs_lblcr.c
104945 @@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
104946 * IPVS LBLCR sysctl table
104947 */
104948
104949 -static struct ctl_table vs_vars_table[] = {
104950 +static ctl_table_no_const vs_vars_table[] __read_only = {
104951 {
104952 .procname = "lblcr_expiration",
104953 .data = NULL,
104954 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
104955 index eadffb2..c2feeae 100644
104956 --- a/net/netfilter/ipvs/ip_vs_sync.c
104957 +++ b/net/netfilter/ipvs/ip_vs_sync.c
104958 @@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
104959 cp = cp->control;
104960 if (cp) {
104961 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
104962 - pkts = atomic_add_return(1, &cp->in_pkts);
104963 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
104964 else
104965 pkts = sysctl_sync_threshold(ipvs);
104966 ip_vs_sync_conn(net, cp->control, pkts);
104967 @@ -771,7 +771,7 @@ control:
104968 if (!cp)
104969 return;
104970 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
104971 - pkts = atomic_add_return(1, &cp->in_pkts);
104972 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
104973 else
104974 pkts = sysctl_sync_threshold(ipvs);
104975 goto sloop;
104976 @@ -894,7 +894,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
104977
104978 if (opt)
104979 memcpy(&cp->in_seq, opt, sizeof(*opt));
104980 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
104981 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
104982 cp->state = state;
104983 cp->old_state = cp->state;
104984 /*
104985 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
104986 index 56896a4..dfe3806 100644
104987 --- a/net/netfilter/ipvs/ip_vs_xmit.c
104988 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
104989 @@ -1114,7 +1114,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
104990 else
104991 rc = NF_ACCEPT;
104992 /* do not touch skb anymore */
104993 - atomic_inc(&cp->in_pkts);
104994 + atomic_inc_unchecked(&cp->in_pkts);
104995 goto out;
104996 }
104997
104998 @@ -1206,7 +1206,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
104999 else
105000 rc = NF_ACCEPT;
105001 /* do not touch skb anymore */
105002 - atomic_inc(&cp->in_pkts);
105003 + atomic_inc_unchecked(&cp->in_pkts);
105004 goto out;
105005 }
105006
105007 diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
105008 index a4b5e2a..13b1de3 100644
105009 --- a/net/netfilter/nf_conntrack_acct.c
105010 +++ b/net/netfilter/nf_conntrack_acct.c
105011 @@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
105012 #ifdef CONFIG_SYSCTL
105013 static int nf_conntrack_acct_init_sysctl(struct net *net)
105014 {
105015 - struct ctl_table *table;
105016 + ctl_table_no_const *table;
105017
105018 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
105019 GFP_KERNEL);
105020 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
105021 index de88c4a..ec84234 100644
105022 --- a/net/netfilter/nf_conntrack_core.c
105023 +++ b/net/netfilter/nf_conntrack_core.c
105024 @@ -1739,6 +1739,10 @@ void nf_conntrack_init_end(void)
105025 #define DYING_NULLS_VAL ((1<<30)+1)
105026 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
105027
105028 +#ifdef CONFIG_GRKERNSEC_HIDESYM
105029 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
105030 +#endif
105031 +
105032 int nf_conntrack_init_net(struct net *net)
105033 {
105034 int ret = -ENOMEM;
105035 @@ -1764,7 +1768,11 @@ int nf_conntrack_init_net(struct net *net)
105036 if (!net->ct.stat)
105037 goto err_pcpu_lists;
105038
105039 +#ifdef CONFIG_GRKERNSEC_HIDESYM
105040 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08x", atomic_inc_return_unchecked(&conntrack_cache_id));
105041 +#else
105042 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
105043 +#endif
105044 if (!net->ct.slabname)
105045 goto err_slabname;
105046
105047 diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
105048 index 4e78c57..ec8fb74 100644
105049 --- a/net/netfilter/nf_conntrack_ecache.c
105050 +++ b/net/netfilter/nf_conntrack_ecache.c
105051 @@ -264,7 +264,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
105052 #ifdef CONFIG_SYSCTL
105053 static int nf_conntrack_event_init_sysctl(struct net *net)
105054 {
105055 - struct ctl_table *table;
105056 + ctl_table_no_const *table;
105057
105058 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
105059 GFP_KERNEL);
105060 diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
105061 index 5b3eae7..dd4b8fe 100644
105062 --- a/net/netfilter/nf_conntrack_helper.c
105063 +++ b/net/netfilter/nf_conntrack_helper.c
105064 @@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
105065
105066 static int nf_conntrack_helper_init_sysctl(struct net *net)
105067 {
105068 - struct ctl_table *table;
105069 + ctl_table_no_const *table;
105070
105071 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
105072 GFP_KERNEL);
105073 diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
105074 index b65d586..beec902 100644
105075 --- a/net/netfilter/nf_conntrack_proto.c
105076 +++ b/net/netfilter/nf_conntrack_proto.c
105077 @@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
105078
105079 static void
105080 nf_ct_unregister_sysctl(struct ctl_table_header **header,
105081 - struct ctl_table **table,
105082 + ctl_table_no_const **table,
105083 unsigned int users)
105084 {
105085 if (users > 0)
105086 diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
105087 index f641751..d3c5b51 100644
105088 --- a/net/netfilter/nf_conntrack_standalone.c
105089 +++ b/net/netfilter/nf_conntrack_standalone.c
105090 @@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
105091
105092 static int nf_conntrack_standalone_init_sysctl(struct net *net)
105093 {
105094 - struct ctl_table *table;
105095 + ctl_table_no_const *table;
105096
105097 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
105098 GFP_KERNEL);
105099 diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
105100 index 7a394df..bd91a8a 100644
105101 --- a/net/netfilter/nf_conntrack_timestamp.c
105102 +++ b/net/netfilter/nf_conntrack_timestamp.c
105103 @@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
105104 #ifdef CONFIG_SYSCTL
105105 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
105106 {
105107 - struct ctl_table *table;
105108 + ctl_table_no_const *table;
105109
105110 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
105111 GFP_KERNEL);
105112 diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
105113 index daad602..384be13 100644
105114 --- a/net/netfilter/nf_log.c
105115 +++ b/net/netfilter/nf_log.c
105116 @@ -353,7 +353,7 @@ static const struct file_operations nflog_file_ops = {
105117
105118 #ifdef CONFIG_SYSCTL
105119 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
105120 -static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
105121 +static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
105122
105123 static int nf_log_proc_dostring(struct ctl_table *table, int write,
105124 void __user *buffer, size_t *lenp, loff_t *ppos)
105125 @@ -384,14 +384,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
105126 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
105127 mutex_unlock(&nf_log_mutex);
105128 } else {
105129 + ctl_table_no_const nf_log_table = *table;
105130 +
105131 mutex_lock(&nf_log_mutex);
105132 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
105133 lockdep_is_held(&nf_log_mutex));
105134 if (!logger)
105135 - table->data = "NONE";
105136 + nf_log_table.data = "NONE";
105137 else
105138 - table->data = logger->name;
105139 - r = proc_dostring(table, write, buffer, lenp, ppos);
105140 + nf_log_table.data = logger->name;
105141 + r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
105142 mutex_unlock(&nf_log_mutex);
105143 }
105144
105145 diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
105146 index c68c1e5..8b5d670 100644
105147 --- a/net/netfilter/nf_sockopt.c
105148 +++ b/net/netfilter/nf_sockopt.c
105149 @@ -43,7 +43,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
105150 }
105151 }
105152
105153 - list_add(&reg->list, &nf_sockopts);
105154 + pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
105155 out:
105156 mutex_unlock(&nf_sockopt_mutex);
105157 return ret;
105158 @@ -53,7 +53,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
105159 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
105160 {
105161 mutex_lock(&nf_sockopt_mutex);
105162 - list_del(&reg->list);
105163 + pax_list_del((struct list_head *)&reg->list);
105164 mutex_unlock(&nf_sockopt_mutex);
105165 }
105166 EXPORT_SYMBOL(nf_unregister_sockopt);
105167 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
105168 index 3250735..1fac969 100644
105169 --- a/net/netfilter/nfnetlink_log.c
105170 +++ b/net/netfilter/nfnetlink_log.c
105171 @@ -80,7 +80,7 @@ static int nfnl_log_net_id __read_mostly;
105172 struct nfnl_log_net {
105173 spinlock_t instances_lock;
105174 struct hlist_head instance_table[INSTANCE_BUCKETS];
105175 - atomic_t global_seq;
105176 + atomic_unchecked_t global_seq;
105177 };
105178
105179 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
105180 @@ -563,7 +563,7 @@ __build_packet_message(struct nfnl_log_net *log,
105181 /* global sequence number */
105182 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
105183 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
105184 - htonl(atomic_inc_return(&log->global_seq))))
105185 + htonl(atomic_inc_return_unchecked(&log->global_seq))))
105186 goto nla_put_failure;
105187
105188 if (data_len) {
105189 diff --git a/net/netfilter/nfnetlink_queue_core.c b/net/netfilter/nfnetlink_queue_core.c
105190 index 108120f..5b169db 100644
105191 --- a/net/netfilter/nfnetlink_queue_core.c
105192 +++ b/net/netfilter/nfnetlink_queue_core.c
105193 @@ -665,7 +665,7 @@ nfqnl_enqueue_packet(struct nf_queue_entry *entry, unsigned int queuenum)
105194 * returned by nf_queue. For instance, callers rely on -ECANCELED to
105195 * mean 'ignore this hook'.
105196 */
105197 - if (IS_ERR(segs))
105198 + if (IS_ERR_OR_NULL(segs))
105199 goto out_err;
105200 queued = 0;
105201 err = 0;
105202 diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
105203 index 5b5ab9e..fc1015c 100644
105204 --- a/net/netfilter/nft_compat.c
105205 +++ b/net/netfilter/nft_compat.c
105206 @@ -225,7 +225,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
105207 /* We want to reuse existing compat_to_user */
105208 old_fs = get_fs();
105209 set_fs(KERNEL_DS);
105210 - t->compat_to_user(out, in);
105211 + t->compat_to_user((void __force_user *)out, in);
105212 set_fs(old_fs);
105213 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
105214 kfree(out);
105215 @@ -421,7 +421,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
105216 /* We want to reuse existing compat_to_user */
105217 old_fs = get_fs();
105218 set_fs(KERNEL_DS);
105219 - m->compat_to_user(out, in);
105220 + m->compat_to_user((void __force_user *)out, in);
105221 set_fs(old_fs);
105222 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
105223 kfree(out);
105224 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
105225 new file mode 100644
105226 index 0000000..c566332
105227 --- /dev/null
105228 +++ b/net/netfilter/xt_gradm.c
105229 @@ -0,0 +1,51 @@
105230 +/*
105231 + * gradm match for netfilter
105232 + * Copyright © Zbigniew Krzystolik, 2010
105233 + *
105234 + * This program is free software; you can redistribute it and/or modify
105235 + * it under the terms of the GNU General Public License; either version
105236 + * 2 or 3 as published by the Free Software Foundation.
105237 + */
105238 +#include <linux/module.h>
105239 +#include <linux/moduleparam.h>
105240 +#include <linux/skbuff.h>
105241 +#include <linux/netfilter/x_tables.h>
105242 +#include <linux/grsecurity.h>
105243 +#include <linux/netfilter/xt_gradm.h>
105244 +
105245 +static bool
105246 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
105247 +{
105248 + const struct xt_gradm_mtinfo *info = par->matchinfo;
105249 + bool retval = false;
105250 + if (gr_acl_is_enabled())
105251 + retval = true;
105252 + return retval ^ info->invflags;
105253 +}
105254 +
105255 +static struct xt_match gradm_mt_reg __read_mostly = {
105256 + .name = "gradm",
105257 + .revision = 0,
105258 + .family = NFPROTO_UNSPEC,
105259 + .match = gradm_mt,
105260 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
105261 + .me = THIS_MODULE,
105262 +};
105263 +
105264 +static int __init gradm_mt_init(void)
105265 +{
105266 + return xt_register_match(&gradm_mt_reg);
105267 +}
105268 +
105269 +static void __exit gradm_mt_exit(void)
105270 +{
105271 + xt_unregister_match(&gradm_mt_reg);
105272 +}
105273 +
105274 +module_init(gradm_mt_init);
105275 +module_exit(gradm_mt_exit);
105276 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
105277 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
105278 +MODULE_LICENSE("GPL");
105279 +MODULE_ALIAS("ipt_gradm");
105280 +MODULE_ALIAS("ip6t_gradm");
105281 diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
105282 index 47dc683..2e0d52c 100644
105283 --- a/net/netfilter/xt_hashlimit.c
105284 +++ b/net/netfilter/xt_hashlimit.c
105285 @@ -871,11 +871,11 @@ static int __net_init hashlimit_proc_net_init(struct net *net)
105286 {
105287 struct hashlimit_net *hashlimit_net = hashlimit_pernet(net);
105288
105289 - hashlimit_net->ipt_hashlimit = proc_mkdir("ipt_hashlimit", net->proc_net);
105290 + hashlimit_net->ipt_hashlimit = proc_mkdir_restrict("ipt_hashlimit", net->proc_net);
105291 if (!hashlimit_net->ipt_hashlimit)
105292 return -ENOMEM;
105293 #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
105294 - hashlimit_net->ip6t_hashlimit = proc_mkdir("ip6t_hashlimit", net->proc_net);
105295 + hashlimit_net->ip6t_hashlimit = proc_mkdir_restrict("ip6t_hashlimit", net->proc_net);
105296 if (!hashlimit_net->ip6t_hashlimit) {
105297 remove_proc_entry("ipt_hashlimit", net->proc_net);
105298 return -ENOMEM;
105299 diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c
105300 index a9faae8..1ea30e0 100644
105301 --- a/net/netfilter/xt_recent.c
105302 +++ b/net/netfilter/xt_recent.c
105303 @@ -615,7 +615,7 @@ static int __net_init recent_proc_net_init(struct net *net)
105304 {
105305 struct recent_net *recent_net = recent_pernet(net);
105306
105307 - recent_net->xt_recent = proc_mkdir("xt_recent", net->proc_net);
105308 + recent_net->xt_recent = proc_mkdir_restrict("xt_recent", net->proc_net);
105309 if (!recent_net->xt_recent)
105310 return -ENOMEM;
105311 return 0;
105312 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
105313 index 11de55e..f25e448 100644
105314 --- a/net/netfilter/xt_statistic.c
105315 +++ b/net/netfilter/xt_statistic.c
105316 @@ -19,7 +19,7 @@
105317 #include <linux/module.h>
105318
105319 struct xt_statistic_priv {
105320 - atomic_t count;
105321 + atomic_unchecked_t count;
105322 } ____cacheline_aligned_in_smp;
105323
105324 MODULE_LICENSE("GPL");
105325 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
105326 break;
105327 case XT_STATISTIC_MODE_NTH:
105328 do {
105329 - oval = atomic_read(&info->master->count);
105330 + oval = atomic_read_unchecked(&info->master->count);
105331 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
105332 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
105333 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
105334 if (nval == 0)
105335 ret = !ret;
105336 break;
105337 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
105338 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
105339 if (info->master == NULL)
105340 return -ENOMEM;
105341 - atomic_set(&info->master->count, info->u.nth.count);
105342 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
105343
105344 return 0;
105345 }
105346 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
105347 index 0007b81..cb08369 100644
105348 --- a/net/netlink/af_netlink.c
105349 +++ b/net/netlink/af_netlink.c
105350 @@ -273,7 +273,7 @@ static void netlink_overrun(struct sock *sk)
105351 sk->sk_error_report(sk);
105352 }
105353 }
105354 - atomic_inc(&sk->sk_drops);
105355 + atomic_inc_unchecked(&sk->sk_drops);
105356 }
105357
105358 static void netlink_rcv_wake(struct sock *sk)
105359 @@ -3010,7 +3010,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
105360 sk_wmem_alloc_get(s),
105361 nlk->cb_running,
105362 atomic_read(&s->sk_refcnt),
105363 - atomic_read(&s->sk_drops),
105364 + atomic_read_unchecked(&s->sk_drops),
105365 sock_i_ino(s)
105366 );
105367
105368 diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
105369 index 64dc864..7a9e2a4 100644
105370 --- a/net/openvswitch/datapath.c
105371 +++ b/net/openvswitch/datapath.c
105372 @@ -332,6 +332,8 @@ static int queue_gso_packets(struct datapath *dp, struct sk_buff *skb,
105373 segs = __skb_gso_segment(skb, NETIF_F_SG, false);
105374 if (IS_ERR(segs))
105375 return PTR_ERR(segs);
105376 + if (segs == NULL)
105377 + return -EINVAL;
105378
105379 /* Queue all of the segments. */
105380 skb = segs;
105381 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
105382 index 93896d2..b701c88 100644
105383 --- a/net/packet/af_packet.c
105384 +++ b/net/packet/af_packet.c
105385 @@ -275,7 +275,7 @@ static int packet_direct_xmit(struct sk_buff *skb)
105386
105387 return ret;
105388 drop:
105389 - atomic_long_inc(&dev->tx_dropped);
105390 + atomic_long_inc_unchecked(&dev->tx_dropped);
105391 kfree_skb(skb);
105392 return NET_XMIT_DROP;
105393 }
105394 @@ -1842,7 +1842,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
105395
105396 spin_lock(&sk->sk_receive_queue.lock);
105397 po->stats.stats1.tp_packets++;
105398 - skb->dropcount = atomic_read(&sk->sk_drops);
105399 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
105400 __skb_queue_tail(&sk->sk_receive_queue, skb);
105401 spin_unlock(&sk->sk_receive_queue.lock);
105402 sk->sk_data_ready(sk);
105403 @@ -1851,7 +1851,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
105404 drop_n_acct:
105405 spin_lock(&sk->sk_receive_queue.lock);
105406 po->stats.stats1.tp_drops++;
105407 - atomic_inc(&sk->sk_drops);
105408 + atomic_inc_unchecked(&sk->sk_drops);
105409 spin_unlock(&sk->sk_receive_queue.lock);
105410
105411 drop_n_restore:
105412 @@ -3466,7 +3466,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
105413 case PACKET_HDRLEN:
105414 if (len > sizeof(int))
105415 len = sizeof(int);
105416 - if (copy_from_user(&val, optval, len))
105417 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
105418 return -EFAULT;
105419 switch (val) {
105420 case TPACKET_V1:
105421 @@ -3512,7 +3512,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
105422 len = lv;
105423 if (put_user(len, optlen))
105424 return -EFAULT;
105425 - if (copy_to_user(optval, data, len))
105426 + if (len > sizeof(st) || copy_to_user(optval, data, len))
105427 return -EFAULT;
105428 return 0;
105429 }
105430 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
105431 index 70a547e..23477fe 100644
105432 --- a/net/phonet/pep.c
105433 +++ b/net/phonet/pep.c
105434 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
105435
105436 case PNS_PEP_CTRL_REQ:
105437 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
105438 - atomic_inc(&sk->sk_drops);
105439 + atomic_inc_unchecked(&sk->sk_drops);
105440 break;
105441 }
105442 __skb_pull(skb, 4);
105443 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
105444 }
105445
105446 if (pn->rx_credits == 0) {
105447 - atomic_inc(&sk->sk_drops);
105448 + atomic_inc_unchecked(&sk->sk_drops);
105449 err = -ENOBUFS;
105450 break;
105451 }
105452 @@ -579,7 +579,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
105453 }
105454
105455 if (pn->rx_credits == 0) {
105456 - atomic_inc(&sk->sk_drops);
105457 + atomic_inc_unchecked(&sk->sk_drops);
105458 err = NET_RX_DROP;
105459 break;
105460 }
105461 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
105462 index 008214a..bb68240 100644
105463 --- a/net/phonet/socket.c
105464 +++ b/net/phonet/socket.c
105465 @@ -611,7 +611,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
105466 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
105467 sock_i_ino(sk),
105468 atomic_read(&sk->sk_refcnt), sk,
105469 - atomic_read(&sk->sk_drops));
105470 + atomic_read_unchecked(&sk->sk_drops));
105471 }
105472 seq_pad(seq, '\n');
105473 return 0;
105474 diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
105475 index c02a8c4..3c5b600 100644
105476 --- a/net/phonet/sysctl.c
105477 +++ b/net/phonet/sysctl.c
105478 @@ -67,7 +67,7 @@ static int proc_local_port_range(struct ctl_table *table, int write,
105479 {
105480 int ret;
105481 int range[2] = {local_port_range[0], local_port_range[1]};
105482 - struct ctl_table tmp = {
105483 + ctl_table_no_const tmp = {
105484 .data = &range,
105485 .maxlen = sizeof(range),
105486 .mode = table->mode,
105487 diff --git a/net/rds/cong.c b/net/rds/cong.c
105488 index e5b65ac..f3b6fb7 100644
105489 --- a/net/rds/cong.c
105490 +++ b/net/rds/cong.c
105491 @@ -78,7 +78,7 @@
105492 * finds that the saved generation number is smaller than the global generation
105493 * number, it wakes up the process.
105494 */
105495 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
105496 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
105497
105498 /*
105499 * Congestion monitoring
105500 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
105501 rdsdebug("waking map %p for %pI4\n",
105502 map, &map->m_addr);
105503 rds_stats_inc(s_cong_update_received);
105504 - atomic_inc(&rds_cong_generation);
105505 + atomic_inc_unchecked(&rds_cong_generation);
105506 if (waitqueue_active(&map->m_waitq))
105507 wake_up(&map->m_waitq);
105508 if (waitqueue_active(&rds_poll_waitq))
105509 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
105510
105511 int rds_cong_updated_since(unsigned long *recent)
105512 {
105513 - unsigned long gen = atomic_read(&rds_cong_generation);
105514 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
105515
105516 if (likely(*recent == gen))
105517 return 0;
105518 diff --git a/net/rds/ib.h b/net/rds/ib.h
105519 index 7280ab8..e04f4ea 100644
105520 --- a/net/rds/ib.h
105521 +++ b/net/rds/ib.h
105522 @@ -128,7 +128,7 @@ struct rds_ib_connection {
105523 /* sending acks */
105524 unsigned long i_ack_flags;
105525 #ifdef KERNEL_HAS_ATOMIC64
105526 - atomic64_t i_ack_next; /* next ACK to send */
105527 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
105528 #else
105529 spinlock_t i_ack_lock; /* protect i_ack_next */
105530 u64 i_ack_next; /* next ACK to send */
105531 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
105532 index 31b74f5..dc1fbfa 100644
105533 --- a/net/rds/ib_cm.c
105534 +++ b/net/rds/ib_cm.c
105535 @@ -717,7 +717,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
105536 /* Clear the ACK state */
105537 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
105538 #ifdef KERNEL_HAS_ATOMIC64
105539 - atomic64_set(&ic->i_ack_next, 0);
105540 + atomic64_set_unchecked(&ic->i_ack_next, 0);
105541 #else
105542 ic->i_ack_next = 0;
105543 #endif
105544 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
105545 index d67de45..73dbf51 100644
105546 --- a/net/rds/ib_recv.c
105547 +++ b/net/rds/ib_recv.c
105548 @@ -596,7 +596,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
105549 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
105550 int ack_required)
105551 {
105552 - atomic64_set(&ic->i_ack_next, seq);
105553 + atomic64_set_unchecked(&ic->i_ack_next, seq);
105554 if (ack_required) {
105555 smp_mb__before_atomic();
105556 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
105557 @@ -608,7 +608,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
105558 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
105559 smp_mb__after_atomic();
105560
105561 - return atomic64_read(&ic->i_ack_next);
105562 + return atomic64_read_unchecked(&ic->i_ack_next);
105563 }
105564 #endif
105565
105566 diff --git a/net/rds/iw.h b/net/rds/iw.h
105567 index 04ce3b1..48119a6 100644
105568 --- a/net/rds/iw.h
105569 +++ b/net/rds/iw.h
105570 @@ -134,7 +134,7 @@ struct rds_iw_connection {
105571 /* sending acks */
105572 unsigned long i_ack_flags;
105573 #ifdef KERNEL_HAS_ATOMIC64
105574 - atomic64_t i_ack_next; /* next ACK to send */
105575 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
105576 #else
105577 spinlock_t i_ack_lock; /* protect i_ack_next */
105578 u64 i_ack_next; /* next ACK to send */
105579 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
105580 index a91e1db..cf3053f 100644
105581 --- a/net/rds/iw_cm.c
105582 +++ b/net/rds/iw_cm.c
105583 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
105584 /* Clear the ACK state */
105585 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
105586 #ifdef KERNEL_HAS_ATOMIC64
105587 - atomic64_set(&ic->i_ack_next, 0);
105588 + atomic64_set_unchecked(&ic->i_ack_next, 0);
105589 #else
105590 ic->i_ack_next = 0;
105591 #endif
105592 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
105593 index aa8bf67..b70133c 100644
105594 --- a/net/rds/iw_recv.c
105595 +++ b/net/rds/iw_recv.c
105596 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
105597 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
105598 int ack_required)
105599 {
105600 - atomic64_set(&ic->i_ack_next, seq);
105601 + atomic64_set_unchecked(&ic->i_ack_next, seq);
105602 if (ack_required) {
105603 smp_mb__before_atomic();
105604 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
105605 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
105606 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
105607 smp_mb__after_atomic();
105608
105609 - return atomic64_read(&ic->i_ack_next);
105610 + return atomic64_read_unchecked(&ic->i_ack_next);
105611 }
105612 #endif
105613
105614 diff --git a/net/rds/rdma.c b/net/rds/rdma.c
105615 index 4e37c1c..40084d8 100644
105616 --- a/net/rds/rdma.c
105617 +++ b/net/rds/rdma.c
105618 @@ -564,12 +564,12 @@ int rds_cmsg_rdma_args(struct rds_sock *rs, struct rds_message *rm,
105619
105620 if (rs->rs_bound_addr == 0) {
105621 ret = -ENOTCONN; /* XXX not a great errno */
105622 - goto out;
105623 + goto out_ret;
105624 }
105625
105626 if (args->nr_local > UIO_MAXIOV) {
105627 ret = -EMSGSIZE;
105628 - goto out;
105629 + goto out_ret;
105630 }
105631
105632 /* Check whether to allocate the iovec area */
105633 @@ -578,7 +578,7 @@ int rds_cmsg_rdma_args(struct rds_sock *rs, struct rds_message *rm,
105634 iovs = sock_kmalloc(rds_rs_to_sk(rs), iov_size, GFP_KERNEL);
105635 if (!iovs) {
105636 ret = -ENOMEM;
105637 - goto out;
105638 + goto out_ret;
105639 }
105640 }
105641
105642 @@ -696,6 +696,7 @@ out:
105643 if (iovs != iovstack)
105644 sock_kfree_s(rds_rs_to_sk(rs), iovs, iov_size);
105645 kfree(pages);
105646 +out_ret:
105647 if (ret)
105648 rds_rdma_free_op(op);
105649 else
105650 diff --git a/net/rds/rds.h b/net/rds/rds.h
105651 index 48f8ffc..0ef3eec 100644
105652 --- a/net/rds/rds.h
105653 +++ b/net/rds/rds.h
105654 @@ -449,7 +449,7 @@ struct rds_transport {
105655 void (*sync_mr)(void *trans_private, int direction);
105656 void (*free_mr)(void *trans_private, int invalidate);
105657 void (*flush_mrs)(void);
105658 -};
105659 +} __do_const;
105660
105661 struct rds_sock {
105662 struct sock rs_sk;
105663 diff --git a/net/rds/send.c b/net/rds/send.c
105664 index 2371816..0a64541 100644
105665 --- a/net/rds/send.c
105666 +++ b/net/rds/send.c
105667 @@ -593,8 +593,11 @@ static void rds_send_remove_from_sock(struct list_head *messages, int status)
105668 sock_put(rds_rs_to_sk(rs));
105669 }
105670 rs = rm->m_rs;
105671 - sock_hold(rds_rs_to_sk(rs));
105672 + if (rs)
105673 + sock_hold(rds_rs_to_sk(rs));
105674 }
105675 + if (!rs)
105676 + goto unlock_and_drop;
105677 spin_lock(&rs->rs_lock);
105678
105679 if (test_and_clear_bit(RDS_MSG_ON_SOCK, &rm->m_flags)) {
105680 @@ -638,9 +641,6 @@ unlock_and_drop:
105681 * queue. This means that in the TCP case, the message may not have been
105682 * assigned the m_ack_seq yet - but that's fine as long as tcp_is_acked
105683 * checks the RDS_MSG_HAS_ACK_SEQ bit.
105684 - *
105685 - * XXX It's not clear to me how this is safely serialized with socket
105686 - * destruction. Maybe it should bail if it sees SOCK_DEAD.
105687 */
105688 void rds_send_drop_acked(struct rds_connection *conn, u64 ack,
105689 is_acked_func is_acked)
105690 @@ -711,6 +711,9 @@ void rds_send_drop_to(struct rds_sock *rs, struct sockaddr_in *dest)
105691 */
105692 if (!test_and_clear_bit(RDS_MSG_ON_CONN, &rm->m_flags)) {
105693 spin_unlock_irqrestore(&conn->c_lock, flags);
105694 + spin_lock_irqsave(&rm->m_rs_lock, flags);
105695 + rm->m_rs = NULL;
105696 + spin_unlock_irqrestore(&rm->m_rs_lock, flags);
105697 continue;
105698 }
105699 list_del_init(&rm->m_conn_item);
105700 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
105701 index edac9ef..16bcb98 100644
105702 --- a/net/rds/tcp.c
105703 +++ b/net/rds/tcp.c
105704 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
105705 int val = 1;
105706
105707 set_fs(KERNEL_DS);
105708 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
105709 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
105710 sizeof(val));
105711 set_fs(oldfs);
105712 }
105713 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
105714 index 53b17ca..45463e7 100644
105715 --- a/net/rds/tcp_send.c
105716 +++ b/net/rds/tcp_send.c
105717 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
105718
105719 oldfs = get_fs();
105720 set_fs(KERNEL_DS);
105721 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
105722 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
105723 sizeof(val));
105724 set_fs(oldfs);
105725 }
105726 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
105727 index 7b16704..9628ec6 100644
105728 --- a/net/rxrpc/af_rxrpc.c
105729 +++ b/net/rxrpc/af_rxrpc.c
105730 @@ -40,7 +40,7 @@ static const struct proto_ops rxrpc_rpc_ops;
105731 __be32 rxrpc_epoch;
105732
105733 /* current debugging ID */
105734 -atomic_t rxrpc_debug_id;
105735 +atomic_unchecked_t rxrpc_debug_id;
105736
105737 /* count of skbs currently in use */
105738 atomic_t rxrpc_n_skbs;
105739 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
105740 index c6be17a..2a6200a 100644
105741 --- a/net/rxrpc/ar-ack.c
105742 +++ b/net/rxrpc/ar-ack.c
105743 @@ -223,7 +223,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
105744
105745 _enter("{%d,%d,%d,%d},",
105746 call->acks_hard, call->acks_unacked,
105747 - atomic_read(&call->sequence),
105748 + atomic_read_unchecked(&call->sequence),
105749 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
105750
105751 stop = 0;
105752 @@ -247,7 +247,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
105753
105754 /* each Tx packet has a new serial number */
105755 sp->hdr.serial =
105756 - htonl(atomic_inc_return(&call->conn->serial));
105757 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
105758
105759 hdr = (struct rxrpc_header *) txb->head;
105760 hdr->serial = sp->hdr.serial;
105761 @@ -451,7 +451,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
105762 */
105763 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
105764 {
105765 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
105766 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
105767 }
105768
105769 /*
105770 @@ -677,7 +677,7 @@ process_further:
105771
105772 latest = ntohl(sp->hdr.serial);
105773 hard = ntohl(ack.firstPacket);
105774 - tx = atomic_read(&call->sequence);
105775 + tx = atomic_read_unchecked(&call->sequence);
105776
105777 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
105778 latest,
105779 @@ -1209,7 +1209,7 @@ void rxrpc_process_call(struct work_struct *work)
105780 goto maybe_reschedule;
105781
105782 send_ACK_with_skew:
105783 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
105784 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
105785 ntohl(ack.serial));
105786 send_ACK:
105787 mtu = call->conn->trans->peer->if_mtu;
105788 @@ -1221,7 +1221,7 @@ send_ACK:
105789 ackinfo.rxMTU = htonl(rxrpc_rx_mtu);
105790 ackinfo.jumbo_max = htonl(rxrpc_rx_jumbo_max);
105791
105792 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
105793 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
105794 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
105795 ntohl(hdr.serial),
105796 ntohs(ack.maxSkew),
105797 @@ -1239,7 +1239,7 @@ send_ACK:
105798 send_message:
105799 _debug("send message");
105800
105801 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
105802 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
105803 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
105804 send_message_2:
105805
105806 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
105807 index a9e05db..194e793 100644
105808 --- a/net/rxrpc/ar-call.c
105809 +++ b/net/rxrpc/ar-call.c
105810 @@ -232,7 +232,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
105811 spin_lock_init(&call->lock);
105812 rwlock_init(&call->state_lock);
105813 atomic_set(&call->usage, 1);
105814 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
105815 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
105816 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
105817
105818 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
105819 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
105820 index 6631f4f..bfdf056 100644
105821 --- a/net/rxrpc/ar-connection.c
105822 +++ b/net/rxrpc/ar-connection.c
105823 @@ -210,7 +210,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
105824 rwlock_init(&conn->lock);
105825 spin_lock_init(&conn->state_lock);
105826 atomic_set(&conn->usage, 1);
105827 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
105828 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
105829 conn->avail_calls = RXRPC_MAXCALLS;
105830 conn->size_align = 4;
105831 conn->header_size = sizeof(struct rxrpc_header);
105832 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
105833 index e7ed43a..6afa140 100644
105834 --- a/net/rxrpc/ar-connevent.c
105835 +++ b/net/rxrpc/ar-connevent.c
105836 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
105837
105838 len = iov[0].iov_len + iov[1].iov_len;
105839
105840 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
105841 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
105842 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
105843
105844 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
105845 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
105846 index 63b21e5..330232e 100644
105847 --- a/net/rxrpc/ar-input.c
105848 +++ b/net/rxrpc/ar-input.c
105849 @@ -338,9 +338,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
105850 /* track the latest serial number on this connection for ACK packet
105851 * information */
105852 serial = ntohl(sp->hdr.serial);
105853 - hi_serial = atomic_read(&call->conn->hi_serial);
105854 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
105855 while (serial > hi_serial)
105856 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
105857 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
105858 serial);
105859
105860 /* request ACK generation for any ACK or DATA packet that requests
105861 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
105862 index ba9fd36..9bbfe01 100644
105863 --- a/net/rxrpc/ar-internal.h
105864 +++ b/net/rxrpc/ar-internal.h
105865 @@ -272,8 +272,8 @@ struct rxrpc_connection {
105866 int error; /* error code for local abort */
105867 int debug_id; /* debug ID for printks */
105868 unsigned int call_counter; /* call ID counter */
105869 - atomic_t serial; /* packet serial number counter */
105870 - atomic_t hi_serial; /* highest serial number received */
105871 + atomic_unchecked_t serial; /* packet serial number counter */
105872 + atomic_unchecked_t hi_serial; /* highest serial number received */
105873 u8 avail_calls; /* number of calls available */
105874 u8 size_align; /* data size alignment (for security) */
105875 u8 header_size; /* rxrpc + security header size */
105876 @@ -346,7 +346,7 @@ struct rxrpc_call {
105877 spinlock_t lock;
105878 rwlock_t state_lock; /* lock for state transition */
105879 atomic_t usage;
105880 - atomic_t sequence; /* Tx data packet sequence counter */
105881 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
105882 u32 abort_code; /* local/remote abort code */
105883 enum { /* current state of call */
105884 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
105885 @@ -431,7 +431,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
105886 */
105887 extern atomic_t rxrpc_n_skbs;
105888 extern __be32 rxrpc_epoch;
105889 -extern atomic_t rxrpc_debug_id;
105890 +extern atomic_unchecked_t rxrpc_debug_id;
105891 extern struct workqueue_struct *rxrpc_workqueue;
105892
105893 /*
105894 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
105895 index 87f7135..74d3703 100644
105896 --- a/net/rxrpc/ar-local.c
105897 +++ b/net/rxrpc/ar-local.c
105898 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
105899 spin_lock_init(&local->lock);
105900 rwlock_init(&local->services_lock);
105901 atomic_set(&local->usage, 1);
105902 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
105903 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
105904 memcpy(&local->srx, srx, sizeof(*srx));
105905 }
105906
105907 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
105908 index 0b4b9a7..966ffbb 100644
105909 --- a/net/rxrpc/ar-output.c
105910 +++ b/net/rxrpc/ar-output.c
105911 @@ -682,14 +682,14 @@ static int rxrpc_send_data(struct kiocb *iocb,
105912 memset(skb_put(skb, pad), 0, pad);
105913 }
105914
105915 - seq = atomic_inc_return(&call->sequence);
105916 + seq = atomic_inc_return_unchecked(&call->sequence);
105917
105918 sp->hdr.epoch = conn->epoch;
105919 sp->hdr.cid = call->cid;
105920 sp->hdr.callNumber = call->call_id;
105921 sp->hdr.seq = htonl(seq);
105922 sp->hdr.serial =
105923 - htonl(atomic_inc_return(&conn->serial));
105924 + htonl(atomic_inc_return_unchecked(&conn->serial));
105925 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
105926 sp->hdr.userStatus = 0;
105927 sp->hdr.securityIndex = conn->security_ix;
105928 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
105929 index bebaa43..2644591 100644
105930 --- a/net/rxrpc/ar-peer.c
105931 +++ b/net/rxrpc/ar-peer.c
105932 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
105933 INIT_LIST_HEAD(&peer->error_targets);
105934 spin_lock_init(&peer->lock);
105935 atomic_set(&peer->usage, 1);
105936 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
105937 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
105938 memcpy(&peer->srx, srx, sizeof(*srx));
105939
105940 rxrpc_assess_MTU_size(peer);
105941 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
105942 index 38047f7..9f48511 100644
105943 --- a/net/rxrpc/ar-proc.c
105944 +++ b/net/rxrpc/ar-proc.c
105945 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
105946 atomic_read(&conn->usage),
105947 rxrpc_conn_states[conn->state],
105948 key_serial(conn->key),
105949 - atomic_read(&conn->serial),
105950 - atomic_read(&conn->hi_serial));
105951 + atomic_read_unchecked(&conn->serial),
105952 + atomic_read_unchecked(&conn->hi_serial));
105953
105954 return 0;
105955 }
105956 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
105957 index 1976dec..aa70be5 100644
105958 --- a/net/rxrpc/ar-transport.c
105959 +++ b/net/rxrpc/ar-transport.c
105960 @@ -51,7 +51,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
105961 spin_lock_init(&trans->client_lock);
105962 rwlock_init(&trans->conn_lock);
105963 atomic_set(&trans->usage, 1);
105964 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
105965 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
105966
105967 if (peer->srx.transport.family == AF_INET) {
105968 switch (peer->srx.transport_type) {
105969 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
105970 index f226709..0e735a8 100644
105971 --- a/net/rxrpc/rxkad.c
105972 +++ b/net/rxrpc/rxkad.c
105973 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
105974
105975 len = iov[0].iov_len + iov[1].iov_len;
105976
105977 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
105978 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
105979 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
105980
105981 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
105982 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
105983
105984 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
105985
105986 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
105987 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
105988 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
105989
105990 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
105991 diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
105992 index fc04fe9..8167357 100644
105993 --- a/net/sched/sch_generic.c
105994 +++ b/net/sched/sch_generic.c
105995 @@ -310,7 +310,7 @@ void netif_carrier_on(struct net_device *dev)
105996 if (test_and_clear_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
105997 if (dev->reg_state == NETREG_UNINITIALIZED)
105998 return;
105999 - atomic_inc(&dev->carrier_changes);
106000 + atomic_inc_unchecked(&dev->carrier_changes);
106001 linkwatch_fire_event(dev);
106002 if (netif_running(dev))
106003 __netdev_watchdog_up(dev);
106004 @@ -329,7 +329,7 @@ void netif_carrier_off(struct net_device *dev)
106005 if (!test_and_set_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
106006 if (dev->reg_state == NETREG_UNINITIALIZED)
106007 return;
106008 - atomic_inc(&dev->carrier_changes);
106009 + atomic_inc_unchecked(&dev->carrier_changes);
106010 linkwatch_fire_event(dev);
106011 }
106012 }
106013 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
106014 index 0e4198e..f94193e 100644
106015 --- a/net/sctp/ipv6.c
106016 +++ b/net/sctp/ipv6.c
106017 @@ -972,7 +972,7 @@ static const struct inet6_protocol sctpv6_protocol = {
106018 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
106019 };
106020
106021 -static struct sctp_af sctp_af_inet6 = {
106022 +static struct sctp_af sctp_af_inet6 __read_only = {
106023 .sa_family = AF_INET6,
106024 .sctp_xmit = sctp_v6_xmit,
106025 .setsockopt = ipv6_setsockopt,
106026 @@ -1002,7 +1002,7 @@ static struct sctp_af sctp_af_inet6 = {
106027 #endif
106028 };
106029
106030 -static struct sctp_pf sctp_pf_inet6 = {
106031 +static struct sctp_pf sctp_pf_inet6 __read_only = {
106032 .event_msgname = sctp_inet6_event_msgname,
106033 .skb_msgname = sctp_inet6_skb_msgname,
106034 .af_supported = sctp_inet6_af_supported,
106035 @@ -1029,7 +1029,7 @@ void sctp_v6_pf_init(void)
106036
106037 void sctp_v6_pf_exit(void)
106038 {
106039 - list_del(&sctp_af_inet6.list);
106040 + pax_list_del(&sctp_af_inet6.list);
106041 }
106042
106043 /* Initialize IPv6 support and register with socket layer. */
106044 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
106045 index 6240834..cac4b52 100644
106046 --- a/net/sctp/protocol.c
106047 +++ b/net/sctp/protocol.c
106048 @@ -836,8 +836,10 @@ int sctp_register_af(struct sctp_af *af)
106049 return 0;
106050 }
106051
106052 + pax_open_kernel();
106053 INIT_LIST_HEAD(&af->list);
106054 - list_add_tail(&af->list, &sctp_address_families);
106055 + pax_close_kernel();
106056 + pax_list_add_tail(&af->list, &sctp_address_families);
106057 return 1;
106058 }
106059
106060 @@ -967,7 +969,7 @@ static inline int sctp_v4_xmit(struct sk_buff *skb,
106061
106062 static struct sctp_af sctp_af_inet;
106063
106064 -static struct sctp_pf sctp_pf_inet = {
106065 +static struct sctp_pf sctp_pf_inet __read_only = {
106066 .event_msgname = sctp_inet_event_msgname,
106067 .skb_msgname = sctp_inet_skb_msgname,
106068 .af_supported = sctp_inet_af_supported,
106069 @@ -1039,7 +1041,7 @@ static const struct net_protocol sctp_protocol = {
106070 };
106071
106072 /* IPv4 address related functions. */
106073 -static struct sctp_af sctp_af_inet = {
106074 +static struct sctp_af sctp_af_inet __read_only = {
106075 .sa_family = AF_INET,
106076 .sctp_xmit = sctp_v4_xmit,
106077 .setsockopt = ip_setsockopt,
106078 @@ -1123,7 +1125,7 @@ static void sctp_v4_pf_init(void)
106079
106080 static void sctp_v4_pf_exit(void)
106081 {
106082 - list_del(&sctp_af_inet.list);
106083 + pax_list_del(&sctp_af_inet.list);
106084 }
106085
106086 static int sctp_v4_protosw_init(void)
106087 diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
106088 index fef2acd..c705c4f 100644
106089 --- a/net/sctp/sm_sideeffect.c
106090 +++ b/net/sctp/sm_sideeffect.c
106091 @@ -439,7 +439,7 @@ static void sctp_generate_sack_event(unsigned long data)
106092 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
106093 }
106094
106095 -sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
106096 +sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
106097 NULL,
106098 sctp_generate_t1_cookie_event,
106099 sctp_generate_t1_init_event,
106100 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
106101 index 634a2ab..8e93929 100644
106102 --- a/net/sctp/socket.c
106103 +++ b/net/sctp/socket.c
106104 @@ -2199,11 +2199,13 @@ static int sctp_setsockopt_events(struct sock *sk, char __user *optval,
106105 {
106106 struct sctp_association *asoc;
106107 struct sctp_ulpevent *event;
106108 + struct sctp_event_subscribe subscribe;
106109
106110 if (optlen > sizeof(struct sctp_event_subscribe))
106111 return -EINVAL;
106112 - if (copy_from_user(&sctp_sk(sk)->subscribe, optval, optlen))
106113 + if (copy_from_user(&subscribe, optval, optlen))
106114 return -EFAULT;
106115 + sctp_sk(sk)->subscribe = subscribe;
106116
106117 if (sctp_sk(sk)->subscribe.sctp_data_io_event)
106118 pr_warn_ratelimited(DEPRECATED "%s (pid %d) "
106119 @@ -4372,13 +4374,16 @@ static int sctp_getsockopt_disable_fragments(struct sock *sk, int len,
106120 static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
106121 int __user *optlen)
106122 {
106123 + struct sctp_event_subscribe subscribe;
106124 +
106125 if (len <= 0)
106126 return -EINVAL;
106127 if (len > sizeof(struct sctp_event_subscribe))
106128 len = sizeof(struct sctp_event_subscribe);
106129 if (put_user(len, optlen))
106130 return -EFAULT;
106131 - if (copy_to_user(optval, &sctp_sk(sk)->subscribe, len))
106132 + subscribe = sctp_sk(sk)->subscribe;
106133 + if (copy_to_user(optval, &subscribe, len))
106134 return -EFAULT;
106135 return 0;
106136 }
106137 @@ -4396,6 +4401,8 @@ static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
106138 */
106139 static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optval, int __user *optlen)
106140 {
106141 + __u32 autoclose;
106142 +
106143 /* Applicable to UDP-style socket only */
106144 if (sctp_style(sk, TCP))
106145 return -EOPNOTSUPP;
106146 @@ -4404,7 +4411,8 @@ static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optv
106147 len = sizeof(int);
106148 if (put_user(len, optlen))
106149 return -EFAULT;
106150 - if (copy_to_user(optval, &sctp_sk(sk)->autoclose, sizeof(int)))
106151 + autoclose = sctp_sk(sk)->autoclose;
106152 + if (copy_to_user(optval, &autoclose, sizeof(int)))
106153 return -EFAULT;
106154 return 0;
106155 }
106156 @@ -4778,12 +4786,15 @@ static int sctp_getsockopt_delayed_ack(struct sock *sk, int len,
106157 */
106158 static int sctp_getsockopt_initmsg(struct sock *sk, int len, char __user *optval, int __user *optlen)
106159 {
106160 + struct sctp_initmsg initmsg;
106161 +
106162 if (len < sizeof(struct sctp_initmsg))
106163 return -EINVAL;
106164 len = sizeof(struct sctp_initmsg);
106165 if (put_user(len, optlen))
106166 return -EFAULT;
106167 - if (copy_to_user(optval, &sctp_sk(sk)->initmsg, len))
106168 + initmsg = sctp_sk(sk)->initmsg;
106169 + if (copy_to_user(optval, &initmsg, len))
106170 return -EFAULT;
106171 return 0;
106172 }
106173 @@ -4824,6 +4835,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
106174 ->addr_to_user(sp, &temp);
106175 if (space_left < addrlen)
106176 return -ENOMEM;
106177 + if (addrlen > sizeof(temp) || addrlen < 0)
106178 + return -EFAULT;
106179 if (copy_to_user(to, &temp, addrlen))
106180 return -EFAULT;
106181 to += addrlen;
106182 diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
106183 index 2e9ada1..40f425d 100644
106184 --- a/net/sctp/sysctl.c
106185 +++ b/net/sctp/sysctl.c
106186 @@ -321,7 +321,7 @@ static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
106187 loff_t *ppos)
106188 {
106189 struct net *net = current->nsproxy->net_ns;
106190 - struct ctl_table tbl;
106191 + ctl_table_no_const tbl;
106192 bool changed = false;
106193 char *none = "none";
106194 char tmp[8];
106195 @@ -369,7 +369,7 @@ static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
106196 struct net *net = current->nsproxy->net_ns;
106197 unsigned int min = *(unsigned int *) ctl->extra1;
106198 unsigned int max = *(unsigned int *) ctl->extra2;
106199 - struct ctl_table tbl;
106200 + ctl_table_no_const tbl;
106201 int ret, new_value;
106202
106203 memset(&tbl, 0, sizeof(struct ctl_table));
106204 @@ -398,7 +398,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
106205 struct net *net = current->nsproxy->net_ns;
106206 unsigned int min = *(unsigned int *) ctl->extra1;
106207 unsigned int max = *(unsigned int *) ctl->extra2;
106208 - struct ctl_table tbl;
106209 + ctl_table_no_const tbl;
106210 int ret, new_value;
106211
106212 memset(&tbl, 0, sizeof(struct ctl_table));
106213 @@ -436,7 +436,7 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
106214 loff_t *ppos)
106215 {
106216 struct net *net = current->nsproxy->net_ns;
106217 - struct ctl_table tbl;
106218 + ctl_table_no_const tbl;
106219 int new_value, ret;
106220
106221 memset(&tbl, 0, sizeof(struct ctl_table));
106222 @@ -463,7 +463,7 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
106223
106224 int sctp_sysctl_net_register(struct net *net)
106225 {
106226 - struct ctl_table *table;
106227 + ctl_table_no_const *table;
106228 int i;
106229
106230 table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL);
106231 diff --git a/net/socket.c b/net/socket.c
106232 index 4cdbc10..f075204 100644
106233 --- a/net/socket.c
106234 +++ b/net/socket.c
106235 @@ -89,6 +89,7 @@
106236 #include <linux/magic.h>
106237 #include <linux/slab.h>
106238 #include <linux/xattr.h>
106239 +#include <linux/in.h>
106240
106241 #include <asm/uaccess.h>
106242 #include <asm/unistd.h>
106243 @@ -113,6 +114,8 @@ unsigned int sysctl_net_busy_read __read_mostly;
106244 unsigned int sysctl_net_busy_poll __read_mostly;
106245 #endif
106246
106247 +#include <linux/grsock.h>
106248 +
106249 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
106250 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
106251 unsigned long nr_segs, loff_t pos);
106252 @@ -164,7 +167,7 @@ static const struct file_operations socket_file_ops = {
106253 */
106254
106255 static DEFINE_SPINLOCK(net_family_lock);
106256 -static const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
106257 +const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
106258
106259 /*
106260 * Statistics counters of the socket lists
106261 @@ -330,7 +333,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
106262 &sockfs_dentry_operations, SOCKFS_MAGIC);
106263 }
106264
106265 -static struct vfsmount *sock_mnt __read_mostly;
106266 +struct vfsmount *sock_mnt __read_mostly;
106267
106268 static struct file_system_type sock_fs_type = {
106269 .name = "sockfs",
106270 @@ -1265,6 +1268,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
106271 return -EAFNOSUPPORT;
106272 if (type < 0 || type >= SOCK_MAX)
106273 return -EINVAL;
106274 + if (protocol < 0)
106275 + return -EINVAL;
106276
106277 /* Compatibility.
106278
106279 @@ -1285,6 +1290,20 @@ int __sock_create(struct net *net, int family, int type, int protocol,
106280 if (err)
106281 return err;
106282
106283 + if(!kern && !gr_search_socket(family, type, protocol)) {
106284 + if (rcu_access_pointer(net_families[family]) == NULL)
106285 + return -EAFNOSUPPORT;
106286 + else
106287 + return -EACCES;
106288 + }
106289 +
106290 + if (!kern && gr_handle_sock_all(family, type, protocol)) {
106291 + if (rcu_access_pointer(net_families[family]) == NULL)
106292 + return -EAFNOSUPPORT;
106293 + else
106294 + return -EACCES;
106295 + }
106296 +
106297 /*
106298 * Allocate the socket and allow the family to set things up. if
106299 * the protocol is 0, the family is instructed to select an appropriate
106300 @@ -1536,6 +1555,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
106301 if (sock) {
106302 err = move_addr_to_kernel(umyaddr, addrlen, &address);
106303 if (err >= 0) {
106304 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
106305 + err = -EACCES;
106306 + goto error;
106307 + }
106308 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
106309 + if (err)
106310 + goto error;
106311 +
106312 err = security_socket_bind(sock,
106313 (struct sockaddr *)&address,
106314 addrlen);
106315 @@ -1544,6 +1571,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
106316 (struct sockaddr *)
106317 &address, addrlen);
106318 }
106319 +error:
106320 fput_light(sock->file, fput_needed);
106321 }
106322 return err;
106323 @@ -1567,10 +1595,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
106324 if ((unsigned int)backlog > somaxconn)
106325 backlog = somaxconn;
106326
106327 + if (gr_handle_sock_server_other(sock->sk)) {
106328 + err = -EPERM;
106329 + goto error;
106330 + }
106331 +
106332 + err = gr_search_listen(sock);
106333 + if (err)
106334 + goto error;
106335 +
106336 err = security_socket_listen(sock, backlog);
106337 if (!err)
106338 err = sock->ops->listen(sock, backlog);
106339
106340 +error:
106341 fput_light(sock->file, fput_needed);
106342 }
106343 return err;
106344 @@ -1614,6 +1652,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
106345 newsock->type = sock->type;
106346 newsock->ops = sock->ops;
106347
106348 + if (gr_handle_sock_server_other(sock->sk)) {
106349 + err = -EPERM;
106350 + sock_release(newsock);
106351 + goto out_put;
106352 + }
106353 +
106354 + err = gr_search_accept(sock);
106355 + if (err) {
106356 + sock_release(newsock);
106357 + goto out_put;
106358 + }
106359 +
106360 /*
106361 * We don't need try_module_get here, as the listening socket (sock)
106362 * has the protocol module (sock->ops->owner) held.
106363 @@ -1659,6 +1709,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
106364 fd_install(newfd, newfile);
106365 err = newfd;
106366
106367 + gr_attach_curr_ip(newsock->sk);
106368 +
106369 out_put:
106370 fput_light(sock->file, fput_needed);
106371 out:
106372 @@ -1691,6 +1743,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
106373 int, addrlen)
106374 {
106375 struct socket *sock;
106376 + struct sockaddr *sck;
106377 struct sockaddr_storage address;
106378 int err, fput_needed;
106379
106380 @@ -1701,6 +1754,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
106381 if (err < 0)
106382 goto out_put;
106383
106384 + sck = (struct sockaddr *)&address;
106385 +
106386 + if (gr_handle_sock_client(sck)) {
106387 + err = -EACCES;
106388 + goto out_put;
106389 + }
106390 +
106391 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
106392 + if (err)
106393 + goto out_put;
106394 +
106395 err =
106396 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
106397 if (err)
106398 @@ -1782,6 +1846,8 @@ SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr __user *, usockaddr,
106399 * the protocol.
106400 */
106401
106402 +asmlinkage long sys_sendto(int, void __user *, size_t, unsigned, struct sockaddr __user *, int);
106403 +
106404 SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
106405 unsigned int, flags, struct sockaddr __user *, addr,
106406 int, addr_len)
106407 @@ -1848,7 +1914,7 @@ SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, size_t, size,
106408 struct socket *sock;
106409 struct iovec iov;
106410 struct msghdr msg;
106411 - struct sockaddr_storage address;
106412 + struct sockaddr_storage address = { };
106413 int err, err2;
106414 int fput_needed;
106415
106416 @@ -2077,7 +2143,7 @@ static int ___sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
106417 * checking falls down on this.
106418 */
106419 if (copy_from_user(ctl_buf,
106420 - (void __user __force *)msg_sys->msg_control,
106421 + (void __force_user *)msg_sys->msg_control,
106422 ctl_len))
106423 goto out_freectl;
106424 msg_sys->msg_control = ctl_buf;
106425 @@ -2228,7 +2294,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
106426 int err, total_len, len;
106427
106428 /* kernel mode address */
106429 - struct sockaddr_storage addr;
106430 + struct sockaddr_storage addr = { };
106431
106432 /* user mode address pointers */
106433 struct sockaddr __user *uaddr;
106434 @@ -2257,7 +2323,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
106435 /* Save the user-mode address (verify_iovec will change the
106436 * kernel msghdr to use the kernel address space)
106437 */
106438 - uaddr = (__force void __user *)msg_sys->msg_name;
106439 + uaddr = (void __force_user *)msg_sys->msg_name;
106440 uaddr_len = COMPAT_NAMELEN(msg);
106441 if (MSG_CMSG_COMPAT & flags)
106442 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
106443 @@ -2898,7 +2964,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
106444 ifr = compat_alloc_user_space(buf_size);
106445 rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
106446
106447 - if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
106448 + if (copy_in_user(ifr->ifr_name, ifr32->ifr_name, IFNAMSIZ))
106449 return -EFAULT;
106450
106451 if (put_user(convert_in ? rxnfc : compat_ptr(data),
106452 @@ -3009,7 +3075,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
106453 old_fs = get_fs();
106454 set_fs(KERNEL_DS);
106455 err = dev_ioctl(net, cmd,
106456 - (struct ifreq __user __force *) &kifr);
106457 + (struct ifreq __force_user *) &kifr);
106458 set_fs(old_fs);
106459
106460 return err;
106461 @@ -3102,7 +3168,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
106462
106463 old_fs = get_fs();
106464 set_fs(KERNEL_DS);
106465 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
106466 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
106467 set_fs(old_fs);
106468
106469 if (cmd == SIOCGIFMAP && !err) {
106470 @@ -3186,7 +3252,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
106471 ret |= get_user(rtdev, &(ur4->rt_dev));
106472 if (rtdev) {
106473 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
106474 - r4.rt_dev = (char __user __force *)devname;
106475 + r4.rt_dev = (char __force_user *)devname;
106476 devname[15] = 0;
106477 } else
106478 r4.rt_dev = NULL;
106479 @@ -3413,8 +3479,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
106480 int __user *uoptlen;
106481 int err;
106482
106483 - uoptval = (char __user __force *) optval;
106484 - uoptlen = (int __user __force *) optlen;
106485 + uoptval = (char __force_user *) optval;
106486 + uoptlen = (int __force_user *) optlen;
106487
106488 set_fs(KERNEL_DS);
106489 if (level == SOL_SOCKET)
106490 @@ -3434,7 +3500,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
106491 char __user *uoptval;
106492 int err;
106493
106494 - uoptval = (char __user __force *) optval;
106495 + uoptval = (char __force_user *) optval;
106496
106497 set_fs(KERNEL_DS);
106498 if (level == SOL_SOCKET)
106499 diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
106500 index c548ab2..4e1b68b 100644
106501 --- a/net/sunrpc/auth_gss/svcauth_gss.c
106502 +++ b/net/sunrpc/auth_gss/svcauth_gss.c
106503 @@ -1140,7 +1140,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
106504 uint64_t *handle)
106505 {
106506 struct rsc rsci, *rscp = NULL;
106507 - static atomic64_t ctxhctr;
106508 + static atomic64_unchecked_t ctxhctr = ATOMIC64_INIT(0);
106509 long long ctxh;
106510 struct gss_api_mech *gm = NULL;
106511 time_t expiry;
106512 @@ -1151,7 +1151,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
106513 status = -ENOMEM;
106514 /* the handle needs to be just a unique id,
106515 * use a static counter */
106516 - ctxh = atomic64_inc_return(&ctxhctr);
106517 + ctxh = atomic64_inc_return_unchecked(&ctxhctr);
106518
106519 /* make a copy for the caller */
106520 *handle = ctxh;
106521 diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
106522 index 0663621..c4928d4 100644
106523 --- a/net/sunrpc/cache.c
106524 +++ b/net/sunrpc/cache.c
106525 @@ -1609,7 +1609,7 @@ static int create_cache_proc_entries(struct cache_detail *cd, struct net *net)
106526 struct sunrpc_net *sn;
106527
106528 sn = net_generic(net, sunrpc_net_id);
106529 - cd->u.procfs.proc_ent = proc_mkdir(cd->name, sn->proc_net_rpc);
106530 + cd->u.procfs.proc_ent = proc_mkdir_restrict(cd->name, sn->proc_net_rpc);
106531 if (cd->u.procfs.proc_ent == NULL)
106532 goto out_nomem;
106533 cd->u.procfs.channel_ent = NULL;
106534 diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
106535 index e0b94ce..6135813 100644
106536 --- a/net/sunrpc/clnt.c
106537 +++ b/net/sunrpc/clnt.c
106538 @@ -1428,7 +1428,9 @@ call_start(struct rpc_task *task)
106539 (RPC_IS_ASYNC(task) ? "async" : "sync"));
106540
106541 /* Increment call count */
106542 - task->tk_msg.rpc_proc->p_count++;
106543 + pax_open_kernel();
106544 + (*(unsigned int *)&task->tk_msg.rpc_proc->p_count)++;
106545 + pax_close_kernel();
106546 clnt->cl_stats->rpccnt++;
106547 task->tk_action = call_reserve;
106548 }
106549 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
106550 index 9358c79..22d0a5b 100644
106551 --- a/net/sunrpc/sched.c
106552 +++ b/net/sunrpc/sched.c
106553 @@ -261,9 +261,9 @@ static int rpc_wait_bit_killable(struct wait_bit_key *key)
106554 #if defined(RPC_DEBUG) || defined(RPC_TRACEPOINTS)
106555 static void rpc_task_set_debuginfo(struct rpc_task *task)
106556 {
106557 - static atomic_t rpc_pid;
106558 + static atomic_unchecked_t rpc_pid;
106559
106560 - task->tk_pid = atomic_inc_return(&rpc_pid);
106561 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
106562 }
106563 #else
106564 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
106565 diff --git a/net/sunrpc/stats.c b/net/sunrpc/stats.c
106566 index 5453049..465669a 100644
106567 --- a/net/sunrpc/stats.c
106568 +++ b/net/sunrpc/stats.c
106569 @@ -267,7 +267,7 @@ int rpc_proc_init(struct net *net)
106570
106571 dprintk("RPC: registering /proc/net/rpc\n");
106572 sn = net_generic(net, sunrpc_net_id);
106573 - sn->proc_net_rpc = proc_mkdir("rpc", net->proc_net);
106574 + sn->proc_net_rpc = proc_mkdir_restrict("rpc", net->proc_net);
106575 if (sn->proc_net_rpc == NULL)
106576 return -ENOMEM;
106577
106578 diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
106579 index 1db5007..6e66296 100644
106580 --- a/net/sunrpc/svc.c
106581 +++ b/net/sunrpc/svc.c
106582 @@ -1167,7 +1167,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
106583 svc_putnl(resv, RPC_SUCCESS);
106584
106585 /* Bump per-procedure stats counter */
106586 - procp->pc_count++;
106587 + pax_open_kernel();
106588 + (*(unsigned int *)&procp->pc_count)++;
106589 + pax_close_kernel();
106590
106591 /* Initialize storage for argp and resp */
106592 memset(rqstp->rq_argp, 0, procp->pc_argsize);
106593 diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
106594 index 621ca7b..59421dd 100644
106595 --- a/net/sunrpc/svcauth_unix.c
106596 +++ b/net/sunrpc/svcauth_unix.c
106597 @@ -414,7 +414,7 @@ struct unix_gid {
106598 struct group_info *gi;
106599 };
106600
106601 -static int unix_gid_hash(kuid_t uid)
106602 +static int __intentional_overflow(-1) unix_gid_hash(kuid_t uid)
106603 {
106604 return hash_long(from_kuid(&init_user_ns, uid), GID_HASHBITS);
106605 }
106606 @@ -470,7 +470,7 @@ static void unix_gid_request(struct cache_detail *cd,
106607 (*bpp)[-1] = '\n';
106608 }
106609
106610 -static struct unix_gid *unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
106611 +static struct unix_gid * __intentional_overflow(-1) unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
106612
106613 static int unix_gid_parse(struct cache_detail *cd,
106614 char *mesg, int mlen)
106615 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
106616 index c1b6270..05089c1 100644
106617 --- a/net/sunrpc/xprtrdma/svc_rdma.c
106618 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
106619 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
106620 static unsigned int min_max_inline = 4096;
106621 static unsigned int max_max_inline = 65536;
106622
106623 -atomic_t rdma_stat_recv;
106624 -atomic_t rdma_stat_read;
106625 -atomic_t rdma_stat_write;
106626 -atomic_t rdma_stat_sq_starve;
106627 -atomic_t rdma_stat_rq_starve;
106628 -atomic_t rdma_stat_rq_poll;
106629 -atomic_t rdma_stat_rq_prod;
106630 -atomic_t rdma_stat_sq_poll;
106631 -atomic_t rdma_stat_sq_prod;
106632 +atomic_unchecked_t rdma_stat_recv;
106633 +atomic_unchecked_t rdma_stat_read;
106634 +atomic_unchecked_t rdma_stat_write;
106635 +atomic_unchecked_t rdma_stat_sq_starve;
106636 +atomic_unchecked_t rdma_stat_rq_starve;
106637 +atomic_unchecked_t rdma_stat_rq_poll;
106638 +atomic_unchecked_t rdma_stat_rq_prod;
106639 +atomic_unchecked_t rdma_stat_sq_poll;
106640 +atomic_unchecked_t rdma_stat_sq_prod;
106641
106642 /* Temporary NFS request map and context caches */
106643 struct kmem_cache *svc_rdma_map_cachep;
106644 @@ -110,7 +110,7 @@ static int read_reset_stat(struct ctl_table *table, int write,
106645 len -= *ppos;
106646 if (len > *lenp)
106647 len = *lenp;
106648 - if (len && copy_to_user(buffer, str_buf, len))
106649 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
106650 return -EFAULT;
106651 *lenp = len;
106652 *ppos += len;
106653 @@ -151,63 +151,63 @@ static struct ctl_table svcrdma_parm_table[] = {
106654 {
106655 .procname = "rdma_stat_read",
106656 .data = &rdma_stat_read,
106657 - .maxlen = sizeof(atomic_t),
106658 + .maxlen = sizeof(atomic_unchecked_t),
106659 .mode = 0644,
106660 .proc_handler = read_reset_stat,
106661 },
106662 {
106663 .procname = "rdma_stat_recv",
106664 .data = &rdma_stat_recv,
106665 - .maxlen = sizeof(atomic_t),
106666 + .maxlen = sizeof(atomic_unchecked_t),
106667 .mode = 0644,
106668 .proc_handler = read_reset_stat,
106669 },
106670 {
106671 .procname = "rdma_stat_write",
106672 .data = &rdma_stat_write,
106673 - .maxlen = sizeof(atomic_t),
106674 + .maxlen = sizeof(atomic_unchecked_t),
106675 .mode = 0644,
106676 .proc_handler = read_reset_stat,
106677 },
106678 {
106679 .procname = "rdma_stat_sq_starve",
106680 .data = &rdma_stat_sq_starve,
106681 - .maxlen = sizeof(atomic_t),
106682 + .maxlen = sizeof(atomic_unchecked_t),
106683 .mode = 0644,
106684 .proc_handler = read_reset_stat,
106685 },
106686 {
106687 .procname = "rdma_stat_rq_starve",
106688 .data = &rdma_stat_rq_starve,
106689 - .maxlen = sizeof(atomic_t),
106690 + .maxlen = sizeof(atomic_unchecked_t),
106691 .mode = 0644,
106692 .proc_handler = read_reset_stat,
106693 },
106694 {
106695 .procname = "rdma_stat_rq_poll",
106696 .data = &rdma_stat_rq_poll,
106697 - .maxlen = sizeof(atomic_t),
106698 + .maxlen = sizeof(atomic_unchecked_t),
106699 .mode = 0644,
106700 .proc_handler = read_reset_stat,
106701 },
106702 {
106703 .procname = "rdma_stat_rq_prod",
106704 .data = &rdma_stat_rq_prod,
106705 - .maxlen = sizeof(atomic_t),
106706 + .maxlen = sizeof(atomic_unchecked_t),
106707 .mode = 0644,
106708 .proc_handler = read_reset_stat,
106709 },
106710 {
106711 .procname = "rdma_stat_sq_poll",
106712 .data = &rdma_stat_sq_poll,
106713 - .maxlen = sizeof(atomic_t),
106714 + .maxlen = sizeof(atomic_unchecked_t),
106715 .mode = 0644,
106716 .proc_handler = read_reset_stat,
106717 },
106718 {
106719 .procname = "rdma_stat_sq_prod",
106720 .data = &rdma_stat_sq_prod,
106721 - .maxlen = sizeof(atomic_t),
106722 + .maxlen = sizeof(atomic_unchecked_t),
106723 .mode = 0644,
106724 .proc_handler = read_reset_stat,
106725 },
106726 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
106727 index e011027..9d3c4e1 100644
106728 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
106729 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
106730 @@ -220,7 +220,7 @@ static int rdma_read_chunk_lcl(struct svcxprt_rdma *xprt,
106731 *page_no = pg_no;
106732 *page_offset = pg_off;
106733 ret = read;
106734 - atomic_inc(&rdma_stat_read);
106735 + atomic_inc_unchecked(&rdma_stat_read);
106736 return ret;
106737 err:
106738 svc_rdma_unmap_dma(ctxt);
106739 @@ -356,7 +356,7 @@ static int rdma_read_chunk_frmr(struct svcxprt_rdma *xprt,
106740 *page_no = pg_no;
106741 *page_offset = pg_off;
106742 ret = read;
106743 - atomic_inc(&rdma_stat_read);
106744 + atomic_inc_unchecked(&rdma_stat_read);
106745 return ret;
106746 err:
106747 svc_rdma_unmap_dma(ctxt);
106748 @@ -540,7 +540,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
106749 dto_q);
106750 list_del_init(&ctxt->dto_q);
106751 } else {
106752 - atomic_inc(&rdma_stat_rq_starve);
106753 + atomic_inc_unchecked(&rdma_stat_rq_starve);
106754 clear_bit(XPT_DATA, &xprt->xpt_flags);
106755 ctxt = NULL;
106756 }
106757 @@ -559,7 +559,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
106758 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
106759 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
106760 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
106761 - atomic_inc(&rdma_stat_recv);
106762 + atomic_inc_unchecked(&rdma_stat_recv);
106763
106764 /* Build up the XDR from the receive buffers. */
106765 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
106766 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
106767 index 9f1b506..2e0b321 100644
106768 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
106769 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
106770 @@ -208,7 +208,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
106771 write_wr.wr.rdma.remote_addr = to;
106772
106773 /* Post It */
106774 - atomic_inc(&rdma_stat_write);
106775 + atomic_inc_unchecked(&rdma_stat_write);
106776 if (svc_rdma_send(xprt, &write_wr))
106777 goto err;
106778 return write_len - bc;
106779 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
106780 index 374feb4..46487d5 100644
106781 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
106782 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
106783 @@ -295,7 +295,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
106784 return;
106785
106786 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
106787 - atomic_inc(&rdma_stat_rq_poll);
106788 + atomic_inc_unchecked(&rdma_stat_rq_poll);
106789
106790 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
106791 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
106792 @@ -317,7 +317,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
106793 }
106794
106795 if (ctxt)
106796 - atomic_inc(&rdma_stat_rq_prod);
106797 + atomic_inc_unchecked(&rdma_stat_rq_prod);
106798
106799 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
106800 /*
106801 @@ -392,7 +392,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
106802 return;
106803
106804 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
106805 - atomic_inc(&rdma_stat_sq_poll);
106806 + atomic_inc_unchecked(&rdma_stat_sq_poll);
106807 while ((ret = ib_poll_cq(cq, ARRAY_SIZE(wc_a), wc_a)) > 0) {
106808 int i;
106809
106810 @@ -420,7 +420,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
106811 }
106812
106813 if (ctxt)
106814 - atomic_inc(&rdma_stat_sq_prod);
106815 + atomic_inc_unchecked(&rdma_stat_sq_prod);
106816 }
106817
106818 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
106819 @@ -1264,7 +1264,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
106820 spin_lock_bh(&xprt->sc_lock);
106821 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
106822 spin_unlock_bh(&xprt->sc_lock);
106823 - atomic_inc(&rdma_stat_sq_starve);
106824 + atomic_inc_unchecked(&rdma_stat_sq_starve);
106825
106826 /* See if we can opportunistically reap SQ WR to make room */
106827 sq_cq_reap(xprt);
106828 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
106829 index e7000be..e3b0ba7 100644
106830 --- a/net/sysctl_net.c
106831 +++ b/net/sysctl_net.c
106832 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head,
106833 kgid_t root_gid = make_kgid(net->user_ns, 0);
106834
106835 /* Allow network administrator to have same access as root. */
106836 - if (ns_capable(net->user_ns, CAP_NET_ADMIN) ||
106837 + if (ns_capable_nolog(net->user_ns, CAP_NET_ADMIN) ||
106838 uid_eq(root_uid, current_euid())) {
106839 int mode = (table->mode >> 6) & 7;
106840 return (mode << 6) | (mode << 3) | mode;
106841 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
106842 index 6424372..afd36e9 100644
106843 --- a/net/tipc/subscr.c
106844 +++ b/net/tipc/subscr.c
106845 @@ -97,7 +97,7 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower,
106846 struct tipc_subscriber *subscriber = sub->subscriber;
106847 struct kvec msg_sect;
106848
106849 - msg_sect.iov_base = (void *)&sub->evt;
106850 + msg_sect.iov_base = &sub->evt;
106851 msg_sect.iov_len = sizeof(struct tipc_event);
106852 sub->evt.event = htohl(event, sub->swap);
106853 sub->evt.found_lower = htohl(found_lower, sub->swap);
106854 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
106855 index e968843..bc95776 100644
106856 --- a/net/unix/af_unix.c
106857 +++ b/net/unix/af_unix.c
106858 @@ -791,6 +791,12 @@ static struct sock *unix_find_other(struct net *net,
106859 err = -ECONNREFUSED;
106860 if (!S_ISSOCK(inode->i_mode))
106861 goto put_fail;
106862 +
106863 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
106864 + err = -EACCES;
106865 + goto put_fail;
106866 + }
106867 +
106868 u = unix_find_socket_byinode(inode);
106869 if (!u)
106870 goto put_fail;
106871 @@ -811,6 +817,13 @@ static struct sock *unix_find_other(struct net *net,
106872 if (u) {
106873 struct dentry *dentry;
106874 dentry = unix_sk(u)->path.dentry;
106875 +
106876 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
106877 + err = -EPERM;
106878 + sock_put(u);
106879 + goto fail;
106880 + }
106881 +
106882 if (dentry)
106883 touch_atime(&unix_sk(u)->path);
106884 } else
106885 @@ -844,12 +857,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
106886 */
106887 err = security_path_mknod(&path, dentry, mode, 0);
106888 if (!err) {
106889 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
106890 + err = -EACCES;
106891 + goto out;
106892 + }
106893 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
106894 if (!err) {
106895 res->mnt = mntget(path.mnt);
106896 res->dentry = dget(dentry);
106897 + gr_handle_create(dentry, path.mnt);
106898 }
106899 }
106900 +out:
106901 done_path_create(&path, dentry);
106902 return err;
106903 }
106904 @@ -2350,9 +2369,13 @@ static int unix_seq_show(struct seq_file *seq, void *v)
106905 seq_puts(seq, "Num RefCount Protocol Flags Type St "
106906 "Inode Path\n");
106907 else {
106908 - struct sock *s = v;
106909 + struct sock *s = v, *peer;
106910 struct unix_sock *u = unix_sk(s);
106911 unix_state_lock(s);
106912 + peer = unix_peer(s);
106913 + unix_state_unlock(s);
106914 +
106915 + unix_state_double_lock(s, peer);
106916
106917 seq_printf(seq, "%pK: %08X %08X %08X %04X %02X %5lu",
106918 s,
106919 @@ -2379,8 +2402,10 @@ static int unix_seq_show(struct seq_file *seq, void *v)
106920 }
106921 for ( ; i < len; i++)
106922 seq_putc(seq, u->addr->name->sun_path[i]);
106923 - }
106924 - unix_state_unlock(s);
106925 + } else if (peer)
106926 + seq_printf(seq, " P%lu", sock_i_ino(peer));
106927 +
106928 + unix_state_double_unlock(s, peer);
106929 seq_putc(seq, '\n');
106930 }
106931
106932 diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
106933 index b3d5150..ff3a837 100644
106934 --- a/net/unix/sysctl_net_unix.c
106935 +++ b/net/unix/sysctl_net_unix.c
106936 @@ -28,7 +28,7 @@ static struct ctl_table unix_table[] = {
106937
106938 int __net_init unix_sysctl_register(struct net *net)
106939 {
106940 - struct ctl_table *table;
106941 + ctl_table_no_const *table;
106942
106943 table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
106944 if (table == NULL)
106945 diff --git a/net/vmw_vsock/vmci_transport_notify.c b/net/vmw_vsock/vmci_transport_notify.c
106946 index 9b7f207..2596621 100644
106947 --- a/net/vmw_vsock/vmci_transport_notify.c
106948 +++ b/net/vmw_vsock/vmci_transport_notify.c
106949 @@ -662,19 +662,19 @@ static void vmci_transport_notify_pkt_process_negotiate(struct sock *sk)
106950
106951 /* Socket control packet based operations. */
106952 struct vmci_transport_notify_ops vmci_transport_notify_pkt_ops = {
106953 - vmci_transport_notify_pkt_socket_init,
106954 - vmci_transport_notify_pkt_socket_destruct,
106955 - vmci_transport_notify_pkt_poll_in,
106956 - vmci_transport_notify_pkt_poll_out,
106957 - vmci_transport_notify_pkt_handle_pkt,
106958 - vmci_transport_notify_pkt_recv_init,
106959 - vmci_transport_notify_pkt_recv_pre_block,
106960 - vmci_transport_notify_pkt_recv_pre_dequeue,
106961 - vmci_transport_notify_pkt_recv_post_dequeue,
106962 - vmci_transport_notify_pkt_send_init,
106963 - vmci_transport_notify_pkt_send_pre_block,
106964 - vmci_transport_notify_pkt_send_pre_enqueue,
106965 - vmci_transport_notify_pkt_send_post_enqueue,
106966 - vmci_transport_notify_pkt_process_request,
106967 - vmci_transport_notify_pkt_process_negotiate,
106968 + .socket_init = vmci_transport_notify_pkt_socket_init,
106969 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
106970 + .poll_in = vmci_transport_notify_pkt_poll_in,
106971 + .poll_out = vmci_transport_notify_pkt_poll_out,
106972 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
106973 + .recv_init = vmci_transport_notify_pkt_recv_init,
106974 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
106975 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
106976 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
106977 + .send_init = vmci_transport_notify_pkt_send_init,
106978 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
106979 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
106980 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
106981 + .process_request = vmci_transport_notify_pkt_process_request,
106982 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
106983 };
106984 diff --git a/net/vmw_vsock/vmci_transport_notify_qstate.c b/net/vmw_vsock/vmci_transport_notify_qstate.c
106985 index dc9c792..3089de0 100644
106986 --- a/net/vmw_vsock/vmci_transport_notify_qstate.c
106987 +++ b/net/vmw_vsock/vmci_transport_notify_qstate.c
106988 @@ -420,19 +420,19 @@ vmci_transport_notify_pkt_send_pre_enqueue(
106989
106990 /* Socket always on control packet based operations. */
106991 struct vmci_transport_notify_ops vmci_transport_notify_pkt_q_state_ops = {
106992 - vmci_transport_notify_pkt_socket_init,
106993 - vmci_transport_notify_pkt_socket_destruct,
106994 - vmci_transport_notify_pkt_poll_in,
106995 - vmci_transport_notify_pkt_poll_out,
106996 - vmci_transport_notify_pkt_handle_pkt,
106997 - vmci_transport_notify_pkt_recv_init,
106998 - vmci_transport_notify_pkt_recv_pre_block,
106999 - vmci_transport_notify_pkt_recv_pre_dequeue,
107000 - vmci_transport_notify_pkt_recv_post_dequeue,
107001 - vmci_transport_notify_pkt_send_init,
107002 - vmci_transport_notify_pkt_send_pre_block,
107003 - vmci_transport_notify_pkt_send_pre_enqueue,
107004 - vmci_transport_notify_pkt_send_post_enqueue,
107005 - vmci_transport_notify_pkt_process_request,
107006 - vmci_transport_notify_pkt_process_negotiate,
107007 + .socket_init = vmci_transport_notify_pkt_socket_init,
107008 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
107009 + .poll_in = vmci_transport_notify_pkt_poll_in,
107010 + .poll_out = vmci_transport_notify_pkt_poll_out,
107011 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
107012 + .recv_init = vmci_transport_notify_pkt_recv_init,
107013 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
107014 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
107015 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
107016 + .send_init = vmci_transport_notify_pkt_send_init,
107017 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
107018 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
107019 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
107020 + .process_request = vmci_transport_notify_pkt_process_request,
107021 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
107022 };
107023 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
107024 index c8717c1..08539f5 100644
107025 --- a/net/wireless/wext-core.c
107026 +++ b/net/wireless/wext-core.c
107027 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
107028 */
107029
107030 /* Support for very large requests */
107031 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
107032 - (user_length > descr->max_tokens)) {
107033 + if (user_length > descr->max_tokens) {
107034 /* Allow userspace to GET more than max so
107035 * we can support any size GET requests.
107036 * There is still a limit : -ENOMEM.
107037 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
107038 }
107039 }
107040
107041 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
107042 - /*
107043 - * If this is a GET, but not NOMAX, it means that the extra
107044 - * data is not bounded by userspace, but by max_tokens. Thus
107045 - * set the length to max_tokens. This matches the extra data
107046 - * allocation.
107047 - * The driver should fill it with the number of tokens it
107048 - * provided, and it may check iwp->length rather than having
107049 - * knowledge of max_tokens. If the driver doesn't change the
107050 - * iwp->length, this ioctl just copies back max_token tokens
107051 - * filled with zeroes. Hopefully the driver isn't claiming
107052 - * them to be valid data.
107053 - */
107054 - iwp->length = descr->max_tokens;
107055 - }
107056 -
107057 err = handler(dev, info, (union iwreq_data *) iwp, extra);
107058
107059 iwp->length += essid_compat;
107060 diff --git a/net/x25/sysctl_net_x25.c b/net/x25/sysctl_net_x25.c
107061 index 4323952..a06dfe1 100644
107062 --- a/net/x25/sysctl_net_x25.c
107063 +++ b/net/x25/sysctl_net_x25.c
107064 @@ -70,7 +70,7 @@ static struct ctl_table x25_table[] = {
107065 .mode = 0644,
107066 .proc_handler = proc_dointvec,
107067 },
107068 - { 0, },
107069 + { },
107070 };
107071
107072 void __init x25_register_sysctl(void)
107073 diff --git a/net/x25/x25_proc.c b/net/x25/x25_proc.c
107074 index 0917f04..f4e3d8c 100644
107075 --- a/net/x25/x25_proc.c
107076 +++ b/net/x25/x25_proc.c
107077 @@ -209,7 +209,7 @@ static const struct file_operations x25_seq_forward_fops = {
107078
107079 int __init x25_proc_init(void)
107080 {
107081 - if (!proc_mkdir("x25", init_net.proc_net))
107082 + if (!proc_mkdir_restrict("x25", init_net.proc_net))
107083 return -ENOMEM;
107084
107085 if (!proc_create("x25/route", S_IRUGO, init_net.proc_net,
107086 diff --git a/net/xfrm/xfrm_output.c b/net/xfrm/xfrm_output.c
107087 index c51e8f7b..e44f360 100644
107088 --- a/net/xfrm/xfrm_output.c
107089 +++ b/net/xfrm/xfrm_output.c
107090 @@ -157,6 +157,8 @@ static int xfrm_output_gso(struct sk_buff *skb)
107091 kfree_skb(skb);
107092 if (IS_ERR(segs))
107093 return PTR_ERR(segs);
107094 + if (segs == NULL)
107095 + return -EINVAL;
107096
107097 do {
107098 struct sk_buff *nskb = segs->next;
107099 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
107100 index fdde51f..4839450 100644
107101 --- a/net/xfrm/xfrm_policy.c
107102 +++ b/net/xfrm/xfrm_policy.c
107103 @@ -330,7 +330,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
107104 {
107105 policy->walk.dead = 1;
107106
107107 - atomic_inc(&policy->genid);
107108 + atomic_inc_unchecked(&policy->genid);
107109
107110 if (del_timer(&policy->polq.hold_timer))
107111 xfrm_pol_put(policy);
107112 @@ -664,7 +664,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
107113 hlist_add_head(&policy->bydst, chain);
107114 xfrm_pol_hold(policy);
107115 net->xfrm.policy_count[dir]++;
107116 - atomic_inc(&net->xfrm.flow_cache_genid);
107117 + atomic_inc_unchecked(&net->xfrm.flow_cache_genid);
107118
107119 /* After previous checking, family can either be AF_INET or AF_INET6 */
107120 if (policy->family == AF_INET)
107121 @@ -1754,7 +1754,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
107122
107123 xdst->num_pols = num_pols;
107124 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy *) * num_pols);
107125 - xdst->policy_genid = atomic_read(&pols[0]->genid);
107126 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
107127
107128 return xdst;
107129 }
107130 @@ -2570,10 +2570,11 @@ void xfrm_garbage_collect(struct net *net)
107131 }
107132 EXPORT_SYMBOL(xfrm_garbage_collect);
107133
107134 -static void xfrm_garbage_collect_deferred(struct net *net)
107135 +void xfrm_garbage_collect_deferred(struct net *net)
107136 {
107137 flow_cache_flush_deferred(net);
107138 }
107139 +EXPORT_SYMBOL(xfrm_garbage_collect_deferred);
107140
107141 static void xfrm_init_pmtu(struct dst_entry *dst)
107142 {
107143 @@ -2623,7 +2624,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
107144 if (xdst->xfrm_genid != dst->xfrm->genid)
107145 return 0;
107146 if (xdst->num_pols > 0 &&
107147 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
107148 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
107149 return 0;
107150
107151 mtu = dst_mtu(dst->child);
107152 @@ -2711,8 +2712,6 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
107153 dst_ops->link_failure = xfrm_link_failure;
107154 if (likely(dst_ops->neigh_lookup == NULL))
107155 dst_ops->neigh_lookup = xfrm_neigh_lookup;
107156 - if (likely(afinfo->garbage_collect == NULL))
107157 - afinfo->garbage_collect = xfrm_garbage_collect_deferred;
107158 rcu_assign_pointer(xfrm_policy_afinfo[afinfo->family], afinfo);
107159 }
107160 spin_unlock(&xfrm_policy_afinfo_lock);
107161 @@ -2766,7 +2765,6 @@ int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo)
107162 dst_ops->check = NULL;
107163 dst_ops->negative_advice = NULL;
107164 dst_ops->link_failure = NULL;
107165 - afinfo->garbage_collect = NULL;
107166 }
107167 return err;
107168 }
107169 @@ -3151,7 +3149,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
107170 sizeof(pol->xfrm_vec[i].saddr));
107171 pol->xfrm_vec[i].encap_family = mp->new_family;
107172 /* flush bundles */
107173 - atomic_inc(&pol->genid);
107174 + atomic_inc_unchecked(&pol->genid);
107175 }
107176 }
107177
107178 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
107179 index 0ab5413..73dd2cf 100644
107180 --- a/net/xfrm/xfrm_state.c
107181 +++ b/net/xfrm/xfrm_state.c
107182 @@ -173,12 +173,14 @@ int xfrm_register_type(const struct xfrm_type *type, unsigned short family)
107183
107184 if (unlikely(afinfo == NULL))
107185 return -EAFNOSUPPORT;
107186 - typemap = afinfo->type_map;
107187 + typemap = (const struct xfrm_type **)afinfo->type_map;
107188 spin_lock_bh(&xfrm_type_lock);
107189
107190 - if (likely(typemap[type->proto] == NULL))
107191 + if (likely(typemap[type->proto] == NULL)) {
107192 + pax_open_kernel();
107193 typemap[type->proto] = type;
107194 - else
107195 + pax_close_kernel();
107196 + } else
107197 err = -EEXIST;
107198 spin_unlock_bh(&xfrm_type_lock);
107199 xfrm_state_put_afinfo(afinfo);
107200 @@ -194,13 +196,16 @@ int xfrm_unregister_type(const struct xfrm_type *type, unsigned short family)
107201
107202 if (unlikely(afinfo == NULL))
107203 return -EAFNOSUPPORT;
107204 - typemap = afinfo->type_map;
107205 + typemap = (const struct xfrm_type **)afinfo->type_map;
107206 spin_lock_bh(&xfrm_type_lock);
107207
107208 if (unlikely(typemap[type->proto] != type))
107209 err = -ENOENT;
107210 - else
107211 + else {
107212 + pax_open_kernel();
107213 typemap[type->proto] = NULL;
107214 + pax_close_kernel();
107215 + }
107216 spin_unlock_bh(&xfrm_type_lock);
107217 xfrm_state_put_afinfo(afinfo);
107218 return err;
107219 @@ -210,7 +215,6 @@ EXPORT_SYMBOL(xfrm_unregister_type);
107220 static const struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
107221 {
107222 struct xfrm_state_afinfo *afinfo;
107223 - const struct xfrm_type **typemap;
107224 const struct xfrm_type *type;
107225 int modload_attempted = 0;
107226
107227 @@ -218,9 +222,8 @@ retry:
107228 afinfo = xfrm_state_get_afinfo(family);
107229 if (unlikely(afinfo == NULL))
107230 return NULL;
107231 - typemap = afinfo->type_map;
107232
107233 - type = typemap[proto];
107234 + type = afinfo->type_map[proto];
107235 if (unlikely(type && !try_module_get(type->owner)))
107236 type = NULL;
107237 if (!type && !modload_attempted) {
107238 @@ -254,7 +257,7 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
107239 return -EAFNOSUPPORT;
107240
107241 err = -EEXIST;
107242 - modemap = afinfo->mode_map;
107243 + modemap = (struct xfrm_mode **)afinfo->mode_map;
107244 spin_lock_bh(&xfrm_mode_lock);
107245 if (modemap[mode->encap])
107246 goto out;
107247 @@ -263,8 +266,10 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
107248 if (!try_module_get(afinfo->owner))
107249 goto out;
107250
107251 - mode->afinfo = afinfo;
107252 + pax_open_kernel();
107253 + *(const void **)&mode->afinfo = afinfo;
107254 modemap[mode->encap] = mode;
107255 + pax_close_kernel();
107256 err = 0;
107257
107258 out:
107259 @@ -288,10 +293,12 @@ int xfrm_unregister_mode(struct xfrm_mode *mode, int family)
107260 return -EAFNOSUPPORT;
107261
107262 err = -ENOENT;
107263 - modemap = afinfo->mode_map;
107264 + modemap = (struct xfrm_mode **)afinfo->mode_map;
107265 spin_lock_bh(&xfrm_mode_lock);
107266 if (likely(modemap[mode->encap] == mode)) {
107267 + pax_open_kernel();
107268 modemap[mode->encap] = NULL;
107269 + pax_close_kernel();
107270 module_put(mode->afinfo->owner);
107271 err = 0;
107272 }
107273 @@ -1512,10 +1519,10 @@ EXPORT_SYMBOL(xfrm_find_acq_byseq);
107274 u32 xfrm_get_acqseq(void)
107275 {
107276 u32 res;
107277 - static atomic_t acqseq;
107278 + static atomic_unchecked_t acqseq;
107279
107280 do {
107281 - res = atomic_inc_return(&acqseq);
107282 + res = atomic_inc_return_unchecked(&acqseq);
107283 } while (!res);
107284
107285 return res;
107286 diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c
107287 index 05a6e3d..6716ec9 100644
107288 --- a/net/xfrm/xfrm_sysctl.c
107289 +++ b/net/xfrm/xfrm_sysctl.c
107290 @@ -42,7 +42,7 @@ static struct ctl_table xfrm_table[] = {
107291
107292 int __net_init xfrm_sysctl_init(struct net *net)
107293 {
107294 - struct ctl_table *table;
107295 + ctl_table_no_const *table;
107296
107297 __xfrm_sysctl_init(net);
107298
107299 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
107300 index bf3e677..c7d426e 100644
107301 --- a/scripts/Makefile.build
107302 +++ b/scripts/Makefile.build
107303 @@ -60,7 +60,7 @@ endif
107304 endif
107305
107306 # Do not include host rules unless needed
107307 -ifneq ($(hostprogs-y)$(hostprogs-m),)
107308 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
107309 include scripts/Makefile.host
107310 endif
107311
107312 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
107313 index a651cee..6b3b9a3 100644
107314 --- a/scripts/Makefile.clean
107315 +++ b/scripts/Makefile.clean
107316 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
107317 __clean-files := $(extra-y) $(extra-m) $(extra-) \
107318 $(always) $(targets) $(clean-files) \
107319 $(host-progs) \
107320 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
107321 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
107322 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
107323
107324 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
107325
107326 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
107327 index ab5980f..85fd3e1 100644
107328 --- a/scripts/Makefile.host
107329 +++ b/scripts/Makefile.host
107330 @@ -20,7 +20,19 @@
107331 # Will compile qconf as a C++ program, and menu as a C program.
107332 # They are linked as C++ code to the executable qconf
107333
107334 +# hostprogs-y := conf
107335 +# conf-objs := conf.o libkconfig.so
107336 +# libkconfig-objs := expr.o type.o
107337 +# Will create a shared library named libkconfig.so that consists of
107338 +# expr.o and type.o (they are both compiled as C code and the object files
107339 +# are made as position independent code).
107340 +# conf.c is compiled as a C program, and conf.o is linked together with
107341 +# libkconfig.so as the executable conf.
107342 +# Note: Shared libraries consisting of C++ files are not supported
107343 +
107344 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
107345 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
107346 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
107347
107348 # C code
107349 # Executables compiled from a single .c file
107350 @@ -42,6 +54,19 @@ host-cxxmulti := $(foreach m,$(__hostprogs),$(if $($(m)-cxxobjs),$(m)))
107351 # C++ Object (.o) files compiled from .cc files
107352 host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
107353
107354 +# Shared libaries (only .c supported)
107355 +# Shared libraries (.so) - all .so files referenced in "xxx-objs"
107356 +host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
107357 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
107358 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
107359 +# Remove .so files from "xxx-objs"
107360 +host-cobjs := $(filter-out %.so,$(host-cobjs))
107361 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
107362 +
107363 +# Object (.o) files used by the shared libaries
107364 +host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
107365 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
107366 +
107367 # output directory for programs/.o files
107368 # hostprogs-y := tools/build may have been specified.
107369 # Retrieve also directory of .o files from prog-objs or prog-cxxobjs notation
107370 @@ -56,6 +81,10 @@ host-cmulti := $(addprefix $(obj)/,$(host-cmulti))
107371 host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
107372 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
107373 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
107374 +host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
107375 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
107376 +host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
107377 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
107378 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
107379
107380 obj-dirs += $(host-objdirs)
107381 @@ -96,7 +125,7 @@ quiet_cmd_host-cmulti = HOSTLD $@
107382 cmd_host-cmulti = $(HOSTCC) $(HOSTLDFLAGS) -o $@ \
107383 $(addprefix $(obj)/,$($(@F)-objs)) \
107384 $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
107385 -$(host-cmulti): $(obj)/%: $(host-cobjs) FORCE
107386 +$(host-cmulti): $(obj)/%: $(host-cobjs) $(host-cshlib) FORCE
107387 $(call if_changed,host-cmulti)
107388
107389 # Create .o file from a single .c file
107390 @@ -113,7 +142,7 @@ quiet_cmd_host-cxxmulti = HOSTLD $@
107391 $(foreach o,objs cxxobjs,\
107392 $(addprefix $(obj)/,$($(@F)-$(o)))) \
107393 $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
107394 -$(host-cxxmulti): $(obj)/%: $(host-cobjs) $(host-cxxobjs) FORCE
107395 +$(host-cxxmulti): $(obj)/%: $(host-cobjs) $(host-cxxobjs) $(host-cshlib) FORCE
107396 $(call if_changed,host-cxxmulti)
107397
107398 # Create .o file from a single .cc (C++) file
107399 @@ -122,5 +151,37 @@ quiet_cmd_host-cxxobjs = HOSTCXX $@
107400 $(host-cxxobjs): $(obj)/%.o: $(src)/%.cc FORCE
107401 $(call if_changed_dep,host-cxxobjs)
107402
107403 +# Compile .c file, create position independent .o file
107404 +# host-cshobjs -> .o
107405 +quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
107406 + cmd_host-cshobjs = $(HOSTCC) $(hostc_flags) -fPIC -c -o $@ $<
107407 +$(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
107408 + $(call if_changed_dep,host-cshobjs)
107409 +
107410 +# Compile .c file, create position independent .o file
107411 +# host-cxxshobjs -> .o
107412 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
107413 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
107414 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
107415 + $(call if_changed_dep,host-cxxshobjs)
107416 +
107417 +# Link a shared library, based on position independent .o files
107418 +# *.o -> .so shared library (host-cshlib)
107419 +quiet_cmd_host-cshlib = HOSTLLD -shared $@
107420 + cmd_host-cshlib = $(HOSTCC) $(HOSTLDFLAGS) -shared -o $@ \
107421 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
107422 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
107423 +$(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
107424 + $(call if_changed,host-cshlib)
107425 +
107426 +# Link a shared library, based on position independent .o files
107427 +# *.o -> .so shared library (host-cxxshlib)
107428 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
107429 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
107430 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
107431 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
107432 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
107433 + $(call if_changed,host-cxxshlib)
107434 +
107435 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
107436 - $(host-cxxmulti) $(host-cxxobjs)
107437 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
107438 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
107439 index b304068..462d24e 100644
107440 --- a/scripts/basic/fixdep.c
107441 +++ b/scripts/basic/fixdep.c
107442 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
107443 /*
107444 * Lookup a value in the configuration string.
107445 */
107446 -static int is_defined_config(const char *name, int len, unsigned int hash)
107447 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
107448 {
107449 struct item *aux;
107450
107451 @@ -211,10 +211,10 @@ static void clear_config(void)
107452 /*
107453 * Record the use of a CONFIG_* word.
107454 */
107455 -static void use_config(const char *m, int slen)
107456 +static void use_config(const char *m, unsigned int slen)
107457 {
107458 unsigned int hash = strhash(m, slen);
107459 - int c, i;
107460 + unsigned int c, i;
107461
107462 if (is_defined_config(m, slen, hash))
107463 return;
107464 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
107465
107466 static void parse_config_file(const char *map, size_t len)
107467 {
107468 - const int *end = (const int *) (map + len);
107469 + const unsigned int *end = (const unsigned int *) (map + len);
107470 /* start at +1, so that p can never be < map */
107471 - const int *m = (const int *) map + 1;
107472 + const unsigned int *m = (const unsigned int *) map + 1;
107473 const char *p, *q;
107474
107475 for (; m < end; m++) {
107476 @@ -435,7 +435,7 @@ static void print_deps(void)
107477 static void traps(void)
107478 {
107479 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
107480 - int *p = (int *)test;
107481 + unsigned int *p = (unsigned int *)test;
107482
107483 if (*p != INT_CONF) {
107484 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianness? %#x\n",
107485 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
107486 new file mode 100644
107487 index 0000000..42018ed
107488 --- /dev/null
107489 +++ b/scripts/gcc-plugin.sh
107490 @@ -0,0 +1,51 @@
107491 +#!/bin/sh
107492 +srctree=$(dirname "$0")
107493 +gccplugins_dir=$($3 -print-file-name=plugin)
107494 +plugincc=$($1 -E - -o /dev/null -I${srctree}/../tools/gcc -I${gccplugins_dir}/include 2>&1 <<EOF
107495 +#include "gcc-common.h"
107496 +#if BUILDING_GCC_VERSION >= 4008 || defined(ENABLE_BUILD_WITH_CXX)
107497 +#warning $2 CXX
107498 +#else
107499 +#warning $1 CC
107500 +#endif
107501 +EOF
107502 +)
107503 +
107504 +if [ $? -ne 0 ]
107505 +then
107506 + exit 1
107507 +fi
107508 +
107509 +case "$plugincc" in
107510 + *"$1 CC"*)
107511 + echo "$1"
107512 + exit 0
107513 + ;;
107514 +
107515 + *"$2 CXX"*)
107516 + # the c++ compiler needs another test, see below
107517 + ;;
107518 +
107519 + *)
107520 + exit 1
107521 + ;;
107522 +esac
107523 +
107524 +# we need a c++ compiler that supports the designated initializer GNU extension
107525 +plugincc=$($2 -c -x c++ -std=gnu++98 - -fsyntax-only -I${srctree}/../tools/gcc -I${gccplugins_dir}/include 2>&1 <<EOF
107526 +#include "gcc-common.h"
107527 +class test {
107528 +public:
107529 + int test;
107530 +} test = {
107531 + .test = 1
107532 +};
107533 +EOF
107534 +)
107535 +
107536 +if [ $? -eq 0 ]
107537 +then
107538 + echo "$2"
107539 + exit 0
107540 +fi
107541 +exit 1
107542 diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh
107543 index 5de5660..d3deb89 100644
107544 --- a/scripts/headers_install.sh
107545 +++ b/scripts/headers_install.sh
107546 @@ -32,6 +32,7 @@ do
107547 FILE="$(basename "$i")"
107548 sed -r \
107549 -e 's/([ \t(])(__user|__force|__iomem)[ \t]/\1/g' \
107550 + -e 's/__intentional_overflow\([- \t,0-9]*\)//g' \
107551 -e 's/__attribute_const__([ \t]|$)/\1/g' \
107552 -e 's@^#include <linux/compiler.h>@@' \
107553 -e 's/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g' \
107554 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
107555 index 86a4fe7..99e91f9 100644
107556 --- a/scripts/link-vmlinux.sh
107557 +++ b/scripts/link-vmlinux.sh
107558 @@ -166,7 +166,7 @@ else
107559 fi;
107560
107561 # final build of init/
107562 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
107563 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
107564
107565 kallsymso=""
107566 kallsyms_vmlinux=""
107567 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
107568 index e614ef6..d9d2b01 100644
107569 --- a/scripts/mod/file2alias.c
107570 +++ b/scripts/mod/file2alias.c
107571 @@ -142,7 +142,7 @@ static void device_id_check(const char *modname, const char *device_id,
107572 unsigned long size, unsigned long id_size,
107573 void *symval)
107574 {
107575 - int i;
107576 + unsigned int i;
107577
107578 if (size % id_size || size < id_size) {
107579 fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
107580 @@ -171,7 +171,7 @@ static void device_id_check(const char *modname, const char *device_id,
107581 /* USB is special because the bcdDevice can be matched against a numeric range */
107582 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
107583 static void do_usb_entry(void *symval,
107584 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
107585 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
107586 unsigned char range_lo, unsigned char range_hi,
107587 unsigned char max, struct module *mod)
107588 {
107589 @@ -281,7 +281,7 @@ static void do_usb_entry_multi(void *symval, struct module *mod)
107590 {
107591 unsigned int devlo, devhi;
107592 unsigned char chi, clo, max;
107593 - int ndigits;
107594 + unsigned int ndigits;
107595
107596 DEF_FIELD(symval, usb_device_id, match_flags);
107597 DEF_FIELD(symval, usb_device_id, idVendor);
107598 @@ -534,7 +534,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
107599 for (i = 0; i < count; i++) {
107600 DEF_FIELD_ADDR(symval + i*id_size, pnp_device_id, id);
107601 char acpi_id[sizeof(*id)];
107602 - int j;
107603 + unsigned int j;
107604
107605 buf_printf(&mod->dev_table_buf,
107606 "MODULE_ALIAS(\"pnp:d%s*\");\n", *id);
107607 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
107608
107609 for (j = 0; j < PNP_MAX_DEVICES; j++) {
107610 const char *id = (char *)(*devs)[j].id;
107611 - int i2, j2;
107612 + unsigned int i2, j2;
107613 int dup = 0;
107614
107615 if (!id[0])
107616 @@ -589,7 +589,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
107617 /* add an individual alias for every device entry */
107618 if (!dup) {
107619 char acpi_id[PNP_ID_LEN];
107620 - int k;
107621 + unsigned int k;
107622
107623 buf_printf(&mod->dev_table_buf,
107624 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
107625 @@ -939,7 +939,7 @@ static void dmi_ascii_filter(char *d, const char *s)
107626 static int do_dmi_entry(const char *filename, void *symval,
107627 char *alias)
107628 {
107629 - int i, j;
107630 + unsigned int i, j;
107631 DEF_FIELD_ADDR(symval, dmi_system_id, matches);
107632 sprintf(alias, "dmi*");
107633
107634 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
107635 index 091d905..77b88c7 100644
107636 --- a/scripts/mod/modpost.c
107637 +++ b/scripts/mod/modpost.c
107638 @@ -920,6 +920,7 @@ enum mismatch {
107639 ANY_INIT_TO_ANY_EXIT,
107640 ANY_EXIT_TO_ANY_INIT,
107641 EXPORT_TO_INIT_EXIT,
107642 + DATA_TO_TEXT
107643 };
107644
107645 struct sectioncheck {
107646 @@ -1006,6 +1007,12 @@ const struct sectioncheck sectioncheck[] = {
107647 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
107648 .mismatch = EXPORT_TO_INIT_EXIT,
107649 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
107650 +},
107651 +/* Do not reference code from writable data */
107652 +{
107653 + .fromsec = { DATA_SECTIONS, NULL },
107654 + .tosec = { TEXT_SECTIONS, NULL },
107655 + .mismatch = DATA_TO_TEXT
107656 }
107657 };
107658
107659 @@ -1126,10 +1133,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
107660 continue;
107661 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
107662 continue;
107663 - if (sym->st_value == addr)
107664 - return sym;
107665 /* Find a symbol nearby - addr are maybe negative */
107666 d = sym->st_value - addr;
107667 + if (d == 0)
107668 + return sym;
107669 if (d < 0)
107670 d = addr - sym->st_value;
107671 if (d < distance) {
107672 @@ -1407,6 +1414,14 @@ static void report_sec_mismatch(const char *modname,
107673 tosym, prl_to, prl_to, tosym);
107674 free(prl_to);
107675 break;
107676 + case DATA_TO_TEXT:
107677 +#if 0
107678 + fprintf(stderr,
107679 + "The %s %s:%s references\n"
107680 + "the %s %s:%s%s\n",
107681 + from, fromsec, fromsym, to, tosec, tosym, to_p);
107682 +#endif
107683 + break;
107684 }
107685 fprintf(stderr, "\n");
107686 }
107687 @@ -1658,7 +1673,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
107688 static void check_sec_ref(struct module *mod, const char *modname,
107689 struct elf_info *elf)
107690 {
107691 - int i;
107692 + unsigned int i;
107693 Elf_Shdr *sechdrs = elf->sechdrs;
107694
107695 /* Walk through all sections */
107696 @@ -1789,7 +1804,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
107697 va_end(ap);
107698 }
107699
107700 -void buf_write(struct buffer *buf, const char *s, int len)
107701 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
107702 {
107703 if (buf->size - buf->pos < len) {
107704 buf->size += len + SZ;
107705 @@ -2008,7 +2023,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
107706 if (fstat(fileno(file), &st) < 0)
107707 goto close_write;
107708
107709 - if (st.st_size != b->pos)
107710 + if (st.st_size != (off_t)b->pos)
107711 goto close_write;
107712
107713 tmp = NOFAIL(malloc(b->pos));
107714 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
107715 index 168b43d..77914bf 100644
107716 --- a/scripts/mod/modpost.h
107717 +++ b/scripts/mod/modpost.h
107718 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
107719
107720 struct buffer {
107721 char *p;
107722 - int pos;
107723 - int size;
107724 + unsigned int pos;
107725 + unsigned int size;
107726 };
107727
107728 void __attribute__((format(printf, 2, 3)))
107729 buf_printf(struct buffer *buf, const char *fmt, ...);
107730
107731 void
107732 -buf_write(struct buffer *buf, const char *s, int len);
107733 +buf_write(struct buffer *buf, const char *s, unsigned int len);
107734
107735 struct module {
107736 struct module *next;
107737 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
107738 index 944418d..15291e4 100644
107739 --- a/scripts/mod/sumversion.c
107740 +++ b/scripts/mod/sumversion.c
107741 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
107742 goto out;
107743 }
107744
107745 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
107746 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
107747 warn("writing sum in %s failed: %s\n",
107748 filename, strerror(errno));
107749 goto out;
107750 diff --git a/scripts/module-common.lds b/scripts/module-common.lds
107751 index 0865b3e..7235dd4 100644
107752 --- a/scripts/module-common.lds
107753 +++ b/scripts/module-common.lds
107754 @@ -6,6 +6,10 @@
107755 SECTIONS {
107756 /DISCARD/ : { *(.discard) }
107757
107758 + .rodata : {
107759 + *(.rodata) *(.rodata.*)
107760 + *(.data..read_only)
107761 + }
107762 __ksymtab : { *(SORT(___ksymtab+*)) }
107763 __ksymtab_gpl : { *(SORT(___ksymtab_gpl+*)) }
107764 __ksymtab_unused : { *(SORT(___ksymtab_unused+*)) }
107765 diff --git a/scripts/package/Makefile b/scripts/package/Makefile
107766 index 99ca6e7..3a1a1a1 100644
107767 --- a/scripts/package/Makefile
107768 +++ b/scripts/package/Makefile
107769 @@ -46,7 +46,7 @@ rpm-pkg rpm: FORCE
107770 ln -sf $(srctree) $(KERNELPATH)
107771 $(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec
107772 $(CONFIG_SHELL) $(srctree)/scripts/setlocalversion --save-scmversion
107773 - tar -cz $(RCS_TAR_IGNORE) -f $(KERNELPATH).tar.gz $(TAR_CONTENT)
107774 + tar --owner=root --group=root -cz $(RCS_TAR_IGNORE) -f $(KERNELPATH).tar.gz $(TAR_CONTENT)
107775 rm $(KERNELPATH)
107776 rm -f $(objtree)/.scmversion
107777 $(CONFIG_SHELL) $(srctree)/scripts/mkversion > $(objtree)/.tmp_version
107778 diff --git a/scripts/package/builddeb b/scripts/package/builddeb
107779 index 7c0e6e4..bf2c90e 100644
107780 --- a/scripts/package/builddeb
107781 +++ b/scripts/package/builddeb
107782 @@ -293,6 +293,7 @@ fi
107783 (cd $srctree; find arch/$SRCARCH -name module.lds -o -name Kbuild.platforms -o -name Platform) >> "$objtree/debian/hdrsrcfiles"
107784 (cd $srctree; find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f) >> "$objtree/debian/hdrsrcfiles"
107785 (cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f) >> "$objtree/debian/hdrobjfiles"
107786 +(cd $objtree; find tools/gcc -name \*.so >> "$objtree/debian/hdrobjfiles")
107787 destdir=$kernel_headers_dir/usr/src/linux-headers-$version
107788 mkdir -p "$destdir"
107789 (cd $srctree; tar -c -f - -T -) < "$objtree/debian/hdrsrcfiles" | (cd $destdir; tar -xf -)
107790 diff --git a/scripts/package/mkspec b/scripts/package/mkspec
107791 index 1395760..6ceef68 100755
107792 --- a/scripts/package/mkspec
107793 +++ b/scripts/package/mkspec
107794 @@ -121,14 +121,27 @@ echo 'rm -f $RPM_BUILD_ROOT'"/lib/modules/$KERNELRELEASE/{build,source}"
107795 echo "mkdir -p "'$RPM_BUILD_ROOT'"/usr/src/kernels/$KERNELRELEASE"
107796 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\""
107797 echo "tar "'$EXCLUDES'" -cf- . | (cd "'$RPM_BUILD_ROOT'"/usr/src/kernels/$KERNELRELEASE;tar xvf -)"
107798 -echo 'cd $RPM_BUILD_ROOT'"/lib/modules/$KERNELRELEASE"
107799 -echo "ln -sf /usr/src/kernels/$KERNELRELEASE build"
107800 -echo "ln -sf /usr/src/kernels/$KERNELRELEASE source"
107801
107802 echo ""
107803 echo "%clean"
107804 echo 'rm -rf $RPM_BUILD_ROOT'
107805 echo ""
107806 +echo "%pre"
107807 +echo 'chmod -f 0500 /boot'
107808 +echo 'if [ -d /lib/modules ]; then'
107809 +echo 'chmod -f 0500 /lib/modules'
107810 +echo 'fi'
107811 +echo 'if [ -d /lib32/modules ]; then'
107812 +echo 'chmod -f 0500 /lib32/modules'
107813 +echo 'fi'
107814 +echo 'if [ -d /lib64/modules ]; then'
107815 +echo 'chmod -f 0500 /lib64/modules'
107816 +echo 'fi'
107817 +echo ""
107818 +echo "%post devel"
107819 +echo "ln -sf /usr/src/kernels/$KERNELRELEASE /lib/modules/$KERNELRELEASE/build"
107820 +echo "ln -sf /usr/src/kernels/$KERNELRELEASE /lib/modules/$KERNELRELEASE/source"
107821 +echo ""
107822 echo "%post"
107823 echo "if [ -x /sbin/installkernel -a -r /boot/vmlinuz-$KERNELRELEASE -a -r /boot/System.map-$KERNELRELEASE ]; then"
107824 echo "cp /boot/vmlinuz-$KERNELRELEASE /boot/vmlinuz-$KERNELRELEASE-rpm"
107825 @@ -139,11 +152,11 @@ echo "rm -f /boot/vmlinuz-$KERNELRELEASE-rpm /boot/System.map-$KERNELRELEASE-rpm
107826 echo "fi"
107827 echo ""
107828 echo "%files"
107829 -echo '%defattr (-, root, root)'
107830 +echo '%defattr (400, root, root, 500)'
107831 echo "%dir /lib/modules"
107832 -echo "/lib/modules/$KERNELRELEASE"
107833 echo "%exclude /lib/modules/$KERNELRELEASE/build"
107834 echo "%exclude /lib/modules/$KERNELRELEASE/source"
107835 +echo "/lib/modules/$KERNELRELEASE"
107836 echo "/lib/firmware/$KERNELRELEASE"
107837 echo "/boot/*"
107838 echo ""
107839 @@ -152,8 +165,7 @@ echo '%defattr (-, root, root)'
107840 echo "/usr/include"
107841 echo ""
107842 echo "%files devel"
107843 -echo '%defattr (-, root, root)'
107844 +echo '%defattr (400, root, root, 500)'
107845 +echo "%dir /lib/modules/$KERNELRELEASE"
107846 echo "/usr/src/kernels/$KERNELRELEASE"
107847 -echo "/lib/modules/$KERNELRELEASE/build"
107848 -echo "/lib/modules/$KERNELRELEASE/source"
107849 echo ""
107850 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
107851 index 4718d78..9220d58 100644
107852 --- a/scripts/pnmtologo.c
107853 +++ b/scripts/pnmtologo.c
107854 @@ -244,14 +244,14 @@ static void write_header(void)
107855 fprintf(out, " * Linux logo %s\n", logoname);
107856 fputs(" */\n\n", out);
107857 fputs("#include <linux/linux_logo.h>\n\n", out);
107858 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
107859 + fprintf(out, "static unsigned char %s_data[] = {\n",
107860 logoname);
107861 }
107862
107863 static void write_footer(void)
107864 {
107865 fputs("\n};\n\n", out);
107866 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
107867 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
107868 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
107869 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
107870 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
107871 @@ -381,7 +381,7 @@ static void write_logo_clut224(void)
107872 fputs("\n};\n\n", out);
107873
107874 /* write logo clut */
107875 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
107876 + fprintf(out, "static unsigned char %s_clut[] = {\n",
107877 logoname);
107878 write_hex_cnt = 0;
107879 for (i = 0; i < logo_clutsize; i++) {
107880 diff --git a/scripts/sortextable.h b/scripts/sortextable.h
107881 index 8fac3fd..32ff38d 100644
107882 --- a/scripts/sortextable.h
107883 +++ b/scripts/sortextable.h
107884 @@ -108,9 +108,9 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
107885 const char *secstrtab;
107886 const char *strtab;
107887 char *extab_image;
107888 - int extab_index = 0;
107889 - int i;
107890 - int idx;
107891 + unsigned int extab_index = 0;
107892 + unsigned int i;
107893 + unsigned int idx;
107894 unsigned int num_sections;
107895 unsigned int secindex_strings;
107896
107897 diff --git a/scripts/tags.sh b/scripts/tags.sh
107898 index 293828b..9fbe696 100755
107899 --- a/scripts/tags.sh
107900 +++ b/scripts/tags.sh
107901 @@ -26,7 +26,7 @@ else
107902 fi
107903
107904 # ignore userspace tools
107905 -ignore="$ignore ( -path ${tree}tools ) -prune -o"
107906 +ignore="$ignore ( -path \"${tree}tools/[^g]*\" ) -prune -o"
107907
107908 # Find all available archs
107909 find_all_archs()
107910 diff --git a/security/Kconfig b/security/Kconfig
107911 index beb86b5..1a953b1 100644
107912 --- a/security/Kconfig
107913 +++ b/security/Kconfig
107914 @@ -4,6 +4,974 @@
107915
107916 menu "Security options"
107917
107918 +menu "Grsecurity"
107919 +
107920 + config ARCH_TRACK_EXEC_LIMIT
107921 + bool
107922 +
107923 + config PAX_KERNEXEC_PLUGIN
107924 + bool
107925 +
107926 + config PAX_PER_CPU_PGD
107927 + bool
107928 +
107929 + config TASK_SIZE_MAX_SHIFT
107930 + int
107931 + depends on X86_64
107932 + default 47 if !PAX_PER_CPU_PGD
107933 + default 42 if PAX_PER_CPU_PGD
107934 +
107935 + config PAX_ENABLE_PAE
107936 + bool
107937 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
107938 +
107939 + config PAX_USERCOPY_SLABS
107940 + bool
107941 +
107942 +config GRKERNSEC
107943 + bool "Grsecurity"
107944 + select CRYPTO
107945 + select CRYPTO_SHA256
107946 + select PROC_FS
107947 + select STOP_MACHINE
107948 + select TTY
107949 + select DEBUG_KERNEL
107950 + select DEBUG_LIST
107951 + help
107952 + If you say Y here, you will be able to configure many features
107953 + that will enhance the security of your system. It is highly
107954 + recommended that you say Y here and read through the help
107955 + for each option so that you fully understand the features and
107956 + can evaluate their usefulness for your machine.
107957 +
107958 +choice
107959 + prompt "Configuration Method"
107960 + depends on GRKERNSEC
107961 + default GRKERNSEC_CONFIG_CUSTOM
107962 + help
107963 +
107964 +config GRKERNSEC_CONFIG_AUTO
107965 + bool "Automatic"
107966 + help
107967 + If you choose this configuration method, you'll be able to answer a small
107968 + number of simple questions about how you plan to use this kernel.
107969 + The settings of grsecurity and PaX will be automatically configured for
107970 + the highest commonly-used settings within the provided constraints.
107971 +
107972 + If you require additional configuration, custom changes can still be made
107973 + from the "custom configuration" menu.
107974 +
107975 +config GRKERNSEC_CONFIG_CUSTOM
107976 + bool "Custom"
107977 + help
107978 + If you choose this configuration method, you'll be able to configure all
107979 + grsecurity and PaX settings manually. Via this method, no options are
107980 + automatically enabled.
107981 +
107982 +endchoice
107983 +
107984 +choice
107985 + prompt "Usage Type"
107986 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
107987 + default GRKERNSEC_CONFIG_SERVER
107988 + help
107989 +
107990 +config GRKERNSEC_CONFIG_SERVER
107991 + bool "Server"
107992 + help
107993 + Choose this option if you plan to use this kernel on a server.
107994 +
107995 +config GRKERNSEC_CONFIG_DESKTOP
107996 + bool "Desktop"
107997 + help
107998 + Choose this option if you plan to use this kernel on a desktop.
107999 +
108000 +endchoice
108001 +
108002 +choice
108003 + prompt "Virtualization Type"
108004 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
108005 + default GRKERNSEC_CONFIG_VIRT_NONE
108006 + help
108007 +
108008 +config GRKERNSEC_CONFIG_VIRT_NONE
108009 + bool "None"
108010 + help
108011 + Choose this option if this kernel will be run on bare metal.
108012 +
108013 +config GRKERNSEC_CONFIG_VIRT_GUEST
108014 + bool "Guest"
108015 + help
108016 + Choose this option if this kernel will be run as a VM guest.
108017 +
108018 +config GRKERNSEC_CONFIG_VIRT_HOST
108019 + bool "Host"
108020 + help
108021 + Choose this option if this kernel will be run as a VM host.
108022 +
108023 +endchoice
108024 +
108025 +choice
108026 + prompt "Virtualization Hardware"
108027 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
108028 + help
108029 +
108030 +config GRKERNSEC_CONFIG_VIRT_EPT
108031 + bool "EPT/RVI Processor Support"
108032 + depends on X86
108033 + help
108034 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
108035 + hardware virtualization. This allows for additional kernel hardening protections
108036 + to operate without additional performance impact.
108037 +
108038 + To see if your Intel processor supports EPT, see:
108039 + http://ark.intel.com/Products/VirtualizationTechnology
108040 + (Most Core i3/5/7 support EPT)
108041 +
108042 + To see if your AMD processor supports RVI, see:
108043 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
108044 +
108045 +config GRKERNSEC_CONFIG_VIRT_SOFT
108046 + bool "First-gen/No Hardware Virtualization"
108047 + help
108048 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
108049 + support hardware virtualization or doesn't support the EPT/RVI extensions.
108050 +
108051 +endchoice
108052 +
108053 +choice
108054 + prompt "Virtualization Software"
108055 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
108056 + help
108057 +
108058 +config GRKERNSEC_CONFIG_VIRT_XEN
108059 + bool "Xen"
108060 + help
108061 + Choose this option if this kernel is running as a Xen guest or host.
108062 +
108063 +config GRKERNSEC_CONFIG_VIRT_VMWARE
108064 + bool "VMWare"
108065 + help
108066 + Choose this option if this kernel is running as a VMWare guest or host.
108067 +
108068 +config GRKERNSEC_CONFIG_VIRT_KVM
108069 + bool "KVM"
108070 + help
108071 + Choose this option if this kernel is running as a KVM guest or host.
108072 +
108073 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
108074 + bool "VirtualBox"
108075 + help
108076 + Choose this option if this kernel is running as a VirtualBox guest or host.
108077 +
108078 +config GRKERNSEC_CONFIG_VIRT_HYPERV
108079 + bool "Hyper-V"
108080 + help
108081 + Choose this option if this kernel is running as a Hyper-V guest.
108082 +
108083 +endchoice
108084 +
108085 +choice
108086 + prompt "Required Priorities"
108087 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
108088 + default GRKERNSEC_CONFIG_PRIORITY_PERF
108089 + help
108090 +
108091 +config GRKERNSEC_CONFIG_PRIORITY_PERF
108092 + bool "Performance"
108093 + help
108094 + Choose this option if performance is of highest priority for this deployment
108095 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
108096 + clearing of structures intended for userland, and freed memory sanitizing will
108097 + be disabled.
108098 +
108099 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
108100 + bool "Security"
108101 + help
108102 + Choose this option if security is of highest priority for this deployment of
108103 + grsecurity. UDEREF, kernel stack clearing, clearing of structures intended
108104 + for userland, and freed memory sanitizing will be enabled for this kernel.
108105 + In a worst-case scenario, these features can introduce a 20% performance hit
108106 + (UDEREF on x64 contributing half of this hit).
108107 +
108108 +endchoice
108109 +
108110 +menu "Default Special Groups"
108111 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
108112 +
108113 +config GRKERNSEC_PROC_GID
108114 + int "GID exempted from /proc restrictions"
108115 + default 1001
108116 + help
108117 + Setting this GID determines which group will be exempted from
108118 + grsecurity's /proc restrictions, allowing users of the specified
108119 + group to view network statistics and the existence of other users'
108120 + processes on the system. This GID may also be chosen at boot time
108121 + via "grsec_proc_gid=" on the kernel commandline.
108122 +
108123 +config GRKERNSEC_TPE_UNTRUSTED_GID
108124 + int "GID for TPE-untrusted users"
108125 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
108126 + default 1005
108127 + help
108128 + Setting this GID determines which group untrusted users should
108129 + be added to. These users will be placed under grsecurity's Trusted Path
108130 + Execution mechanism, preventing them from executing their own binaries.
108131 + The users will only be able to execute binaries in directories owned and
108132 + writable only by the root user. If the sysctl option is enabled, a sysctl
108133 + option with name "tpe_gid" is created.
108134 +
108135 +config GRKERNSEC_TPE_TRUSTED_GID
108136 + int "GID for TPE-trusted users"
108137 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
108138 + default 1005
108139 + help
108140 + Setting this GID determines what group TPE restrictions will be
108141 + *disabled* for. If the sysctl option is enabled, a sysctl option
108142 + with name "tpe_gid" is created.
108143 +
108144 +config GRKERNSEC_SYMLINKOWN_GID
108145 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
108146 + depends on GRKERNSEC_CONFIG_SERVER
108147 + default 1006
108148 + help
108149 + Setting this GID determines what group kernel-enforced
108150 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
108151 + is enabled, a sysctl option with name "symlinkown_gid" is created.
108152 +
108153 +
108154 +endmenu
108155 +
108156 +menu "Customize Configuration"
108157 +depends on GRKERNSEC
108158 +
108159 +menu "PaX"
108160 +
108161 +config PAX
108162 + bool "Enable various PaX features"
108163 + default y if GRKERNSEC_CONFIG_AUTO
108164 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
108165 + help
108166 + This allows you to enable various PaX features. PaX adds
108167 + intrusion prevention mechanisms to the kernel that reduce
108168 + the risks posed by exploitable memory corruption bugs.
108169 +
108170 +menu "PaX Control"
108171 + depends on PAX
108172 +
108173 +config PAX_SOFTMODE
108174 + bool 'Support soft mode'
108175 + help
108176 + Enabling this option will allow you to run PaX in soft mode, that
108177 + is, PaX features will not be enforced by default, only on executables
108178 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
108179 + support as they are the only way to mark executables for soft mode use.
108180 +
108181 + Soft mode can be activated by using the "pax_softmode=1" kernel command
108182 + line option on boot. Furthermore you can control various PaX features
108183 + at runtime via the entries in /proc/sys/kernel/pax.
108184 +
108185 +config PAX_EI_PAX
108186 + bool 'Use legacy ELF header marking'
108187 + default y if GRKERNSEC_CONFIG_AUTO
108188 + help
108189 + Enabling this option will allow you to control PaX features on
108190 + a per executable basis via the 'chpax' utility available at
108191 + http://pax.grsecurity.net/. The control flags will be read from
108192 + an otherwise reserved part of the ELF header. This marking has
108193 + numerous drawbacks (no support for soft-mode, toolchain does not
108194 + know about the non-standard use of the ELF header) therefore it
108195 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
108196 + support.
108197 +
108198 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
108199 + support as well, they will override the legacy EI_PAX marks.
108200 +
108201 + If you enable none of the marking options then all applications
108202 + will run with PaX enabled on them by default.
108203 +
108204 +config PAX_PT_PAX_FLAGS
108205 + bool 'Use ELF program header marking'
108206 + default y if GRKERNSEC_CONFIG_AUTO
108207 + help
108208 + Enabling this option will allow you to control PaX features on
108209 + a per executable basis via the 'paxctl' utility available at
108210 + http://pax.grsecurity.net/. The control flags will be read from
108211 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
108212 + has the benefits of supporting both soft mode and being fully
108213 + integrated into the toolchain (the binutils patch is available
108214 + from http://pax.grsecurity.net).
108215 +
108216 + Note that if you enable the legacy EI_PAX marking support as well,
108217 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
108218 +
108219 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
108220 + must make sure that the marks are the same if a binary has both marks.
108221 +
108222 + If you enable none of the marking options then all applications
108223 + will run with PaX enabled on them by default.
108224 +
108225 +config PAX_XATTR_PAX_FLAGS
108226 + bool 'Use filesystem extended attributes marking'
108227 + default y if GRKERNSEC_CONFIG_AUTO
108228 + select CIFS_XATTR if CIFS
108229 + select F2FS_FS_XATTR if F2FS_FS
108230 + select EXT2_FS_XATTR if EXT2_FS
108231 + select EXT3_FS_XATTR if EXT3_FS
108232 + select JFFS2_FS_XATTR if JFFS2_FS
108233 + select REISERFS_FS_XATTR if REISERFS_FS
108234 + select SQUASHFS_XATTR if SQUASHFS
108235 + select TMPFS_XATTR if TMPFS
108236 + help
108237 + Enabling this option will allow you to control PaX features on
108238 + a per executable basis via the 'setfattr' utility. The control
108239 + flags will be read from the user.pax.flags extended attribute of
108240 + the file. This marking has the benefit of supporting binary-only
108241 + applications that self-check themselves (e.g., skype) and would
108242 + not tolerate chpax/paxctl changes. The main drawback is that
108243 + extended attributes are not supported by some filesystems (e.g.,
108244 + isofs, udf, vfat) so copying files through such filesystems will
108245 + lose the extended attributes and these PaX markings.
108246 +
108247 + Note that if you enable the legacy EI_PAX marking support as well,
108248 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
108249 +
108250 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
108251 + must make sure that the marks are the same if a binary has both marks.
108252 +
108253 + If you enable none of the marking options then all applications
108254 + will run with PaX enabled on them by default.
108255 +
108256 +choice
108257 + prompt 'MAC system integration'
108258 + default PAX_HAVE_ACL_FLAGS
108259 + help
108260 + Mandatory Access Control systems have the option of controlling
108261 + PaX flags on a per executable basis, choose the method supported
108262 + by your particular system.
108263 +
108264 + - "none": if your MAC system does not interact with PaX,
108265 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
108266 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
108267 +
108268 + NOTE: this option is for developers/integrators only.
108269 +
108270 + config PAX_NO_ACL_FLAGS
108271 + bool 'none'
108272 +
108273 + config PAX_HAVE_ACL_FLAGS
108274 + bool 'direct'
108275 +
108276 + config PAX_HOOK_ACL_FLAGS
108277 + bool 'hook'
108278 +endchoice
108279 +
108280 +endmenu
108281 +
108282 +menu "Non-executable pages"
108283 + depends on PAX
108284 +
108285 +config PAX_NOEXEC
108286 + bool "Enforce non-executable pages"
108287 + default y if GRKERNSEC_CONFIG_AUTO
108288 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
108289 + help
108290 + By design some architectures do not allow for protecting memory
108291 + pages against execution or even if they do, Linux does not make
108292 + use of this feature. In practice this means that if a page is
108293 + readable (such as the stack or heap) it is also executable.
108294 +
108295 + There is a well known exploit technique that makes use of this
108296 + fact and a common programming mistake where an attacker can
108297 + introduce code of his choice somewhere in the attacked program's
108298 + memory (typically the stack or the heap) and then execute it.
108299 +
108300 + If the attacked program was running with different (typically
108301 + higher) privileges than that of the attacker, then he can elevate
108302 + his own privilege level (e.g. get a root shell, write to files for
108303 + which he does not have write access to, etc).
108304 +
108305 + Enabling this option will let you choose from various features
108306 + that prevent the injection and execution of 'foreign' code in
108307 + a program.
108308 +
108309 + This will also break programs that rely on the old behaviour and
108310 + expect that dynamically allocated memory via the malloc() family
108311 + of functions is executable (which it is not). Notable examples
108312 + are the XFree86 4.x server, the java runtime and wine.
108313 +
108314 +config PAX_PAGEEXEC
108315 + bool "Paging based non-executable pages"
108316 + default y if GRKERNSEC_CONFIG_AUTO
108317 + 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)
108318 + select ARCH_TRACK_EXEC_LIMIT if X86_32
108319 + help
108320 + This implementation is based on the paging feature of the CPU.
108321 + On i386 without hardware non-executable bit support there is a
108322 + variable but usually low performance impact, however on Intel's
108323 + P4 core based CPUs it is very high so you should not enable this
108324 + for kernels meant to be used on such CPUs.
108325 +
108326 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
108327 + with hardware non-executable bit support there is no performance
108328 + impact, on ppc the impact is negligible.
108329 +
108330 + Note that several architectures require various emulations due to
108331 + badly designed userland ABIs, this will cause a performance impact
108332 + but will disappear as soon as userland is fixed. For example, ppc
108333 + userland MUST have been built with secure-plt by a recent toolchain.
108334 +
108335 +config PAX_SEGMEXEC
108336 + bool "Segmentation based non-executable pages"
108337 + default y if GRKERNSEC_CONFIG_AUTO
108338 + depends on PAX_NOEXEC && X86_32
108339 + help
108340 + This implementation is based on the segmentation feature of the
108341 + CPU and has a very small performance impact, however applications
108342 + will be limited to a 1.5 GB address space instead of the normal
108343 + 3 GB.
108344 +
108345 +config PAX_EMUTRAMP
108346 + bool "Emulate trampolines"
108347 + default y if PARISC || GRKERNSEC_CONFIG_AUTO
108348 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
108349 + help
108350 + There are some programs and libraries that for one reason or
108351 + another attempt to execute special small code snippets from
108352 + non-executable memory pages. Most notable examples are the
108353 + signal handler return code generated by the kernel itself and
108354 + the GCC trampolines.
108355 +
108356 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
108357 + such programs will no longer work under your kernel.
108358 +
108359 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
108360 + utilities to enable trampoline emulation for the affected programs
108361 + yet still have the protection provided by the non-executable pages.
108362 +
108363 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
108364 + your system will not even boot.
108365 +
108366 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
108367 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
108368 + for the affected files.
108369 +
108370 + NOTE: enabling this feature *may* open up a loophole in the
108371 + protection provided by non-executable pages that an attacker
108372 + could abuse. Therefore the best solution is to not have any
108373 + files on your system that would require this option. This can
108374 + be achieved by not using libc5 (which relies on the kernel
108375 + signal handler return code) and not using or rewriting programs
108376 + that make use of the nested function implementation of GCC.
108377 + Skilled users can just fix GCC itself so that it implements
108378 + nested function calls in a way that does not interfere with PaX.
108379 +
108380 +config PAX_EMUSIGRT
108381 + bool "Automatically emulate sigreturn trampolines"
108382 + depends on PAX_EMUTRAMP && PARISC
108383 + default y
108384 + help
108385 + Enabling this option will have the kernel automatically detect
108386 + and emulate signal return trampolines executing on the stack
108387 + that would otherwise lead to task termination.
108388 +
108389 + This solution is intended as a temporary one for users with
108390 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
108391 + Modula-3 runtime, etc) or executables linked to such, basically
108392 + everything that does not specify its own SA_RESTORER function in
108393 + normal executable memory like glibc 2.1+ does.
108394 +
108395 + On parisc you MUST enable this option, otherwise your system will
108396 + not even boot.
108397 +
108398 + NOTE: this feature cannot be disabled on a per executable basis
108399 + and since it *does* open up a loophole in the protection provided
108400 + by non-executable pages, the best solution is to not have any
108401 + files on your system that would require this option.
108402 +
108403 +config PAX_MPROTECT
108404 + bool "Restrict mprotect()"
108405 + default y if GRKERNSEC_CONFIG_AUTO
108406 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
108407 + help
108408 + Enabling this option will prevent programs from
108409 + - changing the executable status of memory pages that were
108410 + not originally created as executable,
108411 + - making read-only executable pages writable again,
108412 + - creating executable pages from anonymous memory,
108413 + - making read-only-after-relocations (RELRO) data pages writable again.
108414 +
108415 + You should say Y here to complete the protection provided by
108416 + the enforcement of non-executable pages.
108417 +
108418 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
108419 + this feature on a per file basis.
108420 +
108421 +config PAX_MPROTECT_COMPAT
108422 + bool "Use legacy/compat protection demoting (read help)"
108423 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
108424 + depends on PAX_MPROTECT
108425 + help
108426 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
108427 + by sending the proper error code to the application. For some broken
108428 + userland, this can cause problems with Python or other applications. The
108429 + current implementation however allows for applications like clamav to
108430 + detect if JIT compilation/execution is allowed and to fall back gracefully
108431 + to an interpreter-based mode if it does not. While we encourage everyone
108432 + to use the current implementation as-is and push upstream to fix broken
108433 + userland (note that the RWX logging option can assist with this), in some
108434 + environments this may not be possible. Having to disable MPROTECT
108435 + completely on certain binaries reduces the security benefit of PaX,
108436 + so this option is provided for those environments to revert to the old
108437 + behavior.
108438 +
108439 +config PAX_ELFRELOCS
108440 + bool "Allow ELF text relocations (read help)"
108441 + depends on PAX_MPROTECT
108442 + default n
108443 + help
108444 + Non-executable pages and mprotect() restrictions are effective
108445 + in preventing the introduction of new executable code into an
108446 + attacked task's address space. There remain only two venues
108447 + for this kind of attack: if the attacker can execute already
108448 + existing code in the attacked task then he can either have it
108449 + create and mmap() a file containing his code or have it mmap()
108450 + an already existing ELF library that does not have position
108451 + independent code in it and use mprotect() on it to make it
108452 + writable and copy his code there. While protecting against
108453 + the former approach is beyond PaX, the latter can be prevented
108454 + by having only PIC ELF libraries on one's system (which do not
108455 + need to relocate their code). If you are sure this is your case,
108456 + as is the case with all modern Linux distributions, then leave
108457 + this option disabled. You should say 'n' here.
108458 +
108459 +config PAX_ETEXECRELOCS
108460 + bool "Allow ELF ET_EXEC text relocations"
108461 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
108462 + select PAX_ELFRELOCS
108463 + default y
108464 + help
108465 + On some architectures there are incorrectly created applications
108466 + that require text relocations and would not work without enabling
108467 + this option. If you are an alpha, ia64 or parisc user, you should
108468 + enable this option and disable it once you have made sure that
108469 + none of your applications need it.
108470 +
108471 +config PAX_EMUPLT
108472 + bool "Automatically emulate ELF PLT"
108473 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
108474 + default y
108475 + help
108476 + Enabling this option will have the kernel automatically detect
108477 + and emulate the Procedure Linkage Table entries in ELF files.
108478 + On some architectures such entries are in writable memory, and
108479 + become non-executable leading to task termination. Therefore
108480 + it is mandatory that you enable this option on alpha, parisc,
108481 + sparc and sparc64, otherwise your system would not even boot.
108482 +
108483 + NOTE: this feature *does* open up a loophole in the protection
108484 + provided by the non-executable pages, therefore the proper
108485 + solution is to modify the toolchain to produce a PLT that does
108486 + not need to be writable.
108487 +
108488 +config PAX_DLRESOLVE
108489 + bool 'Emulate old glibc resolver stub'
108490 + depends on PAX_EMUPLT && SPARC
108491 + default n
108492 + help
108493 + This option is needed if userland has an old glibc (before 2.4)
108494 + that puts a 'save' instruction into the runtime generated resolver
108495 + stub that needs special emulation.
108496 +
108497 +config PAX_KERNEXEC
108498 + bool "Enforce non-executable kernel pages"
108499 + 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))
108500 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !(ARM_LPAE && MODULES))) && !XEN
108501 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
108502 + select PAX_KERNEXEC_PLUGIN if X86_64
108503 + help
108504 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
108505 + that is, enabling this option will make it harder to inject
108506 + and execute 'foreign' code in kernel memory itself.
108507 +
108508 + Note that on amd64, CONFIG_EFI enabled with "efi=old_map" on
108509 + the kernel command-line will result in an RWX physical map.
108510 +
108511 + Likewise, the EFI runtime services are necessarily mapped as
108512 + RWX. If CONFIG_EFI is enabled on an EFI-capable system, it
108513 + is recommended that you boot with "noefi" on the kernel
108514 + command-line if possible to eliminate the mapping.
108515 +
108516 +choice
108517 + prompt "Return Address Instrumentation Method"
108518 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
108519 + depends on PAX_KERNEXEC_PLUGIN
108520 + help
108521 + Select the method used to instrument function pointer dereferences.
108522 + Note that binary modules cannot be instrumented by this approach.
108523 +
108524 + Note that the implementation requires a gcc with plugin support,
108525 + i.e., gcc 4.5 or newer. You may need to install the supporting
108526 + headers explicitly in addition to the normal gcc package.
108527 +
108528 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
108529 + bool "bts"
108530 + help
108531 + This method is compatible with binary only modules but has
108532 + a higher runtime overhead.
108533 +
108534 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
108535 + bool "or"
108536 + depends on !PARAVIRT
108537 + help
108538 + This method is incompatible with binary only modules but has
108539 + a lower runtime overhead.
108540 +endchoice
108541 +
108542 +config PAX_KERNEXEC_PLUGIN_METHOD
108543 + string
108544 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
108545 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
108546 + default ""
108547 +
108548 +config PAX_KERNEXEC_MODULE_TEXT
108549 + int "Minimum amount of memory reserved for module code"
108550 + default "8" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
108551 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
108552 + depends on PAX_KERNEXEC && X86_32
108553 + help
108554 + Due to implementation details the kernel must reserve a fixed
108555 + amount of memory for runtime allocated code (such as modules)
108556 + at compile time that cannot be changed at runtime. Here you
108557 + can specify the minimum amount in MB that will be reserved.
108558 + Due to the same implementation details this size will always
108559 + be rounded up to the next 2/4 MB boundary (depends on PAE) so
108560 + the actually available memory for runtime allocated code will
108561 + usually be more than this minimum.
108562 +
108563 + The default 4 MB should be enough for most users but if you have
108564 + an excessive number of modules (e.g., most distribution configs
108565 + compile many drivers as modules) or use huge modules such as
108566 + nvidia's kernel driver, you will need to adjust this amount.
108567 + A good rule of thumb is to look at your currently loaded kernel
108568 + modules and add up their sizes.
108569 +
108570 +endmenu
108571 +
108572 +menu "Address Space Layout Randomization"
108573 + depends on PAX
108574 +
108575 +config PAX_ASLR
108576 + bool "Address Space Layout Randomization"
108577 + default y if GRKERNSEC_CONFIG_AUTO
108578 + help
108579 + Many if not most exploit techniques rely on the knowledge of
108580 + certain addresses in the attacked program. The following options
108581 + will allow the kernel to apply a certain amount of randomization
108582 + to specific parts of the program thereby forcing an attacker to
108583 + guess them in most cases. Any failed guess will most likely crash
108584 + the attacked program which allows the kernel to detect such attempts
108585 + and react on them. PaX itself provides no reaction mechanisms,
108586 + instead it is strongly encouraged that you make use of grsecurity's
108587 + (http://www.grsecurity.net/) built-in crash detection features or
108588 + develop one yourself.
108589 +
108590 + By saying Y here you can choose to randomize the following areas:
108591 + - top of the task's kernel stack
108592 + - top of the task's userland stack
108593 + - base address for mmap() requests that do not specify one
108594 + (this includes all libraries)
108595 + - base address of the main executable
108596 +
108597 + It is strongly recommended to say Y here as address space layout
108598 + randomization has negligible impact on performance yet it provides
108599 + a very effective protection.
108600 +
108601 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
108602 + this feature on a per file basis.
108603 +
108604 +config PAX_RANDKSTACK
108605 + bool "Randomize kernel stack base"
108606 + default y if GRKERNSEC_CONFIG_AUTO && !(GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_VIRTUALBOX)
108607 + depends on X86_TSC && X86
108608 + help
108609 + By saying Y here the kernel will randomize every task's kernel
108610 + stack on every system call. This will not only force an attacker
108611 + to guess it but also prevent him from making use of possible
108612 + leaked information about it.
108613 +
108614 + Since the kernel stack is a rather scarce resource, randomization
108615 + may cause unexpected stack overflows, therefore you should very
108616 + carefully test your system. Note that once enabled in the kernel
108617 + configuration, this feature cannot be disabled on a per file basis.
108618 +
108619 +config PAX_RANDUSTACK
108620 + bool
108621 +
108622 +config PAX_RANDMMAP
108623 + bool "Randomize user stack and mmap() bases"
108624 + default y if GRKERNSEC_CONFIG_AUTO
108625 + depends on PAX_ASLR
108626 + select PAX_RANDUSTACK
108627 + help
108628 + By saying Y here the kernel will randomize every task's userland
108629 + stack and use a randomized base address for mmap() requests that
108630 + do not specify one themselves.
108631 +
108632 + The stack randomization is done in two steps where the second
108633 + one may apply a big amount of shift to the top of the stack and
108634 + cause problems for programs that want to use lots of memory (more
108635 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
108636 +
108637 + As a result of mmap randomization all dynamically loaded libraries
108638 + will appear at random addresses and therefore be harder to exploit
108639 + by a technique where an attacker attempts to execute library code
108640 + for his purposes (e.g. spawn a shell from an exploited program that
108641 + is running at an elevated privilege level).
108642 +
108643 + Furthermore, if a program is relinked as a dynamic ELF file, its
108644 + base address will be randomized as well, completing the full
108645 + randomization of the address space layout. Attacking such programs
108646 + becomes a guess game. You can find an example of doing this at
108647 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
108648 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
108649 +
108650 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
108651 + feature on a per file basis.
108652 +
108653 +endmenu
108654 +
108655 +menu "Miscellaneous hardening features"
108656 +
108657 +config PAX_MEMORY_SANITIZE
108658 + bool "Sanitize all freed memory"
108659 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
108660 + help
108661 + By saying Y here the kernel will erase memory pages and slab objects
108662 + as soon as they are freed. This in turn reduces the lifetime of data
108663 + stored in them, making it less likely that sensitive information such
108664 + as passwords, cryptographic secrets, etc stay in memory for too long.
108665 +
108666 + This is especially useful for programs whose runtime is short, long
108667 + lived processes and the kernel itself benefit from this as long as
108668 + they ensure timely freeing of memory that may hold sensitive
108669 + information.
108670 +
108671 + A nice side effect of the sanitization of slab objects is the
108672 + reduction of possible info leaks caused by padding bytes within the
108673 + leaky structures. Use-after-free bugs for structures containing
108674 + pointers can also be detected as dereferencing the sanitized pointer
108675 + will generate an access violation.
108676 +
108677 + The tradeoff is performance impact, on a single CPU system kernel
108678 + compilation sees a 3% slowdown, other systems and workloads may vary
108679 + and you are advised to test this feature on your expected workload
108680 + before deploying it.
108681 +
108682 + The slab sanitization feature excludes a few slab caches per default
108683 + for performance reasons. To extend the feature to cover those as
108684 + well, pass "pax_sanitize_slab=full" as kernel command line parameter.
108685 +
108686 + To reduce the performance penalty by sanitizing pages only, albeit
108687 + limiting the effectiveness of this feature at the same time, slab
108688 + sanitization can be disabled with the kernel command line parameter
108689 + "pax_sanitize_slab=off".
108690 +
108691 + Note that this feature does not protect data stored in live pages,
108692 + e.g., process memory swapped to disk may stay there for a long time.
108693 +
108694 +config PAX_MEMORY_STACKLEAK
108695 + bool "Sanitize kernel stack"
108696 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
108697 + depends on X86
108698 + help
108699 + By saying Y here the kernel will erase the kernel stack before it
108700 + returns from a system call. This in turn reduces the information
108701 + that a kernel stack leak bug can reveal.
108702 +
108703 + Note that such a bug can still leak information that was put on
108704 + the stack by the current system call (the one eventually triggering
108705 + the bug) but traces of earlier system calls on the kernel stack
108706 + cannot leak anymore.
108707 +
108708 + The tradeoff is performance impact: on a single CPU system kernel
108709 + compilation sees a 1% slowdown, other systems and workloads may vary
108710 + and you are advised to test this feature on your expected workload
108711 + before deploying it.
108712 +
108713 + Note that the full feature requires a gcc with plugin support,
108714 + i.e., gcc 4.5 or newer. You may need to install the supporting
108715 + headers explicitly in addition to the normal gcc package. Using
108716 + older gcc versions means that functions with large enough stack
108717 + frames may leave uninitialized memory behind that may be exposed
108718 + to a later syscall leaking the stack.
108719 +
108720 +config PAX_MEMORY_STRUCTLEAK
108721 + bool "Forcibly initialize local variables copied to userland"
108722 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
108723 + help
108724 + By saying Y here the kernel will zero initialize some local
108725 + variables that are going to be copied to userland. This in
108726 + turn prevents unintended information leakage from the kernel
108727 + stack should later code forget to explicitly set all parts of
108728 + the copied variable.
108729 +
108730 + The tradeoff is less performance impact than PAX_MEMORY_STACKLEAK
108731 + at a much smaller coverage.
108732 +
108733 + Note that the implementation requires a gcc with plugin support,
108734 + i.e., gcc 4.5 or newer. You may need to install the supporting
108735 + headers explicitly in addition to the normal gcc package.
108736 +
108737 +config PAX_MEMORY_UDEREF
108738 + bool "Prevent invalid userland pointer dereference"
108739 + default y if GRKERNSEC_CONFIG_AUTO && !(X86_64 && GRKERNSEC_CONFIG_PRIORITY_PERF) && (!X86 || GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
108740 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !ARM_LPAE)) && !UML_X86 && !XEN
108741 + select PAX_PER_CPU_PGD if X86_64
108742 + help
108743 + By saying Y here the kernel will be prevented from dereferencing
108744 + userland pointers in contexts where the kernel expects only kernel
108745 + pointers. This is both a useful runtime debugging feature and a
108746 + security measure that prevents exploiting a class of kernel bugs.
108747 +
108748 + The tradeoff is that some virtualization solutions may experience
108749 + a huge slowdown and therefore you should not enable this feature
108750 + for kernels meant to run in such environments. Whether a given VM
108751 + solution is affected or not is best determined by simply trying it
108752 + out, the performance impact will be obvious right on boot as this
108753 + mechanism engages from very early on. A good rule of thumb is that
108754 + VMs running on CPUs without hardware virtualization support (i.e.,
108755 + the majority of IA-32 CPUs) will likely experience the slowdown.
108756 +
108757 + On X86_64 the kernel will make use of PCID support when available
108758 + (Intel's Westmere, Sandy Bridge, etc) for better security (default)
108759 + or performance impact. Pass pax_weakuderef on the kernel command
108760 + line to choose the latter.
108761 +
108762 +config PAX_REFCOUNT
108763 + bool "Prevent various kernel object reference counter overflows"
108764 + default y if GRKERNSEC_CONFIG_AUTO
108765 + depends on GRKERNSEC && ((ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || MIPS || PPC || SPARC64 || X86)
108766 + help
108767 + By saying Y here the kernel will detect and prevent overflowing
108768 + various (but not all) kinds of object reference counters. Such
108769 + overflows can normally occur due to bugs only and are often, if
108770 + not always, exploitable.
108771 +
108772 + The tradeoff is that data structures protected by an overflowed
108773 + refcount will never be freed and therefore will leak memory. Note
108774 + that this leak also happens even without this protection but in
108775 + that case the overflow can eventually trigger the freeing of the
108776 + data structure while it is still being used elsewhere, resulting
108777 + in the exploitable situation that this feature prevents.
108778 +
108779 + Since this has a negligible performance impact, you should enable
108780 + this feature.
108781 +
108782 +config PAX_CONSTIFY_PLUGIN
108783 + bool "Automatically constify eligible structures"
108784 + default y
108785 + depends on !UML && PAX_KERNEXEC
108786 + help
108787 + By saying Y here the compiler will automatically constify a class
108788 + of types that contain only function pointers. This reduces the
108789 + kernel's attack surface and also produces a better memory layout.
108790 +
108791 + Note that the implementation requires a gcc with plugin support,
108792 + i.e., gcc 4.5 or newer. You may need to install the supporting
108793 + headers explicitly in addition to the normal gcc package.
108794 +
108795 + Note that if some code really has to modify constified variables
108796 + then the source code will have to be patched to allow it. Examples
108797 + can be found in PaX itself (the no_const attribute) and for some
108798 + out-of-tree modules at http://www.grsecurity.net/~paxguy1/ .
108799 +
108800 +config PAX_USERCOPY
108801 + bool "Harden heap object copies between kernel and userland"
108802 + default y if GRKERNSEC_CONFIG_AUTO
108803 + depends on ARM || IA64 || PPC || SPARC || X86
108804 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
108805 + select PAX_USERCOPY_SLABS
108806 + help
108807 + By saying Y here the kernel will enforce the size of heap objects
108808 + when they are copied in either direction between the kernel and
108809 + userland, even if only a part of the heap object is copied.
108810 +
108811 + Specifically, this checking prevents information leaking from the
108812 + kernel heap during kernel to userland copies (if the kernel heap
108813 + object is otherwise fully initialized) and prevents kernel heap
108814 + overflows during userland to kernel copies.
108815 +
108816 + Note that the current implementation provides the strictest bounds
108817 + checks for the SLUB allocator.
108818 +
108819 + Enabling this option also enables per-slab cache protection against
108820 + data in a given cache being copied into/out of via userland
108821 + accessors. Though the whitelist of regions will be reduced over
108822 + time, it notably protects important data structures like task structs.
108823 +
108824 + If frame pointers are enabled on x86, this option will also restrict
108825 + copies into and out of the kernel stack to local variables within a
108826 + single frame.
108827 +
108828 + Since this has a negligible performance impact, you should enable
108829 + this feature.
108830 +
108831 +config PAX_USERCOPY_DEBUG
108832 + bool
108833 + depends on X86 && PAX_USERCOPY
108834 + default n
108835 +
108836 +config PAX_SIZE_OVERFLOW
108837 + bool "Prevent various integer overflows in function size parameters"
108838 + default y if GRKERNSEC_CONFIG_AUTO
108839 + depends on X86
108840 + help
108841 + By saying Y here the kernel recomputes expressions of function
108842 + arguments marked by a size_overflow attribute with double integer
108843 + precision (DImode/TImode for 32/64 bit integer types).
108844 +
108845 + The recomputed argument is checked against TYPE_MAX and an event
108846 + is logged on overflow and the triggering process is killed.
108847 +
108848 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
108849 +
108850 + Note that the implementation requires a gcc with plugin support,
108851 + i.e., gcc 4.5 or newer. You may need to install the supporting
108852 + headers explicitly in addition to the normal gcc package.
108853 +
108854 +config PAX_LATENT_ENTROPY
108855 + bool "Generate some entropy during boot and runtime"
108856 + default y if GRKERNSEC_CONFIG_AUTO
108857 + help
108858 + By saying Y here the kernel will instrument some kernel code to
108859 + extract some entropy from both original and artificially created
108860 + program state. This will help especially embedded systems where
108861 + there is little 'natural' source of entropy normally. The cost
108862 + is some slowdown of the boot process and fork and irq processing.
108863 +
108864 + When pax_extra_latent_entropy is passed on the kernel command line,
108865 + entropy will be extracted from up to the first 4GB of RAM while the
108866 + runtime memory allocator is being initialized. This costs even more
108867 + slowdown of the boot process.
108868 +
108869 + Note that the implementation requires a gcc with plugin support,
108870 + i.e., gcc 4.5 or newer. You may need to install the supporting
108871 + headers explicitly in addition to the normal gcc package.
108872 +
108873 + Note that entropy extracted this way is not cryptographically
108874 + secure!
108875 +
108876 +endmenu
108877 +
108878 +endmenu
108879 +
108880 +source grsecurity/Kconfig
108881 +
108882 +endmenu
108883 +
108884 +endmenu
108885 +
108886 source security/keys/Kconfig
108887
108888 config SECURITY_DMESG_RESTRICT
108889 @@ -103,7 +1071,7 @@ config INTEL_TXT
108890 config LSM_MMAP_MIN_ADDR
108891 int "Low address space for LSM to protect from user allocation"
108892 depends on SECURITY && SECURITY_SELINUX
108893 - default 32768 if ARM || (ARM64 && COMPAT)
108894 + default 32768 if ALPHA || ARM || (ARM64 && COMPAT) || PARISC || SPARC32
108895 default 65536
108896 help
108897 This is the portion of low virtual memory which should be protected
108898 diff --git a/security/apparmor/file.c b/security/apparmor/file.c
108899 index fdaa50c..2761dcb 100644
108900 --- a/security/apparmor/file.c
108901 +++ b/security/apparmor/file.c
108902 @@ -348,8 +348,8 @@ static inline bool xindex_is_subset(u32 link, u32 target)
108903 int aa_path_link(struct aa_profile *profile, struct dentry *old_dentry,
108904 struct path *new_dir, struct dentry *new_dentry)
108905 {
108906 - struct path link = { new_dir->mnt, new_dentry };
108907 - struct path target = { new_dir->mnt, old_dentry };
108908 + struct path link = { .mnt = new_dir->mnt, .dentry = new_dentry };
108909 + struct path target = { .mnt = new_dir->mnt, .dentry = old_dentry };
108910 struct path_cond cond = {
108911 old_dentry->d_inode->i_uid,
108912 old_dentry->d_inode->i_mode
108913 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
108914 index 9981000..eb21356 100644
108915 --- a/security/apparmor/lsm.c
108916 +++ b/security/apparmor/lsm.c
108917 @@ -186,7 +186,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
108918 struct dentry *dentry, u32 mask,
108919 struct path_cond *cond)
108920 {
108921 - struct path path = { dir->mnt, dentry };
108922 + struct path path = { .mnt = dir->mnt, .dentry = dentry };
108923
108924 return common_perm(op, &path, mask, cond);
108925 }
108926 @@ -203,7 +203,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
108927 static int common_perm_mnt_dentry(int op, struct vfsmount *mnt,
108928 struct dentry *dentry, u32 mask)
108929 {
108930 - struct path path = { mnt, dentry };
108931 + struct path path = { .mnt = mnt, .dentry = dentry };
108932 struct path_cond cond = { dentry->d_inode->i_uid,
108933 dentry->d_inode->i_mode
108934 };
108935 @@ -325,8 +325,8 @@ static int apparmor_path_rename(struct path *old_dir, struct dentry *old_dentry,
108936
108937 profile = aa_current_profile();
108938 if (!unconfined(profile)) {
108939 - struct path old_path = { old_dir->mnt, old_dentry };
108940 - struct path new_path = { new_dir->mnt, new_dentry };
108941 + struct path old_path = { .mnt = old_dir->mnt, .dentry = old_dentry };
108942 + struct path new_path = { .mnt = new_dir->mnt, .dentry = new_dentry };
108943 struct path_cond cond = { old_dentry->d_inode->i_uid,
108944 old_dentry->d_inode->i_mode
108945 };
108946 @@ -615,7 +615,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
108947 return error;
108948 }
108949
108950 -static struct security_operations apparmor_ops = {
108951 +static struct security_operations apparmor_ops __read_only = {
108952 .name = "apparmor",
108953
108954 .ptrace_access_check = apparmor_ptrace_access_check,
108955 diff --git a/security/commoncap.c b/security/commoncap.c
108956 index bab0611..f9a0ff5 100644
108957 --- a/security/commoncap.c
108958 +++ b/security/commoncap.c
108959 @@ -427,6 +427,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
108960 return 0;
108961 }
108962
108963 +/* returns:
108964 + 1 for suid privilege
108965 + 2 for sgid privilege
108966 + 3 for fscap privilege
108967 +*/
108968 +int is_privileged_binary(const struct dentry *dentry)
108969 +{
108970 + struct cpu_vfs_cap_data capdata;
108971 + struct inode *inode = dentry->d_inode;
108972 +
108973 + if (!inode || S_ISDIR(inode->i_mode))
108974 + return 0;
108975 +
108976 + if (inode->i_mode & S_ISUID)
108977 + return 1;
108978 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
108979 + return 2;
108980 +
108981 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
108982 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
108983 + return 3;
108984 + }
108985 +
108986 + return 0;
108987 +}
108988 +
108989 /*
108990 * Attempt to get the on-exec apply capability sets for an executable file from
108991 * its xattrs and, if present, apply them to the proposed credentials being
108992 @@ -595,6 +621,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
108993 const struct cred *cred = current_cred();
108994 kuid_t root_uid = make_kuid(cred->user_ns, 0);
108995
108996 + if (gr_acl_enable_at_secure())
108997 + return 1;
108998 +
108999 if (!uid_eq(cred->uid, root_uid)) {
109000 if (bprm->cap_effective)
109001 return 1;
109002 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
109003 index 0fb456c..83711f9 100644
109004 --- a/security/integrity/ima/ima.h
109005 +++ b/security/integrity/ima/ima.h
109006 @@ -118,8 +118,8 @@ int ima_init_template(void);
109007 extern spinlock_t ima_queue_lock;
109008
109009 struct ima_h_table {
109010 - atomic_long_t len; /* number of stored measurements in the list */
109011 - atomic_long_t violations;
109012 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
109013 + atomic_long_unchecked_t violations;
109014 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
109015 };
109016 extern struct ima_h_table ima_htable;
109017 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
109018 index d9cd5ce..c5c29ac 100644
109019 --- a/security/integrity/ima/ima_api.c
109020 +++ b/security/integrity/ima/ima_api.c
109021 @@ -137,7 +137,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename,
109022 int result;
109023
109024 /* can overflow, only indicator */
109025 - atomic_long_inc(&ima_htable.violations);
109026 + atomic_long_inc_unchecked(&ima_htable.violations);
109027
109028 result = ima_alloc_init_template(NULL, file, filename,
109029 NULL, 0, &entry);
109030 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
109031 index da92fcc..8a5d390 100644
109032 --- a/security/integrity/ima/ima_fs.c
109033 +++ b/security/integrity/ima/ima_fs.c
109034 @@ -28,12 +28,12 @@
109035 static int valid_policy = 1;
109036 #define TMPBUFLEN 12
109037 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
109038 - loff_t *ppos, atomic_long_t *val)
109039 + loff_t *ppos, atomic_long_unchecked_t *val)
109040 {
109041 char tmpbuf[TMPBUFLEN];
109042 ssize_t len;
109043
109044 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
109045 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
109046 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
109047 }
109048
109049 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
109050 index 552705d..9920f4fb 100644
109051 --- a/security/integrity/ima/ima_queue.c
109052 +++ b/security/integrity/ima/ima_queue.c
109053 @@ -83,7 +83,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
109054 INIT_LIST_HEAD(&qe->later);
109055 list_add_tail_rcu(&qe->later, &ima_measurements);
109056
109057 - atomic_long_inc(&ima_htable.len);
109058 + atomic_long_inc_unchecked(&ima_htable.len);
109059 key = ima_hash_key(entry->digest);
109060 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
109061 return 0;
109062 diff --git a/security/keys/compat.c b/security/keys/compat.c
109063 index 3478965..ec7bb9e 100644
109064 --- a/security/keys/compat.c
109065 +++ b/security/keys/compat.c
109066 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
109067 if (ret == 0)
109068 goto no_payload_free;
109069
109070 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
109071 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
109072 err:
109073 if (iov != iovstack)
109074 kfree(iov);
109075 diff --git a/security/keys/internal.h b/security/keys/internal.h
109076 index 5f20da0..444ccf1 100644
109077 --- a/security/keys/internal.h
109078 +++ b/security/keys/internal.h
109079 @@ -244,7 +244,7 @@ extern long keyctl_instantiate_key_iov(key_serial_t,
109080 extern long keyctl_invalidate_key(key_serial_t);
109081
109082 extern long keyctl_instantiate_key_common(key_serial_t,
109083 - const struct iovec *,
109084 + const struct iovec __user *,
109085 unsigned, size_t, key_serial_t);
109086 #ifdef CONFIG_PERSISTENT_KEYRINGS
109087 extern long keyctl_get_persistent(uid_t, key_serial_t);
109088 diff --git a/security/keys/key.c b/security/keys/key.c
109089 index 6d0cad1..8f957df 100644
109090 --- a/security/keys/key.c
109091 +++ b/security/keys/key.c
109092 @@ -285,7 +285,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
109093
109094 atomic_set(&key->usage, 1);
109095 init_rwsem(&key->sem);
109096 - lockdep_set_class(&key->sem, &type->lock_class);
109097 + lockdep_set_class(&key->sem, (struct lock_class_key *)&type->lock_class);
109098 key->index_key.type = type;
109099 key->user = user;
109100 key->quotalen = quotalen;
109101 @@ -1075,7 +1075,9 @@ int register_key_type(struct key_type *ktype)
109102 struct key_type *p;
109103 int ret;
109104
109105 - memset(&ktype->lock_class, 0, sizeof(ktype->lock_class));
109106 + pax_open_kernel();
109107 + memset((void *)&ktype->lock_class, 0, sizeof(ktype->lock_class));
109108 + pax_close_kernel();
109109
109110 ret = -EEXIST;
109111 down_write(&key_types_sem);
109112 @@ -1087,7 +1089,7 @@ int register_key_type(struct key_type *ktype)
109113 }
109114
109115 /* store the type */
109116 - list_add(&ktype->link, &key_types_list);
109117 + pax_list_add((struct list_head *)&ktype->link, &key_types_list);
109118
109119 pr_notice("Key type %s registered\n", ktype->name);
109120 ret = 0;
109121 @@ -1109,7 +1111,7 @@ EXPORT_SYMBOL(register_key_type);
109122 void unregister_key_type(struct key_type *ktype)
109123 {
109124 down_write(&key_types_sem);
109125 - list_del_init(&ktype->link);
109126 + pax_list_del_init((struct list_head *)&ktype->link);
109127 downgrade_write(&key_types_sem);
109128 key_gc_keytype(ktype);
109129 pr_notice("Key type %s unregistered\n", ktype->name);
109130 @@ -1127,10 +1129,10 @@ void __init key_init(void)
109131 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
109132
109133 /* add the special key types */
109134 - list_add_tail(&key_type_keyring.link, &key_types_list);
109135 - list_add_tail(&key_type_dead.link, &key_types_list);
109136 - list_add_tail(&key_type_user.link, &key_types_list);
109137 - list_add_tail(&key_type_logon.link, &key_types_list);
109138 + pax_list_add_tail((struct list_head *)&key_type_keyring.link, &key_types_list);
109139 + pax_list_add_tail((struct list_head *)&key_type_dead.link, &key_types_list);
109140 + pax_list_add_tail((struct list_head *)&key_type_user.link, &key_types_list);
109141 + pax_list_add_tail((struct list_head *)&key_type_logon.link, &key_types_list);
109142
109143 /* record the root user tracking */
109144 rb_link_node(&root_key_user.node,
109145 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
109146 index eff88a5..51d35ef 100644
109147 --- a/security/keys/keyctl.c
109148 +++ b/security/keys/keyctl.c
109149 @@ -1004,7 +1004,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
109150 /*
109151 * Copy the iovec data from userspace
109152 */
109153 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
109154 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
109155 unsigned ioc)
109156 {
109157 for (; ioc > 0; ioc--) {
109158 @@ -1026,7 +1026,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
109159 * If successful, 0 will be returned.
109160 */
109161 long keyctl_instantiate_key_common(key_serial_t id,
109162 - const struct iovec *payload_iov,
109163 + const struct iovec __user *payload_iov,
109164 unsigned ioc,
109165 size_t plen,
109166 key_serial_t ringid)
109167 @@ -1121,7 +1121,7 @@ long keyctl_instantiate_key(key_serial_t id,
109168 [0].iov_len = plen
109169 };
109170
109171 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
109172 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
109173 }
109174
109175 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
109176 @@ -1154,7 +1154,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
109177 if (ret == 0)
109178 goto no_payload_free;
109179
109180 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
109181 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
109182 err:
109183 if (iov != iovstack)
109184 kfree(iov);
109185 diff --git a/security/min_addr.c b/security/min_addr.c
109186 index f728728..6457a0c 100644
109187 --- a/security/min_addr.c
109188 +++ b/security/min_addr.c
109189 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
109190 */
109191 static void update_mmap_min_addr(void)
109192 {
109193 +#ifndef SPARC
109194 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
109195 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
109196 mmap_min_addr = dac_mmap_min_addr;
109197 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
109198 #else
109199 mmap_min_addr = dac_mmap_min_addr;
109200 #endif
109201 +#endif
109202 }
109203
109204 /*
109205 diff --git a/security/security.c b/security/security.c
109206 index e41b1a8..b66a558 100644
109207 --- a/security/security.c
109208 +++ b/security/security.c
109209 @@ -33,8 +33,8 @@
109210 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
109211 CONFIG_DEFAULT_SECURITY;
109212
109213 -static struct security_operations *security_ops;
109214 -static struct security_operations default_security_ops = {
109215 +struct security_operations *security_ops __read_only;
109216 +struct security_operations default_security_ops __read_only = {
109217 .name = "default",
109218 };
109219
109220 @@ -73,11 +73,6 @@ int __init security_init(void)
109221 return 0;
109222 }
109223
109224 -void reset_security_ops(void)
109225 -{
109226 - security_ops = &default_security_ops;
109227 -}
109228 -
109229 /* Save user chosen LSM */
109230 static int __init choose_lsm(char *str)
109231 {
109232 diff --git a/security/selinux/avc.c b/security/selinux/avc.c
109233 index a18f1fa..c9b9fc4 100644
109234 --- a/security/selinux/avc.c
109235 +++ b/security/selinux/avc.c
109236 @@ -59,7 +59,7 @@ struct avc_node {
109237 struct avc_cache {
109238 struct hlist_head slots[AVC_CACHE_SLOTS]; /* head for avc_node->list */
109239 spinlock_t slots_lock[AVC_CACHE_SLOTS]; /* lock for writes */
109240 - atomic_t lru_hint; /* LRU hint for reclaim scan */
109241 + atomic_unchecked_t lru_hint; /* LRU hint for reclaim scan */
109242 atomic_t active_nodes;
109243 u32 latest_notif; /* latest revocation notification */
109244 };
109245 @@ -167,7 +167,7 @@ void __init avc_init(void)
109246 spin_lock_init(&avc_cache.slots_lock[i]);
109247 }
109248 atomic_set(&avc_cache.active_nodes, 0);
109249 - atomic_set(&avc_cache.lru_hint, 0);
109250 + atomic_set_unchecked(&avc_cache.lru_hint, 0);
109251
109252 avc_node_cachep = kmem_cache_create("avc_node", sizeof(struct avc_node),
109253 0, SLAB_PANIC, NULL);
109254 @@ -242,7 +242,7 @@ static inline int avc_reclaim_node(void)
109255 spinlock_t *lock;
109256
109257 for (try = 0, ecx = 0; try < AVC_CACHE_SLOTS; try++) {
109258 - hvalue = atomic_inc_return(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
109259 + hvalue = atomic_inc_return_unchecked(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
109260 head = &avc_cache.slots[hvalue];
109261 lock = &avc_cache.slots_lock[hvalue];
109262
109263 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
109264 index e03bad5..b15da09 100644
109265 --- a/security/selinux/hooks.c
109266 +++ b/security/selinux/hooks.c
109267 @@ -95,8 +95,6 @@
109268 #include "audit.h"
109269 #include "avc_ss.h"
109270
109271 -extern struct security_operations *security_ops;
109272 -
109273 /* SECMARK reference count */
109274 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
109275
109276 @@ -5772,7 +5770,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
109277
109278 #endif
109279
109280 -static struct security_operations selinux_ops = {
109281 +static struct security_operations selinux_ops __read_only = {
109282 .name = "selinux",
109283
109284 .ptrace_access_check = selinux_ptrace_access_check,
109285 @@ -6128,6 +6126,9 @@ static void selinux_nf_ip_exit(void)
109286 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
109287 static int selinux_disabled;
109288
109289 +extern struct security_operations *security_ops;
109290 +extern struct security_operations default_security_ops;
109291 +
109292 int selinux_disable(void)
109293 {
109294 if (ss_initialized) {
109295 @@ -6145,7 +6146,9 @@ int selinux_disable(void)
109296 selinux_disabled = 1;
109297 selinux_enabled = 0;
109298
109299 - reset_security_ops();
109300 + pax_open_kernel();
109301 + security_ops = &default_security_ops;
109302 + pax_close_kernel();
109303
109304 /* Try to destroy the avc node cache */
109305 avc_disable();
109306 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
109307 index 1450f85..a91e0bc 100644
109308 --- a/security/selinux/include/xfrm.h
109309 +++ b/security/selinux/include/xfrm.h
109310 @@ -48,7 +48,7 @@ static inline void selinux_xfrm_notify_policyload(void)
109311
109312 rtnl_lock();
109313 for_each_net(net) {
109314 - atomic_inc(&net->xfrm.flow_cache_genid);
109315 + atomic_inc_unchecked(&net->xfrm.flow_cache_genid);
109316 rt_genid_bump_all(net);
109317 }
109318 rtnl_unlock();
109319 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
109320 index e6ab307..2008c98 100644
109321 --- a/security/smack/smack_lsm.c
109322 +++ b/security/smack/smack_lsm.c
109323 @@ -3849,7 +3849,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
109324 return 0;
109325 }
109326
109327 -struct security_operations smack_ops = {
109328 +struct security_operations smack_ops __read_only = {
109329 .name = "smack",
109330
109331 .ptrace_access_check = smack_ptrace_access_check,
109332 diff --git a/security/tomoyo/file.c b/security/tomoyo/file.c
109333 index 4003907..13a2b55 100644
109334 --- a/security/tomoyo/file.c
109335 +++ b/security/tomoyo/file.c
109336 @@ -692,7 +692,7 @@ int tomoyo_path_number_perm(const u8 type, struct path *path,
109337 {
109338 struct tomoyo_request_info r;
109339 struct tomoyo_obj_info obj = {
109340 - .path1 = *path,
109341 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
109342 };
109343 int error = -ENOMEM;
109344 struct tomoyo_path_info buf;
109345 @@ -740,7 +740,7 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
109346 struct tomoyo_path_info buf;
109347 struct tomoyo_request_info r;
109348 struct tomoyo_obj_info obj = {
109349 - .path1 = *path,
109350 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
109351 };
109352 int idx;
109353
109354 @@ -786,7 +786,7 @@ int tomoyo_path_perm(const u8 operation, struct path *path, const char *target)
109355 {
109356 struct tomoyo_request_info r;
109357 struct tomoyo_obj_info obj = {
109358 - .path1 = *path,
109359 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
109360 };
109361 int error;
109362 struct tomoyo_path_info buf;
109363 @@ -843,7 +843,7 @@ int tomoyo_mkdev_perm(const u8 operation, struct path *path,
109364 {
109365 struct tomoyo_request_info r;
109366 struct tomoyo_obj_info obj = {
109367 - .path1 = *path,
109368 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
109369 };
109370 int error = -ENOMEM;
109371 struct tomoyo_path_info buf;
109372 @@ -890,8 +890,8 @@ int tomoyo_path2_perm(const u8 operation, struct path *path1,
109373 struct tomoyo_path_info buf2;
109374 struct tomoyo_request_info r;
109375 struct tomoyo_obj_info obj = {
109376 - .path1 = *path1,
109377 - .path2 = *path2,
109378 + .path1 = { .mnt = path1->mnt, .dentry = path1->dentry },
109379 + .path2 = { .mnt = path2->mnt, .dentry = path2->dentry }
109380 };
109381 int idx;
109382
109383 diff --git a/security/tomoyo/mount.c b/security/tomoyo/mount.c
109384 index 390c646..f2f8db3 100644
109385 --- a/security/tomoyo/mount.c
109386 +++ b/security/tomoyo/mount.c
109387 @@ -118,6 +118,10 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r,
109388 type == tomoyo_mounts[TOMOYO_MOUNT_MOVE]) {
109389 need_dev = -1; /* dev_name is a directory */
109390 } else {
109391 + if (!capable(CAP_SYS_ADMIN)) {
109392 + error = -EPERM;
109393 + goto out;
109394 + }
109395 fstype = get_fs_type(type);
109396 if (!fstype) {
109397 error = -ENODEV;
109398 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
109399 index f0b756e..8aa497b 100644
109400 --- a/security/tomoyo/tomoyo.c
109401 +++ b/security/tomoyo/tomoyo.c
109402 @@ -146,7 +146,7 @@ static int tomoyo_bprm_check_security(struct linux_binprm *bprm)
109403 */
109404 static int tomoyo_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
109405 {
109406 - struct path path = { mnt, dentry };
109407 + struct path path = { .mnt = mnt, .dentry = dentry };
109408 return tomoyo_path_perm(TOMOYO_TYPE_GETATTR, &path, NULL);
109409 }
109410
109411 @@ -172,7 +172,7 @@ static int tomoyo_path_truncate(struct path *path)
109412 */
109413 static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
109414 {
109415 - struct path path = { parent->mnt, dentry };
109416 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109417 return tomoyo_path_perm(TOMOYO_TYPE_UNLINK, &path, NULL);
109418 }
109419
109420 @@ -188,7 +188,7 @@ static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
109421 static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
109422 umode_t mode)
109423 {
109424 - struct path path = { parent->mnt, dentry };
109425 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109426 return tomoyo_path_number_perm(TOMOYO_TYPE_MKDIR, &path,
109427 mode & S_IALLUGO);
109428 }
109429 @@ -203,7 +203,7 @@ static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
109430 */
109431 static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
109432 {
109433 - struct path path = { parent->mnt, dentry };
109434 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109435 return tomoyo_path_perm(TOMOYO_TYPE_RMDIR, &path, NULL);
109436 }
109437
109438 @@ -219,7 +219,7 @@ static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
109439 static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
109440 const char *old_name)
109441 {
109442 - struct path path = { parent->mnt, dentry };
109443 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109444 return tomoyo_path_perm(TOMOYO_TYPE_SYMLINK, &path, old_name);
109445 }
109446
109447 @@ -236,7 +236,7 @@ static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
109448 static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
109449 umode_t mode, unsigned int dev)
109450 {
109451 - struct path path = { parent->mnt, dentry };
109452 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109453 int type = TOMOYO_TYPE_CREATE;
109454 const unsigned int perm = mode & S_IALLUGO;
109455
109456 @@ -275,8 +275,8 @@ static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
109457 static int tomoyo_path_link(struct dentry *old_dentry, struct path *new_dir,
109458 struct dentry *new_dentry)
109459 {
109460 - struct path path1 = { new_dir->mnt, old_dentry };
109461 - struct path path2 = { new_dir->mnt, new_dentry };
109462 + struct path path1 = { .mnt = new_dir->mnt, .dentry = old_dentry };
109463 + struct path path2 = { .mnt = new_dir->mnt, .dentry = new_dentry };
109464 return tomoyo_path2_perm(TOMOYO_TYPE_LINK, &path1, &path2);
109465 }
109466
109467 @@ -295,8 +295,8 @@ static int tomoyo_path_rename(struct path *old_parent,
109468 struct path *new_parent,
109469 struct dentry *new_dentry)
109470 {
109471 - struct path path1 = { old_parent->mnt, old_dentry };
109472 - struct path path2 = { new_parent->mnt, new_dentry };
109473 + struct path path1 = { .mnt = old_parent->mnt, .dentry = old_dentry };
109474 + struct path path2 = { .mnt = new_parent->mnt, .dentry = new_dentry };
109475 return tomoyo_path2_perm(TOMOYO_TYPE_RENAME, &path1, &path2);
109476 }
109477
109478 @@ -424,7 +424,7 @@ static int tomoyo_sb_mount(const char *dev_name, struct path *path,
109479 */
109480 static int tomoyo_sb_umount(struct vfsmount *mnt, int flags)
109481 {
109482 - struct path path = { mnt, mnt->mnt_root };
109483 + struct path path = { .mnt = mnt, .dentry = mnt->mnt_root };
109484 return tomoyo_path_perm(TOMOYO_TYPE_UMOUNT, &path, NULL);
109485 }
109486
109487 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
109488 * tomoyo_security_ops is a "struct security_operations" which is used for
109489 * registering TOMOYO.
109490 */
109491 -static struct security_operations tomoyo_security_ops = {
109492 +static struct security_operations tomoyo_security_ops __read_only = {
109493 .name = "tomoyo",
109494 .cred_alloc_blank = tomoyo_cred_alloc_blank,
109495 .cred_prepare = tomoyo_cred_prepare,
109496 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
109497 index 20ef514..4182bed 100644
109498 --- a/security/yama/Kconfig
109499 +++ b/security/yama/Kconfig
109500 @@ -1,6 +1,6 @@
109501 config SECURITY_YAMA
109502 bool "Yama support"
109503 - depends on SECURITY
109504 + depends on SECURITY && !GRKERNSEC
109505 select SECURITYFS
109506 select SECURITY_PATH
109507 default n
109508 diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
109509 index 13c88fbc..f8c115e 100644
109510 --- a/security/yama/yama_lsm.c
109511 +++ b/security/yama/yama_lsm.c
109512 @@ -365,7 +365,7 @@ int yama_ptrace_traceme(struct task_struct *parent)
109513 }
109514
109515 #ifndef CONFIG_SECURITY_YAMA_STACKED
109516 -static struct security_operations yama_ops = {
109517 +static struct security_operations yama_ops __read_only = {
109518 .name = "yama",
109519
109520 .ptrace_access_check = yama_ptrace_access_check,
109521 @@ -376,28 +376,24 @@ static struct security_operations yama_ops = {
109522 #endif
109523
109524 #ifdef CONFIG_SYSCTL
109525 +static int zero __read_only;
109526 +static int max_scope __read_only = YAMA_SCOPE_NO_ATTACH;
109527 +
109528 static int yama_dointvec_minmax(struct ctl_table *table, int write,
109529 void __user *buffer, size_t *lenp, loff_t *ppos)
109530 {
109531 - int rc;
109532 + ctl_table_no_const yama_table;
109533
109534 if (write && !capable(CAP_SYS_PTRACE))
109535 return -EPERM;
109536
109537 - rc = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
109538 - if (rc)
109539 - return rc;
109540 -
109541 + yama_table = *table;
109542 /* Lock the max value if it ever gets set. */
109543 - if (write && *(int *)table->data == *(int *)table->extra2)
109544 - table->extra1 = table->extra2;
109545 -
109546 - return rc;
109547 + if (ptrace_scope == max_scope)
109548 + yama_table.extra1 = &max_scope;
109549 + return proc_dointvec_minmax(&yama_table, write, buffer, lenp, ppos);
109550 }
109551
109552 -static int zero;
109553 -static int max_scope = YAMA_SCOPE_NO_ATTACH;
109554 -
109555 struct ctl_path yama_sysctl_path[] = {
109556 { .procname = "kernel", },
109557 { .procname = "yama", },
109558 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
109559 index 401107b..b9c47c6 100644
109560 --- a/sound/aoa/codecs/onyx.c
109561 +++ b/sound/aoa/codecs/onyx.c
109562 @@ -54,7 +54,7 @@ struct onyx {
109563 spdif_locked:1,
109564 analog_locked:1,
109565 original_mute:2;
109566 - int open_count;
109567 + local_t open_count;
109568 struct codec_info *codec_info;
109569
109570 /* mutex serializes concurrent access to the device
109571 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
109572 struct onyx *onyx = cii->codec_data;
109573
109574 mutex_lock(&onyx->mutex);
109575 - onyx->open_count++;
109576 + local_inc(&onyx->open_count);
109577 mutex_unlock(&onyx->mutex);
109578
109579 return 0;
109580 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
109581 struct onyx *onyx = cii->codec_data;
109582
109583 mutex_lock(&onyx->mutex);
109584 - onyx->open_count--;
109585 - if (!onyx->open_count)
109586 + if (local_dec_and_test(&onyx->open_count))
109587 onyx->spdif_locked = onyx->analog_locked = 0;
109588 mutex_unlock(&onyx->mutex);
109589
109590 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
109591 index ffd2025..df062c9 100644
109592 --- a/sound/aoa/codecs/onyx.h
109593 +++ b/sound/aoa/codecs/onyx.h
109594 @@ -11,6 +11,7 @@
109595 #include <linux/i2c.h>
109596 #include <asm/pmac_low_i2c.h>
109597 #include <asm/prom.h>
109598 +#include <asm/local.h>
109599
109600 /* PCM3052 register definitions */
109601
109602 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
109603 index ada69d7..5f65386 100644
109604 --- a/sound/core/oss/pcm_oss.c
109605 +++ b/sound/core/oss/pcm_oss.c
109606 @@ -1190,10 +1190,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
109607 if (in_kernel) {
109608 mm_segment_t fs;
109609 fs = snd_enter_user();
109610 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
109611 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
109612 snd_leave_user(fs);
109613 } else {
109614 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
109615 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
109616 }
109617 if (ret != -EPIPE && ret != -ESTRPIPE)
109618 break;
109619 @@ -1233,10 +1233,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
109620 if (in_kernel) {
109621 mm_segment_t fs;
109622 fs = snd_enter_user();
109623 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
109624 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
109625 snd_leave_user(fs);
109626 } else {
109627 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
109628 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
109629 }
109630 if (ret == -EPIPE) {
109631 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
109632 @@ -1332,7 +1332,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
109633 struct snd_pcm_plugin_channel *channels;
109634 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
109635 if (!in_kernel) {
109636 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
109637 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
109638 return -EFAULT;
109639 buf = runtime->oss.buffer;
109640 }
109641 @@ -1402,7 +1402,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
109642 }
109643 } else {
109644 tmp = snd_pcm_oss_write2(substream,
109645 - (const char __force *)buf,
109646 + (const char __force_kernel *)buf,
109647 runtime->oss.period_bytes, 0);
109648 if (tmp <= 0)
109649 goto err;
109650 @@ -1428,7 +1428,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
109651 struct snd_pcm_runtime *runtime = substream->runtime;
109652 snd_pcm_sframes_t frames, frames1;
109653 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
109654 - char __user *final_dst = (char __force __user *)buf;
109655 + char __user *final_dst = (char __force_user *)buf;
109656 if (runtime->oss.plugin_first) {
109657 struct snd_pcm_plugin_channel *channels;
109658 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
109659 @@ -1490,7 +1490,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
109660 xfer += tmp;
109661 runtime->oss.buffer_used -= tmp;
109662 } else {
109663 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
109664 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
109665 runtime->oss.period_bytes, 0);
109666 if (tmp <= 0)
109667 goto err;
109668 @@ -1659,7 +1659,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
109669 size1);
109670 size1 /= runtime->channels; /* frames */
109671 fs = snd_enter_user();
109672 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
109673 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
109674 snd_leave_user(fs);
109675 }
109676 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
109677 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
109678 index 2d957ba..fda022c 100644
109679 --- a/sound/core/pcm_compat.c
109680 +++ b/sound/core/pcm_compat.c
109681 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
109682 int err;
109683
109684 fs = snd_enter_user();
109685 - err = snd_pcm_delay(substream, &delay);
109686 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
109687 snd_leave_user(fs);
109688 if (err < 0)
109689 return err;
109690 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
109691 index a95356f..0f5eabf 100644
109692 --- a/sound/core/pcm_native.c
109693 +++ b/sound/core/pcm_native.c
109694 @@ -2815,11 +2815,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
109695 switch (substream->stream) {
109696 case SNDRV_PCM_STREAM_PLAYBACK:
109697 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
109698 - (void __user *)arg);
109699 + (void __force_user *)arg);
109700 break;
109701 case SNDRV_PCM_STREAM_CAPTURE:
109702 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
109703 - (void __user *)arg);
109704 + (void __force_user *)arg);
109705 break;
109706 default:
109707 result = -EINVAL;
109708 diff --git a/sound/core/seq/oss/seq_oss.c b/sound/core/seq/oss/seq_oss.c
109709 index 16d4267..fe8b49b 100644
109710 --- a/sound/core/seq/oss/seq_oss.c
109711 +++ b/sound/core/seq/oss/seq_oss.c
109712 @@ -69,8 +69,8 @@ static int __init alsa_seq_oss_init(void)
109713 {
109714 int rc;
109715 static struct snd_seq_dev_ops ops = {
109716 - snd_seq_oss_synth_register,
109717 - snd_seq_oss_synth_unregister,
109718 + .init_device = snd_seq_oss_synth_register,
109719 + .free_device = snd_seq_oss_synth_unregister,
109720 };
109721
109722 snd_seq_autoload_lock();
109723 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
109724 index 91a786a..4c07ed4 100644
109725 --- a/sound/core/seq/seq_device.c
109726 +++ b/sound/core/seq/seq_device.c
109727 @@ -64,7 +64,7 @@ struct ops_list {
109728 int argsize; /* argument size */
109729
109730 /* operators */
109731 - struct snd_seq_dev_ops ops;
109732 + struct snd_seq_dev_ops *ops;
109733
109734 /* registered devices */
109735 struct list_head dev_list; /* list of devices */
109736 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
109737
109738 mutex_lock(&ops->reg_mutex);
109739 /* copy driver operators */
109740 - ops->ops = *entry;
109741 + ops->ops = entry;
109742 ops->driver |= DRIVER_LOADED;
109743 ops->argsize = argsize;
109744
109745 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
109746 dev->name, ops->id, ops->argsize, dev->argsize);
109747 return -EINVAL;
109748 }
109749 - if (ops->ops.init_device(dev) >= 0) {
109750 + if (ops->ops->init_device(dev) >= 0) {
109751 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
109752 ops->num_init_devices++;
109753 } else {
109754 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
109755 dev->name, ops->id, ops->argsize, dev->argsize);
109756 return -EINVAL;
109757 }
109758 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
109759 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
109760 dev->status = SNDRV_SEQ_DEVICE_FREE;
109761 dev->driver_data = NULL;
109762 ops->num_init_devices--;
109763 diff --git a/sound/core/seq/seq_midi.c b/sound/core/seq/seq_midi.c
109764 index a1fd77a..69cd659 100644
109765 --- a/sound/core/seq/seq_midi.c
109766 +++ b/sound/core/seq/seq_midi.c
109767 @@ -462,8 +462,8 @@ snd_seq_midisynth_unregister_port(struct snd_seq_device *dev)
109768 static int __init alsa_seq_midi_init(void)
109769 {
109770 static struct snd_seq_dev_ops ops = {
109771 - snd_seq_midisynth_register_port,
109772 - snd_seq_midisynth_unregister_port,
109773 + .init_device = snd_seq_midisynth_register_port,
109774 + .free_device = snd_seq_midisynth_unregister_port,
109775 };
109776 memset(&synths, 0, sizeof(synths));
109777 snd_seq_autoload_lock();
109778 diff --git a/sound/core/sound.c b/sound/core/sound.c
109779 index 38ad1a0..5010a40 100644
109780 --- a/sound/core/sound.c
109781 +++ b/sound/core/sound.c
109782 @@ -86,7 +86,7 @@ static void snd_request_other(int minor)
109783 case SNDRV_MINOR_TIMER: str = "snd-timer"; break;
109784 default: return;
109785 }
109786 - request_module(str);
109787 + request_module("%s", str);
109788 }
109789
109790 #endif /* modular kernel */
109791 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
109792 index f5fd448..6ae276da 100644
109793 --- a/sound/drivers/mts64.c
109794 +++ b/sound/drivers/mts64.c
109795 @@ -29,6 +29,7 @@
109796 #include <sound/initval.h>
109797 #include <sound/rawmidi.h>
109798 #include <sound/control.h>
109799 +#include <asm/local.h>
109800
109801 #define CARD_NAME "Miditerminal 4140"
109802 #define DRIVER_NAME "MTS64"
109803 @@ -67,7 +68,7 @@ struct mts64 {
109804 struct pardevice *pardev;
109805 int pardev_claimed;
109806
109807 - int open_count;
109808 + local_t open_count;
109809 int current_midi_output_port;
109810 int current_midi_input_port;
109811 u8 mode[MTS64_NUM_INPUT_PORTS];
109812 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
109813 {
109814 struct mts64 *mts = substream->rmidi->private_data;
109815
109816 - if (mts->open_count == 0) {
109817 + if (local_read(&mts->open_count) == 0) {
109818 /* We don't need a spinlock here, because this is just called
109819 if the device has not been opened before.
109820 So there aren't any IRQs from the device */
109821 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
109822
109823 msleep(50);
109824 }
109825 - ++(mts->open_count);
109826 + local_inc(&mts->open_count);
109827
109828 return 0;
109829 }
109830 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
109831 struct mts64 *mts = substream->rmidi->private_data;
109832 unsigned long flags;
109833
109834 - --(mts->open_count);
109835 - if (mts->open_count == 0) {
109836 + if (local_dec_return(&mts->open_count) == 0) {
109837 /* We need the spinlock_irqsave here because we can still
109838 have IRQs at this point */
109839 spin_lock_irqsave(&mts->lock, flags);
109840 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
109841
109842 msleep(500);
109843
109844 - } else if (mts->open_count < 0)
109845 - mts->open_count = 0;
109846 + } else if (local_read(&mts->open_count) < 0)
109847 + local_set(&mts->open_count, 0);
109848
109849 return 0;
109850 }
109851 diff --git a/sound/drivers/opl3/opl3_seq.c b/sound/drivers/opl3/opl3_seq.c
109852 index 6839953..7a0f4b9 100644
109853 --- a/sound/drivers/opl3/opl3_seq.c
109854 +++ b/sound/drivers/opl3/opl3_seq.c
109855 @@ -281,8 +281,8 @@ static int __init alsa_opl3_seq_init(void)
109856 {
109857 static struct snd_seq_dev_ops ops =
109858 {
109859 - snd_opl3_seq_new_device,
109860 - snd_opl3_seq_delete_device
109861 + .init_device = snd_opl3_seq_new_device,
109862 + .free_device = snd_opl3_seq_delete_device
109863 };
109864
109865 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL3, &ops,
109866 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
109867 index b953fb4..1999c01 100644
109868 --- a/sound/drivers/opl4/opl4_lib.c
109869 +++ b/sound/drivers/opl4/opl4_lib.c
109870 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
109871 MODULE_DESCRIPTION("OPL4 driver");
109872 MODULE_LICENSE("GPL");
109873
109874 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
109875 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
109876 {
109877 int timeout = 10;
109878 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
109879 diff --git a/sound/drivers/opl4/opl4_seq.c b/sound/drivers/opl4/opl4_seq.c
109880 index 9919769..d7de36c 100644
109881 --- a/sound/drivers/opl4/opl4_seq.c
109882 +++ b/sound/drivers/opl4/opl4_seq.c
109883 @@ -198,8 +198,8 @@ static int snd_opl4_seq_delete_device(struct snd_seq_device *dev)
109884 static int __init alsa_opl4_synth_init(void)
109885 {
109886 static struct snd_seq_dev_ops ops = {
109887 - snd_opl4_seq_new_device,
109888 - snd_opl4_seq_delete_device
109889 + .init_device = snd_opl4_seq_new_device,
109890 + .free_device = snd_opl4_seq_delete_device
109891 };
109892
109893 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL4, &ops,
109894 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
109895 index 78ccfa4..7a0857b 100644
109896 --- a/sound/drivers/portman2x4.c
109897 +++ b/sound/drivers/portman2x4.c
109898 @@ -48,6 +48,7 @@
109899 #include <sound/initval.h>
109900 #include <sound/rawmidi.h>
109901 #include <sound/control.h>
109902 +#include <asm/local.h>
109903
109904 #define CARD_NAME "Portman 2x4"
109905 #define DRIVER_NAME "portman"
109906 @@ -85,7 +86,7 @@ struct portman {
109907 struct pardevice *pardev;
109908 int pardev_claimed;
109909
109910 - int open_count;
109911 + local_t open_count;
109912 int mode[PORTMAN_NUM_INPUT_PORTS];
109913 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
109914 };
109915 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
109916 index 95fc2eaf..ea5d6a7 100644
109917 --- a/sound/firewire/amdtp.c
109918 +++ b/sound/firewire/amdtp.c
109919 @@ -521,7 +521,7 @@ static void update_pcm_pointers(struct amdtp_stream *s,
109920 ptr = s->pcm_buffer_pointer + frames;
109921 if (ptr >= pcm->runtime->buffer_size)
109922 ptr -= pcm->runtime->buffer_size;
109923 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
109924 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
109925
109926 s->pcm_period_pointer += frames;
109927 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
109928 @@ -961,7 +961,7 @@ EXPORT_SYMBOL(amdtp_stream_pcm_pointer);
109929 */
109930 void amdtp_stream_update(struct amdtp_stream *s)
109931 {
109932 - ACCESS_ONCE(s->source_node_id_field) =
109933 + ACCESS_ONCE_RW(s->source_node_id_field) =
109934 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
109935 }
109936 EXPORT_SYMBOL(amdtp_stream_update);
109937 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
109938 index 4823c08..47a5f7c 100644
109939 --- a/sound/firewire/amdtp.h
109940 +++ b/sound/firewire/amdtp.h
109941 @@ -212,7 +212,7 @@ static inline bool amdtp_stream_pcm_running(struct amdtp_stream *s)
109942 static inline void amdtp_stream_pcm_trigger(struct amdtp_stream *s,
109943 struct snd_pcm_substream *pcm)
109944 {
109945 - ACCESS_ONCE(s->pcm) = pcm;
109946 + ACCESS_ONCE_RW(s->pcm) = pcm;
109947 }
109948
109949 /**
109950 @@ -230,7 +230,7 @@ static inline void amdtp_stream_midi_trigger(struct amdtp_stream *s,
109951 struct snd_rawmidi_substream *midi)
109952 {
109953 if (port < s->midi_ports)
109954 - ACCESS_ONCE(s->midi[port]) = midi;
109955 + ACCESS_ONCE_RW(s->midi[port]) = midi;
109956 }
109957
109958 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
109959 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
109960 index 7ac9443..0ec6274 100644
109961 --- a/sound/firewire/isight.c
109962 +++ b/sound/firewire/isight.c
109963 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
109964 ptr += count;
109965 if (ptr >= runtime->buffer_size)
109966 ptr -= runtime->buffer_size;
109967 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
109968 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
109969
109970 isight->period_counter += count;
109971 if (isight->period_counter >= runtime->period_size) {
109972 @@ -299,7 +299,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
109973 if (err < 0)
109974 return err;
109975
109976 - ACCESS_ONCE(isight->pcm_active) = true;
109977 + ACCESS_ONCE_RW(isight->pcm_active) = true;
109978
109979 return 0;
109980 }
109981 @@ -337,7 +337,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
109982 {
109983 struct isight *isight = substream->private_data;
109984
109985 - ACCESS_ONCE(isight->pcm_active) = false;
109986 + ACCESS_ONCE_RW(isight->pcm_active) = false;
109987
109988 mutex_lock(&isight->mutex);
109989 isight_stop_streaming(isight);
109990 @@ -430,10 +430,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
109991
109992 switch (cmd) {
109993 case SNDRV_PCM_TRIGGER_START:
109994 - ACCESS_ONCE(isight->pcm_running) = true;
109995 + ACCESS_ONCE_RW(isight->pcm_running) = true;
109996 break;
109997 case SNDRV_PCM_TRIGGER_STOP:
109998 - ACCESS_ONCE(isight->pcm_running) = false;
109999 + ACCESS_ONCE_RW(isight->pcm_running) = false;
110000 break;
110001 default:
110002 return -EINVAL;
110003 diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
110004 index 2dba848..c682aef 100644
110005 --- a/sound/firewire/scs1x.c
110006 +++ b/sound/firewire/scs1x.c
110007 @@ -74,7 +74,7 @@ static void scs_output_trigger(struct snd_rawmidi_substream *stream, int up)
110008 {
110009 struct scs *scs = stream->rmidi->private_data;
110010
110011 - ACCESS_ONCE(scs->output) = up ? stream : NULL;
110012 + ACCESS_ONCE_RW(scs->output) = up ? stream : NULL;
110013 if (up) {
110014 scs->output_idle = false;
110015 tasklet_schedule(&scs->tasklet);
110016 @@ -257,7 +257,7 @@ static void scs_input_trigger(struct snd_rawmidi_substream *stream, int up)
110017 {
110018 struct scs *scs = stream->rmidi->private_data;
110019
110020 - ACCESS_ONCE(scs->input) = up ? stream : NULL;
110021 + ACCESS_ONCE_RW(scs->input) = up ? stream : NULL;
110022 }
110023
110024 static void scs_input_escaped_byte(struct snd_rawmidi_substream *stream,
110025 @@ -473,8 +473,8 @@ static void scs_remove(struct fw_unit *unit)
110026
110027 snd_card_disconnect(scs->card);
110028
110029 - ACCESS_ONCE(scs->output) = NULL;
110030 - ACCESS_ONCE(scs->input) = NULL;
110031 + ACCESS_ONCE_RW(scs->output) = NULL;
110032 + ACCESS_ONCE_RW(scs->input) = NULL;
110033
110034 wait_event(scs->idle_wait, scs->output_idle);
110035
110036 diff --git a/sound/isa/sb/emu8000_synth.c b/sound/isa/sb/emu8000_synth.c
110037 index 4e3fcfb..ab45a9d 100644
110038 --- a/sound/isa/sb/emu8000_synth.c
110039 +++ b/sound/isa/sb/emu8000_synth.c
110040 @@ -120,8 +120,8 @@ static int __init alsa_emu8000_init(void)
110041 {
110042
110043 static struct snd_seq_dev_ops ops = {
110044 - snd_emu8000_new_device,
110045 - snd_emu8000_delete_device,
110046 + .init_device = snd_emu8000_new_device,
110047 + .free_device = snd_emu8000_delete_device,
110048 };
110049 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU8000, &ops,
110050 sizeof(struct snd_emu8000*));
110051 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
110052 index 048439a..3be9f6f 100644
110053 --- a/sound/oss/sb_audio.c
110054 +++ b/sound/oss/sb_audio.c
110055 @@ -904,7 +904,7 @@ sb16_copy_from_user(int dev,
110056 buf16 = (signed short *)(localbuf + localoffs);
110057 while (c)
110058 {
110059 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
110060 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
110061 if (copy_from_user(lbuf8,
110062 userbuf+useroffs + p,
110063 locallen))
110064 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
110065 index a33e8ce..2262303 100644
110066 --- a/sound/oss/swarm_cs4297a.c
110067 +++ b/sound/oss/swarm_cs4297a.c
110068 @@ -2623,7 +2623,6 @@ static int __init cs4297a_init(void)
110069 {
110070 struct cs4297a_state *s;
110071 u32 pwr, id;
110072 - mm_segment_t fs;
110073 int rval;
110074 u64 cfg;
110075 int mdio_val;
110076 @@ -2709,22 +2708,23 @@ static int __init cs4297a_init(void)
110077 if (!rval) {
110078 char *sb1250_duart_present;
110079
110080 +#if 0
110081 + mm_segment_t fs;
110082 fs = get_fs();
110083 set_fs(KERNEL_DS);
110084 -#if 0
110085 val = SOUND_MASK_LINE;
110086 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
110087 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
110088 val = initvol[i].vol;
110089 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
110090 }
110091 + set_fs(fs);
110092 // cs4297a_write_ac97(s, 0x18, 0x0808);
110093 #else
110094 // cs4297a_write_ac97(s, 0x5e, 0x180);
110095 cs4297a_write_ac97(s, 0x02, 0x0808);
110096 cs4297a_write_ac97(s, 0x18, 0x0808);
110097 #endif
110098 - set_fs(fs);
110099
110100 list_add(&s->list, &cs4297a_devs);
110101
110102 diff --git a/sound/pci/emu10k1/emu10k1_synth.c b/sound/pci/emu10k1/emu10k1_synth.c
110103 index 4c41c90..37f3631 100644
110104 --- a/sound/pci/emu10k1/emu10k1_synth.c
110105 +++ b/sound/pci/emu10k1/emu10k1_synth.c
110106 @@ -108,8 +108,8 @@ static int __init alsa_emu10k1_synth_init(void)
110107 {
110108
110109 static struct snd_seq_dev_ops ops = {
110110 - snd_emu10k1_synth_new_device,
110111 - snd_emu10k1_synth_delete_device,
110112 + .init_device = snd_emu10k1_synth_new_device,
110113 + .free_device = snd_emu10k1_synth_delete_device,
110114 };
110115 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops,
110116 sizeof(struct snd_emu10k1_synth_arg));
110117 diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
110118 index ec6a7d0..4e578f7 100644
110119 --- a/sound/pci/hda/hda_codec.c
110120 +++ b/sound/pci/hda/hda_codec.c
110121 @@ -966,14 +966,10 @@ find_codec_preset(struct hda_codec *codec)
110122 mutex_unlock(&preset_mutex);
110123
110124 if (mod_requested < HDA_MODREQ_MAX_COUNT) {
110125 - char name[32];
110126 if (!mod_requested)
110127 - snprintf(name, sizeof(name), "snd-hda-codec-id:%08x",
110128 - codec->vendor_id);
110129 + request_module("snd-hda-codec-id:%08x", codec->vendor_id);
110130 else
110131 - snprintf(name, sizeof(name), "snd-hda-codec-id:%04x*",
110132 - (codec->vendor_id >> 16) & 0xffff);
110133 - request_module(name);
110134 + request_module("snd-hda-codec-id:%04x*", (codec->vendor_id >> 16) & 0xffff);
110135 mod_requested++;
110136 goto again;
110137 }
110138 @@ -2780,7 +2776,7 @@ static int get_kctl_0dB_offset(struct hda_codec *codec,
110139 /* FIXME: set_fs() hack for obtaining user-space TLV data */
110140 mm_segment_t fs = get_fs();
110141 set_fs(get_ds());
110142 - if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), _tlv))
110143 + if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), (unsigned int __force_user *)_tlv))
110144 tlv = _tlv;
110145 set_fs(fs);
110146 } else if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_READ)
110147 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
110148 index 4631a23..001ae57 100644
110149 --- a/sound/pci/ymfpci/ymfpci.h
110150 +++ b/sound/pci/ymfpci/ymfpci.h
110151 @@ -358,7 +358,7 @@ struct snd_ymfpci {
110152 spinlock_t reg_lock;
110153 spinlock_t voice_lock;
110154 wait_queue_head_t interrupt_sleep;
110155 - atomic_t interrupt_sleep_count;
110156 + atomic_unchecked_t interrupt_sleep_count;
110157 struct snd_info_entry *proc_entry;
110158 const struct firmware *dsp_microcode;
110159 const struct firmware *controller_microcode;
110160 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
110161 index 81c916a..516f0bf 100644
110162 --- a/sound/pci/ymfpci/ymfpci_main.c
110163 +++ b/sound/pci/ymfpci/ymfpci_main.c
110164 @@ -204,8 +204,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
110165 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
110166 break;
110167 }
110168 - if (atomic_read(&chip->interrupt_sleep_count)) {
110169 - atomic_set(&chip->interrupt_sleep_count, 0);
110170 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
110171 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
110172 wake_up(&chip->interrupt_sleep);
110173 }
110174 __end:
110175 @@ -789,7 +789,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
110176 continue;
110177 init_waitqueue_entry(&wait, current);
110178 add_wait_queue(&chip->interrupt_sleep, &wait);
110179 - atomic_inc(&chip->interrupt_sleep_count);
110180 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
110181 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
110182 remove_wait_queue(&chip->interrupt_sleep, &wait);
110183 }
110184 @@ -827,8 +827,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
110185 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
110186 spin_unlock(&chip->reg_lock);
110187
110188 - if (atomic_read(&chip->interrupt_sleep_count)) {
110189 - atomic_set(&chip->interrupt_sleep_count, 0);
110190 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
110191 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
110192 wake_up(&chip->interrupt_sleep);
110193 }
110194 }
110195 @@ -2423,7 +2423,7 @@ int snd_ymfpci_create(struct snd_card *card,
110196 spin_lock_init(&chip->reg_lock);
110197 spin_lock_init(&chip->voice_lock);
110198 init_waitqueue_head(&chip->interrupt_sleep);
110199 - atomic_set(&chip->interrupt_sleep_count, 0);
110200 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
110201 chip->card = card;
110202 chip->pci = pci;
110203 chip->irq = -1;
110204 diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
110205 index a3e0a0d..ab98399 100644
110206 --- a/sound/soc/soc-core.c
110207 +++ b/sound/soc/soc-core.c
110208 @@ -2286,8 +2286,10 @@ int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
110209 if (ret)
110210 return ret;
110211
110212 - ops->warm_reset = snd_soc_ac97_warm_reset;
110213 - ops->reset = snd_soc_ac97_reset;
110214 + pax_open_kernel();
110215 + *(void **)&ops->warm_reset = snd_soc_ac97_warm_reset;
110216 + *(void **)&ops->reset = snd_soc_ac97_reset;
110217 + pax_close_kernel();
110218
110219 snd_ac97_rst_cfg = cfg;
110220 return 0;
110221 diff --git a/sound/synth/emux/emux_seq.c b/sound/synth/emux/emux_seq.c
110222 index 7778b8e..3d619fc 100644
110223 --- a/sound/synth/emux/emux_seq.c
110224 +++ b/sound/synth/emux/emux_seq.c
110225 @@ -33,13 +33,13 @@ static int snd_emux_unuse(void *private_data, struct snd_seq_port_subscribe *inf
110226 * MIDI emulation operators
110227 */
110228 static struct snd_midi_op emux_ops = {
110229 - snd_emux_note_on,
110230 - snd_emux_note_off,
110231 - snd_emux_key_press,
110232 - snd_emux_terminate_note,
110233 - snd_emux_control,
110234 - snd_emux_nrpn,
110235 - snd_emux_sysex,
110236 + .note_on = snd_emux_note_on,
110237 + .note_off = snd_emux_note_off,
110238 + .key_press = snd_emux_key_press,
110239 + .note_terminate = snd_emux_terminate_note,
110240 + .control = snd_emux_control,
110241 + .nrpn = snd_emux_nrpn,
110242 + .sysex = snd_emux_sysex,
110243 };
110244
110245
110246 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
110247 new file mode 100644
110248 index 0000000..de92ed9
110249 --- /dev/null
110250 +++ b/tools/gcc/.gitignore
110251 @@ -0,0 +1 @@
110252 +randomize_layout_seed.h
110253 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
110254 new file mode 100644
110255 index 0000000..7b8921f
110256 --- /dev/null
110257 +++ b/tools/gcc/Makefile
110258 @@ -0,0 +1,52 @@
110259 +#CC := gcc
110260 +#PLUGIN_SOURCE_FILES := pax_plugin.c
110261 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
110262 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
110263 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
110264 +
110265 +ifeq ($(PLUGINCC),$(HOSTCC))
110266 +HOSTLIBS := hostlibs
110267 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu99 -ggdb
110268 +export HOST_EXTRACFLAGS
110269 +else
110270 +HOSTLIBS := hostcxxlibs
110271 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu++98 -fno-rtti -ggdb -Wno-unused-parameter -Wno-narrowing -Wno-unused-variable
110272 +export HOST_EXTRACXXFLAGS
110273 +endif
110274 +
110275 +export GCCPLUGINS_DIR HOSTLIBS
110276 +
110277 +$(HOSTLIBS)-$(CONFIG_PAX_CONSTIFY_PLUGIN) := constify_plugin.so
110278 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
110279 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
110280 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
110281 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
110282 +$(HOSTLIBS)-y += colorize_plugin.so
110283 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
110284 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STRUCTLEAK) += structleak_plugin.so
110285 +$(HOSTLIBS)-$(CONFIG_GRKERNSEC_RANDSTRUCT) += randomize_layout_plugin.so
110286 +
110287 +subdir-$(CONFIG_PAX_SIZE_OVERFLOW) := size_overflow_plugin
110288 +subdir- += size_overflow_plugin
110289 +
110290 +always := $($(HOSTLIBS)-y)
110291 +
110292 +constify_plugin-objs := constify_plugin.o
110293 +stackleak_plugin-objs := stackleak_plugin.o
110294 +kallocstat_plugin-objs := kallocstat_plugin.o
110295 +kernexec_plugin-objs := kernexec_plugin.o
110296 +checker_plugin-objs := checker_plugin.o
110297 +colorize_plugin-objs := colorize_plugin.o
110298 +latent_entropy_plugin-objs := latent_entropy_plugin.o
110299 +structleak_plugin-objs := structleak_plugin.o
110300 +randomize_layout_plugin-objs := randomize_layout_plugin.o
110301 +
110302 +$(obj)/randomize_layout_plugin.o: $(objtree)/$(obj)/randomize_layout_seed.h
110303 +
110304 +quiet_cmd_create_randomize_layout_seed = GENSEED $@
110305 + cmd_create_randomize_layout_seed = \
110306 + $(CONFIG_SHELL) $(srctree)/$(src)/gen-random-seed.sh $@ $(objtree)/include/generated/randomize_layout_hash.h
110307 +$(objtree)/$(obj)/randomize_layout_seed.h: FORCE
110308 + $(call if_changed,create_randomize_layout_seed)
110309 +
110310 +targets += randomize_layout_seed.h randomize_layout_hash.h
110311 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
110312 new file mode 100644
110313 index 0000000..5452feea
110314 --- /dev/null
110315 +++ b/tools/gcc/checker_plugin.c
110316 @@ -0,0 +1,150 @@
110317 +/*
110318 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
110319 + * Licensed under the GPL v2
110320 + *
110321 + * Note: the choice of the license means that the compilation process is
110322 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
110323 + * but for the kernel it doesn't matter since it doesn't link against
110324 + * any of the gcc libraries
110325 + *
110326 + * gcc plugin to implement various sparse (source code checker) features
110327 + *
110328 + * TODO:
110329 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
110330 + *
110331 + * BUGS:
110332 + * - none known
110333 + */
110334 +
110335 +#include "gcc-common.h"
110336 +
110337 +extern void c_register_addr_space (const char *str, addr_space_t as);
110338 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
110339 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
110340 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
110341 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
110342 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
110343 +
110344 +int plugin_is_GPL_compatible;
110345 +
110346 +static struct plugin_info checker_plugin_info = {
110347 + .version = "201304082245",
110348 + .help = NULL,
110349 +};
110350 +
110351 +#define ADDR_SPACE_KERNEL 0
110352 +#define ADDR_SPACE_FORCE_KERNEL 1
110353 +#define ADDR_SPACE_USER 2
110354 +#define ADDR_SPACE_FORCE_USER 3
110355 +#define ADDR_SPACE_IOMEM 0
110356 +#define ADDR_SPACE_FORCE_IOMEM 0
110357 +#define ADDR_SPACE_PERCPU 0
110358 +#define ADDR_SPACE_FORCE_PERCPU 0
110359 +#define ADDR_SPACE_RCU 0
110360 +#define ADDR_SPACE_FORCE_RCU 0
110361 +
110362 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
110363 +{
110364 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
110365 +}
110366 +
110367 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
110368 +{
110369 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
110370 +}
110371 +
110372 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
110373 +{
110374 + return default_addr_space_valid_pointer_mode(mode, as);
110375 +}
110376 +
110377 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
110378 +{
110379 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
110380 +}
110381 +
110382 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
110383 +{
110384 + return default_addr_space_legitimize_address(x, oldx, mode, as);
110385 +}
110386 +
110387 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
110388 +{
110389 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
110390 + return true;
110391 +
110392 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
110393 + return true;
110394 +
110395 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
110396 + return true;
110397 +
110398 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
110399 + return true;
110400 +
110401 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
110402 + return true;
110403 +
110404 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
110405 + return true;
110406 +
110407 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
110408 + return true;
110409 +
110410 + return subset == superset;
110411 +}
110412 +
110413 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
110414 +{
110415 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
110416 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
110417 +
110418 + return op;
110419 +}
110420 +
110421 +static void register_checker_address_spaces(void *event_data, void *data)
110422 +{
110423 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
110424 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
110425 + c_register_addr_space("__user", ADDR_SPACE_USER);
110426 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
110427 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
110428 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
110429 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
110430 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
110431 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
110432 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
110433 +
110434 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
110435 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
110436 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
110437 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
110438 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
110439 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
110440 + targetm.addr_space.convert = checker_addr_space_convert;
110441 +}
110442 +
110443 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
110444 +{
110445 + const char * const plugin_name = plugin_info->base_name;
110446 + const int argc = plugin_info->argc;
110447 + const struct plugin_argument * const argv = plugin_info->argv;
110448 + int i;
110449 +
110450 + if (!plugin_default_version_check(version, &gcc_version)) {
110451 + error(G_("incompatible gcc/plugin versions"));
110452 + return 1;
110453 + }
110454 +
110455 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
110456 +
110457 + for (i = 0; i < argc; ++i)
110458 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
110459 +
110460 + if (TARGET_64BIT == 0)
110461 + return 0;
110462 +
110463 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
110464 +
110465 + return 0;
110466 +}
110467 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
110468 new file mode 100644
110469 index 0000000..54461af
110470 --- /dev/null
110471 +++ b/tools/gcc/colorize_plugin.c
110472 @@ -0,0 +1,210 @@
110473 +/*
110474 + * Copyright 2012-2014 by PaX Team <pageexec@freemail.hu>
110475 + * Licensed under the GPL v2
110476 + *
110477 + * Note: the choice of the license means that the compilation process is
110478 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
110479 + * but for the kernel it doesn't matter since it doesn't link against
110480 + * any of the gcc libraries
110481 + *
110482 + * gcc plugin to colorize diagnostic output
110483 + *
110484 + */
110485 +
110486 +#include "gcc-common.h"
110487 +
110488 +int plugin_is_GPL_compatible;
110489 +
110490 +static struct plugin_info colorize_plugin_info = {
110491 + .version = "201404202350",
110492 + .help = "color=[never|always|auto]\tdetermine when to colorize\n",
110493 +};
110494 +
110495 +#define GREEN "\033[32m\033[K"
110496 +#define LIGHTGREEN "\033[1;32m\033[K"
110497 +#define YELLOW "\033[33m\033[K"
110498 +#define LIGHTYELLOW "\033[1;33m\033[K"
110499 +#define RED "\033[31m\033[K"
110500 +#define LIGHTRED "\033[1;31m\033[K"
110501 +#define BLUE "\033[34m\033[K"
110502 +#define LIGHTBLUE "\033[1;34m\033[K"
110503 +#define BRIGHT "\033[1;m\033[K"
110504 +#define NORMAL "\033[m\033[K"
110505 +
110506 +static diagnostic_starter_fn old_starter;
110507 +static diagnostic_finalizer_fn old_finalizer;
110508 +
110509 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
110510 +{
110511 + const char *color;
110512 + char *newprefix;
110513 +
110514 + switch (diagnostic->kind) {
110515 + case DK_NOTE:
110516 + color = LIGHTBLUE;
110517 + break;
110518 +
110519 + case DK_PEDWARN:
110520 + case DK_WARNING:
110521 + color = LIGHTYELLOW;
110522 + break;
110523 +
110524 + case DK_ERROR:
110525 + case DK_FATAL:
110526 + case DK_ICE:
110527 + case DK_PERMERROR:
110528 + case DK_SORRY:
110529 + color = LIGHTRED;
110530 + break;
110531 +
110532 + default:
110533 + color = NORMAL;
110534 + }
110535 +
110536 + old_starter(context, diagnostic);
110537 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
110538 + return;
110539 + pp_destroy_prefix(context->printer);
110540 + pp_set_prefix(context->printer, newprefix);
110541 +}
110542 +
110543 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
110544 +{
110545 + old_finalizer(context, diagnostic);
110546 +}
110547 +
110548 +static void colorize_arm(void)
110549 +{
110550 + old_starter = diagnostic_starter(global_dc);
110551 + old_finalizer = diagnostic_finalizer(global_dc);
110552 +
110553 + diagnostic_starter(global_dc) = start_colorize;
110554 + diagnostic_finalizer(global_dc) = finalize_colorize;
110555 +}
110556 +
110557 +static unsigned int execute_colorize_rearm(void)
110558 +{
110559 + if (diagnostic_starter(global_dc) == start_colorize)
110560 + return 0;
110561 +
110562 + colorize_arm();
110563 + return 0;
110564 +}
110565 +
110566 +#if BUILDING_GCC_VERSION >= 4009
110567 +static const struct pass_data colorize_rearm_pass_data = {
110568 +#else
110569 +struct simple_ipa_opt_pass colorize_rearm_pass = {
110570 + .pass = {
110571 +#endif
110572 + .type = SIMPLE_IPA_PASS,
110573 + .name = "colorize_rearm",
110574 +#if BUILDING_GCC_VERSION >= 4008
110575 + .optinfo_flags = OPTGROUP_NONE,
110576 +#endif
110577 +#if BUILDING_GCC_VERSION >= 4009
110578 + .has_gate = false,
110579 + .has_execute = true,
110580 +#else
110581 + .gate = NULL,
110582 + .execute = execute_colorize_rearm,
110583 + .sub = NULL,
110584 + .next = NULL,
110585 + .static_pass_number = 0,
110586 +#endif
110587 + .tv_id = TV_NONE,
110588 + .properties_required = 0,
110589 + .properties_provided = 0,
110590 + .properties_destroyed = 0,
110591 + .todo_flags_start = 0,
110592 + .todo_flags_finish = 0
110593 +#if BUILDING_GCC_VERSION < 4009
110594 + }
110595 +#endif
110596 +};
110597 +
110598 +#if BUILDING_GCC_VERSION >= 4009
110599 +namespace {
110600 +class colorize_rearm_pass : public simple_ipa_opt_pass {
110601 +public:
110602 + colorize_rearm_pass() : simple_ipa_opt_pass(colorize_rearm_pass_data, g) {}
110603 + unsigned int execute() { return execute_colorize_rearm(); }
110604 +};
110605 +}
110606 +
110607 +static opt_pass *make_colorize_rearm_pass(void)
110608 +{
110609 + return new colorize_rearm_pass();
110610 +}
110611 +#else
110612 +static struct opt_pass *make_colorize_rearm_pass(void)
110613 +{
110614 + return &colorize_rearm_pass.pass;
110615 +}
110616 +#endif
110617 +
110618 +static void colorize_start_unit(void *gcc_data, void *user_data)
110619 +{
110620 + colorize_arm();
110621 +}
110622 +
110623 +static bool should_colorize(void)
110624 +{
110625 +#if BUILDING_GCC_VERSION >= 4009
110626 + return false;
110627 +#else
110628 + char const *t = getenv("TERM");
110629 +
110630 + return t && strcmp(t, "dumb") && isatty(STDERR_FILENO);
110631 +#endif
110632 +}
110633 +
110634 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
110635 +{
110636 + const char * const plugin_name = plugin_info->base_name;
110637 + const int argc = plugin_info->argc;
110638 + const struct plugin_argument * const argv = plugin_info->argv;
110639 + int i;
110640 + struct register_pass_info colorize_rearm_pass_info;
110641 + bool colorize;
110642 +
110643 + colorize_rearm_pass_info.pass = make_colorize_rearm_pass();
110644 + colorize_rearm_pass_info.reference_pass_name = "*free_lang_data";
110645 + colorize_rearm_pass_info.ref_pass_instance_number = 1;
110646 + colorize_rearm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
110647 +
110648 + if (!plugin_default_version_check(version, &gcc_version)) {
110649 + error(G_("incompatible gcc/plugin versions"));
110650 + return 1;
110651 + }
110652 +
110653 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
110654 +
110655 + colorize = getenv("GCC_COLORS") ? should_colorize() : false;
110656 +
110657 + for (i = 0; i < argc; ++i) {
110658 + if (!strcmp(argv[i].key, "color")) {
110659 + if (!argv[i].value) {
110660 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
110661 + continue;
110662 + }
110663 + if (!strcmp(argv[i].value, "always"))
110664 + colorize = true;
110665 + else if (!strcmp(argv[i].value, "never"))
110666 + colorize = false;
110667 + else if (!strcmp(argv[i].value, "auto"))
110668 + colorize = should_colorize();
110669 + else
110670 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
110671 + continue;
110672 + }
110673 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
110674 + }
110675 +
110676 + if (colorize) {
110677 + // TODO: parse GCC_COLORS as used by gcc 4.9+
110678 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
110679 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
110680 + }
110681 + return 0;
110682 +}
110683 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
110684 new file mode 100644
110685 index 0000000..82bc5a8
110686 --- /dev/null
110687 +++ b/tools/gcc/constify_plugin.c
110688 @@ -0,0 +1,557 @@
110689 +/*
110690 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
110691 + * Copyright 2011-2014 by PaX Team <pageexec@freemail.hu>
110692 + * Licensed under the GPL v2, or (at your option) v3
110693 + *
110694 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
110695 + *
110696 + * Homepage:
110697 + * http://www.grsecurity.net/~ephox/const_plugin/
110698 + *
110699 + * Usage:
110700 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
110701 + * $ gcc -fplugin=constify_plugin.so test.c -O2
110702 + */
110703 +
110704 +#include "gcc-common.h"
110705 +
110706 +// unused C type flag in all versions 4.5-4.9
110707 +#define TYPE_CONSTIFY_VISITED(TYPE) TYPE_LANG_FLAG_4(TYPE)
110708 +
110709 +int plugin_is_GPL_compatible;
110710 +
110711 +static struct plugin_info const_plugin_info = {
110712 + .version = "201401270210",
110713 + .help = "no-constify\tturn off constification\n",
110714 +};
110715 +
110716 +typedef struct {
110717 + bool has_fptr_field;
110718 + bool has_writable_field;
110719 + bool has_do_const_field;
110720 + bool has_no_const_field;
110721 +} constify_info;
110722 +
110723 +static const_tree get_field_type(const_tree field)
110724 +{
110725 + return strip_array_types(TREE_TYPE(field));
110726 +}
110727 +
110728 +static bool is_fptr(const_tree field)
110729 +{
110730 + const_tree ptr = get_field_type(field);
110731 +
110732 + if (TREE_CODE(ptr) != POINTER_TYPE)
110733 + return false;
110734 +
110735 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
110736 +}
110737 +
110738 +/*
110739 + * determine whether the given structure type meets the requirements for automatic constification,
110740 + * including the constification attributes on nested structure types
110741 + */
110742 +static void constifiable(const_tree node, constify_info *cinfo)
110743 +{
110744 + const_tree field;
110745 +
110746 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
110747 +
110748 + // e.g., pointer to structure fields while still constructing the structure type
110749 + if (TYPE_FIELDS(node) == NULL_TREE)
110750 + return;
110751 +
110752 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
110753 + const_tree type = get_field_type(field);
110754 + enum tree_code code = TREE_CODE(type);
110755 +
110756 + if (node == type)
110757 + continue;
110758 +
110759 + if (is_fptr(field))
110760 + cinfo->has_fptr_field = true;
110761 + else if (!TREE_READONLY(field))
110762 + cinfo->has_writable_field = true;
110763 +
110764 + if (code == RECORD_TYPE || code == UNION_TYPE) {
110765 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
110766 + cinfo->has_do_const_field = true;
110767 + else if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
110768 + cinfo->has_no_const_field = true;
110769 + else
110770 + constifiable(type, cinfo);
110771 + }
110772 + }
110773 +}
110774 +
110775 +static bool constified(const_tree node)
110776 +{
110777 + constify_info cinfo = {
110778 + .has_fptr_field = false,
110779 + .has_writable_field = false,
110780 + .has_do_const_field = false,
110781 + .has_no_const_field = false
110782 + };
110783 +
110784 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
110785 +
110786 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
110787 +// gcc_assert(!TYPE_READONLY(node));
110788 + return false;
110789 + }
110790 +
110791 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node))) {
110792 + gcc_assert(TYPE_READONLY(node));
110793 + return true;
110794 + }
110795 +
110796 + constifiable(node, &cinfo);
110797 + if ((!cinfo.has_fptr_field || cinfo.has_writable_field) && !cinfo.has_do_const_field)
110798 + return false;
110799 +
110800 + return TYPE_READONLY(node);
110801 +}
110802 +
110803 +static void deconstify_tree(tree node);
110804 +
110805 +static void deconstify_type(tree type)
110806 +{
110807 + tree field;
110808 +
110809 + gcc_assert(TREE_CODE(type) == RECORD_TYPE || TREE_CODE(type) == UNION_TYPE);
110810 +
110811 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
110812 + const_tree fieldtype = get_field_type(field);
110813 +
110814 + // special case handling of simple ptr-to-same-array-type members
110815 + if (TREE_CODE(TREE_TYPE(field)) == POINTER_TYPE) {
110816 + tree ptrtype = TREE_TYPE(TREE_TYPE(field));
110817 +
110818 + if (TREE_TYPE(TREE_TYPE(field)) == type)
110819 + continue;
110820 + if (TREE_CODE(ptrtype) != RECORD_TYPE && TREE_CODE(ptrtype) != UNION_TYPE)
110821 + continue;
110822 + if (!constified(ptrtype))
110823 + continue;
110824 + if (TYPE_MAIN_VARIANT(ptrtype) == TYPE_MAIN_VARIANT(type)) {
110825 + TREE_TYPE(field) = copy_node(TREE_TYPE(field));
110826 + TREE_TYPE(TREE_TYPE(field)) = build_qualified_type(type, TYPE_QUALS(ptrtype) & ~TYPE_QUAL_CONST);
110827 + }
110828 + continue;
110829 + }
110830 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
110831 + continue;
110832 + if (!constified(fieldtype))
110833 + continue;
110834 +
110835 + deconstify_tree(field);
110836 + TREE_READONLY(field) = 0;
110837 + }
110838 + TYPE_READONLY(type) = 0;
110839 + C_TYPE_FIELDS_READONLY(type) = 0;
110840 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
110841 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
110842 + TYPE_ATTRIBUTES(type) = remove_attribute("do_const", TYPE_ATTRIBUTES(type));
110843 + }
110844 +}
110845 +
110846 +static void deconstify_tree(tree node)
110847 +{
110848 + tree old_type, new_type, field;
110849 +
110850 + old_type = TREE_TYPE(node);
110851 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
110852 + node = TREE_TYPE(node) = copy_node(old_type);
110853 + old_type = TREE_TYPE(old_type);
110854 + }
110855 +
110856 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
110857 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
110858 +
110859 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
110860 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
110861 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
110862 + DECL_FIELD_CONTEXT(field) = new_type;
110863 +
110864 + deconstify_type(new_type);
110865 +
110866 + TREE_TYPE(node) = new_type;
110867 +}
110868 +
110869 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
110870 +{
110871 + tree type;
110872 + constify_info cinfo = {
110873 + .has_fptr_field = false,
110874 + .has_writable_field = false,
110875 + .has_do_const_field = false,
110876 + .has_no_const_field = false
110877 + };
110878 +
110879 + *no_add_attrs = true;
110880 + if (TREE_CODE(*node) == FUNCTION_DECL) {
110881 + error("%qE attribute does not apply to functions (%qF)", name, *node);
110882 + return NULL_TREE;
110883 + }
110884 +
110885 + if (TREE_CODE(*node) == PARM_DECL) {
110886 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
110887 + return NULL_TREE;
110888 + }
110889 +
110890 + if (TREE_CODE(*node) == VAR_DECL) {
110891 + error("%qE attribute does not apply to variables (%qD)", name, *node);
110892 + return NULL_TREE;
110893 + }
110894 +
110895 + if (TYPE_P(*node)) {
110896 + type = *node;
110897 + } else {
110898 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
110899 + type = TREE_TYPE(*node);
110900 + }
110901 +
110902 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
110903 + error("%qE attribute used on %qT applies to struct and union types only", name, type);
110904 + return NULL_TREE;
110905 + }
110906 +
110907 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
110908 + error("%qE attribute is already applied to the type %qT", name, type);
110909 + return NULL_TREE;
110910 + }
110911 +
110912 + if (TYPE_P(*node)) {
110913 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
110914 + error("%qE attribute used on type %qT is incompatible with 'do_const'", name, type);
110915 + else
110916 + *no_add_attrs = false;
110917 + return NULL_TREE;
110918 + }
110919 +
110920 + constifiable(type, &cinfo);
110921 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
110922 + deconstify_tree(*node);
110923 + TYPE_CONSTIFY_VISITED(TREE_TYPE(*node)) = 1;
110924 + return NULL_TREE;
110925 + }
110926 +
110927 + error("%qE attribute used on type %qT that is not constified", name, type);
110928 + return NULL_TREE;
110929 +}
110930 +
110931 +static void constify_type(tree type)
110932 +{
110933 + TYPE_READONLY(type) = 1;
110934 + C_TYPE_FIELDS_READONLY(type) = 1;
110935 + TYPE_CONSTIFY_VISITED(type) = 1;
110936 +// TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
110937 +// TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("do_const"), NULL_TREE, TYPE_ATTRIBUTES(type));
110938 +}
110939 +
110940 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
110941 +{
110942 + *no_add_attrs = true;
110943 + if (!TYPE_P(*node)) {
110944 + error("%qE attribute applies to types only (%qD)", name, *node);
110945 + return NULL_TREE;
110946 + }
110947 +
110948 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
110949 + error("%qE attribute used on %qT applies to struct and union types only", name, *node);
110950 + return NULL_TREE;
110951 + }
110952 +
110953 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(*node))) {
110954 + error("%qE attribute used on %qT is already applied to the type", name, *node);
110955 + return NULL_TREE;
110956 + }
110957 +
110958 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(*node))) {
110959 + error("%qE attribute used on %qT is incompatible with 'no_const'", name, *node);
110960 + return NULL_TREE;
110961 + }
110962 +
110963 + *no_add_attrs = false;
110964 + return NULL_TREE;
110965 +}
110966 +
110967 +static struct attribute_spec no_const_attr = {
110968 + .name = "no_const",
110969 + .min_length = 0,
110970 + .max_length = 0,
110971 + .decl_required = false,
110972 + .type_required = false,
110973 + .function_type_required = false,
110974 + .handler = handle_no_const_attribute,
110975 +#if BUILDING_GCC_VERSION >= 4007
110976 + .affects_type_identity = true
110977 +#endif
110978 +};
110979 +
110980 +static struct attribute_spec do_const_attr = {
110981 + .name = "do_const",
110982 + .min_length = 0,
110983 + .max_length = 0,
110984 + .decl_required = false,
110985 + .type_required = false,
110986 + .function_type_required = false,
110987 + .handler = handle_do_const_attribute,
110988 +#if BUILDING_GCC_VERSION >= 4007
110989 + .affects_type_identity = true
110990 +#endif
110991 +};
110992 +
110993 +static void register_attributes(void *event_data, void *data)
110994 +{
110995 + register_attribute(&no_const_attr);
110996 + register_attribute(&do_const_attr);
110997 +}
110998 +
110999 +static void finish_type(void *event_data, void *data)
111000 +{
111001 + tree type = (tree)event_data;
111002 + constify_info cinfo = {
111003 + .has_fptr_field = false,
111004 + .has_writable_field = false,
111005 + .has_do_const_field = false,
111006 + .has_no_const_field = false
111007 + };
111008 +
111009 + if (type == NULL_TREE || type == error_mark_node)
111010 + return;
111011 +
111012 + if (TYPE_FIELDS(type) == NULL_TREE || TYPE_CONSTIFY_VISITED(type))
111013 + return;
111014 +
111015 + constifiable(type, &cinfo);
111016 +
111017 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type))) {
111018 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || cinfo.has_do_const_field) {
111019 + deconstify_type(type);
111020 + TYPE_CONSTIFY_VISITED(type) = 1;
111021 + } else
111022 + error("'no_const' attribute used on type %qT that is not constified", type);
111023 + return;
111024 + }
111025 +
111026 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
111027 + if (!cinfo.has_writable_field) {
111028 + error("'do_const' attribute used on type %qT that is%sconstified", type, cinfo.has_fptr_field ? " " : " not ");
111029 + return;
111030 + }
111031 + constify_type(type);
111032 + return;
111033 + }
111034 +
111035 + if (cinfo.has_fptr_field && !cinfo.has_writable_field) {
111036 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
111037 + error("'do_const' attribute used on type %qT that is constified", type);
111038 + return;
111039 + }
111040 + constify_type(type);
111041 + return;
111042 + }
111043 +
111044 + deconstify_type(type);
111045 + TYPE_CONSTIFY_VISITED(type) = 1;
111046 +}
111047 +
111048 +static void check_global_variables(void *event_data, void *data)
111049 +{
111050 +#if BUILDING_GCC_VERSION >= 4009
111051 + varpool_node *node;
111052 +#else
111053 + struct varpool_node *node;
111054 +#endif
111055 +
111056 + FOR_EACH_VARIABLE(node) {
111057 + tree var = NODE_DECL(node);
111058 + tree type = TREE_TYPE(var);
111059 +
111060 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
111061 + continue;
111062 +
111063 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
111064 + continue;
111065 +
111066 + if (!TYPE_CONSTIFY_VISITED(type))
111067 + continue;
111068 +
111069 + if (DECL_EXTERNAL(var))
111070 + continue;
111071 +
111072 + if (DECL_INITIAL(var))
111073 + continue;
111074 +
111075 + // this works around a gcc bug/feature where uninitialized globals
111076 + // are moved into the .bss section regardless of any constification
111077 + DECL_INITIAL(var) = build_constructor(type, NULL);
111078 +// inform(DECL_SOURCE_LOCATION(var), "constified variable %qE moved into .rodata", var);
111079 + }
111080 +}
111081 +
111082 +static unsigned int check_local_variables(void)
111083 +{
111084 + unsigned int ret = 0;
111085 + tree var;
111086 +
111087 + unsigned int i;
111088 +
111089 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
111090 + tree type = TREE_TYPE(var);
111091 +
111092 + gcc_assert(DECL_P(var));
111093 + if (is_global_var(var))
111094 + continue;
111095 +
111096 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
111097 + continue;
111098 +
111099 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
111100 + continue;
111101 +
111102 + if (!TYPE_CONSTIFY_VISITED(type))
111103 + continue;
111104 +
111105 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
111106 + ret = 1;
111107 + }
111108 + return ret;
111109 +}
111110 +
111111 +#if BUILDING_GCC_VERSION >= 4009
111112 +static const struct pass_data check_local_variables_pass_data = {
111113 +#else
111114 +static struct gimple_opt_pass check_local_variables_pass = {
111115 + .pass = {
111116 +#endif
111117 + .type = GIMPLE_PASS,
111118 + .name = "check_local_variables",
111119 +#if BUILDING_GCC_VERSION >= 4008
111120 + .optinfo_flags = OPTGROUP_NONE,
111121 +#endif
111122 +#if BUILDING_GCC_VERSION >= 4009
111123 + .has_gate = false,
111124 + .has_execute = true,
111125 +#else
111126 + .gate = NULL,
111127 + .execute = check_local_variables,
111128 + .sub = NULL,
111129 + .next = NULL,
111130 + .static_pass_number = 0,
111131 +#endif
111132 + .tv_id = TV_NONE,
111133 + .properties_required = 0,
111134 + .properties_provided = 0,
111135 + .properties_destroyed = 0,
111136 + .todo_flags_start = 0,
111137 + .todo_flags_finish = 0
111138 +#if BUILDING_GCC_VERSION < 4009
111139 + }
111140 +#endif
111141 +};
111142 +
111143 +#if BUILDING_GCC_VERSION >= 4009
111144 +namespace {
111145 +class check_local_variables_pass : public gimple_opt_pass {
111146 +public:
111147 + check_local_variables_pass() : gimple_opt_pass(check_local_variables_pass_data, g) {}
111148 + unsigned int execute() { return check_local_variables(); }
111149 +};
111150 +}
111151 +
111152 +static opt_pass *make_check_local_variables_pass(void)
111153 +{
111154 + return new check_local_variables_pass();
111155 +}
111156 +#else
111157 +static struct opt_pass *make_check_local_variables_pass(void)
111158 +{
111159 + return &check_local_variables_pass.pass;
111160 +}
111161 +#endif
111162 +
111163 +static struct {
111164 + const char *name;
111165 + const char *asm_op;
111166 +} sections[] = {
111167 + {".init.rodata", "\t.section\t.init.rodata,\"a\""},
111168 + {".ref.rodata", "\t.section\t.ref.rodata,\"a\""},
111169 + {".devinit.rodata", "\t.section\t.devinit.rodata,\"a\""},
111170 + {".devexit.rodata", "\t.section\t.devexit.rodata,\"a\""},
111171 + {".cpuinit.rodata", "\t.section\t.cpuinit.rodata,\"a\""},
111172 + {".cpuexit.rodata", "\t.section\t.cpuexit.rodata,\"a\""},
111173 + {".meminit.rodata", "\t.section\t.meminit.rodata,\"a\""},
111174 + {".memexit.rodata", "\t.section\t.memexit.rodata,\"a\""},
111175 + {".data..read_only", "\t.section\t.data..read_only,\"a\""},
111176 +};
111177 +
111178 +static unsigned int (*old_section_type_flags)(tree decl, const char *name, int reloc);
111179 +
111180 +static unsigned int constify_section_type_flags(tree decl, const char *name, int reloc)
111181 +{
111182 + size_t i;
111183 +
111184 + for (i = 0; i < ARRAY_SIZE(sections); i++)
111185 + if (!strcmp(sections[i].name, name))
111186 + return 0;
111187 + return old_section_type_flags(decl, name, reloc);
111188 +}
111189 +
111190 +static void constify_start_unit(void *gcc_data, void *user_data)
111191 +{
111192 +// size_t i;
111193 +
111194 +// for (i = 0; i < ARRAY_SIZE(sections); i++)
111195 +// sections[i].section = get_unnamed_section(0, output_section_asm_op, sections[i].asm_op);
111196 +// sections[i].section = get_section(sections[i].name, 0, NULL);
111197 +
111198 + old_section_type_flags = targetm.section_type_flags;
111199 + targetm.section_type_flags = constify_section_type_flags;
111200 +}
111201 +
111202 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
111203 +{
111204 + const char * const plugin_name = plugin_info->base_name;
111205 + const int argc = plugin_info->argc;
111206 + const struct plugin_argument * const argv = plugin_info->argv;
111207 + int i;
111208 + bool constify = true;
111209 +
111210 + struct register_pass_info check_local_variables_pass_info;
111211 +
111212 + check_local_variables_pass_info.pass = make_check_local_variables_pass();
111213 + check_local_variables_pass_info.reference_pass_name = "ssa";
111214 + check_local_variables_pass_info.ref_pass_instance_number = 1;
111215 + check_local_variables_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
111216 +
111217 + if (!plugin_default_version_check(version, &gcc_version)) {
111218 + error(G_("incompatible gcc/plugin versions"));
111219 + return 1;
111220 + }
111221 +
111222 + for (i = 0; i < argc; ++i) {
111223 + if (!(strcmp(argv[i].key, "no-constify"))) {
111224 + constify = false;
111225 + continue;
111226 + }
111227 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
111228 + }
111229 +
111230 + if (strcmp(lang_hooks.name, "GNU C")) {
111231 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
111232 + constify = false;
111233 + }
111234 +
111235 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
111236 + if (constify) {
111237 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
111238 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
111239 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &check_local_variables_pass_info);
111240 + register_callback(plugin_name, PLUGIN_START_UNIT, constify_start_unit, NULL);
111241 + }
111242 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
111243 +
111244 + return 0;
111245 +}
111246 diff --git a/tools/gcc/gcc-common.h b/tools/gcc/gcc-common.h
111247 new file mode 100644
111248 index 0000000..e90c205
111249 --- /dev/null
111250 +++ b/tools/gcc/gcc-common.h
111251 @@ -0,0 +1,295 @@
111252 +#ifndef GCC_COMMON_H_INCLUDED
111253 +#define GCC_COMMON_H_INCLUDED
111254 +
111255 +#include "plugin.h"
111256 +#include "bversion.h"
111257 +#include "plugin-version.h"
111258 +#include "config.h"
111259 +#include "system.h"
111260 +#include "coretypes.h"
111261 +#include "tm.h"
111262 +#include "line-map.h"
111263 +#include "input.h"
111264 +#include "tree.h"
111265 +
111266 +#include "tree-inline.h"
111267 +#include "version.h"
111268 +#include "rtl.h"
111269 +#include "tm_p.h"
111270 +#include "flags.h"
111271 +//#include "insn-attr.h"
111272 +//#include "insn-config.h"
111273 +//#include "insn-flags.h"
111274 +#include "hard-reg-set.h"
111275 +//#include "recog.h"
111276 +#include "output.h"
111277 +#include "except.h"
111278 +#include "function.h"
111279 +#include "toplev.h"
111280 +//#include "expr.h"
111281 +#include "basic-block.h"
111282 +#include "intl.h"
111283 +#include "ggc.h"
111284 +//#include "regs.h"
111285 +#include "timevar.h"
111286 +
111287 +#include "params.h"
111288 +#include "pointer-set.h"
111289 +#include "emit-rtl.h"
111290 +//#include "reload.h"
111291 +//#include "ira.h"
111292 +//#include "dwarf2asm.h"
111293 +#include "debug.h"
111294 +#include "target.h"
111295 +#include "langhooks.h"
111296 +#include "cfgloop.h"
111297 +//#include "hosthooks.h"
111298 +#include "cgraph.h"
111299 +#include "opts.h"
111300 +//#include "coverage.h"
111301 +//#include "value-prof.h"
111302 +
111303 +#if BUILDING_GCC_VERSION >= 4007
111304 +#include "tree-pretty-print.h"
111305 +#include "gimple-pretty-print.h"
111306 +#include "c-tree.h"
111307 +//#include "alloc-pool.h"
111308 +#endif
111309 +
111310 +#if BUILDING_GCC_VERSION <= 4008
111311 +#include "tree-flow.h"
111312 +#else
111313 +#include "tree-cfgcleanup.h"
111314 +#endif
111315 +
111316 +#include "diagnostic.h"
111317 +//#include "tree-diagnostic.h"
111318 +#include "tree-dump.h"
111319 +#include "tree-pass.h"
111320 +//#include "df.h"
111321 +#include "predict.h"
111322 +#include "ipa-utils.h"
111323 +
111324 +#if BUILDING_GCC_VERSION >= 4009
111325 +#include "varasm.h"
111326 +#include "stor-layout.h"
111327 +#include "internal-fn.h"
111328 +#include "gimple-expr.h"
111329 +//#include "diagnostic-color.h"
111330 +#include "context.h"
111331 +#include "tree-ssa-alias.h"
111332 +#include "stringpool.h"
111333 +#include "tree-ssanames.h"
111334 +#include "print-tree.h"
111335 +#include "tree-eh.h"
111336 +#include "stmt.h"
111337 +#endif
111338 +
111339 +#include "gimple.h"
111340 +
111341 +#if BUILDING_GCC_VERSION >= 4009
111342 +#include "tree-ssa-operands.h"
111343 +#include "tree-phinodes.h"
111344 +#include "tree-cfg.h"
111345 +#include "gimple-iterator.h"
111346 +#include "gimple-ssa.h"
111347 +#include "ssa-iterators.h"
111348 +#endif
111349 +
111350 +//#include "lto/lto.h"
111351 +//#include "data-streamer.h"
111352 +//#include "lto-compress.h"
111353 +
111354 +//#include "expr.h" where are you...
111355 +extern rtx emit_move_insn(rtx x, rtx y);
111356 +
111357 +// missing from basic_block.h...
111358 +extern void debug_dominance_info(enum cdi_direction dir);
111359 +extern void debug_dominance_tree(enum cdi_direction dir, basic_block root);
111360 +
111361 +#define __unused __attribute__((__unused__))
111362 +
111363 +#define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
111364 +#define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
111365 +#define TYPE_NAME_POINTER(node) IDENTIFIER_POINTER(TYPE_NAME(node))
111366 +#define TYPE_NAME_LENGTH(node) IDENTIFIER_LENGTH(TYPE_NAME(node))
111367 +
111368 +#if BUILDING_GCC_VERSION == 4005
111369 +#define FOR_EACH_LOCAL_DECL(FUN, I, D) for (tree vars = (FUN)->local_decls; vars && (D = TREE_VALUE(vars)); vars = TREE_CHAIN(vars), I)
111370 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
111371 +#define FOR_EACH_VEC_ELT(T, V, I, P) for (I = 0; VEC_iterate(T, (V), (I), (P)); ++(I))
111372 +#define TODO_rebuild_cgraph_edges 0
111373 +
111374 +static inline bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
111375 +{
111376 + tree fndecl;
111377 +
111378 + if (!is_gimple_call(stmt))
111379 + return false;
111380 + fndecl = gimple_call_fndecl(stmt);
111381 + if (!fndecl || DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
111382 + return false;
111383 +// print_node(stderr, "pax", fndecl, 4);
111384 + return DECL_FUNCTION_CODE(fndecl) == code;
111385 +}
111386 +
111387 +static inline bool is_simple_builtin(tree decl)
111388 +{
111389 + if (decl && DECL_BUILT_IN_CLASS(decl) != BUILT_IN_NORMAL)
111390 + return false;
111391 +
111392 + switch (DECL_FUNCTION_CODE(decl)) {
111393 + /* Builtins that expand to constants. */
111394 + case BUILT_IN_CONSTANT_P:
111395 + case BUILT_IN_EXPECT:
111396 + case BUILT_IN_OBJECT_SIZE:
111397 + case BUILT_IN_UNREACHABLE:
111398 + /* Simple register moves or loads from stack. */
111399 + case BUILT_IN_RETURN_ADDRESS:
111400 + case BUILT_IN_EXTRACT_RETURN_ADDR:
111401 + case BUILT_IN_FROB_RETURN_ADDR:
111402 + case BUILT_IN_RETURN:
111403 + case BUILT_IN_AGGREGATE_INCOMING_ADDRESS:
111404 + case BUILT_IN_FRAME_ADDRESS:
111405 + case BUILT_IN_VA_END:
111406 + case BUILT_IN_STACK_SAVE:
111407 + case BUILT_IN_STACK_RESTORE:
111408 + /* Exception state returns or moves registers around. */
111409 + case BUILT_IN_EH_FILTER:
111410 + case BUILT_IN_EH_POINTER:
111411 + case BUILT_IN_EH_COPY_VALUES:
111412 + return true;
111413 +
111414 + default:
111415 + return false;
111416 + }
111417 +}
111418 +#endif
111419 +
111420 +#if BUILDING_GCC_VERSION <= 4006
111421 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
111422 +#define C_DECL_REGISTER(EXP) DECL_LANG_FLAG_4(EXP)
111423 +
111424 +// should come from c-tree.h if only it were installed for gcc 4.5...
111425 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
111426 +
111427 +#define get_random_seed(noinit) ({ \
111428 + unsigned HOST_WIDE_INT seed; \
111429 + sscanf(get_random_seed(noinit), "%" HOST_WIDE_INT_PRINT "x", &seed); \
111430 + seed * seed; })
111431 +
111432 +static inline bool gimple_clobber_p(gimple s)
111433 +{
111434 + return false;
111435 +}
111436 +
111437 +static inline tree builtin_decl_implicit(enum built_in_function fncode)
111438 +{
111439 + return implicit_built_in_decls[fncode];
111440 +}
111441 +
111442 +static inline struct cgraph_node *cgraph_get_create_node(tree decl)
111443 +{
111444 + struct cgraph_node *node = cgraph_get_node(decl);
111445 +
111446 + return node ? node : cgraph_node(decl);
111447 +}
111448 +
111449 +static inline bool cgraph_function_with_gimple_body_p(struct cgraph_node *node)
111450 +{
111451 + return node->analyzed && !node->thunk.thunk_p && !node->alias;
111452 +}
111453 +
111454 +static inline struct cgraph_node *cgraph_first_function_with_gimple_body(void)
111455 +{
111456 + struct cgraph_node *node;
111457 +
111458 + for (node = cgraph_nodes; node; node = node->next)
111459 + if (cgraph_function_with_gimple_body_p(node))
111460 + return node;
111461 + return NULL;
111462 +}
111463 +
111464 +static inline struct cgraph_node *cgraph_next_function_with_gimple_body(struct cgraph_node *node)
111465 +{
111466 + for (node = node->next; node; node = node->next)
111467 + if (cgraph_function_with_gimple_body_p(node))
111468 + return node;
111469 + return NULL;
111470 +}
111471 +
111472 +#define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
111473 + for ((node) = cgraph_first_function_with_gimple_body(); (node); \
111474 + (node) = cgraph_next_function_with_gimple_body(node))
111475 +#endif
111476 +
111477 +#if BUILDING_GCC_VERSION == 4006
111478 +extern void debug_gimple_stmt(gimple);
111479 +extern void debug_gimple_seq(gimple_seq);
111480 +extern void print_gimple_seq(FILE *, gimple_seq, int, int);
111481 +extern void print_gimple_stmt(FILE *, gimple, int, int);
111482 +extern void print_gimple_expr(FILE *, gimple, int, int);
111483 +extern void dump_gimple_stmt(pretty_printer *, gimple, int, int);
111484 +#endif
111485 +
111486 +#if BUILDING_GCC_VERSION <= 4007
111487 +#define FOR_EACH_VARIABLE(node) for (node = varpool_nodes; node; node = node->next)
111488 +#define PROP_loops 0
111489 +
111490 +static inline int bb_loop_depth(const_basic_block bb)
111491 +{
111492 + return bb->loop_father ? loop_depth(bb->loop_father) : 0;
111493 +}
111494 +
111495 +static inline bool gimple_store_p(gimple gs)
111496 +{
111497 + tree lhs = gimple_get_lhs(gs);
111498 + return lhs && !is_gimple_reg(lhs);
111499 +}
111500 +#endif
111501 +
111502 +#if BUILDING_GCC_VERSION >= 4007
111503 +#define cgraph_create_edge(caller, callee, call_stmt, count, freq, nest) \
111504 + cgraph_create_edge((caller), (callee), (call_stmt), (count), (freq))
111505 +#define cgraph_create_edge_including_clones(caller, callee, old_call_stmt, call_stmt, count, freq, nest, reason) \
111506 + cgraph_create_edge_including_clones((caller), (callee), (old_call_stmt), (call_stmt), (count), (freq), (reason))
111507 +#endif
111508 +
111509 +#if BUILDING_GCC_VERSION <= 4008
111510 +#define ENTRY_BLOCK_PTR_FOR_FN(FN) ENTRY_BLOCK_PTR_FOR_FUNCTION(FN)
111511 +#define EXIT_BLOCK_PTR_FOR_FN(FN) EXIT_BLOCK_PTR_FOR_FUNCTION(FN)
111512 +#define basic_block_info_for_fn(FN) ((FN)->cfg->x_basic_block_info)
111513 +#define n_basic_blocks_for_fn(FN) ((FN)->cfg->x_n_basic_blocks)
111514 +#define n_edges_for_fn(FN) ((FN)->cfg->x_n_edges)
111515 +#define last_basic_block_for_fn(FN) ((FN)->cfg->x_last_basic_block)
111516 +#define label_to_block_map_for_fn(FN) ((FN)->cfg->x_label_to_block_map)
111517 +#define profile_status_for_fn(FN) ((FN)->cfg->x_profile_status)
111518 +
111519 +static inline const char *get_tree_code_name(enum tree_code code)
111520 +{
111521 + gcc_assert(code < MAX_TREE_CODES);
111522 + return tree_code_name[code];
111523 +}
111524 +
111525 +#define ipa_remove_stmt_references(cnode, stmt)
111526 +#endif
111527 +
111528 +#if BUILDING_GCC_VERSION == 4008
111529 +#define NODE_DECL(node) node->symbol.decl
111530 +#else
111531 +#define NODE_DECL(node) node->decl
111532 +#endif
111533 +
111534 +#if BUILDING_GCC_VERSION >= 4008
111535 +#define add_referenced_var(var)
111536 +#define mark_sym_for_renaming(var)
111537 +#define varpool_mark_needed_node(node)
111538 +#define TODO_dump_func 0
111539 +#define TODO_dump_cgraph 0
111540 +#endif
111541 +
111542 +#if BUILDING_GCC_VERSION >= 4009
111543 +#define TODO_ggc_collect 0
111544 +#endif
111545 +
111546 +#endif
111547 diff --git a/tools/gcc/gen-random-seed.sh b/tools/gcc/gen-random-seed.sh
111548 new file mode 100644
111549 index 0000000..7514850
111550 --- /dev/null
111551 +++ b/tools/gcc/gen-random-seed.sh
111552 @@ -0,0 +1,8 @@
111553 +#!/bin/sh
111554 +
111555 +if [ ! -f "$1" ]; then
111556 + SEED=`od -A n -t x8 -N 32 /dev/urandom | tr -d ' \n'`
111557 + echo "const char *randstruct_seed = \"$SEED\";" > "$1"
111558 + HASH=`echo -n "$SEED" | sha256sum | cut -d" " -f1 | tr -d ' \n'`
111559 + echo "#define RANDSTRUCT_HASHED_SEED \"$HASH\"" > "$2"
111560 +fi
111561 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
111562 new file mode 100644
111563 index 0000000..d81c094
111564 --- /dev/null
111565 +++ b/tools/gcc/kallocstat_plugin.c
111566 @@ -0,0 +1,183 @@
111567 +/*
111568 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
111569 + * Licensed under the GPL v2
111570 + *
111571 + * Note: the choice of the license means that the compilation process is
111572 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
111573 + * but for the kernel it doesn't matter since it doesn't link against
111574 + * any of the gcc libraries
111575 + *
111576 + * gcc plugin to find the distribution of k*alloc sizes
111577 + *
111578 + * TODO:
111579 + *
111580 + * BUGS:
111581 + * - none known
111582 + */
111583 +
111584 +#include "gcc-common.h"
111585 +
111586 +int plugin_is_GPL_compatible;
111587 +
111588 +static struct plugin_info kallocstat_plugin_info = {
111589 + .version = "201401260140",
111590 + .help = NULL
111591 +};
111592 +
111593 +static const char * const kalloc_functions[] = {
111594 + "__kmalloc",
111595 + "kmalloc",
111596 + "kmalloc_large",
111597 + "kmalloc_node",
111598 + "kmalloc_order",
111599 + "kmalloc_order_trace",
111600 + "kmalloc_slab",
111601 + "kzalloc",
111602 + "kzalloc_node",
111603 +};
111604 +
111605 +static bool is_kalloc(const char *fnname)
111606 +{
111607 + size_t i;
111608 +
111609 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
111610 + if (!strcmp(fnname, kalloc_functions[i]))
111611 + return true;
111612 + return false;
111613 +}
111614 +
111615 +static unsigned int execute_kallocstat(void)
111616 +{
111617 + basic_block bb;
111618 +
111619 + // 1. loop through BBs and GIMPLE statements
111620 + FOR_EACH_BB_FN(bb, cfun) {
111621 + gimple_stmt_iterator gsi;
111622 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
111623 + // gimple match:
111624 + tree fndecl, size;
111625 + gimple stmt;
111626 + const char *fnname;
111627 +
111628 + // is it a call
111629 + stmt = gsi_stmt(gsi);
111630 + if (!is_gimple_call(stmt))
111631 + continue;
111632 + fndecl = gimple_call_fndecl(stmt);
111633 + if (fndecl == NULL_TREE)
111634 + continue;
111635 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
111636 + continue;
111637 +
111638 + // is it a call to k*alloc
111639 + fnname = DECL_NAME_POINTER(fndecl);
111640 + if (!is_kalloc(fnname))
111641 + continue;
111642 +
111643 + // is the size arg const or the result of a simple const assignment
111644 + size = gimple_call_arg(stmt, 0);
111645 + while (true) {
111646 + expanded_location xloc;
111647 + size_t size_val;
111648 +
111649 + if (TREE_CONSTANT(size)) {
111650 + xloc = expand_location(gimple_location(stmt));
111651 + if (!xloc.file)
111652 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
111653 + size_val = TREE_INT_CST_LOW(size);
111654 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
111655 + break;
111656 + }
111657 +
111658 + if (TREE_CODE(size) != SSA_NAME)
111659 + break;
111660 + stmt = SSA_NAME_DEF_STMT(size);
111661 +//debug_gimple_stmt(stmt);
111662 +//debug_tree(size);
111663 + if (!stmt || !is_gimple_assign(stmt))
111664 + break;
111665 + if (gimple_num_ops(stmt) != 2)
111666 + break;
111667 + size = gimple_assign_rhs1(stmt);
111668 + }
111669 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
111670 +//debug_tree(gimple_call_fn(call_stmt));
111671 +//print_node(stderr, "pax", fndecl, 4);
111672 + }
111673 + }
111674 +
111675 + return 0;
111676 +}
111677 +
111678 +#if BUILDING_GCC_VERSION >= 4009
111679 +static const struct pass_data kallocstat_pass_data = {
111680 +#else
111681 +static struct gimple_opt_pass kallocstat_pass = {
111682 + .pass = {
111683 +#endif
111684 + .type = GIMPLE_PASS,
111685 + .name = "kallocstat",
111686 +#if BUILDING_GCC_VERSION >= 4008
111687 + .optinfo_flags = OPTGROUP_NONE,
111688 +#endif
111689 +#if BUILDING_GCC_VERSION >= 4009
111690 + .has_gate = false,
111691 + .has_execute = true,
111692 +#else
111693 + .gate = NULL,
111694 + .execute = execute_kallocstat,
111695 + .sub = NULL,
111696 + .next = NULL,
111697 + .static_pass_number = 0,
111698 +#endif
111699 + .tv_id = TV_NONE,
111700 + .properties_required = 0,
111701 + .properties_provided = 0,
111702 + .properties_destroyed = 0,
111703 + .todo_flags_start = 0,
111704 + .todo_flags_finish = 0
111705 +#if BUILDING_GCC_VERSION < 4009
111706 + }
111707 +#endif
111708 +};
111709 +
111710 +#if BUILDING_GCC_VERSION >= 4009
111711 +namespace {
111712 +class kallocstat_pass : public gimple_opt_pass {
111713 +public:
111714 + kallocstat_pass() : gimple_opt_pass(kallocstat_pass_data, g) {}
111715 + unsigned int execute() { return execute_kallocstat(); }
111716 +};
111717 +}
111718 +
111719 +static opt_pass *make_kallocstat_pass(void)
111720 +{
111721 + return new kallocstat_pass();
111722 +}
111723 +#else
111724 +static struct opt_pass *make_kallocstat_pass(void)
111725 +{
111726 + return &kallocstat_pass.pass;
111727 +}
111728 +#endif
111729 +
111730 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
111731 +{
111732 + const char * const plugin_name = plugin_info->base_name;
111733 + struct register_pass_info kallocstat_pass_info;
111734 +
111735 + kallocstat_pass_info.pass = make_kallocstat_pass();
111736 + kallocstat_pass_info.reference_pass_name = "ssa";
111737 + kallocstat_pass_info.ref_pass_instance_number = 1;
111738 + kallocstat_pass_info.pos_op = PASS_POS_INSERT_AFTER;
111739 +
111740 + if (!plugin_default_version_check(version, &gcc_version)) {
111741 + error(G_("incompatible gcc/plugin versions"));
111742 + return 1;
111743 + }
111744 +
111745 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
111746 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
111747 +
111748 + return 0;
111749 +}
111750 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
111751 new file mode 100644
111752 index 0000000..89f256d
111753 --- /dev/null
111754 +++ b/tools/gcc/kernexec_plugin.c
111755 @@ -0,0 +1,522 @@
111756 +/*
111757 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
111758 + * Licensed under the GPL v2
111759 + *
111760 + * Note: the choice of the license means that the compilation process is
111761 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
111762 + * but for the kernel it doesn't matter since it doesn't link against
111763 + * any of the gcc libraries
111764 + *
111765 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
111766 + *
111767 + * TODO:
111768 + *
111769 + * BUGS:
111770 + * - none known
111771 + */
111772 +
111773 +#include "gcc-common.h"
111774 +
111775 +int plugin_is_GPL_compatible;
111776 +
111777 +static struct plugin_info kernexec_plugin_info = {
111778 + .version = "201401260140",
111779 + .help = "method=[bts|or]\tinstrumentation method\n"
111780 +};
111781 +
111782 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
111783 +static void (*kernexec_instrument_retaddr)(rtx);
111784 +
111785 +/*
111786 + * add special KERNEXEC instrumentation: reload %r12 after it has been clobbered
111787 + */
111788 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
111789 +{
111790 + gimple asm_movabs_stmt;
111791 +
111792 + // build asm volatile("movabs $0x8000000000000000, %%r12\n\t" : : : );
111793 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r12\n\t", NULL, NULL, NULL, NULL);
111794 + gimple_asm_set_volatile(asm_movabs_stmt, true);
111795 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
111796 + update_stmt(asm_movabs_stmt);
111797 +}
111798 +
111799 +/*
111800 + * find all asm() stmts that clobber r12 and add a reload of r12
111801 + */
111802 +static unsigned int execute_kernexec_reload(void)
111803 +{
111804 + basic_block bb;
111805 +
111806 + // 1. loop through BBs and GIMPLE statements
111807 + FOR_EACH_BB_FN(bb, cfun) {
111808 + gimple_stmt_iterator gsi;
111809 +
111810 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
111811 + // gimple match: __asm__ ("" : : : "r12");
111812 + gimple asm_stmt;
111813 + size_t nclobbers;
111814 +
111815 + // is it an asm ...
111816 + asm_stmt = gsi_stmt(gsi);
111817 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
111818 + continue;
111819 +
111820 + // ... clobbering r12
111821 + nclobbers = gimple_asm_nclobbers(asm_stmt);
111822 + while (nclobbers--) {
111823 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
111824 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r12"))
111825 + continue;
111826 + kernexec_reload_fptr_mask(&gsi);
111827 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
111828 + break;
111829 + }
111830 + }
111831 + }
111832 +
111833 + return 0;
111834 +}
111835 +
111836 +/*
111837 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
111838 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
111839 + */
111840 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
111841 +{
111842 + gimple assign_intptr, assign_new_fptr, call_stmt;
111843 + tree intptr, orptr, old_fptr, new_fptr, kernexec_mask;
111844 +
111845 + call_stmt = gsi_stmt(*gsi);
111846 + old_fptr = gimple_call_fn(call_stmt);
111847 +
111848 + // create temporary unsigned long variable used for bitops and cast fptr to it
111849 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
111850 + add_referenced_var(intptr);
111851 + intptr = make_ssa_name(intptr, NULL);
111852 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
111853 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
111854 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
111855 + update_stmt(assign_intptr);
111856 +
111857 + // apply logical or to temporary unsigned long and bitmask
111858 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
111859 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
111860 + orptr = fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask);
111861 + intptr = make_ssa_name(SSA_NAME_VAR(intptr), NULL);
111862 + assign_intptr = gimple_build_assign(intptr, orptr);
111863 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
111864 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
111865 + update_stmt(assign_intptr);
111866 +
111867 + // cast temporary unsigned long back to a temporary fptr variable
111868 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
111869 + add_referenced_var(new_fptr);
111870 + new_fptr = make_ssa_name(new_fptr, NULL);
111871 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
111872 + SSA_NAME_DEF_STMT(new_fptr) = assign_new_fptr;
111873 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
111874 + update_stmt(assign_new_fptr);
111875 +
111876 + // replace call stmt fn with the new fptr
111877 + gimple_call_set_fn(call_stmt, new_fptr);
111878 + update_stmt(call_stmt);
111879 +}
111880 +
111881 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
111882 +{
111883 + gimple asm_or_stmt, call_stmt;
111884 + tree old_fptr, new_fptr, input, output;
111885 +#if BUILDING_GCC_VERSION <= 4007
111886 + VEC(tree, gc) *inputs = NULL;
111887 + VEC(tree, gc) *outputs = NULL;
111888 +#else
111889 + vec<tree, va_gc> *inputs = NULL;
111890 + vec<tree, va_gc> *outputs = NULL;
111891 +#endif
111892 +
111893 + call_stmt = gsi_stmt(*gsi);
111894 + old_fptr = gimple_call_fn(call_stmt);
111895 +
111896 + // create temporary fptr variable
111897 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
111898 + add_referenced_var(new_fptr);
111899 + new_fptr = make_ssa_name(new_fptr, NULL);
111900 +
111901 + // build asm volatile("orq %%r12, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
111902 + input = build_tree_list(NULL_TREE, build_string(1, "0"));
111903 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
111904 + output = build_tree_list(NULL_TREE, build_string(2, "=r"));
111905 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
111906 +#if BUILDING_GCC_VERSION <= 4007
111907 + VEC_safe_push(tree, gc, inputs, input);
111908 + VEC_safe_push(tree, gc, outputs, output);
111909 +#else
111910 + vec_safe_push(inputs, input);
111911 + vec_safe_push(outputs, output);
111912 +#endif
111913 + asm_or_stmt = gimple_build_asm_vec("orq %%r12, %0\n\t", inputs, outputs, NULL, NULL);
111914 + SSA_NAME_DEF_STMT(new_fptr) = asm_or_stmt;
111915 + gimple_asm_set_volatile(asm_or_stmt, true);
111916 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
111917 + update_stmt(asm_or_stmt);
111918 +
111919 + // replace call stmt fn with the new fptr
111920 + gimple_call_set_fn(call_stmt, new_fptr);
111921 + update_stmt(call_stmt);
111922 +}
111923 +
111924 +/*
111925 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
111926 + */
111927 +static unsigned int execute_kernexec_fptr(void)
111928 +{
111929 + basic_block bb;
111930 +
111931 + // 1. loop through BBs and GIMPLE statements
111932 + FOR_EACH_BB_FN(bb, cfun) {
111933 + gimple_stmt_iterator gsi;
111934 +
111935 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
111936 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
111937 + tree fn;
111938 + gimple call_stmt;
111939 +
111940 + // is it a call ...
111941 + call_stmt = gsi_stmt(gsi);
111942 + if (!is_gimple_call(call_stmt))
111943 + continue;
111944 + fn = gimple_call_fn(call_stmt);
111945 + if (TREE_CODE(fn) == ADDR_EXPR)
111946 + continue;
111947 + if (TREE_CODE(fn) != SSA_NAME)
111948 + gcc_unreachable();
111949 +
111950 + // ... through a function pointer
111951 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
111952 + fn = SSA_NAME_VAR(fn);
111953 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
111954 + debug_tree(fn);
111955 + gcc_unreachable();
111956 + }
111957 + }
111958 + fn = TREE_TYPE(fn);
111959 + if (TREE_CODE(fn) != POINTER_TYPE)
111960 + continue;
111961 + fn = TREE_TYPE(fn);
111962 + if (TREE_CODE(fn) != FUNCTION_TYPE)
111963 + continue;
111964 +
111965 + kernexec_instrument_fptr(&gsi);
111966 +
111967 +//debug_tree(gimple_call_fn(call_stmt));
111968 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
111969 + }
111970 + }
111971 +
111972 + return 0;
111973 +}
111974 +
111975 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
111976 +static void kernexec_instrument_retaddr_bts(rtx insn)
111977 +{
111978 + rtx btsq;
111979 + rtvec argvec, constraintvec, labelvec;
111980 + int line;
111981 +
111982 + // create asm volatile("btsq $63,(%%rsp)":::)
111983 + argvec = rtvec_alloc(0);
111984 + constraintvec = rtvec_alloc(0);
111985 + labelvec = rtvec_alloc(0);
111986 + line = expand_location(RTL_LOCATION(insn)).line;
111987 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
111988 + MEM_VOLATILE_P(btsq) = 1;
111989 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
111990 + emit_insn_before(btsq, insn);
111991 +}
111992 +
111993 +// add special KERNEXEC instrumentation: orq %r12,(%rsp) just before retn
111994 +static void kernexec_instrument_retaddr_or(rtx insn)
111995 +{
111996 + rtx orq;
111997 + rtvec argvec, constraintvec, labelvec;
111998 + int line;
111999 +
112000 + // create asm volatile("orq %%r12,(%%rsp)":::)
112001 + argvec = rtvec_alloc(0);
112002 + constraintvec = rtvec_alloc(0);
112003 + labelvec = rtvec_alloc(0);
112004 + line = expand_location(RTL_LOCATION(insn)).line;
112005 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r12,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
112006 + MEM_VOLATILE_P(orq) = 1;
112007 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
112008 + emit_insn_before(orq, insn);
112009 +}
112010 +
112011 +/*
112012 + * find all asm level function returns and forcibly set the highest bit of the return address
112013 + */
112014 +static unsigned int execute_kernexec_retaddr(void)
112015 +{
112016 + rtx insn;
112017 +
112018 +// if (stack_realign_drap)
112019 +// inform(DECL_SOURCE_LOCATION(current_function_decl), "drap detected in %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
112020 +
112021 + // 1. find function returns
112022 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
112023 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
112024 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
112025 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
112026 + rtx body;
112027 +
112028 + // is it a retn
112029 + if (!JUMP_P(insn))
112030 + continue;
112031 + body = PATTERN(insn);
112032 + if (GET_CODE(body) == PARALLEL)
112033 + body = XVECEXP(body, 0, 0);
112034 + if (!ANY_RETURN_P(body))
112035 + continue;
112036 + kernexec_instrument_retaddr(insn);
112037 + }
112038 +
112039 +// print_simple_rtl(stderr, get_insns());
112040 +// print_rtl(stderr, get_insns());
112041 +
112042 + return 0;
112043 +}
112044 +
112045 +static bool kernexec_cmodel_check(void)
112046 +{
112047 + tree section;
112048 +
112049 + if (ix86_cmodel != CM_KERNEL)
112050 + return false;
112051 +
112052 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
112053 + if (!section || !TREE_VALUE(section))
112054 + return true;
112055 +
112056 + section = TREE_VALUE(TREE_VALUE(section));
112057 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
112058 + return true;
112059 +
112060 + return false;
112061 +}
112062 +
112063 +#if BUILDING_GCC_VERSION >= 4009
112064 +static const struct pass_data kernexec_reload_pass_data = {
112065 +#else
112066 +static struct gimple_opt_pass kernexec_reload_pass = {
112067 + .pass = {
112068 +#endif
112069 + .type = GIMPLE_PASS,
112070 + .name = "kernexec_reload",
112071 +#if BUILDING_GCC_VERSION >= 4008
112072 + .optinfo_flags = OPTGROUP_NONE,
112073 +#endif
112074 +#if BUILDING_GCC_VERSION >= 4009
112075 + .has_gate = true,
112076 + .has_execute = true,
112077 +#else
112078 + .gate = kernexec_cmodel_check,
112079 + .execute = execute_kernexec_reload,
112080 + .sub = NULL,
112081 + .next = NULL,
112082 + .static_pass_number = 0,
112083 +#endif
112084 + .tv_id = TV_NONE,
112085 + .properties_required = 0,
112086 + .properties_provided = 0,
112087 + .properties_destroyed = 0,
112088 + .todo_flags_start = 0,
112089 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
112090 +#if BUILDING_GCC_VERSION < 4009
112091 + }
112092 +#endif
112093 +};
112094 +
112095 +#if BUILDING_GCC_VERSION >= 4009
112096 +static const struct pass_data kernexec_fptr_pass_data = {
112097 +#else
112098 +static struct gimple_opt_pass kernexec_fptr_pass = {
112099 + .pass = {
112100 +#endif
112101 + .type = GIMPLE_PASS,
112102 + .name = "kernexec_fptr",
112103 +#if BUILDING_GCC_VERSION >= 4008
112104 + .optinfo_flags = OPTGROUP_NONE,
112105 +#endif
112106 +#if BUILDING_GCC_VERSION >= 4009
112107 + .has_gate = true,
112108 + .has_execute = true,
112109 +#else
112110 + .gate = kernexec_cmodel_check,
112111 + .execute = execute_kernexec_fptr,
112112 + .sub = NULL,
112113 + .next = NULL,
112114 + .static_pass_number = 0,
112115 +#endif
112116 + .tv_id = TV_NONE,
112117 + .properties_required = 0,
112118 + .properties_provided = 0,
112119 + .properties_destroyed = 0,
112120 + .todo_flags_start = 0,
112121 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
112122 +#if BUILDING_GCC_VERSION < 4009
112123 + }
112124 +#endif
112125 +};
112126 +
112127 +#if BUILDING_GCC_VERSION >= 4009
112128 +static const struct pass_data kernexec_retaddr_pass_data = {
112129 +#else
112130 +static struct rtl_opt_pass kernexec_retaddr_pass = {
112131 + .pass = {
112132 +#endif
112133 + .type = RTL_PASS,
112134 + .name = "kernexec_retaddr",
112135 +#if BUILDING_GCC_VERSION >= 4008
112136 + .optinfo_flags = OPTGROUP_NONE,
112137 +#endif
112138 +#if BUILDING_GCC_VERSION >= 4009
112139 + .has_gate = true,
112140 + .has_execute = true,
112141 +#else
112142 + .gate = kernexec_cmodel_check,
112143 + .execute = execute_kernexec_retaddr,
112144 + .sub = NULL,
112145 + .next = NULL,
112146 + .static_pass_number = 0,
112147 +#endif
112148 + .tv_id = TV_NONE,
112149 + .properties_required = 0,
112150 + .properties_provided = 0,
112151 + .properties_destroyed = 0,
112152 + .todo_flags_start = 0,
112153 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
112154 +#if BUILDING_GCC_VERSION < 4009
112155 + }
112156 +#endif
112157 +};
112158 +
112159 +#if BUILDING_GCC_VERSION >= 4009
112160 +namespace {
112161 +class kernexec_reload_pass : public gimple_opt_pass {
112162 +public:
112163 + kernexec_reload_pass() : gimple_opt_pass(kernexec_reload_pass_data, g) {}
112164 + bool gate() { return kernexec_cmodel_check(); }
112165 + unsigned int execute() { return execute_kernexec_reload(); }
112166 +};
112167 +
112168 +class kernexec_fptr_pass : public gimple_opt_pass {
112169 +public:
112170 + kernexec_fptr_pass() : gimple_opt_pass(kernexec_fptr_pass_data, g) {}
112171 + bool gate() { return kernexec_cmodel_check(); }
112172 + unsigned int execute() { return execute_kernexec_fptr(); }
112173 +};
112174 +
112175 +class kernexec_retaddr_pass : public rtl_opt_pass {
112176 +public:
112177 + kernexec_retaddr_pass() : rtl_opt_pass(kernexec_retaddr_pass_data, g) {}
112178 + bool gate() { return kernexec_cmodel_check(); }
112179 + unsigned int execute() { return execute_kernexec_retaddr(); }
112180 +};
112181 +}
112182 +
112183 +static opt_pass *make_kernexec_reload_pass(void)
112184 +{
112185 + return new kernexec_reload_pass();
112186 +}
112187 +
112188 +static opt_pass *make_kernexec_fptr_pass(void)
112189 +{
112190 + return new kernexec_fptr_pass();
112191 +}
112192 +
112193 +static opt_pass *make_kernexec_retaddr_pass(void)
112194 +{
112195 + return new kernexec_retaddr_pass();
112196 +}
112197 +#else
112198 +static struct opt_pass *make_kernexec_reload_pass(void)
112199 +{
112200 + return &kernexec_reload_pass.pass;
112201 +}
112202 +
112203 +static struct opt_pass *make_kernexec_fptr_pass(void)
112204 +{
112205 + return &kernexec_fptr_pass.pass;
112206 +}
112207 +
112208 +static struct opt_pass *make_kernexec_retaddr_pass(void)
112209 +{
112210 + return &kernexec_retaddr_pass.pass;
112211 +}
112212 +#endif
112213 +
112214 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
112215 +{
112216 + const char * const plugin_name = plugin_info->base_name;
112217 + const int argc = plugin_info->argc;
112218 + const struct plugin_argument * const argv = plugin_info->argv;
112219 + int i;
112220 + struct register_pass_info kernexec_reload_pass_info;
112221 + struct register_pass_info kernexec_fptr_pass_info;
112222 + struct register_pass_info kernexec_retaddr_pass_info;
112223 +
112224 + kernexec_reload_pass_info.pass = make_kernexec_reload_pass();
112225 + kernexec_reload_pass_info.reference_pass_name = "ssa";
112226 + kernexec_reload_pass_info.ref_pass_instance_number = 1;
112227 + kernexec_reload_pass_info.pos_op = PASS_POS_INSERT_AFTER;
112228 +
112229 + kernexec_fptr_pass_info.pass = make_kernexec_fptr_pass();
112230 + kernexec_fptr_pass_info.reference_pass_name = "ssa";
112231 + kernexec_fptr_pass_info.ref_pass_instance_number = 1;
112232 + kernexec_fptr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
112233 +
112234 + kernexec_retaddr_pass_info.pass = make_kernexec_retaddr_pass();
112235 + kernexec_retaddr_pass_info.reference_pass_name = "pro_and_epilogue";
112236 + kernexec_retaddr_pass_info.ref_pass_instance_number = 1;
112237 + kernexec_retaddr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
112238 +
112239 + if (!plugin_default_version_check(version, &gcc_version)) {
112240 + error(G_("incompatible gcc/plugin versions"));
112241 + return 1;
112242 + }
112243 +
112244 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
112245 +
112246 + if (TARGET_64BIT == 0)
112247 + return 0;
112248 +
112249 + for (i = 0; i < argc; ++i) {
112250 + if (!strcmp(argv[i].key, "method")) {
112251 + if (!argv[i].value) {
112252 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
112253 + continue;
112254 + }
112255 + if (!strcmp(argv[i].value, "bts")) {
112256 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
112257 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
112258 + } else if (!strcmp(argv[i].value, "or")) {
112259 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
112260 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
112261 + fix_register("r12", 1, 1);
112262 + } else
112263 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
112264 + continue;
112265 + }
112266 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
112267 + }
112268 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
112269 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
112270 +
112271 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
112272 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
112273 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
112274 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
112275 +
112276 + return 0;
112277 +}
112278 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
112279 new file mode 100644
112280 index 0000000..e48b323
112281 --- /dev/null
112282 +++ b/tools/gcc/latent_entropy_plugin.c
112283 @@ -0,0 +1,466 @@
112284 +/*
112285 + * Copyright 2012-2014 by the PaX Team <pageexec@freemail.hu>
112286 + * Licensed under the GPL v2
112287 + *
112288 + * Note: the choice of the license means that the compilation process is
112289 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
112290 + * but for the kernel it doesn't matter since it doesn't link against
112291 + * any of the gcc libraries
112292 + *
112293 + * gcc plugin to help generate a little bit of entropy from program state,
112294 + * used throughout the uptime of the kernel
112295 + *
112296 + * TODO:
112297 + * - add ipa pass to identify not explicitly marked candidate functions
112298 + * - mix in more program state (function arguments/return values, loop variables, etc)
112299 + * - more instrumentation control via attribute parameters
112300 + *
112301 + * BUGS:
112302 + * - LTO needs -flto-partition=none for now
112303 + */
112304 +
112305 +#include "gcc-common.h"
112306 +
112307 +int plugin_is_GPL_compatible;
112308 +
112309 +static tree latent_entropy_decl;
112310 +
112311 +static struct plugin_info latent_entropy_plugin_info = {
112312 + .version = "201409101820",
112313 + .help = NULL
112314 +};
112315 +
112316 +static unsigned HOST_WIDE_INT seed;
112317 +static unsigned HOST_WIDE_INT get_random_const(void)
112318 +{
112319 + unsigned int i;
112320 + unsigned HOST_WIDE_INT ret = 0;
112321 +
112322 + for (i = 0; i < 8 * sizeof ret; i++) {
112323 + ret = (ret << 1) | (seed & 1);
112324 + seed >>= 1;
112325 + if (ret & 1)
112326 + seed ^= 0xD800000000000000ULL;
112327 + }
112328 +
112329 + return ret;
112330 +}
112331 +
112332 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
112333 +{
112334 + tree type;
112335 + unsigned long long mask;
112336 +#if BUILDING_GCC_VERSION <= 4007
112337 + VEC(constructor_elt, gc) *vals;
112338 +#else
112339 + vec<constructor_elt, va_gc> *vals;
112340 +#endif
112341 +
112342 + switch (TREE_CODE(*node)) {
112343 + default:
112344 + *no_add_attrs = true;
112345 + error("%qE attribute only applies to functions and variables", name);
112346 + break;
112347 +
112348 + case VAR_DECL:
112349 + if (DECL_INITIAL(*node)) {
112350 + *no_add_attrs = true;
112351 + error("variable %qD with %qE attribute must not be initialized", *node, name);
112352 + break;
112353 + }
112354 +
112355 + if (!TREE_STATIC(*node)) {
112356 + *no_add_attrs = true;
112357 + error("variable %qD with %qE attribute must not be local", *node, name);
112358 + break;
112359 + }
112360 +
112361 + type = TREE_TYPE(*node);
112362 + switch (TREE_CODE(type)) {
112363 + default:
112364 + *no_add_attrs = true;
112365 + 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);
112366 + break;
112367 +
112368 + case RECORD_TYPE: {
112369 + tree field;
112370 + unsigned int nelt = 0;
112371 +
112372 + for (field = TYPE_FIELDS(type); field; nelt++, field = TREE_CHAIN(field)) {
112373 + tree fieldtype;
112374 +
112375 + fieldtype = TREE_TYPE(field);
112376 + if (TREE_CODE(fieldtype) != INTEGER_TYPE) {
112377 + *no_add_attrs = true;
112378 + error("structure variable %qD with %qE attribute has a non-integer field %qE", *node, name, field);
112379 + break;
112380 + }
112381 + }
112382 +
112383 + if (field)
112384 + break;
112385 +
112386 +#if BUILDING_GCC_VERSION <= 4007
112387 + vals = VEC_alloc(constructor_elt, gc, nelt);
112388 +#else
112389 + vec_alloc(vals, nelt);
112390 +#endif
112391 +
112392 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
112393 + tree fieldtype;
112394 +
112395 + fieldtype = TREE_TYPE(field);
112396 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(fieldtype)) - 1);
112397 + mask = 2 * (mask - 1) + 1;
112398 +
112399 + if (TYPE_UNSIGNED(fieldtype))
112400 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cstu(fieldtype, mask & get_random_const()));
112401 + else
112402 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cst(fieldtype, mask & get_random_const()));
112403 + }
112404 +
112405 + DECL_INITIAL(*node) = build_constructor(type, vals);
112406 +//debug_tree(DECL_INITIAL(*node));
112407 + break;
112408 + }
112409 +
112410 + case INTEGER_TYPE:
112411 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(type)) - 1);
112412 + mask = 2 * (mask - 1) + 1;
112413 +
112414 + if (TYPE_UNSIGNED(type))
112415 + DECL_INITIAL(*node) = build_int_cstu(type, mask & get_random_const());
112416 + else
112417 + DECL_INITIAL(*node) = build_int_cst(type, mask & get_random_const());
112418 + break;
112419 +
112420 + case ARRAY_TYPE: {
112421 + tree elt_type, array_size, elt_size;
112422 + unsigned int i, nelt;
112423 +
112424 + elt_type = TREE_TYPE(type);
112425 + elt_size = TYPE_SIZE_UNIT(TREE_TYPE(type));
112426 + array_size = TYPE_SIZE_UNIT(type);
112427 +
112428 + if (TREE_CODE(elt_type) != INTEGER_TYPE || !array_size || TREE_CODE(array_size) != INTEGER_CST) {
112429 + *no_add_attrs = true;
112430 + error("array variable %qD with %qE attribute must be a fixed length integer array type", *node, name);
112431 + break;
112432 + }
112433 +
112434 + nelt = TREE_INT_CST_LOW(array_size) / TREE_INT_CST_LOW(elt_size);
112435 +#if BUILDING_GCC_VERSION <= 4007
112436 + vals = VEC_alloc(constructor_elt, gc, nelt);
112437 +#else
112438 + vec_alloc(vals, nelt);
112439 +#endif
112440 +
112441 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(elt_type)) - 1);
112442 + mask = 2 * (mask - 1) + 1;
112443 +
112444 + for (i = 0; i < nelt; i++)
112445 + if (TYPE_UNSIGNED(elt_type))
112446 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cstu(elt_type, mask & get_random_const()));
112447 + else
112448 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cst(elt_type, mask & get_random_const()));
112449 +
112450 + DECL_INITIAL(*node) = build_constructor(type, vals);
112451 +//debug_tree(DECL_INITIAL(*node));
112452 + break;
112453 + }
112454 + }
112455 + break;
112456 +
112457 + case FUNCTION_DECL:
112458 + break;
112459 + }
112460 +
112461 + return NULL_TREE;
112462 +}
112463 +
112464 +static struct attribute_spec latent_entropy_attr = {
112465 + .name = "latent_entropy",
112466 + .min_length = 0,
112467 + .max_length = 0,
112468 + .decl_required = true,
112469 + .type_required = false,
112470 + .function_type_required = false,
112471 + .handler = handle_latent_entropy_attribute,
112472 +#if BUILDING_GCC_VERSION >= 4007
112473 + .affects_type_identity = false
112474 +#endif
112475 +};
112476 +
112477 +static void register_attributes(void *event_data, void *data)
112478 +{
112479 + register_attribute(&latent_entropy_attr);
112480 +}
112481 +
112482 +static bool gate_latent_entropy(void)
112483 +{
112484 + // don't bother with noreturn functions for now
112485 + if (TREE_THIS_VOLATILE(current_function_decl))
112486 + return false;
112487 +
112488 + // gcc-4.5 doesn't discover some trivial noreturn functions
112489 + if (EDGE_COUNT(EXIT_BLOCK_PTR_FOR_FN(cfun)->preds) == 0)
112490 + return false;
112491 +
112492 + return lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl)) != NULL_TREE;
112493 +}
112494 +
112495 +static enum tree_code get_op(tree *rhs)
112496 +{
112497 + static enum tree_code op;
112498 + unsigned HOST_WIDE_INT random_const;
112499 +
112500 + random_const = get_random_const();
112501 +
112502 + switch (op) {
112503 + case BIT_XOR_EXPR:
112504 + op = PLUS_EXPR;
112505 + break;
112506 +
112507 + case PLUS_EXPR:
112508 + if (rhs) {
112509 + op = LROTATE_EXPR;
112510 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
112511 + break;
112512 + }
112513 +
112514 + case LROTATE_EXPR:
112515 + default:
112516 + op = BIT_XOR_EXPR;
112517 + break;
112518 + }
112519 + if (rhs)
112520 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
112521 + return op;
112522 +}
112523 +
112524 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
112525 +{
112526 + gimple_stmt_iterator gsi;
112527 + gimple assign;
112528 + tree addxorrol, rhs;
112529 + enum tree_code op;
112530 +
112531 + op = get_op(&rhs);
112532 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
112533 + assign = gimple_build_assign(local_entropy, addxorrol);
112534 + gsi = gsi_after_labels(bb);
112535 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
112536 + update_stmt(assign);
112537 +//debug_bb(bb);
112538 +}
112539 +
112540 +static void perturb_latent_entropy(basic_block bb, tree rhs)
112541 +{
112542 + gimple_stmt_iterator gsi;
112543 + gimple assign;
112544 + tree addxorrol, temp;
112545 +
112546 + // 1. create temporary copy of latent_entropy
112547 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
112548 + add_referenced_var(temp);
112549 +
112550 + // 2. read...
112551 + temp = make_ssa_name(temp, NULL);
112552 + assign = gimple_build_assign(temp, latent_entropy_decl);
112553 + SSA_NAME_DEF_STMT(temp) = assign;
112554 + add_referenced_var(latent_entropy_decl);
112555 + gsi = gsi_after_labels(bb);
112556 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
112557 + update_stmt(assign);
112558 +
112559 + // 3. ...modify...
112560 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
112561 + temp = make_ssa_name(SSA_NAME_VAR(temp), NULL);
112562 + assign = gimple_build_assign(temp, addxorrol);
112563 + SSA_NAME_DEF_STMT(temp) = assign;
112564 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
112565 + update_stmt(assign);
112566 +
112567 + // 4. ...write latent_entropy
112568 + assign = gimple_build_assign(latent_entropy_decl, temp);
112569 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
112570 + update_stmt(assign);
112571 +}
112572 +
112573 +static unsigned int execute_latent_entropy(void)
112574 +{
112575 + basic_block bb;
112576 + gimple assign;
112577 + gimple_stmt_iterator gsi;
112578 + tree local_entropy;
112579 +
112580 + if (!latent_entropy_decl) {
112581 +#if BUILDING_GCC_VERSION >= 4009
112582 + varpool_node *node;
112583 +#else
112584 + struct varpool_node *node;
112585 +#endif
112586 +
112587 + FOR_EACH_VARIABLE(node) {
112588 + tree var = NODE_DECL(node);
112589 +
112590 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
112591 + continue;
112592 + latent_entropy_decl = var;
112593 +// debug_tree(var);
112594 + break;
112595 + }
112596 + if (!latent_entropy_decl) {
112597 +// debug_tree(current_function_decl);
112598 + return 0;
112599 + }
112600 + }
112601 +
112602 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
112603 +
112604 + // 1. create local entropy variable
112605 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
112606 + add_referenced_var(local_entropy);
112607 + mark_sym_for_renaming(local_entropy);
112608 +
112609 + // 2. initialize local entropy variable
112610 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
112611 + if (dom_info_available_p(CDI_DOMINATORS))
112612 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
112613 + gsi = gsi_start_bb(bb);
112614 +
112615 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
112616 +// gimple_set_location(assign, loc);
112617 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
112618 + update_stmt(assign);
112619 +//debug_bb(bb);
112620 + gcc_assert(single_succ_p(bb));
112621 + bb = single_succ(bb);
112622 +
112623 + // 3. instrument each BB with an operation on the local entropy variable
112624 + while (bb != EXIT_BLOCK_PTR_FOR_FN(cfun)) {
112625 + perturb_local_entropy(bb, local_entropy);
112626 +//debug_bb(bb);
112627 + bb = bb->next_bb;
112628 + };
112629 +
112630 + // 4. mix local entropy into the global entropy variable
112631 + gcc_assert(single_pred_p(EXIT_BLOCK_PTR_FOR_FN(cfun)));
112632 + perturb_latent_entropy(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)), local_entropy);
112633 +//debug_bb(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)));
112634 + return 0;
112635 +}
112636 +
112637 +static void latent_entropy_start_unit(void *gcc_data, void *user_data)
112638 +{
112639 + tree latent_entropy_type;
112640 +
112641 + seed = get_random_seed(false);
112642 +
112643 + if (in_lto_p)
112644 + return;
112645 +
112646 + // extern volatile u64 latent_entropy
112647 + gcc_assert(TYPE_PRECISION(long_long_unsigned_type_node) == 64);
112648 + latent_entropy_type = build_qualified_type(long_long_unsigned_type_node, TYPE_QUALS(long_long_unsigned_type_node) | TYPE_QUAL_VOLATILE);
112649 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), latent_entropy_type);
112650 +
112651 + TREE_STATIC(latent_entropy_decl) = 1;
112652 + TREE_PUBLIC(latent_entropy_decl) = 1;
112653 + TREE_USED(latent_entropy_decl) = 1;
112654 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
112655 + DECL_EXTERNAL(latent_entropy_decl) = 1;
112656 + DECL_ARTIFICIAL(latent_entropy_decl) = 1;
112657 + lang_hooks.decls.pushdecl(latent_entropy_decl);
112658 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
112659 +// varpool_finalize_decl(latent_entropy_decl);
112660 +// varpool_mark_needed_node(latent_entropy_decl);
112661 +}
112662 +
112663 +#if BUILDING_GCC_VERSION >= 4009
112664 +static const struct pass_data latent_entropy_pass_data = {
112665 +#else
112666 +static struct gimple_opt_pass latent_entropy_pass = {
112667 + .pass = {
112668 +#endif
112669 + .type = GIMPLE_PASS,
112670 + .name = "latent_entropy",
112671 +#if BUILDING_GCC_VERSION >= 4008
112672 + .optinfo_flags = OPTGROUP_NONE,
112673 +#endif
112674 +#if BUILDING_GCC_VERSION >= 4009
112675 + .has_gate = true,
112676 + .has_execute = true,
112677 +#else
112678 + .gate = gate_latent_entropy,
112679 + .execute = execute_latent_entropy,
112680 + .sub = NULL,
112681 + .next = NULL,
112682 + .static_pass_number = 0,
112683 +#endif
112684 + .tv_id = TV_NONE,
112685 + .properties_required = PROP_gimple_leh | PROP_cfg,
112686 + .properties_provided = 0,
112687 + .properties_destroyed = 0,
112688 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
112689 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
112690 +#if BUILDING_GCC_VERSION < 4009
112691 + }
112692 +#endif
112693 +};
112694 +
112695 +#if BUILDING_GCC_VERSION >= 4009
112696 +namespace {
112697 +class latent_entropy_pass : public gimple_opt_pass {
112698 +public:
112699 + latent_entropy_pass() : gimple_opt_pass(latent_entropy_pass_data, g) {}
112700 + bool gate() { return gate_latent_entropy(); }
112701 + unsigned int execute() { return execute_latent_entropy(); }
112702 +};
112703 +}
112704 +
112705 +static opt_pass *make_latent_entropy_pass(void)
112706 +{
112707 + return new latent_entropy_pass();
112708 +}
112709 +#else
112710 +static struct opt_pass *make_latent_entropy_pass(void)
112711 +{
112712 + return &latent_entropy_pass.pass;
112713 +}
112714 +#endif
112715 +
112716 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
112717 +{
112718 + const char * const plugin_name = plugin_info->base_name;
112719 + struct register_pass_info latent_entropy_pass_info;
112720 +
112721 + latent_entropy_pass_info.pass = make_latent_entropy_pass();
112722 + latent_entropy_pass_info.reference_pass_name = "optimized";
112723 + latent_entropy_pass_info.ref_pass_instance_number = 1;
112724 + latent_entropy_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
112725 + static const struct ggc_root_tab gt_ggc_r_gt_latent_entropy[] = {
112726 + {
112727 + .base = &latent_entropy_decl,
112728 + .nelt = 1,
112729 + .stride = sizeof(latent_entropy_decl),
112730 + .cb = &gt_ggc_mx_tree_node,
112731 + .pchw = &gt_pch_nx_tree_node
112732 + },
112733 + LAST_GGC_ROOT_TAB
112734 + };
112735 +
112736 + if (!plugin_default_version_check(version, &gcc_version)) {
112737 + error(G_("incompatible gcc/plugin versions"));
112738 + return 1;
112739 + }
112740 +
112741 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
112742 + register_callback(plugin_name, PLUGIN_START_UNIT, &latent_entropy_start_unit, NULL);
112743 + if (!in_lto_p)
112744 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_latent_entropy);
112745 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
112746 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
112747 +
112748 + return 0;
112749 +}
112750 diff --git a/tools/gcc/randomize_layout_plugin.c b/tools/gcc/randomize_layout_plugin.c
112751 new file mode 100644
112752 index 0000000..a5cb46b
112753 --- /dev/null
112754 +++ b/tools/gcc/randomize_layout_plugin.c
112755 @@ -0,0 +1,915 @@
112756 +/*
112757 + * Copyright 2014 by Open Source Security, Inc., Brad Spengler <spender@grsecurity.net>
112758 + * and PaX Team <pageexec@freemail.hu>
112759 + * Licensed under the GPL v2
112760 + *
112761 + * Usage:
112762 + * $ # for 4.5/4.6/C based 4.7
112763 + * $ 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
112764 + * $ # for C++ based 4.7/4.8+
112765 + * $ 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
112766 + * $ gcc -fplugin=./randomize_layout_plugin.so test.c -O2
112767 + */
112768 +
112769 +#include "gcc-common.h"
112770 +#include "randomize_layout_seed.h"
112771 +
112772 +#if BUILDING_GCC_MAJOR < 4 || BUILDING_GCC_MINOR < 6 || (BUILDING_GCC_MINOR == 6 && BUILDING_GCC_PATCHLEVEL < 4)
112773 +#error "The RANDSTRUCT plugin requires GCC 4.6.4 or newer."
112774 +#endif
112775 +
112776 +#define ORIG_TYPE_NAME(node) \
112777 + (TYPE_NAME(TYPE_MAIN_VARIANT(node)) != NULL_TREE ? ((const unsigned char *)IDENTIFIER_POINTER(TYPE_NAME(TYPE_MAIN_VARIANT(node)))) : (const unsigned char *)"anonymous")
112778 +
112779 +int plugin_is_GPL_compatible;
112780 +
112781 +static int performance_mode;
112782 +
112783 +static struct plugin_info randomize_layout_plugin_info = {
112784 + .version = "201402201816",
112785 + .help = "disable\t\t\tdo not activate plugin\n"
112786 + "performance-mode\tenable cacheline-aware layout randomization\n"
112787 +};
112788 +
112789 +/* from old Linux dcache.h */
112790 +static inline unsigned long
112791 +partial_name_hash(unsigned long c, unsigned long prevhash)
112792 +{
112793 + return (prevhash + (c << 4) + (c >> 4)) * 11;
112794 +}
112795 +static inline unsigned int
112796 +name_hash(const unsigned char *name)
112797 +{
112798 + unsigned long hash = 0;
112799 + unsigned int len = strlen((const char *)name);
112800 + while (len--)
112801 + hash = partial_name_hash(*name++, hash);
112802 + return (unsigned int)hash;
112803 +}
112804 +
112805 +static tree handle_randomize_layout_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
112806 +{
112807 + tree type;
112808 +
112809 + *no_add_attrs = true;
112810 + if (TREE_CODE(*node) == FUNCTION_DECL) {
112811 + error("%qE attribute does not apply to functions (%qF)", name, *node);
112812 + return NULL_TREE;
112813 + }
112814 +
112815 + if (TREE_CODE(*node) == PARM_DECL) {
112816 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
112817 + return NULL_TREE;
112818 + }
112819 +
112820 + if (TREE_CODE(*node) == VAR_DECL) {
112821 + error("%qE attribute does not apply to variables (%qD)", name, *node);
112822 + return NULL_TREE;
112823 + }
112824 +
112825 + if (TYPE_P(*node)) {
112826 + type = *node;
112827 + } else {
112828 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
112829 + type = TREE_TYPE(*node);
112830 + }
112831 +
112832 + if (TREE_CODE(type) != RECORD_TYPE) {
112833 + error("%qE attribute used on %qT applies to struct types only", name, type);
112834 + return NULL_TREE;
112835 + }
112836 +
112837 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
112838 + error("%qE attribute is already applied to the type %qT", name, type);
112839 + return NULL_TREE;
112840 + }
112841 +
112842 + *no_add_attrs = false;
112843 +
112844 + return NULL_TREE;
112845 +}
112846 +
112847 +/* set on complete types that we don't need to inspect further at all */
112848 +static tree handle_randomize_considered_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
112849 +{
112850 + *no_add_attrs = false;
112851 + return NULL_TREE;
112852 +}
112853 +
112854 +/*
112855 + * set on types that we've performed a shuffle on, to prevent re-shuffling
112856 + * this does not preclude us from inspecting its fields for potential shuffles
112857 + */
112858 +static tree handle_randomize_performed_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
112859 +{
112860 + *no_add_attrs = false;
112861 + return NULL_TREE;
112862 +}
112863 +
112864 +/*
112865 + * 64bit variant of Bob Jenkins' public domain PRNG
112866 + * 256 bits of internal state
112867 + */
112868 +
112869 +typedef unsigned long long u64;
112870 +
112871 +typedef struct ranctx { u64 a; u64 b; u64 c; u64 d; } ranctx;
112872 +
112873 +#define rot(x,k) (((x)<<(k))|((x)>>(64-(k))))
112874 +static u64 ranval(ranctx *x) {
112875 + u64 e = x->a - rot(x->b, 7);
112876 + x->a = x->b ^ rot(x->c, 13);
112877 + x->b = x->c + rot(x->d, 37);
112878 + x->c = x->d + e;
112879 + x->d = e + x->a;
112880 + return x->d;
112881 +}
112882 +
112883 +static void raninit(ranctx *x, u64 *seed) {
112884 + int i;
112885 +
112886 + x->a = seed[0];
112887 + x->b = seed[1];
112888 + x->c = seed[2];
112889 + x->d = seed[3];
112890 +
112891 + for (i=0; i < 30; ++i)
112892 + (void)ranval(x);
112893 +}
112894 +
112895 +static u64 shuffle_seed[4];
112896 +
112897 +struct partition_group {
112898 + tree tree_start;
112899 + unsigned long start;
112900 + unsigned long length;
112901 +};
112902 +
112903 +static void partition_struct(tree *fields, unsigned long length, struct partition_group *size_groups, unsigned long *num_groups)
112904 +{
112905 + unsigned long i;
112906 + unsigned long accum_size = 0;
112907 + unsigned long accum_length = 0;
112908 + unsigned long group_idx = 0;
112909 +
112910 + gcc_assert(length < INT_MAX);
112911 +
112912 + memset(size_groups, 0, sizeof(struct partition_group) * length);
112913 +
112914 + for (i = 0; i < length; i++) {
112915 + if (size_groups[group_idx].tree_start == NULL_TREE) {
112916 + size_groups[group_idx].tree_start = fields[i];
112917 + size_groups[group_idx].start = i;
112918 + accum_length = 0;
112919 + accum_size = 0;
112920 + }
112921 + accum_size += (unsigned long)int_size_in_bytes(TREE_TYPE(fields[i]));
112922 + accum_length++;
112923 + if (accum_size >= 64) {
112924 + size_groups[group_idx].length = accum_length;
112925 + accum_length = 0;
112926 + group_idx++;
112927 + }
112928 + }
112929 +
112930 + if (size_groups[group_idx].tree_start != NULL_TREE &&
112931 + !size_groups[group_idx].length) {
112932 + size_groups[group_idx].length = accum_length;
112933 + group_idx++;
112934 + }
112935 +
112936 + *num_groups = group_idx;
112937 +}
112938 +
112939 +static void performance_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
112940 +{
112941 + unsigned long i, x;
112942 + struct partition_group size_group[length];
112943 + unsigned long num_groups = 0;
112944 + unsigned long randnum;
112945 +
112946 + partition_struct(newtree, length, (struct partition_group *)&size_group, &num_groups);
112947 + for (i = num_groups - 1; i > 0; i--) {
112948 + struct partition_group tmp;
112949 + randnum = ranval(prng_state) % (i + 1);
112950 + tmp = size_group[i];
112951 + size_group[i] = size_group[randnum];
112952 + size_group[randnum] = tmp;
112953 + }
112954 +
112955 + for (x = 0; x < num_groups; x++) {
112956 + for (i = size_group[x].start + size_group[x].length - 1; i > size_group[x].start; i--) {
112957 + tree tmp;
112958 + if (DECL_BIT_FIELD_TYPE(newtree[i]))
112959 + continue;
112960 + randnum = ranval(prng_state) % (i + 1);
112961 + // we could handle this case differently if desired
112962 + if (DECL_BIT_FIELD_TYPE(newtree[randnum]))
112963 + continue;
112964 + tmp = newtree[i];
112965 + newtree[i] = newtree[randnum];
112966 + newtree[randnum] = tmp;
112967 + }
112968 + }
112969 +}
112970 +
112971 +static void full_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
112972 +{
112973 + unsigned long i, randnum;
112974 +
112975 + for (i = length - 1; i > 0; i--) {
112976 + tree tmp;
112977 + randnum = ranval(prng_state) % (i + 1);
112978 + tmp = newtree[i];
112979 + newtree[i] = newtree[randnum];
112980 + newtree[randnum] = tmp;
112981 + }
112982 +}
112983 +
112984 +/* modern in-place Fisher-Yates shuffle */
112985 +static void shuffle(const_tree type, tree *newtree, unsigned long length)
112986 +{
112987 + unsigned long i;
112988 + u64 seed[4];
112989 + ranctx prng_state;
112990 + const unsigned char *structname;
112991 +
112992 + if (length == 0)
112993 + return;
112994 +
112995 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
112996 +
112997 + structname = ORIG_TYPE_NAME(type);
112998 +
112999 +#ifdef __DEBUG_PLUGIN
113000 + fprintf(stderr, "Shuffling struct %s %p\n", (const char *)structname, type);
113001 +#ifdef __DEBUG_VERBOSE
113002 + debug_tree((tree)type);
113003 +#endif
113004 +#endif
113005 +
113006 + for (i = 0; i < 4; i++) {
113007 + seed[i] = shuffle_seed[i];
113008 + seed[i] ^= name_hash(structname);
113009 + }
113010 +
113011 + raninit(&prng_state, (u64 *)&seed);
113012 +
113013 + if (performance_mode)
113014 + performance_shuffle(newtree, length, &prng_state);
113015 + else
113016 + full_shuffle(newtree, length, &prng_state);
113017 +}
113018 +
113019 +static bool is_flexible_array(const_tree field)
113020 +{
113021 + const_tree fieldtype;
113022 + const_tree typesize;
113023 + const_tree elemtype;
113024 + const_tree elemsize;
113025 +
113026 + fieldtype = TREE_TYPE(field);
113027 + typesize = TYPE_SIZE(fieldtype);
113028 +
113029 + if (TREE_CODE(fieldtype) != ARRAY_TYPE)
113030 + return false;
113031 +
113032 + elemtype = TREE_TYPE(fieldtype);
113033 + elemsize = TYPE_SIZE(elemtype);
113034 +
113035 + /* size of type is represented in bits */
113036 +
113037 + if (typesize == NULL_TREE && TYPE_DOMAIN(fieldtype) != NULL_TREE &&
113038 + TYPE_MAX_VALUE(TYPE_DOMAIN(fieldtype)) == NULL_TREE)
113039 + return true;
113040 +
113041 + if (typesize != NULL_TREE &&
113042 + (TREE_CONSTANT(typesize) && (!TREE_INT_CST_LOW(typesize) ||
113043 + TREE_INT_CST_LOW(typesize) == TREE_INT_CST_LOW(elemsize))))
113044 + return true;
113045 +
113046 + return false;
113047 +}
113048 +
113049 +static int relayout_struct(tree type)
113050 +{
113051 + unsigned long num_fields = (unsigned long)list_length(TYPE_FIELDS(type));
113052 + unsigned long shuffle_length = num_fields;
113053 + tree field;
113054 + tree newtree[num_fields];
113055 + unsigned long i;
113056 + tree list;
113057 + tree variant;
113058 + expanded_location xloc;
113059 +
113060 + if (TYPE_FIELDS(type) == NULL_TREE)
113061 + return 0;
113062 +
113063 + if (num_fields < 2)
113064 + return 0;
113065 +
113066 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
113067 +
113068 + gcc_assert(num_fields < INT_MAX);
113069 +
113070 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)) ||
113071 + lookup_attribute("no_randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))))
113072 + return 0;
113073 +
113074 + /* Workaround for 3rd-party VirtualBox source that we can't modify ourselves */
113075 + if (!strcmp((const char *)ORIG_TYPE_NAME(type), "INTNETTRUNKFACTORY") ||
113076 + !strcmp((const char *)ORIG_TYPE_NAME(type), "RAWPCIFACTORY"))
113077 + return 0;
113078 +
113079 + /* throw out any structs in uapi */
113080 + xloc = expand_location(DECL_SOURCE_LOCATION(TYPE_FIELDS(type)));
113081 +
113082 + if (strstr(xloc.file, "/uapi/"))
113083 + error(G_("attempted to randomize userland API struct %s"), ORIG_TYPE_NAME(type));
113084 +
113085 + for (field = TYPE_FIELDS(type), i = 0; field; field = TREE_CHAIN(field), i++) {
113086 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
113087 + newtree[i] = field;
113088 + }
113089 +
113090 + /*
113091 + * enforce that we don't randomize the layout of the last
113092 + * element of a struct if it's a 0 or 1-length array
113093 + * or a proper flexible array
113094 + */
113095 + if (is_flexible_array(newtree[num_fields - 1]))
113096 + shuffle_length--;
113097 +
113098 + shuffle(type, (tree *)newtree, shuffle_length);
113099 +
113100 + /*
113101 + * set up a bogus anonymous struct field designed to error out on unnamed struct initializers
113102 + * as gcc provides no other way to detect such code
113103 + */
113104 + list = make_node(FIELD_DECL);
113105 + TREE_CHAIN(list) = newtree[0];
113106 + TREE_TYPE(list) = void_type_node;
113107 + DECL_SIZE(list) = bitsize_zero_node;
113108 + DECL_NONADDRESSABLE_P(list) = 1;
113109 + DECL_FIELD_BIT_OFFSET(list) = bitsize_zero_node;
113110 + DECL_SIZE_UNIT(list) = size_zero_node;
113111 + DECL_FIELD_OFFSET(list) = size_zero_node;
113112 + // to satisfy the constify plugin
113113 + TREE_READONLY(list) = 1;
113114 +
113115 + for (i = 0; i < num_fields - 1; i++)
113116 + TREE_CHAIN(newtree[i]) = newtree[i+1];
113117 + TREE_CHAIN(newtree[num_fields - 1]) = NULL_TREE;
113118 +
113119 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
113120 + TYPE_FIELDS(variant) = list;
113121 + TYPE_ATTRIBUTES(variant) = copy_list(TYPE_ATTRIBUTES(variant));
113122 + TYPE_ATTRIBUTES(variant) = tree_cons(get_identifier("randomize_performed"), NULL_TREE, TYPE_ATTRIBUTES(variant));
113123 + // force a re-layout
113124 + TYPE_SIZE(variant) = NULL_TREE;
113125 + layout_type(variant);
113126 + }
113127 +
113128 + return 1;
113129 +}
113130 +
113131 +/* from constify plugin */
113132 +static const_tree get_field_type(const_tree field)
113133 +{
113134 + return strip_array_types(TREE_TYPE(field));
113135 +}
113136 +
113137 +/* from constify plugin */
113138 +static bool is_fptr(const_tree fieldtype)
113139 +{
113140 + if (TREE_CODE(fieldtype) != POINTER_TYPE)
113141 + return false;
113142 +
113143 + return TREE_CODE(TREE_TYPE(fieldtype)) == FUNCTION_TYPE;
113144 +}
113145 +
113146 +/* derived from constify plugin */
113147 +static int is_pure_ops_struct(const_tree node)
113148 +{
113149 + const_tree field;
113150 +
113151 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
113152 +
113153 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
113154 + const_tree fieldtype = get_field_type(field);
113155 + enum tree_code code = TREE_CODE(fieldtype);
113156 +
113157 + if (node == fieldtype)
113158 + continue;
113159 +
113160 + if (!is_fptr(fieldtype))
113161 + return 0;
113162 +
113163 + if (code != RECORD_TYPE && code != UNION_TYPE)
113164 + continue;
113165 +
113166 + if (!is_pure_ops_struct(fieldtype))
113167 + return 0;
113168 + }
113169 +
113170 + return 1;
113171 +}
113172 +
113173 +static void randomize_type(tree type)
113174 +{
113175 + tree variant;
113176 +
113177 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
113178 +
113179 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
113180 + return;
113181 +
113182 + if (lookup_attribute("randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))) || is_pure_ops_struct(type))
113183 + relayout_struct(type);
113184 +
113185 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
113186 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
113187 + TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("randomize_considered"), NULL_TREE, TYPE_ATTRIBUTES(type));
113188 + }
113189 +#ifdef __DEBUG_PLUGIN
113190 + fprintf(stderr, "Marking randomize_considered on struct %s\n", ORIG_TYPE_NAME(type));
113191 +#ifdef __DEBUG_VERBOSE
113192 + debug_tree(type);
113193 +#endif
113194 +#endif
113195 +}
113196 +
113197 +static void randomize_layout_finish_decl(void *event_data, void *data)
113198 +{
113199 + tree decl = (tree)event_data;
113200 + tree type;
113201 +
113202 + if (decl == NULL_TREE || decl == error_mark_node)
113203 + return;
113204 +
113205 + type = TREE_TYPE(decl);
113206 +
113207 + if (TREE_CODE(decl) != VAR_DECL)
113208 + return;
113209 +
113210 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
113211 + return;
113212 +
113213 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)))
113214 + return;
113215 +
113216 + relayout_decl(decl);
113217 +}
113218 +
113219 +static void finish_type(void *event_data, void *data)
113220 +{
113221 + tree type = (tree)event_data;
113222 +
113223 + if (type == NULL_TREE || type == error_mark_node)
113224 + return;
113225 +
113226 + if (TREE_CODE(type) != RECORD_TYPE)
113227 + return;
113228 +
113229 + if (TYPE_FIELDS(type) == NULL_TREE)
113230 + return;
113231 +
113232 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
113233 + return;
113234 +
113235 +#ifdef __DEBUG_PLUGIN
113236 + fprintf(stderr, "Calling randomize_type on %s\n", ORIG_TYPE_NAME(type));
113237 +#endif
113238 +#ifdef __DEBUG_VERBOSE
113239 + debug_tree(type);
113240 +#endif
113241 + randomize_type(type);
113242 +
113243 + return;
113244 +}
113245 +
113246 +static struct attribute_spec randomize_layout_attr = {
113247 + .name = "randomize_layout",
113248 + // related to args
113249 + .min_length = 0,
113250 + .max_length = 0,
113251 + .decl_required = false,
113252 + // need type declaration
113253 + .type_required = true,
113254 + .function_type_required = false,
113255 + .handler = handle_randomize_layout_attr,
113256 +#if BUILDING_GCC_VERSION >= 4007
113257 + .affects_type_identity = true
113258 +#endif
113259 +};
113260 +
113261 +static struct attribute_spec no_randomize_layout_attr = {
113262 + .name = "no_randomize_layout",
113263 + // related to args
113264 + .min_length = 0,
113265 + .max_length = 0,
113266 + .decl_required = false,
113267 + // need type declaration
113268 + .type_required = true,
113269 + .function_type_required = false,
113270 + .handler = handle_randomize_layout_attr,
113271 +#if BUILDING_GCC_VERSION >= 4007
113272 + .affects_type_identity = true
113273 +#endif
113274 +};
113275 +
113276 +static struct attribute_spec randomize_considered_attr = {
113277 + .name = "randomize_considered",
113278 + // related to args
113279 + .min_length = 0,
113280 + .max_length = 0,
113281 + .decl_required = false,
113282 + // need type declaration
113283 + .type_required = true,
113284 + .function_type_required = false,
113285 + .handler = handle_randomize_considered_attr,
113286 +#if BUILDING_GCC_VERSION >= 4007
113287 + .affects_type_identity = false
113288 +#endif
113289 +};
113290 +
113291 +static struct attribute_spec randomize_performed_attr = {
113292 + .name = "randomize_performed",
113293 + // related to args
113294 + .min_length = 0,
113295 + .max_length = 0,
113296 + .decl_required = false,
113297 + // need type declaration
113298 + .type_required = true,
113299 + .function_type_required = false,
113300 + .handler = handle_randomize_performed_attr,
113301 +#if BUILDING_GCC_VERSION >= 4007
113302 + .affects_type_identity = false
113303 +#endif
113304 +};
113305 +
113306 +static void register_attributes(void *event_data, void *data)
113307 +{
113308 + register_attribute(&randomize_layout_attr);
113309 + register_attribute(&no_randomize_layout_attr);
113310 + register_attribute(&randomize_considered_attr);
113311 + register_attribute(&randomize_performed_attr);
113312 +}
113313 +
113314 +static void check_bad_casts_in_constructor(tree var, tree init)
113315 +{
113316 + unsigned HOST_WIDE_INT idx;
113317 + tree field, val;
113318 + tree field_type, val_type;
113319 +
113320 + FOR_EACH_CONSTRUCTOR_ELT(CONSTRUCTOR_ELTS(init), idx, field, val) {
113321 + if (TREE_CODE(val) == CONSTRUCTOR) {
113322 + check_bad_casts_in_constructor(var, val);
113323 + continue;
113324 + }
113325 +
113326 + /* pipacs' plugin creates franken-arrays that differ from those produced by
113327 + normal code which all have valid 'field' trees. work around this */
113328 + if (field == NULL_TREE)
113329 + continue;
113330 + field_type = TREE_TYPE(field);
113331 + val_type = TREE_TYPE(val);
113332 +
113333 + if (TREE_CODE(field_type) != POINTER_TYPE || TREE_CODE(val_type) != POINTER_TYPE)
113334 + continue;
113335 +
113336 + if (field_type == val_type)
113337 + continue;
113338 +
113339 + field_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(field_type))));
113340 + val_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(val_type))));
113341 +
113342 + if (field_type == void_type_node)
113343 + continue;
113344 + if (field_type == val_type)
113345 + continue;
113346 + if (TREE_CODE(val_type) != RECORD_TYPE)
113347 + continue;
113348 +
113349 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(val_type)))
113350 + continue;
113351 + inform(DECL_SOURCE_LOCATION(var), "found mismatched struct pointer types: %qT and %qT\n", TYPE_MAIN_VARIANT(field_type), TYPE_MAIN_VARIANT(val_type));
113352 + }
113353 +}
113354 +
113355 +/* derived from the constify plugin */
113356 +static void check_global_variables(void *event_data, void *data)
113357 +{
113358 + struct varpool_node *node;
113359 + tree init;
113360 +
113361 + FOR_EACH_VARIABLE(node) {
113362 + tree var = NODE_DECL(node);
113363 + init = DECL_INITIAL(var);
113364 + if (init == NULL_TREE)
113365 + continue;
113366 +
113367 + if (TREE_CODE(init) != CONSTRUCTOR)
113368 + continue;
113369 +
113370 + check_bad_casts_in_constructor(var, init);
113371 + }
113372 +}
113373 +
113374 +static bool dominated_by_is_err(const_tree rhs, basic_block bb)
113375 +{
113376 + basic_block dom;
113377 + gimple dom_stmt;
113378 + gimple call_stmt;
113379 + const_tree dom_lhs;
113380 + const_tree poss_is_err_cond;
113381 + const_tree poss_is_err_func;
113382 + const_tree is_err_arg;
113383 +
113384 + dom = get_immediate_dominator(CDI_DOMINATORS, bb);
113385 + if (!dom)
113386 + return false;
113387 +
113388 + dom_stmt = last_stmt(dom);
113389 + if (!dom_stmt)
113390 + return false;
113391 +
113392 + if (gimple_code(dom_stmt) != GIMPLE_COND)
113393 + return false;
113394 +
113395 + if (gimple_cond_code(dom_stmt) != NE_EXPR)
113396 + return false;
113397 +
113398 + if (!integer_zerop(gimple_cond_rhs(dom_stmt)))
113399 + return false;
113400 +
113401 + poss_is_err_cond = gimple_cond_lhs(dom_stmt);
113402 +
113403 + if (TREE_CODE(poss_is_err_cond) != SSA_NAME)
113404 + return false;
113405 +
113406 + call_stmt = SSA_NAME_DEF_STMT(poss_is_err_cond);
113407 +
113408 + if (gimple_code(call_stmt) != GIMPLE_CALL)
113409 + return false;
113410 +
113411 + dom_lhs = gimple_get_lhs(call_stmt);
113412 + poss_is_err_func = gimple_call_fndecl(call_stmt);
113413 + if (!poss_is_err_func)
113414 + return false;
113415 + if (dom_lhs != poss_is_err_cond)
113416 + return false;
113417 + if (strcmp(DECL_NAME_POINTER(poss_is_err_func), "IS_ERR"))
113418 + return false;
113419 +
113420 + is_err_arg = gimple_call_arg(call_stmt, 0);
113421 + if (!is_err_arg)
113422 + return false;
113423 +
113424 + if (is_err_arg != rhs)
113425 + return false;
113426 +
113427 + return true;
113428 +}
113429 +
113430 +static void handle_local_var_initializers(void)
113431 +{
113432 + tree var;
113433 + unsigned int i;
113434 +
113435 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
113436 + tree init = DECL_INITIAL(var);
113437 + if (!init)
113438 + continue;
113439 + if (TREE_CODE(init) != CONSTRUCTOR)
113440 + continue;
113441 + check_bad_casts_in_constructor(var, init);
113442 + }
113443 +}
113444 +
113445 +/*
113446 + * iterate over all statements to find "bad" casts:
113447 + * those where the address of the start of a structure is cast
113448 + * to a pointer of a structure of a different type, or a
113449 + * structure pointer type is cast to a different structure pointer type
113450 + */
113451 +static unsigned int find_bad_casts(void)
113452 +{
113453 + basic_block bb;
113454 +
113455 + handle_local_var_initializers();
113456 +
113457 + FOR_ALL_BB_FN(bb, cfun) {
113458 + gimple_stmt_iterator gsi;
113459 +
113460 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
113461 + gimple stmt;
113462 + const_tree lhs;
113463 + const_tree lhs_type;
113464 + const_tree rhs1;
113465 + const_tree rhs_type;
113466 + const_tree ptr_lhs_type;
113467 + const_tree ptr_rhs_type;
113468 + const_tree op0;
113469 + const_tree op0_type;
113470 + enum tree_code rhs_code;
113471 +
113472 + stmt = gsi_stmt(gsi);
113473 +
113474 +#ifdef __DEBUG_PLUGIN
113475 +#ifdef __DEBUG_VERBOSE
113476 + debug_gimple_stmt(stmt);
113477 + debug_tree(gimple_get_lhs(stmt));
113478 +#endif
113479 +#endif
113480 +
113481 + if (gimple_code(stmt) != GIMPLE_ASSIGN)
113482 + continue;
113483 +
113484 +#ifdef __DEBUG_PLUGIN
113485 +#ifdef __DEBUG_VERBOSE
113486 + debug_tree(gimple_assign_rhs1(stmt));
113487 +#endif
113488 +#endif
113489 +
113490 + rhs_code = gimple_assign_rhs_code(stmt);
113491 +
113492 + if (rhs_code != ADDR_EXPR && rhs_code != SSA_NAME)
113493 + continue;
113494 +
113495 + lhs = gimple_get_lhs(stmt);
113496 + lhs_type = TREE_TYPE(lhs);
113497 + rhs1 = gimple_assign_rhs1(stmt);
113498 + rhs_type = TREE_TYPE(rhs1);
113499 +
113500 + if (TREE_CODE(rhs_type) != POINTER_TYPE ||
113501 + TREE_CODE(lhs_type) != POINTER_TYPE)
113502 + continue;
113503 +
113504 + ptr_lhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(lhs_type))));
113505 + ptr_rhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(rhs_type))));
113506 +
113507 + if (ptr_rhs_type == void_type_node)
113508 + continue;
113509 +
113510 + if (ptr_lhs_type == void_type_node)
113511 + continue;
113512 +
113513 + if (dominated_by_is_err(rhs1, bb))
113514 + continue;
113515 +
113516 + if (TREE_CODE(ptr_rhs_type) != RECORD_TYPE) {
113517 +#ifndef __DEBUG_PLUGIN
113518 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_lhs_type)))
113519 +#endif
113520 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
113521 + continue;
113522 + }
113523 +
113524 + if (rhs_code == SSA_NAME && ptr_lhs_type == ptr_rhs_type)
113525 + continue;
113526 +
113527 + if (rhs_code == ADDR_EXPR) {
113528 + op0 = TREE_OPERAND(rhs1, 0);
113529 +
113530 + if (op0 == NULL_TREE)
113531 + continue;
113532 +
113533 + if (TREE_CODE(op0) != VAR_DECL)
113534 + continue;
113535 +
113536 + op0_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(op0))));
113537 + if (op0_type == ptr_lhs_type)
113538 + continue;
113539 +
113540 +#ifndef __DEBUG_PLUGIN
113541 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(op0_type)))
113542 +#endif
113543 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, op0_type);
113544 + } else {
113545 + const_tree ssa_name_var = SSA_NAME_VAR(rhs1);
113546 + /* skip bogus type casts introduced by container_of */
113547 + if (ssa_name_var != NULL_TREE && DECL_NAME(ssa_name_var) &&
113548 + !strcmp((const char *)DECL_NAME_POINTER(ssa_name_var), "__mptr"))
113549 + continue;
113550 +#ifndef __DEBUG_PLUGIN
113551 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_rhs_type)))
113552 +#endif
113553 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
113554 + }
113555 +
113556 + }
113557 + }
113558 + return 0;
113559 +}
113560 +
113561 +#if BUILDING_GCC_VERSION >= 4009
113562 +static const struct pass_data randomize_layout_bad_cast_data = {
113563 +#else
113564 +static struct gimple_opt_pass randomize_layout_bad_cast = {
113565 + .pass = {
113566 +#endif
113567 + .type = GIMPLE_PASS,
113568 + .name = "randomize_layout_bad_cast",
113569 +#if BUILDING_GCC_VERSION >= 4008
113570 + .optinfo_flags = OPTGROUP_NONE,
113571 +#endif
113572 +#if BUILDING_GCC_VERSION >= 4009
113573 + .has_gate = false,
113574 + .has_execute = true,
113575 +#else
113576 + .gate = NULL,
113577 + .execute = find_bad_casts,
113578 + .sub = NULL,
113579 + .next = NULL,
113580 + .static_pass_number = 0,
113581 +#endif
113582 + .tv_id = TV_NONE,
113583 + .properties_required = PROP_cfg,
113584 + .properties_provided = 0,
113585 + .properties_destroyed = 0,
113586 + .todo_flags_start = 0,
113587 + .todo_flags_finish = TODO_dump_func
113588 +#if BUILDING_GCC_VERSION < 4009
113589 + }
113590 +#endif
113591 +};
113592 +
113593 +#if BUILDING_GCC_VERSION >= 4009
113594 +namespace {
113595 +class randomize_layout_bad_cast : public gimple_opt_pass {
113596 +public:
113597 + randomize_layout_bad_cast() : gimple_opt_pass(randomize_layout_bad_cast_data, g) {}
113598 + unsigned int execute() { return find_bad_casts(); }
113599 +};
113600 +}
113601 +#endif
113602 +
113603 +static struct opt_pass *make_randomize_layout_bad_cast(void)
113604 +{
113605 +#if BUILDING_GCC_VERSION >= 4009
113606 + return new randomize_layout_bad_cast();
113607 +#else
113608 + return &randomize_layout_bad_cast.pass;
113609 +#endif
113610 +}
113611 +
113612 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
113613 +{
113614 + int i;
113615 + const char * const plugin_name = plugin_info->base_name;
113616 + const int argc = plugin_info->argc;
113617 + const struct plugin_argument * const argv = plugin_info->argv;
113618 + bool enable = true;
113619 + int obtained_seed = 0;
113620 + struct register_pass_info randomize_layout_bad_cast_info;
113621 +
113622 + randomize_layout_bad_cast_info.pass = make_randomize_layout_bad_cast();
113623 + randomize_layout_bad_cast_info.reference_pass_name = "ssa";
113624 + randomize_layout_bad_cast_info.ref_pass_instance_number = 1;
113625 + randomize_layout_bad_cast_info.pos_op = PASS_POS_INSERT_AFTER;
113626 +
113627 + if (!plugin_default_version_check(version, &gcc_version)) {
113628 + error(G_("incompatible gcc/plugin versions"));
113629 + return 1;
113630 + }
113631 +
113632 + if (strcmp(lang_hooks.name, "GNU C")) {
113633 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
113634 + enable = false;
113635 + }
113636 +
113637 + for (i = 0; i < argc; ++i) {
113638 + if (!strcmp(argv[i].key, "disable")) {
113639 + enable = false;
113640 + continue;
113641 + }
113642 + if (!strcmp(argv[i].key, "performance-mode")) {
113643 + performance_mode = 1;
113644 + continue;
113645 + }
113646 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
113647 + }
113648 +
113649 + if (strlen(randstruct_seed) != 64) {
113650 + error(G_("invalid seed value supplied for %s plugin"), plugin_name);
113651 + return 1;
113652 + }
113653 + obtained_seed = sscanf(randstruct_seed, "%016llx%016llx%016llx%016llx",
113654 + &shuffle_seed[0], &shuffle_seed[1], &shuffle_seed[2], &shuffle_seed[3]);
113655 + if (obtained_seed != 4) {
113656 + error(G_("Invalid seed supplied for %s plugin"), plugin_name);
113657 + return 1;
113658 + }
113659 +
113660 + register_callback(plugin_name, PLUGIN_INFO, NULL, &randomize_layout_plugin_info);
113661 + if (enable) {
113662 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
113663 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &randomize_layout_bad_cast_info);
113664 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
113665 + register_callback(plugin_name, PLUGIN_FINISH_DECL, randomize_layout_finish_decl, NULL);
113666 + }
113667 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
113668 +
113669 + return 0;
113670 +}
113671 diff --git a/tools/gcc/size_overflow_plugin/.gitignore b/tools/gcc/size_overflow_plugin/.gitignore
113672 new file mode 100644
113673 index 0000000..1f0214f
113674 --- /dev/null
113675 +++ b/tools/gcc/size_overflow_plugin/.gitignore
113676 @@ -0,0 +1,3 @@
113677 +randomize_layout_seed.h
113678 +size_overflow_hash.h
113679 +size_overflow_hash_aux.h
113680 diff --git a/tools/gcc/size_overflow_plugin/Makefile b/tools/gcc/size_overflow_plugin/Makefile
113681 new file mode 100644
113682 index 0000000..1ae2ed5
113683 --- /dev/null
113684 +++ b/tools/gcc/size_overflow_plugin/Makefile
113685 @@ -0,0 +1,20 @@
113686 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
113687 +always := $($(HOSTLIBS)-y)
113688 +
113689 +size_overflow_plugin-objs := $(patsubst $(srctree)/$(src)/%.c,%.o,$(wildcard $(srctree)/$(src)/*.c))
113690 +
113691 +$(patsubst $(srctree)/$(src)/%.c,$(obj)/%.o,$(wildcard $(srctree)/$(src)/*.c)): $(objtree)/$(obj)/size_overflow_hash.h $(objtree)/$(obj)/size_overflow_hash_aux.h
113692 +
113693 +quiet_cmd_build_size_overflow_hash = GENHASH $@
113694 + cmd_build_size_overflow_hash = \
113695 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash -d $< -o $@
113696 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
113697 + $(call if_changed,build_size_overflow_hash)
113698 +
113699 +quiet_cmd_build_size_overflow_hash_aux = GENHASH $@
113700 + cmd_build_size_overflow_hash_aux = \
113701 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash_aux -d $< -o $@
113702 +$(objtree)/$(obj)/size_overflow_hash_aux.h: $(src)/size_overflow_hash_aux.data FORCE
113703 + $(call if_changed,build_size_overflow_hash_aux)
113704 +
113705 +targets += size_overflow_hash.h size_overflow_hash_aux.h
113706 diff --git a/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
113707 new file mode 100644
113708 index 0000000..12b1e3b
113709 --- /dev/null
113710 +++ b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
113711 @@ -0,0 +1,102 @@
113712 +#!/bin/bash
113713 +
113714 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
113715 +
113716 +header1="size_overflow_hash.h"
113717 +database="size_overflow_hash.data"
113718 +n=65536
113719 +hashtable_name="size_overflow_hash"
113720 +
113721 +usage() {
113722 +cat <<EOF
113723 +usage: $0 options
113724 +OPTIONS:
113725 + -h|--help help
113726 + -o header file
113727 + -d database file
113728 + -n hash array size
113729 + -s name of the hash table
113730 +EOF
113731 + return 0
113732 +}
113733 +
113734 +while true
113735 +do
113736 + case "$1" in
113737 + -h|--help) usage && exit 0;;
113738 + -n) n=$2; shift 2;;
113739 + -o) header1="$2"; shift 2;;
113740 + -d) database="$2"; shift 2;;
113741 + -s) hashtable_name="$2"; shift 2;;
113742 + --) shift 1; break ;;
113743 + *) break ;;
113744 + esac
113745 +done
113746 +
113747 +create_defines() {
113748 + for i in `seq 0 31`
113749 + do
113750 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
113751 + done
113752 + echo >> "$header1"
113753 +}
113754 +
113755 +create_structs() {
113756 + rm -f "$header1"
113757 +
113758 + create_defines
113759 +
113760 + cat "$database" | while read data
113761 + do
113762 + data_array=($data)
113763 + struct_hash_name="${data_array[0]}"
113764 + funcn="${data_array[1]}"
113765 + params="${data_array[2]}"
113766 + next="${data_array[4]}"
113767 +
113768 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
113769 +
113770 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
113771 + echo -en "\t.param\t= " >> "$header1"
113772 + line=
113773 + for param_num in ${params//-/ };
113774 + do
113775 + line="${line}PARAM"$param_num"|"
113776 + done
113777 +
113778 + echo -e "${line%?},\n};\n" >> "$header1"
113779 + done
113780 +}
113781 +
113782 +create_headers() {
113783 + echo "const struct size_overflow_hash * const $hashtable_name[$n] = {" >> "$header1"
113784 +}
113785 +
113786 +create_array_elements() {
113787 + index=0
113788 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
113789 + do
113790 + data_array=($data)
113791 + i="${data_array[3]}"
113792 + hash="${data_array[0]}"
113793 + while [[ $index -lt $i ]]
113794 + do
113795 + echo -e "\t["$index"]\t= NULL," >> "$header1"
113796 + index=$(($index + 1))
113797 + done
113798 + index=$(($index + 1))
113799 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
113800 + done
113801 + echo '};' >> $header1
113802 +}
113803 +
113804 +size_overflow_plugin_dir=`dirname $header1`
113805 +if [ "$size_overflow_plugin_dir" != '.' ]; then
113806 + mkdir -p "$size_overflow_plugin_dir" 2> /dev/null
113807 +fi
113808 +
113809 +create_structs
113810 +create_headers
113811 +create_array_elements
113812 +
113813 +exit 0
113814 diff --git a/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
113815 new file mode 100644
113816 index 0000000..c43901f
113817 --- /dev/null
113818 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
113819 @@ -0,0 +1,748 @@
113820 +/*
113821 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
113822 + * Licensed under the GPL v2, or (at your option) v3
113823 + *
113824 + * Homepage:
113825 + * http://www.grsecurity.net/~ephox/overflow_plugin/
113826 + *
113827 + * Documentation:
113828 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
113829 + *
113830 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
113831 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
113832 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
113833 + *
113834 + * Usage:
113835 + * $ make
113836 + * $ make run
113837 + */
113838 +
113839 +#include "gcc-common.h"
113840 +#include "size_overflow.h"
113841 +
113842 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs);
113843 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs);
113844 +
113845 +// data for the size_overflow asm stmt
113846 +struct asm_data {
113847 + gimple def_stmt;
113848 + tree input;
113849 + tree output;
113850 +};
113851 +
113852 +#if BUILDING_GCC_VERSION <= 4007
113853 +static VEC(tree, gc) *create_asm_io_list(tree string, tree io)
113854 +#else
113855 +static vec<tree, va_gc> *create_asm_io_list(tree string, tree io)
113856 +#endif
113857 +{
113858 + tree list;
113859 +#if BUILDING_GCC_VERSION <= 4007
113860 + VEC(tree, gc) *vec_list = NULL;
113861 +#else
113862 + vec<tree, va_gc> *vec_list = NULL;
113863 +#endif
113864 +
113865 + list = build_tree_list(NULL_TREE, string);
113866 + list = chainon(NULL_TREE, build_tree_list(list, io));
113867 +#if BUILDING_GCC_VERSION <= 4007
113868 + VEC_safe_push(tree, gc, vec_list, list);
113869 +#else
113870 + vec_safe_push(vec_list, list);
113871 +#endif
113872 + return vec_list;
113873 +}
113874 +
113875 +static void create_asm_stmt(const char *str, tree str_input, tree str_output, struct asm_data *asm_data)
113876 +{
113877 + gimple asm_stmt;
113878 + gimple_stmt_iterator gsi;
113879 +#if BUILDING_GCC_VERSION <= 4007
113880 + VEC(tree, gc) *input, *output = NULL;
113881 +#else
113882 + vec<tree, va_gc> *input, *output = NULL;
113883 +#endif
113884 +
113885 + input = create_asm_io_list(str_input, asm_data->input);
113886 +
113887 + if (asm_data->output)
113888 + output = create_asm_io_list(str_output, asm_data->output);
113889 +
113890 + asm_stmt = gimple_build_asm_vec(str, input, output, NULL, NULL);
113891 + gsi = gsi_for_stmt(asm_data->def_stmt);
113892 + gsi_insert_after(&gsi, asm_stmt, GSI_NEW_STMT);
113893 +
113894 + if (asm_data->output)
113895 + SSA_NAME_DEF_STMT(asm_data->output) = asm_stmt;
113896 +}
113897 +
113898 +static void replace_call_lhs(const struct asm_data *asm_data)
113899 +{
113900 + gimple_set_lhs(asm_data->def_stmt, asm_data->input);
113901 + update_stmt(asm_data->def_stmt);
113902 + SSA_NAME_DEF_STMT(asm_data->input) = asm_data->def_stmt;
113903 +}
113904 +
113905 +static enum mark search_intentional_phi(struct pointer_set_t *visited, const_tree result)
113906 +{
113907 + enum mark cur_fndecl_attr;
113908 + gimple phi = get_def_stmt(result);
113909 + unsigned int i, n = gimple_phi_num_args(phi);
113910 +
113911 + pointer_set_insert(visited, phi);
113912 + for (i = 0; i < n; i++) {
113913 + tree arg = gimple_phi_arg_def(phi, i);
113914 +
113915 + cur_fndecl_attr = search_intentional(visited, arg);
113916 + if (cur_fndecl_attr != MARK_NO)
113917 + return cur_fndecl_attr;
113918 + }
113919 + return MARK_NO;
113920 +}
113921 +
113922 +static enum mark search_intentional_binary(struct pointer_set_t *visited, const_tree lhs)
113923 +{
113924 + enum mark cur_fndecl_attr;
113925 + const_tree rhs1, rhs2;
113926 + gimple def_stmt = get_def_stmt(lhs);
113927 +
113928 + rhs1 = gimple_assign_rhs1(def_stmt);
113929 + rhs2 = gimple_assign_rhs2(def_stmt);
113930 +
113931 + cur_fndecl_attr = search_intentional(visited, rhs1);
113932 + if (cur_fndecl_attr != MARK_NO)
113933 + return cur_fndecl_attr;
113934 + return search_intentional(visited, rhs2);
113935 +}
113936 +
113937 +// Look up the intentional_overflow attribute on the caller and the callee functions.
113938 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs)
113939 +{
113940 + const_gimple def_stmt;
113941 +
113942 + if (TREE_CODE(lhs) != SSA_NAME)
113943 + return get_intentional_attr_type(lhs);
113944 +
113945 + def_stmt = get_def_stmt(lhs);
113946 + if (!def_stmt)
113947 + return MARK_NO;
113948 +
113949 + if (pointer_set_contains(visited, def_stmt))
113950 + return MARK_NO;
113951 +
113952 + switch (gimple_code(def_stmt)) {
113953 + case GIMPLE_NOP:
113954 + return search_intentional(visited, SSA_NAME_VAR(lhs));
113955 + case GIMPLE_ASM:
113956 + if (is_size_overflow_intentional_asm_turn_off(def_stmt))
113957 + return MARK_TURN_OFF;
113958 + return MARK_NO;
113959 + case GIMPLE_CALL:
113960 + return MARK_NO;
113961 + case GIMPLE_PHI:
113962 + return search_intentional_phi(visited, lhs);
113963 + case GIMPLE_ASSIGN:
113964 + switch (gimple_num_ops(def_stmt)) {
113965 + case 2:
113966 + return search_intentional(visited, gimple_assign_rhs1(def_stmt));
113967 + case 3:
113968 + return search_intentional_binary(visited, lhs);
113969 + }
113970 + case GIMPLE_RETURN:
113971 + return MARK_NO;
113972 + default:
113973 + debug_gimple_stmt((gimple)def_stmt);
113974 + error("%s: unknown gimple code", __func__);
113975 + gcc_unreachable();
113976 + }
113977 +}
113978 +
113979 +// Check the intentional_overflow attribute and create the asm comment string for the size_overflow asm stmt.
113980 +static enum mark check_intentional_attribute_gimple(const_tree arg, const_gimple stmt, unsigned int argnum)
113981 +{
113982 + const_tree fndecl;
113983 + struct pointer_set_t *visited;
113984 + enum mark cur_fndecl_attr, decl_attr = MARK_NO;
113985 +
113986 + fndecl = get_interesting_orig_fndecl(stmt, argnum);
113987 + if (is_end_intentional_intentional_attr(fndecl, argnum))
113988 + decl_attr = MARK_NOT_INTENTIONAL;
113989 + else if (is_yes_intentional_attr(fndecl, argnum))
113990 + decl_attr = MARK_YES;
113991 + else if (is_turn_off_intentional_attr(fndecl) || is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
113992 + return MARK_TURN_OFF;
113993 + }
113994 +
113995 + visited = pointer_set_create();
113996 + cur_fndecl_attr = search_intentional(visited, arg);
113997 + pointer_set_destroy(visited);
113998 +
113999 + switch (cur_fndecl_attr) {
114000 + case MARK_NO:
114001 + case MARK_TURN_OFF:
114002 + return cur_fndecl_attr;
114003 + default:
114004 + print_missing_intentional(decl_attr, cur_fndecl_attr, fndecl, argnum);
114005 + return MARK_YES;
114006 + }
114007 +}
114008 +
114009 +static void check_missing_size_overflow_attribute(tree var)
114010 +{
114011 + tree orig_fndecl;
114012 + unsigned int num;
114013 +
114014 + if (is_a_return_check(var))
114015 + orig_fndecl = DECL_ORIGIN(var);
114016 + else
114017 + orig_fndecl = DECL_ORIGIN(current_function_decl);
114018 +
114019 + num = get_function_num(var, orig_fndecl);
114020 + if (num == CANNOT_FIND_ARG)
114021 + return;
114022 +
114023 + is_missing_function(orig_fndecl, num);
114024 +}
114025 +
114026 +static void search_size_overflow_attribute_phi(struct pointer_set_t *visited, const_tree result)
114027 +{
114028 + gimple phi = get_def_stmt(result);
114029 + unsigned int i, n = gimple_phi_num_args(phi);
114030 +
114031 + pointer_set_insert(visited, phi);
114032 + for (i = 0; i < n; i++) {
114033 + tree arg = gimple_phi_arg_def(phi, i);
114034 +
114035 + search_size_overflow_attribute(visited, arg);
114036 + }
114037 +}
114038 +
114039 +static void search_size_overflow_attribute_binary(struct pointer_set_t *visited, const_tree lhs)
114040 +{
114041 + const_gimple def_stmt = get_def_stmt(lhs);
114042 + tree rhs1, rhs2;
114043 +
114044 + rhs1 = gimple_assign_rhs1(def_stmt);
114045 + rhs2 = gimple_assign_rhs2(def_stmt);
114046 +
114047 + search_size_overflow_attribute(visited, rhs1);
114048 + search_size_overflow_attribute(visited, rhs2);
114049 +}
114050 +
114051 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs)
114052 +{
114053 + const_gimple def_stmt;
114054 +
114055 + if (TREE_CODE(lhs) == PARM_DECL) {
114056 + check_missing_size_overflow_attribute(lhs);
114057 + return;
114058 + }
114059 +
114060 + def_stmt = get_def_stmt(lhs);
114061 + if (!def_stmt)
114062 + return;
114063 +
114064 + if (pointer_set_insert(visited, def_stmt))
114065 + return;
114066 +
114067 + switch (gimple_code(def_stmt)) {
114068 + case GIMPLE_NOP:
114069 + return search_size_overflow_attribute(visited, SSA_NAME_VAR(lhs));
114070 + case GIMPLE_ASM:
114071 + return;
114072 + case GIMPLE_CALL: {
114073 + tree fndecl = gimple_call_fndecl(def_stmt);
114074 +
114075 + if (fndecl == NULL_TREE)
114076 + return;
114077 + check_missing_size_overflow_attribute(fndecl);
114078 + return;
114079 + }
114080 + case GIMPLE_PHI:
114081 + return search_size_overflow_attribute_phi(visited, lhs);
114082 + case GIMPLE_ASSIGN:
114083 + switch (gimple_num_ops(def_stmt)) {
114084 + case 2:
114085 + return search_size_overflow_attribute(visited, gimple_assign_rhs1(def_stmt));
114086 + case 3:
114087 + return search_size_overflow_attribute_binary(visited, lhs);
114088 + }
114089 + default:
114090 + debug_gimple_stmt((gimple)def_stmt);
114091 + error("%s: unknown gimple code", __func__);
114092 + gcc_unreachable();
114093 + }
114094 +}
114095 +
114096 +// Search missing entries in the hash table (invoked from the gimple pass)
114097 +static void search_missing_size_overflow_attribute_gimple(const_gimple stmt, unsigned int num)
114098 +{
114099 + tree fndecl = NULL_TREE;
114100 + tree lhs;
114101 + struct pointer_set_t *visited;
114102 +
114103 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl)))
114104 + return;
114105 +
114106 + if (num == 0) {
114107 + gcc_assert(gimple_code(stmt) == GIMPLE_RETURN);
114108 + lhs = gimple_return_retval(stmt);
114109 + } else {
114110 + gcc_assert(is_gimple_call(stmt));
114111 + lhs = gimple_call_arg(stmt, num - 1);
114112 + fndecl = gimple_call_fndecl(stmt);
114113 + }
114114 +
114115 + if (fndecl != NULL_TREE && is_turn_off_intentional_attr(DECL_ORIGIN(fndecl)))
114116 + return;
114117 +
114118 + visited = pointer_set_create();
114119 + search_size_overflow_attribute(visited, lhs);
114120 + pointer_set_destroy(visited);
114121 +}
114122 +
114123 +static void create_output_from_phi(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
114124 +{
114125 + gimple_stmt_iterator gsi;
114126 + gimple assign;
114127 +
114128 + assign = gimple_build_assign(asm_data->input, asm_data->output);
114129 + gsi = gsi_for_stmt(stmt);
114130 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
114131 + asm_data->def_stmt = assign;
114132 +
114133 + asm_data->output = create_new_var(TREE_TYPE(asm_data->output));
114134 + asm_data->output = make_ssa_name(asm_data->output, stmt);
114135 + if (gimple_code(stmt) == GIMPLE_RETURN)
114136 + gimple_return_set_retval(stmt, asm_data->output);
114137 + else
114138 + gimple_call_set_arg(stmt, argnum - 1, asm_data->output);
114139 + update_stmt(stmt);
114140 +}
114141 +
114142 +static char *create_asm_comment(unsigned int argnum, const_gimple stmt , const char *mark_str)
114143 +{
114144 + const char *fn_name;
114145 + char *asm_comment;
114146 + unsigned int len;
114147 +
114148 + if (argnum == 0)
114149 + fn_name = DECL_NAME_POINTER(current_function_decl);
114150 + else
114151 + fn_name = DECL_NAME_POINTER(gimple_call_fndecl(stmt));
114152 +
114153 + len = asprintf(&asm_comment, "%s %s %u", mark_str, fn_name, argnum);
114154 + gcc_assert(len > 0);
114155 +
114156 + return asm_comment;
114157 +}
114158 +
114159 +static const char *convert_mark_to_str(enum mark mark)
114160 +{
114161 + switch (mark) {
114162 + case MARK_NO:
114163 + return OK_ASM_STR;
114164 + case MARK_YES:
114165 + case MARK_NOT_INTENTIONAL:
114166 + return YES_ASM_STR;
114167 + case MARK_TURN_OFF:
114168 + return TURN_OFF_ASM_STR;
114169 + }
114170 +
114171 + gcc_unreachable();
114172 +}
114173 +
114174 +/* Create the input of the size_overflow asm stmt.
114175 + * When the arg of the callee function is a parm_decl it creates this kind of size_overflow asm stmt:
114176 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
114177 + * The input field in asm_data will be empty if there is no need for further size_overflow asm stmt insertion.
114178 + * otherwise create the input (for a phi stmt the output too) of the asm stmt.
114179 + */
114180 +static void create_asm_input(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
114181 +{
114182 + if (!asm_data->def_stmt) {
114183 + asm_data->input = NULL_TREE;
114184 + return;
114185 + }
114186 +
114187 + asm_data->input = create_new_var(TREE_TYPE(asm_data->output));
114188 + asm_data->input = make_ssa_name(asm_data->input, asm_data->def_stmt);
114189 +
114190 + switch (gimple_code(asm_data->def_stmt)) {
114191 + case GIMPLE_ASSIGN:
114192 + case GIMPLE_CALL:
114193 + replace_call_lhs(asm_data);
114194 + break;
114195 + case GIMPLE_PHI:
114196 + create_output_from_phi(stmt, argnum, asm_data);
114197 + break;
114198 + case GIMPLE_NOP: {
114199 + enum mark mark;
114200 + const char *mark_str;
114201 + char *asm_comment;
114202 +
114203 + mark = check_intentional_attribute_gimple(asm_data->output, stmt, argnum);
114204 +
114205 + asm_data->input = asm_data->output;
114206 + asm_data->output = NULL;
114207 + asm_data->def_stmt = stmt;
114208 +
114209 + mark_str = convert_mark_to_str(mark);
114210 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
114211 +
114212 + create_asm_stmt(asm_comment, build_string(3, "rm"), NULL, asm_data);
114213 + free(asm_comment);
114214 + asm_data->input = NULL_TREE;
114215 + break;
114216 + }
114217 + case GIMPLE_ASM:
114218 + if (is_size_overflow_asm(asm_data->def_stmt)) {
114219 + asm_data->input = NULL_TREE;
114220 + break;
114221 + }
114222 + default:
114223 + debug_gimple_stmt(asm_data->def_stmt);
114224 + gcc_unreachable();
114225 + }
114226 +}
114227 +
114228 +/* This is the gimple part of searching for a missing size_overflow attribute. If the intentional_overflow attribute type
114229 + * is of the right kind create the appropriate size_overflow asm stmts:
114230 + * __asm__("# size_overflow" : =rm" D.3344_8 : "0" cicus.4_16);
114231 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
114232 + */
114233 +static void create_size_overflow_asm(gimple stmt, tree output_node, unsigned int argnum)
114234 +{
114235 + struct asm_data asm_data;
114236 + const char *mark_str;
114237 + char *asm_comment;
114238 + enum mark mark;
114239 +
114240 + if (is_gimple_constant(output_node))
114241 + return;
114242 +
114243 + asm_data.output = output_node;
114244 + mark = check_intentional_attribute_gimple(asm_data.output, stmt, argnum);
114245 + if (mark != MARK_TURN_OFF)
114246 + search_missing_size_overflow_attribute_gimple(stmt, argnum);
114247 +
114248 + asm_data.def_stmt = get_def_stmt(asm_data.output);
114249 + if (is_size_overflow_intentional_asm_turn_off(asm_data.def_stmt))
114250 + return;
114251 +
114252 + create_asm_input(stmt, argnum, &asm_data);
114253 + if (asm_data.input == NULL_TREE)
114254 + return;
114255 +
114256 + mark_str = convert_mark_to_str(mark);
114257 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
114258 + create_asm_stmt(asm_comment, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
114259 + free(asm_comment);
114260 +}
114261 +
114262 +// Insert an asm stmt with "MARK_TURN_OFF", "MARK_YES" or "MARK_NOT_INTENTIONAL".
114263 +static bool create_mark_asm(gimple stmt, enum mark mark)
114264 +{
114265 + struct asm_data asm_data;
114266 + const char *asm_str;
114267 +
114268 + switch (mark) {
114269 + case MARK_TURN_OFF:
114270 + asm_str = TURN_OFF_ASM_STR;
114271 + break;
114272 + case MARK_NOT_INTENTIONAL:
114273 + case MARK_YES:
114274 + asm_str = YES_ASM_STR;
114275 + break;
114276 + default:
114277 + gcc_unreachable();
114278 + }
114279 +
114280 + asm_data.def_stmt = stmt;
114281 + asm_data.output = gimple_call_lhs(stmt);
114282 +
114283 + if (asm_data.output == NULL_TREE) {
114284 + asm_data.input = gimple_call_arg(stmt, 0);
114285 + if (is_gimple_constant(asm_data.input))
114286 + return false;
114287 + asm_data.output = NULL;
114288 + create_asm_stmt(asm_str, build_string(3, "rm"), NULL, &asm_data);
114289 + return true;
114290 + }
114291 +
114292 + create_asm_input(stmt, 0, &asm_data);
114293 + gcc_assert(asm_data.input != NULL_TREE);
114294 +
114295 + create_asm_stmt(asm_str, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
114296 + return true;
114297 +}
114298 +
114299 +static void walk_use_def_ptr(struct pointer_set_t *visited, const_tree lhs)
114300 +{
114301 + gimple def_stmt;
114302 +
114303 + def_stmt = get_def_stmt(lhs);
114304 + if (!def_stmt)
114305 + return;
114306 +
114307 + if (pointer_set_insert(visited, def_stmt))
114308 + return;
114309 +
114310 + switch (gimple_code(def_stmt)) {
114311 + case GIMPLE_NOP:
114312 + case GIMPLE_ASM:
114313 + case GIMPLE_CALL:
114314 + break;
114315 + case GIMPLE_PHI: {
114316 + unsigned int i, n = gimple_phi_num_args(def_stmt);
114317 +
114318 + pointer_set_insert(visited, def_stmt);
114319 +
114320 + for (i = 0; i < n; i++) {
114321 + tree arg = gimple_phi_arg_def(def_stmt, i);
114322 +
114323 + walk_use_def_ptr(visited, arg);
114324 + }
114325 + }
114326 + case GIMPLE_ASSIGN:
114327 + switch (gimple_num_ops(def_stmt)) {
114328 + case 2:
114329 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
114330 + return;
114331 + case 3:
114332 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
114333 + walk_use_def_ptr(visited, gimple_assign_rhs2(def_stmt));
114334 + return;
114335 + default:
114336 + return;
114337 + }
114338 + default:
114339 + debug_gimple_stmt((gimple)def_stmt);
114340 + error("%s: unknown gimple code", __func__);
114341 + gcc_unreachable();
114342 + }
114343 +}
114344 +
114345 +// Look for a ptr - ptr expression (e.g., cpuset_common_file_read() s - page)
114346 +static void insert_mark_not_intentional_asm_at_ptr(const_tree arg)
114347 +{
114348 + struct pointer_set_t *visited;
114349 +
114350 + visited = pointer_set_create();
114351 + walk_use_def_ptr(visited, arg);
114352 + pointer_set_destroy(visited);
114353 +}
114354 +
114355 +// Determine the return value and insert the asm stmt to mark the return stmt.
114356 +static void insert_asm_ret(gimple stmt)
114357 +{
114358 + tree ret;
114359 +
114360 + ret = gimple_return_retval(stmt);
114361 + create_size_overflow_asm(stmt, ret, 0);
114362 +}
114363 +
114364 +// Determine the correct arg index and arg and insert the asm stmt to mark the stmt.
114365 +static void insert_asm_arg(gimple stmt, unsigned int orig_argnum)
114366 +{
114367 + tree arg;
114368 + unsigned int argnum;
114369 +
114370 + argnum = get_correct_arg_count(orig_argnum, gimple_call_fndecl(stmt));
114371 + gcc_assert(argnum != 0);
114372 + if (argnum == CANNOT_FIND_ARG)
114373 + return;
114374 +
114375 + arg = gimple_call_arg(stmt, argnum - 1);
114376 + gcc_assert(arg != NULL_TREE);
114377 +
114378 + // skip all ptr - ptr expressions
114379 + insert_mark_not_intentional_asm_at_ptr(arg);
114380 +
114381 + create_size_overflow_asm(stmt, arg, argnum);
114382 +}
114383 +
114384 +// If a function arg or the return value is marked by the size_overflow attribute then set its index in the array.
114385 +static void set_argnum_attribute(const_tree attr, bool *argnums)
114386 +{
114387 + unsigned int argnum;
114388 + tree attr_value;
114389 +
114390 + for (attr_value = TREE_VALUE(attr); attr_value; attr_value = TREE_CHAIN(attr_value)) {
114391 + argnum = TREE_INT_CST_LOW(TREE_VALUE(attr_value));
114392 + argnums[argnum] = true;
114393 + }
114394 +}
114395 +
114396 +// If a function arg or the return value is in the hash table then set its index in the array.
114397 +static void set_argnum_hash(tree fndecl, bool *argnums)
114398 +{
114399 + unsigned int num;
114400 + const struct size_overflow_hash *hash;
114401 +
114402 + hash = get_function_hash(DECL_ORIGIN(fndecl));
114403 + if (!hash)
114404 + return;
114405 +
114406 + for (num = 0; num <= MAX_PARAM; num++) {
114407 + if (!(hash->param & (1U << num)))
114408 + continue;
114409 +
114410 + argnums[num] = true;
114411 + }
114412 +}
114413 +
114414 +static bool is_all_the_argnums_empty(bool *argnums)
114415 +{
114416 + unsigned int i;
114417 +
114418 + for (i = 0; i <= MAX_PARAM; i++)
114419 + if (argnums[i])
114420 + return false;
114421 + return true;
114422 +}
114423 +
114424 +// Check whether the arguments or the return value of the function are in the hash table or are marked by the size_overflow attribute.
114425 +static void search_interesting_args(tree fndecl, bool *argnums)
114426 +{
114427 + const_tree attr;
114428 +
114429 + set_argnum_hash(fndecl, argnums);
114430 + if (!is_all_the_argnums_empty(argnums))
114431 + return;
114432 +
114433 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
114434 + if (attr && TREE_VALUE(attr))
114435 + set_argnum_attribute(attr, argnums);
114436 +}
114437 +
114438 +/*
114439 + * Look up the intentional_overflow attribute that turns off ipa based duplication
114440 + * on the callee function.
114441 + */
114442 +static bool is_mark_turn_off_attribute(gimple stmt)
114443 +{
114444 + enum mark mark;
114445 + const_tree fndecl = gimple_call_fndecl(stmt);
114446 +
114447 + mark = get_intentional_attr_type(DECL_ORIGIN(fndecl));
114448 + if (mark == MARK_TURN_OFF)
114449 + return true;
114450 + return false;
114451 +}
114452 +
114453 +// 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
114454 +static void handle_interesting_function(gimple stmt)
114455 +{
114456 + unsigned int argnum;
114457 + tree fndecl;
114458 + bool orig_argnums[MAX_PARAM + 1] = {false};
114459 +
114460 + if (gimple_call_num_args(stmt) == 0)
114461 + return;
114462 + fndecl = gimple_call_fndecl(stmt);
114463 + if (fndecl == NULL_TREE)
114464 + return;
114465 + fndecl = DECL_ORIGIN(fndecl);
114466 +
114467 + if (is_mark_turn_off_attribute(stmt)) {
114468 + create_mark_asm(stmt, MARK_TURN_OFF);
114469 + return;
114470 + }
114471 +
114472 + search_interesting_args(fndecl, orig_argnums);
114473 +
114474 + for (argnum = 1; argnum < MAX_PARAM; argnum++)
114475 + if (orig_argnums[argnum])
114476 + insert_asm_arg(stmt, argnum);
114477 +}
114478 +
114479 +// 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
114480 +static void handle_interesting_ret(gimple stmt)
114481 +{
114482 + bool orig_argnums[MAX_PARAM + 1] = {false};
114483 +
114484 + search_interesting_args(current_function_decl, orig_argnums);
114485 +
114486 + if (orig_argnums[0])
114487 + insert_asm_ret(stmt);
114488 +}
114489 +
114490 +// Iterate over all the stmts and search for call and return stmts and mark them if they're in the hash table
114491 +static unsigned int search_interesting_functions(void)
114492 +{
114493 + basic_block bb;
114494 +
114495 + FOR_ALL_BB_FN(bb, cfun) {
114496 + gimple_stmt_iterator gsi;
114497 +
114498 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
114499 + gimple stmt = gsi_stmt(gsi);
114500 +
114501 + if (is_size_overflow_asm(stmt))
114502 + continue;
114503 +
114504 + if (is_gimple_call(stmt))
114505 + handle_interesting_function(stmt);
114506 + else if (gimple_code(stmt) == GIMPLE_RETURN)
114507 + handle_interesting_ret(stmt);
114508 + }
114509 + }
114510 + return 0;
114511 +}
114512 +
114513 +/*
114514 + * A lot of functions get inlined before the ipa passes so after the build_ssa gimple pass
114515 + * this pass inserts asm stmts to mark the interesting args
114516 + * that the ipa pass will detect and insert the size overflow checks for.
114517 + */
114518 +#if BUILDING_GCC_VERSION >= 4009
114519 +static const struct pass_data insert_size_overflow_asm_pass_data = {
114520 +#else
114521 +static struct gimple_opt_pass insert_size_overflow_asm_pass = {
114522 + .pass = {
114523 +#endif
114524 + .type = GIMPLE_PASS,
114525 + .name = "insert_size_overflow_asm",
114526 +#if BUILDING_GCC_VERSION >= 4008
114527 + .optinfo_flags = OPTGROUP_NONE,
114528 +#endif
114529 +#if BUILDING_GCC_VERSION >= 4009
114530 + .has_gate = false,
114531 + .has_execute = true,
114532 +#else
114533 + .gate = NULL,
114534 + .execute = search_interesting_functions,
114535 + .sub = NULL,
114536 + .next = NULL,
114537 + .static_pass_number = 0,
114538 +#endif
114539 + .tv_id = TV_NONE,
114540 + .properties_required = PROP_cfg,
114541 + .properties_provided = 0,
114542 + .properties_destroyed = 0,
114543 + .todo_flags_start = 0,
114544 + .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
114545 +#if BUILDING_GCC_VERSION < 4009
114546 + }
114547 +#endif
114548 +};
114549 +
114550 +#if BUILDING_GCC_VERSION >= 4009
114551 +namespace {
114552 +class insert_size_overflow_asm_pass : public gimple_opt_pass {
114553 +public:
114554 + insert_size_overflow_asm_pass() : gimple_opt_pass(insert_size_overflow_asm_pass_data, g) {}
114555 + unsigned int execute() { return search_interesting_functions(); }
114556 +};
114557 +}
114558 +#endif
114559 +
114560 +struct opt_pass *make_insert_size_overflow_asm_pass(void)
114561 +{
114562 +#if BUILDING_GCC_VERSION >= 4009
114563 + return new insert_size_overflow_asm_pass();
114564 +#else
114565 + return &insert_size_overflow_asm_pass.pass;
114566 +#endif
114567 +}
114568 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
114569 new file mode 100644
114570 index 0000000..73f0a12
114571 --- /dev/null
114572 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_core.c
114573 @@ -0,0 +1,943 @@
114574 +/*
114575 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
114576 + * Licensed under the GPL v2, or (at your option) v3
114577 + *
114578 + * Homepage:
114579 + * http://www.grsecurity.net/~ephox/overflow_plugin/
114580 + *
114581 + * Documentation:
114582 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
114583 + *
114584 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
114585 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
114586 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
114587 + *
114588 + * Usage:
114589 + * $ make
114590 + * $ make run
114591 + */
114592 +
114593 +#include "gcc-common.h"
114594 +#include "size_overflow.h"
114595 +
114596 +#define MIN_CHECK true
114597 +#define MAX_CHECK false
114598 +
114599 +static tree get_size_overflow_type(struct visited *visited, const_gimple stmt, const_tree node)
114600 +{
114601 + const_tree type;
114602 + tree new_type;
114603 +
114604 + gcc_assert(node != NULL_TREE);
114605 +
114606 + type = TREE_TYPE(node);
114607 +
114608 + if (pointer_set_contains(visited->my_stmts, stmt))
114609 + return TREE_TYPE(node);
114610 +
114611 + switch (TYPE_MODE(type)) {
114612 + case QImode:
114613 + new_type = size_overflow_type_HI;
114614 + break;
114615 + case HImode:
114616 + new_type = size_overflow_type_SI;
114617 + break;
114618 + case SImode:
114619 + new_type = size_overflow_type_DI;
114620 + break;
114621 + case DImode:
114622 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
114623 + new_type = TYPE_UNSIGNED(type) ? unsigned_intDI_type_node : intDI_type_node;
114624 + else
114625 + new_type = size_overflow_type_TI;
114626 + break;
114627 + case TImode:
114628 + gcc_assert(!TYPE_UNSIGNED(type));
114629 + new_type = size_overflow_type_TI;
114630 + break;
114631 + default:
114632 + debug_tree((tree)node);
114633 + error("%s: unsupported gcc configuration (%qE).", __func__, current_function_decl);
114634 + gcc_unreachable();
114635 + }
114636 +
114637 + if (TYPE_QUALS(type) != 0)
114638 + return build_qualified_type(new_type, TYPE_QUALS(type));
114639 + return new_type;
114640 +}
114641 +
114642 +static tree get_lhs(const_gimple stmt)
114643 +{
114644 + switch (gimple_code(stmt)) {
114645 + case GIMPLE_ASSIGN:
114646 + case GIMPLE_CALL:
114647 + return gimple_get_lhs(stmt);
114648 + case GIMPLE_PHI:
114649 + return gimple_phi_result(stmt);
114650 + default:
114651 + return NULL_TREE;
114652 + }
114653 +}
114654 +
114655 +static tree cast_to_new_size_overflow_type(struct visited *visited, gimple stmt, tree rhs, tree size_overflow_type, bool before)
114656 +{
114657 + gimple_stmt_iterator gsi;
114658 + tree lhs;
114659 + gimple new_stmt;
114660 +
114661 + if (rhs == NULL_TREE)
114662 + return NULL_TREE;
114663 +
114664 + gsi = gsi_for_stmt(stmt);
114665 + new_stmt = build_cast_stmt(visited, size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before, false);
114666 + pointer_set_insert(visited->my_stmts, new_stmt);
114667 +
114668 + lhs = get_lhs(new_stmt);
114669 + gcc_assert(lhs != NULL_TREE);
114670 + return lhs;
114671 +}
114672 +
114673 +tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before)
114674 +{
114675 + tree lhs, dst_type;
114676 + gimple_stmt_iterator gsi;
114677 +
114678 + if (rhs1 == NULL_TREE) {
114679 + debug_gimple_stmt(oldstmt);
114680 + error("%s: rhs1 is NULL_TREE", __func__);
114681 + gcc_unreachable();
114682 + }
114683 +
114684 + switch (gimple_code(oldstmt)) {
114685 + case GIMPLE_ASM:
114686 + lhs = rhs1;
114687 + break;
114688 + case GIMPLE_CALL:
114689 + case GIMPLE_ASSIGN:
114690 + lhs = gimple_get_lhs(oldstmt);
114691 + break;
114692 + default:
114693 + debug_gimple_stmt(oldstmt);
114694 + gcc_unreachable();
114695 + }
114696 +
114697 + gsi = gsi_for_stmt(oldstmt);
114698 + pointer_set_insert(visited->stmts, oldstmt);
114699 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
114700 + basic_block next_bb, cur_bb;
114701 + const_edge e;
114702 +
114703 + gcc_assert(before == false);
114704 + gcc_assert(stmt_can_throw_internal(oldstmt));
114705 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
114706 + gcc_assert(!gsi_end_p(gsi));
114707 +
114708 + cur_bb = gimple_bb(oldstmt);
114709 + next_bb = cur_bb->next_bb;
114710 + e = find_edge(cur_bb, next_bb);
114711 + gcc_assert(e != NULL);
114712 + gcc_assert(e->flags & EDGE_FALLTHRU);
114713 +
114714 + gsi = gsi_after_labels(next_bb);
114715 + gcc_assert(!gsi_end_p(gsi));
114716 +
114717 + before = true;
114718 + oldstmt = gsi_stmt(gsi);
114719 + }
114720 +
114721 + dst_type = get_size_overflow_type(visited, oldstmt, lhs);
114722 +
114723 + if (is_gimple_constant(rhs1))
114724 + return cast_a_tree(dst_type, rhs1);
114725 + return cast_to_new_size_overflow_type(visited, oldstmt, rhs1, dst_type, before);
114726 +}
114727 +
114728 +tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
114729 +{
114730 + gimple stmt;
114731 + gimple_stmt_iterator gsi;
114732 + tree size_overflow_type, new_var, lhs = gimple_assign_lhs(oldstmt);
114733 +
114734 + if (pointer_set_contains(visited->my_stmts, oldstmt))
114735 + return lhs;
114736 +
114737 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
114738 + rhs1 = gimple_assign_rhs1(oldstmt);
114739 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
114740 + }
114741 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
114742 + rhs2 = gimple_assign_rhs2(oldstmt);
114743 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
114744 + }
114745 +
114746 + stmt = gimple_copy(oldstmt);
114747 + gimple_set_location(stmt, gimple_location(oldstmt));
114748 + pointer_set_insert(visited->my_stmts, stmt);
114749 +
114750 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
114751 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
114752 +
114753 + size_overflow_type = get_size_overflow_type(visited, oldstmt, node);
114754 +
114755 + new_var = create_new_var(size_overflow_type);
114756 + new_var = make_ssa_name(new_var, stmt);
114757 + gimple_assign_set_lhs(stmt, new_var);
114758 +
114759 + if (rhs1 != NULL_TREE)
114760 + gimple_assign_set_rhs1(stmt, rhs1);
114761 +
114762 + if (rhs2 != NULL_TREE)
114763 + gimple_assign_set_rhs2(stmt, rhs2);
114764 +#if BUILDING_GCC_VERSION >= 4006
114765 + if (rhs3 != NULL_TREE)
114766 + gimple_assign_set_rhs3(stmt, rhs3);
114767 +#endif
114768 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
114769 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
114770 +
114771 + gsi = gsi_for_stmt(oldstmt);
114772 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
114773 + update_stmt(stmt);
114774 + pointer_set_insert(visited->stmts, oldstmt);
114775 + return gimple_assign_lhs(stmt);
114776 +}
114777 +
114778 +static tree cast_parm_decl(struct visited *visited, tree phi_ssa_name, tree arg, tree size_overflow_type, basic_block bb)
114779 +{
114780 + gimple assign;
114781 + gimple_stmt_iterator gsi;
114782 + basic_block first_bb;
114783 +
114784 + gcc_assert(SSA_NAME_IS_DEFAULT_DEF(arg));
114785 +
114786 + if (bb->index == 0) {
114787 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
114788 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
114789 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
114790 + bb = first_bb;
114791 + }
114792 +
114793 + gsi = gsi_after_labels(bb);
114794 + assign = build_cast_stmt(visited, size_overflow_type, arg, phi_ssa_name, &gsi, BEFORE_STMT, false);
114795 + pointer_set_insert(visited->my_stmts, assign);
114796 +
114797 + return gimple_assign_lhs(assign);
114798 +}
114799 +
114800 +static tree use_phi_ssa_name(struct visited *visited, tree ssa_name_var, tree new_arg)
114801 +{
114802 + gimple_stmt_iterator gsi;
114803 + gimple assign, def_stmt = get_def_stmt(new_arg);
114804 +
114805 + if (gimple_code(def_stmt) == GIMPLE_PHI) {
114806 + gsi = gsi_after_labels(gimple_bb(def_stmt));
114807 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, BEFORE_STMT, true);
114808 + } else {
114809 + gsi = gsi_for_stmt(def_stmt);
114810 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, AFTER_STMT, true);
114811 + }
114812 +
114813 + pointer_set_insert(visited->my_stmts, assign);
114814 + return gimple_assign_lhs(assign);
114815 +}
114816 +
114817 +static tree cast_visited_phi_arg(struct visited *visited, tree ssa_name_var, tree arg, tree size_overflow_type)
114818 +{
114819 + basic_block bb;
114820 + gimple_stmt_iterator gsi;
114821 + const_gimple def_stmt;
114822 + gimple assign;
114823 +
114824 + def_stmt = get_def_stmt(arg);
114825 + bb = gimple_bb(def_stmt);
114826 + gcc_assert(bb->index != 0);
114827 + gsi = gsi_after_labels(bb);
114828 +
114829 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, BEFORE_STMT, false);
114830 + pointer_set_insert(visited->my_stmts, assign);
114831 + return gimple_assign_lhs(assign);
114832 +}
114833 +
114834 +static tree create_new_phi_arg(struct visited *visited, tree ssa_name_var, tree new_arg, gimple oldstmt, unsigned int i)
114835 +{
114836 + tree size_overflow_type;
114837 + tree arg;
114838 + const_gimple def_stmt;
114839 +
114840 + if (new_arg != NULL_TREE && is_gimple_constant(new_arg))
114841 + return new_arg;
114842 +
114843 + arg = gimple_phi_arg_def(oldstmt, i);
114844 + def_stmt = get_def_stmt(arg);
114845 + gcc_assert(def_stmt != NULL);
114846 + size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
114847 +
114848 + switch (gimple_code(def_stmt)) {
114849 + case GIMPLE_PHI:
114850 + return cast_visited_phi_arg(visited, ssa_name_var, arg, size_overflow_type);
114851 + case GIMPLE_NOP: {
114852 + basic_block bb;
114853 +
114854 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
114855 + return cast_parm_decl(visited, ssa_name_var, arg, size_overflow_type, bb);
114856 + }
114857 + case GIMPLE_ASM: {
114858 + gimple_stmt_iterator gsi;
114859 + gimple assign, stmt = get_def_stmt(arg);
114860 +
114861 + gsi = gsi_for_stmt(stmt);
114862 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, AFTER_STMT, false);
114863 + pointer_set_insert(visited->my_stmts, assign);
114864 + return gimple_assign_lhs(assign);
114865 + }
114866 + default:
114867 + gcc_assert(new_arg != NULL_TREE);
114868 + gcc_assert(types_compatible_p(TREE_TYPE(new_arg), size_overflow_type));
114869 + return use_phi_ssa_name(visited, ssa_name_var, new_arg);
114870 + }
114871 +}
114872 +
114873 +static gimple overflow_create_phi_node(struct visited *visited, gimple oldstmt, tree result)
114874 +{
114875 + basic_block bb;
114876 + gimple phi;
114877 + gimple_seq seq;
114878 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
114879 +
114880 + bb = gsi_bb(gsi);
114881 +
114882 + if (result == NULL_TREE) {
114883 + tree old_result = gimple_phi_result(oldstmt);
114884 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, old_result);
114885 +
114886 + result = create_new_var(size_overflow_type);
114887 + }
114888 +
114889 + phi = create_phi_node(result, bb);
114890 + gimple_phi_set_result(phi, make_ssa_name(result, phi));
114891 + seq = phi_nodes(bb);
114892 + gsi = gsi_last(seq);
114893 + gsi_remove(&gsi, false);
114894 +
114895 + gsi = gsi_for_stmt(oldstmt);
114896 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
114897 + gimple_set_bb(phi, bb);
114898 + return phi;
114899 +}
114900 +
114901 +#if BUILDING_GCC_VERSION <= 4007
114902 +static tree create_new_phi_node(struct visited *visited, VEC(tree, heap) **args, tree ssa_name_var, gimple oldstmt)
114903 +#else
114904 +static tree create_new_phi_node(struct visited *visited, vec<tree, va_heap, vl_embed> *&args, tree ssa_name_var, gimple oldstmt)
114905 +#endif
114906 +{
114907 + gimple new_phi;
114908 + unsigned int i;
114909 + tree arg, result;
114910 + location_t loc = gimple_location(oldstmt);
114911 +
114912 +#if BUILDING_GCC_VERSION <= 4007
114913 + gcc_assert(!VEC_empty(tree, *args));
114914 +#else
114915 + gcc_assert(!args->is_empty());
114916 +#endif
114917 +
114918 + new_phi = overflow_create_phi_node(visited, oldstmt, ssa_name_var);
114919 + result = gimple_phi_result(new_phi);
114920 + ssa_name_var = SSA_NAME_VAR(result);
114921 +
114922 +#if BUILDING_GCC_VERSION <= 4007
114923 + FOR_EACH_VEC_ELT(tree, *args, i, arg) {
114924 +#else
114925 + FOR_EACH_VEC_SAFE_ELT(args, i, arg) {
114926 +#endif
114927 + arg = create_new_phi_arg(visited, ssa_name_var, arg, oldstmt, i);
114928 + add_phi_arg(new_phi, arg, gimple_phi_arg_edge(oldstmt, i), loc);
114929 + }
114930 +
114931 +#if BUILDING_GCC_VERSION <= 4007
114932 + VEC_free(tree, heap, *args);
114933 +#else
114934 + vec_free(args);
114935 +#endif
114936 + update_stmt(new_phi);
114937 + pointer_set_insert(visited->my_stmts, new_phi);
114938 + return result;
114939 +}
114940 +
114941 +static tree handle_phi(struct visited *visited, struct cgraph_node *caller_node, tree orig_result)
114942 +{
114943 + tree ssa_name_var = NULL_TREE;
114944 +#if BUILDING_GCC_VERSION <= 4007
114945 + VEC(tree, heap) *args = NULL;
114946 +#else
114947 + vec<tree, va_heap, vl_embed> *args = NULL;
114948 +#endif
114949 + gimple oldstmt = get_def_stmt(orig_result);
114950 + unsigned int i, len = gimple_phi_num_args(oldstmt);
114951 +
114952 + pointer_set_insert(visited->stmts, oldstmt);
114953 + for (i = 0; i < len; i++) {
114954 + tree arg, new_arg;
114955 +
114956 + arg = gimple_phi_arg_def(oldstmt, i);
114957 + new_arg = expand(visited, caller_node, arg);
114958 +
114959 + if (ssa_name_var == NULL_TREE && new_arg != NULL_TREE)
114960 + ssa_name_var = SSA_NAME_VAR(new_arg);
114961 +
114962 + if (is_gimple_constant(arg)) {
114963 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
114964 +
114965 + new_arg = cast_a_tree(size_overflow_type, arg);
114966 + }
114967 +
114968 +#if BUILDING_GCC_VERSION <= 4007
114969 + VEC_safe_push(tree, heap, args, new_arg);
114970 +#else
114971 + vec_safe_push(args, new_arg);
114972 +#endif
114973 + }
114974 +
114975 +#if BUILDING_GCC_VERSION <= 4007
114976 + return create_new_phi_node(visited, &args, ssa_name_var, oldstmt);
114977 +#else
114978 + return create_new_phi_node(visited, args, ssa_name_var, oldstmt);
114979 +#endif
114980 +}
114981 +
114982 +static tree create_cast_assign(struct visited *visited, gimple stmt)
114983 +{
114984 + tree rhs1 = gimple_assign_rhs1(stmt);
114985 + tree lhs = gimple_assign_lhs(stmt);
114986 + const_tree rhs1_type = TREE_TYPE(rhs1);
114987 + const_tree lhs_type = TREE_TYPE(lhs);
114988 +
114989 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
114990 + return create_assign(visited, stmt, lhs, AFTER_STMT);
114991 +
114992 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
114993 +}
114994 +
114995 +static bool skip_lhs_cast_check(const_gimple stmt)
114996 +{
114997 + const_tree rhs = gimple_assign_rhs1(stmt);
114998 + const_gimple def_stmt = get_def_stmt(rhs);
114999 +
115000 + // 3.8.2 kernel/futex_compat.c compat_exit_robust_list(): get_user() 64 ulong -> int (compat_long_t), int max
115001 + if (gimple_code(def_stmt) == GIMPLE_ASM)
115002 + return true;
115003 +
115004 + if (is_const_plus_unsigned_signed_truncation(rhs))
115005 + return true;
115006 +
115007 + return false;
115008 +}
115009 +
115010 +static tree create_string_param(tree string)
115011 +{
115012 + tree i_type, a_type;
115013 + const int length = TREE_STRING_LENGTH(string);
115014 +
115015 + gcc_assert(length > 0);
115016 +
115017 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
115018 + a_type = build_array_type(char_type_node, i_type);
115019 +
115020 + TREE_TYPE(string) = a_type;
115021 + TREE_CONSTANT(string) = 1;
115022 + TREE_READONLY(string) = 1;
115023 +
115024 + return build1(ADDR_EXPR, ptr_type_node, string);
115025 +}
115026 +
115027 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
115028 +{
115029 + gimple cond_stmt;
115030 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
115031 +
115032 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
115033 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
115034 + update_stmt(cond_stmt);
115035 +}
115036 +
115037 +static void insert_cond_result(struct cgraph_node *caller_node, basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
115038 +{
115039 + gimple func_stmt;
115040 + const_gimple def_stmt;
115041 + const_tree loc_line;
115042 + tree loc_file, ssa_name, current_func;
115043 + expanded_location xloc;
115044 + char *ssa_name_buf;
115045 + int len;
115046 + struct cgraph_edge *edge;
115047 + struct cgraph_node *callee_node;
115048 + int frequency;
115049 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
115050 +
115051 + def_stmt = get_def_stmt(arg);
115052 + xloc = expand_location(gimple_location(def_stmt));
115053 +
115054 + if (!gimple_has_location(def_stmt)) {
115055 + xloc = expand_location(gimple_location(stmt));
115056 + if (!gimple_has_location(stmt))
115057 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
115058 + }
115059 +
115060 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
115061 +
115062 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
115063 + loc_file = create_string_param(loc_file);
115064 +
115065 + current_func = build_string(DECL_NAME_LENGTH(current_function_decl) + 1, DECL_NAME_POINTER(current_function_decl));
115066 + current_func = create_string_param(current_func);
115067 +
115068 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
115069 + call_count++;
115070 + 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);
115071 + gcc_assert(len > 0);
115072 + ssa_name = build_string(len + 1, ssa_name_buf);
115073 + free(ssa_name_buf);
115074 + ssa_name = create_string_param(ssa_name);
115075 +
115076 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
115077 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
115078 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
115079 +
115080 + callee_node = cgraph_get_create_node(report_size_overflow_decl);
115081 + frequency = compute_call_stmt_bb_frequency(current_function_decl, bb_true);
115082 +
115083 + edge = cgraph_create_edge(caller_node, callee_node, func_stmt, bb_true->count, frequency, bb_true->loop_depth);
115084 + gcc_assert(edge != NULL);
115085 +}
115086 +
115087 +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)
115088 +{
115089 + basic_block cond_bb, join_bb, bb_true;
115090 + edge e;
115091 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
115092 +
115093 + cond_bb = gimple_bb(stmt);
115094 + if (before)
115095 + gsi_prev(&gsi);
115096 + if (gsi_end_p(gsi))
115097 + e = split_block_after_labels(cond_bb);
115098 + else
115099 + e = split_block(cond_bb, gsi_stmt(gsi));
115100 + cond_bb = e->src;
115101 + join_bb = e->dest;
115102 + e->flags = EDGE_FALSE_VALUE;
115103 + e->probability = REG_BR_PROB_BASE;
115104 +
115105 + bb_true = create_empty_bb(cond_bb);
115106 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
115107 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
115108 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
115109 +
115110 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
115111 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
115112 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
115113 +
115114 + if (current_loops != NULL) {
115115 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
115116 + add_bb_to_loop(bb_true, cond_bb->loop_father);
115117 + }
115118 +
115119 + insert_cond(cond_bb, arg, cond_code, type_value);
115120 + insert_cond_result(caller_node, bb_true, stmt, arg, min);
115121 +
115122 +// print_the_code_insertions(stmt);
115123 +}
115124 +
115125 +void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
115126 +{
115127 + const_tree rhs_type = TREE_TYPE(rhs);
115128 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
115129 +
115130 + gcc_assert(rhs_type != NULL_TREE);
115131 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
115132 + return;
115133 +
115134 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
115135 +
115136 + if (is_const_plus_unsigned_signed_truncation(rhs))
115137 + return;
115138 +
115139 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
115140 + // typemax (-1) < typemin (0)
115141 + if (TREE_OVERFLOW(type_max))
115142 + return;
115143 +
115144 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
115145 +
115146 + cast_rhs_type = TREE_TYPE(cast_rhs);
115147 + type_max_type = TREE_TYPE(type_max);
115148 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
115149 +
115150 + insert_check_size_overflow(caller_node, stmt, GT_EXPR, cast_rhs, type_max, before, MAX_CHECK);
115151 +
115152 + // special case: get_size_overflow_type(), 32, u64->s
115153 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && TYPE_UNSIGNED(size_overflow_type) && !TYPE_UNSIGNED(rhs_type))
115154 + return;
115155 +
115156 + type_min_type = TREE_TYPE(type_min);
115157 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
115158 + insert_check_size_overflow(caller_node, stmt, LT_EXPR, cast_rhs, type_min, before, MIN_CHECK);
115159 +}
115160 +
115161 +static tree create_cast_overflow_check(struct visited *visited, struct cgraph_node *caller_node, tree new_rhs1, gimple stmt)
115162 +{
115163 + bool cast_lhs, cast_rhs;
115164 + tree lhs = gimple_assign_lhs(stmt);
115165 + tree rhs = gimple_assign_rhs1(stmt);
115166 + const_tree lhs_type = TREE_TYPE(lhs);
115167 + const_tree rhs_type = TREE_TYPE(rhs);
115168 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
115169 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
115170 + unsigned int lhs_size = GET_MODE_BITSIZE(lhs_mode);
115171 + unsigned int rhs_size = GET_MODE_BITSIZE(rhs_mode);
115172 +
115173 + static bool check_lhs[3][4] = {
115174 + // ss su us uu
115175 + { false, true, true, false }, // lhs > rhs
115176 + { false, false, false, false }, // lhs = rhs
115177 + { true, true, true, true }, // lhs < rhs
115178 + };
115179 +
115180 + static bool check_rhs[3][4] = {
115181 + // ss su us uu
115182 + { true, false, true, true }, // lhs > rhs
115183 + { true, false, true, true }, // lhs = rhs
115184 + { true, false, true, true }, // lhs < rhs
115185 + };
115186 +
115187 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast !!!!
115188 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
115189 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115190 +
115191 + if (lhs_size > rhs_size) {
115192 + cast_lhs = check_lhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115193 + cast_rhs = check_rhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115194 + } else if (lhs_size == rhs_size) {
115195 + cast_lhs = check_lhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115196 + cast_rhs = check_rhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115197 + } else {
115198 + cast_lhs = check_lhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115199 + cast_rhs = check_rhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115200 + }
115201 +
115202 + if (!cast_lhs && !cast_rhs)
115203 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115204 +
115205 + if (cast_lhs && !skip_lhs_cast_check(stmt))
115206 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, lhs, BEFORE_STMT);
115207 +
115208 + if (cast_rhs)
115209 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, rhs, BEFORE_STMT);
115210 +
115211 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115212 +}
115213 +
115214 +static tree handle_unary_rhs(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
115215 +{
115216 + enum tree_code rhs_code;
115217 + tree rhs1, new_rhs1, lhs = gimple_assign_lhs(stmt);
115218 +
115219 + if (pointer_set_contains(visited->my_stmts, stmt))
115220 + return lhs;
115221 +
115222 + rhs1 = gimple_assign_rhs1(stmt);
115223 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
115224 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115225 +
115226 + new_rhs1 = expand(visited, caller_node, rhs1);
115227 +
115228 + if (new_rhs1 == NULL_TREE)
115229 + return create_cast_assign(visited, stmt);
115230 +
115231 + if (pointer_set_contains(visited->no_cast_check, stmt))
115232 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115233 +
115234 + rhs_code = gimple_assign_rhs_code(stmt);
115235 + if (rhs_code == BIT_NOT_EXPR || rhs_code == NEGATE_EXPR) {
115236 + tree size_overflow_type = get_size_overflow_type(visited, stmt, rhs1);
115237 +
115238 + new_rhs1 = cast_to_new_size_overflow_type(visited, stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
115239 + check_size_overflow(caller_node, stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
115240 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115241 + }
115242 +
115243 + if (!gimple_assign_cast_p(stmt))
115244 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115245 +
115246 + return create_cast_overflow_check(visited, caller_node, new_rhs1, stmt);
115247 +}
115248 +
115249 +static tree handle_unary_ops(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
115250 +{
115251 + tree rhs1, lhs = gimple_assign_lhs(stmt);
115252 + gimple def_stmt = get_def_stmt(lhs);
115253 +
115254 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
115255 + rhs1 = gimple_assign_rhs1(def_stmt);
115256 +
115257 + if (is_gimple_constant(rhs1))
115258 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115259 +
115260 + switch (TREE_CODE(rhs1)) {
115261 + case SSA_NAME: {
115262 + tree ret = handle_unary_rhs(visited, caller_node, def_stmt);
115263 +
115264 + if (gimple_assign_cast_p(stmt))
115265 + unsigned_signed_cast_intentional_overflow(visited, stmt);
115266 + return ret;
115267 + }
115268 + case ARRAY_REF:
115269 + case BIT_FIELD_REF:
115270 + case ADDR_EXPR:
115271 + case COMPONENT_REF:
115272 + case INDIRECT_REF:
115273 +#if BUILDING_GCC_VERSION >= 4006
115274 + case MEM_REF:
115275 +#endif
115276 + case TARGET_MEM_REF:
115277 + case VIEW_CONVERT_EXPR:
115278 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115279 + case PARM_DECL:
115280 + case VAR_DECL:
115281 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115282 +
115283 + default:
115284 + debug_gimple_stmt(def_stmt);
115285 + debug_tree(rhs1);
115286 + gcc_unreachable();
115287 + }
115288 +}
115289 +
115290 +static void __unused print_the_code_insertions(const_gimple stmt)
115291 +{
115292 + location_t loc = gimple_location(stmt);
115293 +
115294 + inform(loc, "Integer size_overflow check applied here.");
115295 +}
115296 +
115297 +static bool is_from_cast(const_tree node)
115298 +{
115299 + gimple def_stmt = get_def_stmt(node);
115300 +
115301 + if (!def_stmt)
115302 + return false;
115303 +
115304 + if (gimple_assign_cast_p(def_stmt))
115305 + return true;
115306 +
115307 + return false;
115308 +}
115309 +
115310 +// Skip duplication when there is a minus expr and the type of rhs1 or rhs2 is a pointer_type.
115311 +static bool is_a_ptr_minus(gimple stmt)
115312 +{
115313 + const_tree rhs1, rhs2, ptr1_rhs, ptr2_rhs;
115314 +
115315 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
115316 + return false;
115317 +
115318 + rhs1 = gimple_assign_rhs1(stmt);
115319 + if (!is_from_cast(rhs1))
115320 + return false;
115321 +
115322 + rhs2 = gimple_assign_rhs2(stmt);
115323 + if (!is_from_cast(rhs2))
115324 + return false;
115325 +
115326 + ptr1_rhs = gimple_assign_rhs1(get_def_stmt(rhs1));
115327 + ptr2_rhs = gimple_assign_rhs1(get_def_stmt(rhs2));
115328 +
115329 + if (TREE_CODE(TREE_TYPE(ptr1_rhs)) != POINTER_TYPE && TREE_CODE(TREE_TYPE(ptr2_rhs)) != POINTER_TYPE)
115330 + return false;
115331 +
115332 + return true;
115333 +}
115334 +
115335 +static tree handle_binary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
115336 +{
115337 + enum intentional_overflow_type res;
115338 + tree rhs1, rhs2, new_lhs;
115339 + gimple def_stmt = get_def_stmt(lhs);
115340 + tree new_rhs1 = NULL_TREE;
115341 + tree new_rhs2 = NULL_TREE;
115342 +
115343 + if (is_a_ptr_minus(def_stmt))
115344 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115345 +
115346 + rhs1 = gimple_assign_rhs1(def_stmt);
115347 + rhs2 = gimple_assign_rhs2(def_stmt);
115348 +
115349 + /* no DImode/TImode division in the 32/64 bit kernel */
115350 + switch (gimple_assign_rhs_code(def_stmt)) {
115351 + case RDIV_EXPR:
115352 + case TRUNC_DIV_EXPR:
115353 + case CEIL_DIV_EXPR:
115354 + case FLOOR_DIV_EXPR:
115355 + case ROUND_DIV_EXPR:
115356 + case TRUNC_MOD_EXPR:
115357 + case CEIL_MOD_EXPR:
115358 + case FLOOR_MOD_EXPR:
115359 + case ROUND_MOD_EXPR:
115360 + case EXACT_DIV_EXPR:
115361 + case POINTER_PLUS_EXPR:
115362 + case BIT_AND_EXPR:
115363 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115364 + default:
115365 + break;
115366 + }
115367 +
115368 + new_lhs = handle_integer_truncation(visited, caller_node, lhs);
115369 + if (new_lhs != NULL_TREE)
115370 + return new_lhs;
115371 +
115372 + if (TREE_CODE(rhs1) == SSA_NAME)
115373 + new_rhs1 = expand(visited, caller_node, rhs1);
115374 + if (TREE_CODE(rhs2) == SSA_NAME)
115375 + new_rhs2 = expand(visited, caller_node, rhs2);
115376 +
115377 + res = add_mul_intentional_overflow(def_stmt);
115378 + if (res != NO_INTENTIONAL_OVERFLOW) {
115379 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
115380 + insert_cast_expr(visited, get_def_stmt(new_lhs), res);
115381 + return new_lhs;
115382 + }
115383 +
115384 + if (skip_expr_on_double_type(def_stmt)) {
115385 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
115386 + insert_cast_expr(visited, get_def_stmt(new_lhs), NO_INTENTIONAL_OVERFLOW);
115387 + return new_lhs;
115388 + }
115389 +
115390 + if (is_a_neg_overflow(def_stmt, rhs2))
115391 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs1, NULL_TREE);
115392 + if (is_a_neg_overflow(def_stmt, rhs1))
115393 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs2, new_rhs2);
115394 +
115395 +
115396 + if (is_a_constant_overflow(def_stmt, rhs2))
115397 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, NULL_TREE);
115398 + if (is_a_constant_overflow(def_stmt, rhs1))
115399 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, new_rhs2);
115400 +
115401 + // the const is between 0 and (signed) MAX
115402 + if (is_gimple_constant(rhs1))
115403 + new_rhs1 = create_assign(visited, def_stmt, rhs1, BEFORE_STMT);
115404 + if (is_gimple_constant(rhs2))
115405 + new_rhs2 = create_assign(visited, def_stmt, rhs2, BEFORE_STMT);
115406 +
115407 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
115408 +}
115409 +
115410 +#if BUILDING_GCC_VERSION >= 4006
115411 +static tree get_new_rhs(struct visited *visited, struct cgraph_node *caller_node, tree size_overflow_type, tree rhs)
115412 +{
115413 + if (is_gimple_constant(rhs))
115414 + return cast_a_tree(size_overflow_type, rhs);
115415 + if (TREE_CODE(rhs) != SSA_NAME)
115416 + return NULL_TREE;
115417 + return expand(visited, caller_node, rhs);
115418 +}
115419 +
115420 +static tree handle_ternary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
115421 +{
115422 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
115423 + gimple def_stmt = get_def_stmt(lhs);
115424 +
115425 + size_overflow_type = get_size_overflow_type(visited, def_stmt, lhs);
115426 +
115427 + rhs1 = gimple_assign_rhs1(def_stmt);
115428 + rhs2 = gimple_assign_rhs2(def_stmt);
115429 + rhs3 = gimple_assign_rhs3(def_stmt);
115430 + new_rhs1 = get_new_rhs(visited, caller_node, size_overflow_type, rhs1);
115431 + new_rhs2 = get_new_rhs(visited, caller_node, size_overflow_type, rhs2);
115432 + new_rhs3 = get_new_rhs(visited, caller_node, size_overflow_type, rhs3);
115433 +
115434 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
115435 +}
115436 +#endif
115437 +
115438 +static tree get_my_stmt_lhs(struct visited *visited, gimple stmt)
115439 +{
115440 + gimple_stmt_iterator gsi;
115441 + gimple next_stmt = NULL;
115442 +
115443 + gsi = gsi_for_stmt(stmt);
115444 +
115445 + do {
115446 + gsi_next(&gsi);
115447 + next_stmt = gsi_stmt(gsi);
115448 +
115449 + if (gimple_code(stmt) == GIMPLE_PHI && !pointer_set_contains(visited->my_stmts, next_stmt))
115450 + return NULL_TREE;
115451 +
115452 + if (pointer_set_contains(visited->my_stmts, next_stmt) && !pointer_set_contains(visited->skip_expr_casts, next_stmt))
115453 + break;
115454 +
115455 + gcc_assert(pointer_set_contains(visited->my_stmts, next_stmt));
115456 + } while (!gsi_end_p(gsi));
115457 +
115458 + gcc_assert(next_stmt);
115459 + return get_lhs(next_stmt);
115460 +}
115461 +
115462 +static tree expand_visited(struct visited *visited, gimple def_stmt)
115463 +{
115464 + gimple_stmt_iterator gsi;
115465 + enum gimple_code code = gimple_code(def_stmt);
115466 +
115467 + if (code == GIMPLE_ASM)
115468 + return NULL_TREE;
115469 +
115470 + gsi = gsi_for_stmt(def_stmt);
115471 + gsi_next(&gsi);
115472 +
115473 + if (gimple_code(def_stmt) == GIMPLE_PHI && gsi_end_p(gsi))
115474 + return NULL_TREE;
115475 + return get_my_stmt_lhs(visited, def_stmt);
115476 +}
115477 +
115478 +tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
115479 +{
115480 + gimple def_stmt;
115481 +
115482 + def_stmt = get_def_stmt(lhs);
115483 +
115484 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
115485 + return NULL_TREE;
115486 +
115487 + if (pointer_set_contains(visited->my_stmts, def_stmt))
115488 + return lhs;
115489 +
115490 + if (pointer_set_contains(visited->stmts, def_stmt))
115491 + return expand_visited(visited, def_stmt);
115492 +
115493 + switch (gimple_code(def_stmt)) {
115494 + case GIMPLE_PHI:
115495 + return handle_phi(visited, caller_node, lhs);
115496 + case GIMPLE_CALL:
115497 + case GIMPLE_ASM:
115498 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115499 + case GIMPLE_ASSIGN:
115500 + switch (gimple_num_ops(def_stmt)) {
115501 + case 2:
115502 + return handle_unary_ops(visited, caller_node, def_stmt);
115503 + case 3:
115504 + return handle_binary_ops(visited, caller_node, lhs);
115505 +#if BUILDING_GCC_VERSION >= 4006
115506 + case 4:
115507 + return handle_ternary_ops(visited, caller_node, lhs);
115508 +#endif
115509 + }
115510 + default:
115511 + debug_gimple_stmt(def_stmt);
115512 + error("%s: unknown gimple code", __func__);
115513 + gcc_unreachable();
115514 + }
115515 +}
115516 +
115517 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
115518 new file mode 100644
115519 index 0000000..df50164
115520 --- /dev/null
115521 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_ipa.c
115522 @@ -0,0 +1,1141 @@
115523 +/*
115524 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
115525 + * Licensed under the GPL v2, or (at your option) v3
115526 + *
115527 + * Homepage:
115528 + * http://www.grsecurity.net/~ephox/overflow_plugin/
115529 + *
115530 + * Documentation:
115531 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
115532 + *
115533 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
115534 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
115535 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
115536 + *
115537 + * Usage:
115538 + * $ make
115539 + * $ make run
115540 + */
115541 +
115542 +#include "gcc-common.h"
115543 +#include "size_overflow.h"
115544 +
115545 +#define VEC_LEN 128
115546 +#define RET_CHECK NULL_TREE
115547 +#define WRONG_NODE 32
115548 +#define NOT_INTENTIONAL_ASM NULL
115549 +
115550 +unsigned int call_count;
115551 +
115552 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs);
115553 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs);
115554 +
115555 +struct visited_fns {
115556 + struct visited_fns *next;
115557 + const_tree fndecl;
115558 + unsigned int num;
115559 + const_gimple first_stmt;
115560 +};
115561 +
115562 +struct next_cgraph_node {
115563 + struct next_cgraph_node *next;
115564 + struct cgraph_node *current_function;
115565 + tree callee_fndecl;
115566 + unsigned int num;
115567 +};
115568 +
115569 +// Don't want to duplicate entries in next_cgraph_node
115570 +static bool is_in_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, const_tree fndecl, unsigned int num)
115571 +{
115572 + const_tree new_callee_fndecl;
115573 + struct next_cgraph_node *cur_node;
115574 +
115575 + if (fndecl == RET_CHECK)
115576 + new_callee_fndecl = NODE_DECL(node);
115577 + else
115578 + new_callee_fndecl = fndecl;
115579 +
115580 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
115581 + if (!operand_equal_p(NODE_DECL(cur_node->current_function), NODE_DECL(node), 0))
115582 + continue;
115583 + if (!operand_equal_p(cur_node->callee_fndecl, new_callee_fndecl, 0))
115584 + continue;
115585 + if (num == cur_node->num)
115586 + return true;
115587 + }
115588 + return false;
115589 +}
115590 +
115591 +/* Add a next_cgraph_node into the list for handle_function().
115592 + * handle_function() iterates over all the next cgraph nodes and
115593 + * starts the overflow check insertion process.
115594 + */
115595 +static struct next_cgraph_node *create_new_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, tree fndecl, unsigned int num)
115596 +{
115597 + struct next_cgraph_node *new_node;
115598 +
115599 + if (is_in_next_cgraph_node(head, node, fndecl, num))
115600 + return head;
115601 +
115602 + new_node = (struct next_cgraph_node *)xmalloc(sizeof(*new_node));
115603 + new_node->current_function = node;
115604 + new_node->next = NULL;
115605 + new_node->num = num;
115606 + if (fndecl == RET_CHECK)
115607 + new_node->callee_fndecl = NODE_DECL(node);
115608 + else
115609 + new_node->callee_fndecl = fndecl;
115610 +
115611 + if (!head)
115612 + return new_node;
115613 +
115614 + new_node->next = head;
115615 + return new_node;
115616 +}
115617 +
115618 +static struct next_cgraph_node *create_new_next_cgraph_nodes(struct next_cgraph_node *head, struct cgraph_node *node, unsigned int num)
115619 +{
115620 + struct cgraph_edge *e;
115621 +
115622 + if (num == 0)
115623 + return create_new_next_cgraph_node(head, node, RET_CHECK, num);
115624 +
115625 + for (e = node->callers; e; e = e->next_caller) {
115626 + tree fndecl = gimple_call_fndecl(e->call_stmt);
115627 +
115628 + gcc_assert(fndecl != NULL_TREE);
115629 + head = create_new_next_cgraph_node(head, e->caller, fndecl, num);
115630 + }
115631 +
115632 + return head;
115633 +}
115634 +
115635 +struct missing_functions {
115636 + struct missing_functions *next;
115637 + const_tree node;
115638 + tree fndecl;
115639 +};
115640 +
115641 +static struct missing_functions *create_new_missing_function(struct missing_functions *missing_fn_head, tree node)
115642 +{
115643 + struct missing_functions *new_function;
115644 +
115645 + new_function = (struct missing_functions *)xmalloc(sizeof(*new_function));
115646 + new_function->node = node;
115647 + new_function->next = NULL;
115648 +
115649 + if (TREE_CODE(node) == FUNCTION_DECL)
115650 + new_function->fndecl = node;
115651 + else
115652 + new_function->fndecl = current_function_decl;
115653 + gcc_assert(new_function->fndecl);
115654 +
115655 + if (!missing_fn_head)
115656 + return new_function;
115657 +
115658 + new_function->next = missing_fn_head;
115659 + return new_function;
115660 +}
115661 +
115662 +/* If the function is missing from the hash table and it is a static function
115663 + * then create a next_cgraph_node from it for handle_function()
115664 + */
115665 +static struct next_cgraph_node *check_missing_overflow_attribute_and_create_next_node(struct next_cgraph_node *cnodes, struct missing_functions *missing_fn_head)
115666 +{
115667 + unsigned int num;
115668 + const_tree orig_fndecl;
115669 + struct cgraph_node *next_node = NULL;
115670 +
115671 + orig_fndecl = DECL_ORIGIN(missing_fn_head->fndecl);
115672 +
115673 + num = get_function_num(missing_fn_head->node, orig_fndecl);
115674 + if (num == CANNOT_FIND_ARG)
115675 + return cnodes;
115676 +
115677 + if (!is_missing_function(orig_fndecl, num))
115678 + return cnodes;
115679 +
115680 + next_node = cgraph_get_node(missing_fn_head->fndecl);
115681 + if (next_node && next_node->local.local)
115682 + cnodes = create_new_next_cgraph_nodes(cnodes, next_node, num);
115683 + return cnodes;
115684 +}
115685 +
115686 +/* Search for missing size_overflow attributes on the last nodes in ipa and collect them
115687 + * into the next_cgraph_node list. They will be the next interesting returns or callees.
115688 + */
115689 +static struct next_cgraph_node *search_overflow_attribute(struct next_cgraph_node *cnodes, struct interesting_node *cur_node)
115690 +{
115691 + unsigned int i;
115692 + tree node;
115693 + struct missing_functions *cur, *missing_fn_head = NULL;
115694 +
115695 +#if BUILDING_GCC_VERSION <= 4007
115696 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, node) {
115697 +#else
115698 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, node) {
115699 +#endif
115700 + switch (TREE_CODE(node)) {
115701 + case PARM_DECL:
115702 + if (TREE_CODE(TREE_TYPE(node)) != INTEGER_TYPE)
115703 + break;
115704 + case FUNCTION_DECL:
115705 + missing_fn_head = create_new_missing_function(missing_fn_head, node);
115706 + break;
115707 + default:
115708 + break;
115709 + }
115710 + }
115711 +
115712 + while (missing_fn_head) {
115713 + cnodes = check_missing_overflow_attribute_and_create_next_node(cnodes, missing_fn_head);
115714 +
115715 + cur = missing_fn_head->next;
115716 + free(missing_fn_head);
115717 + missing_fn_head = cur;
115718 + }
115719 +
115720 + return cnodes;
115721 +}
115722 +
115723 +static void walk_phi_set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree result)
115724 +{
115725 + gimple phi = get_def_stmt(result);
115726 + unsigned int i, n = gimple_phi_num_args(phi);
115727 +
115728 + pointer_set_insert(visited, phi);
115729 + for (i = 0; i < n; i++) {
115730 + const_tree arg = gimple_phi_arg_def(phi, i);
115731 +
115732 + set_conditions(visited, interesting_conditions, arg);
115733 + }
115734 +}
115735 +
115736 +enum conditions {
115737 + FROM_CONST, NOT_UNARY, CAST, RET, PHI
115738 +};
115739 +
115740 +// Search for constants, cast assignments and binary/ternary assignments
115741 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs)
115742 +{
115743 + gimple def_stmt = get_def_stmt(lhs);
115744 +
115745 + if (is_gimple_constant(lhs)) {
115746 + interesting_conditions[FROM_CONST] = true;
115747 + return;
115748 + }
115749 +
115750 + if (!def_stmt)
115751 + return;
115752 +
115753 + if (pointer_set_contains(visited, def_stmt))
115754 + return;
115755 +
115756 + switch (gimple_code(def_stmt)) {
115757 + case GIMPLE_CALL:
115758 + if (lhs == gimple_call_lhs(def_stmt))
115759 + interesting_conditions[RET] = true;
115760 + return;
115761 + case GIMPLE_NOP:
115762 + case GIMPLE_ASM:
115763 + return;
115764 + case GIMPLE_PHI:
115765 + interesting_conditions[PHI] = true;
115766 + return walk_phi_set_conditions(visited, interesting_conditions, lhs);
115767 + case GIMPLE_ASSIGN:
115768 + if (gimple_num_ops(def_stmt) == 2) {
115769 + const_tree rhs = gimple_assign_rhs1(def_stmt);
115770 +
115771 + if (gimple_assign_cast_p(def_stmt))
115772 + interesting_conditions[CAST] = true;
115773 +
115774 + return set_conditions(visited, interesting_conditions, rhs);
115775 + } else {
115776 + interesting_conditions[NOT_UNARY] = true;
115777 + return;
115778 + }
115779 + default:
115780 + debug_gimple_stmt(def_stmt);
115781 + gcc_unreachable();
115782 + }
115783 +}
115784 +
115785 +// determine whether duplication will be necessary or not.
115786 +static void search_interesting_conditions(struct interesting_node *cur_node, bool *interesting_conditions)
115787 +{
115788 + struct pointer_set_t *visited;
115789 +
115790 + if (gimple_assign_cast_p(cur_node->first_stmt))
115791 + interesting_conditions[CAST] = true;
115792 + else if (is_gimple_assign(cur_node->first_stmt) && gimple_num_ops(cur_node->first_stmt) > 2)
115793 + interesting_conditions[NOT_UNARY] = true;
115794 +
115795 + visited = pointer_set_create();
115796 + set_conditions(visited, interesting_conditions, cur_node->node);
115797 + pointer_set_destroy(visited);
115798 +}
115799 +
115800 +// Remove the size_overflow asm stmt and create an assignment from the input and output of the asm
115801 +static void replace_size_overflow_asm_with_assign(gimple asm_stmt, tree lhs, tree rhs)
115802 +{
115803 + gimple assign;
115804 + gimple_stmt_iterator gsi;
115805 +
115806 + // already removed
115807 + if (gimple_bb(asm_stmt) == NULL)
115808 + return;
115809 + gsi = gsi_for_stmt(asm_stmt);
115810 +
115811 + assign = gimple_build_assign(lhs, rhs);
115812 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
115813 + SSA_NAME_DEF_STMT(lhs) = assign;
115814 +
115815 + gsi_remove(&gsi, true);
115816 +}
115817 +
115818 +/* Get the fndecl of an interesting stmt, the fndecl is the caller function if the interesting
115819 + * stmt is a return otherwise it is the callee function.
115820 + */
115821 +const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum)
115822 +{
115823 + const_tree fndecl;
115824 +
115825 + if (argnum == 0)
115826 + fndecl = current_function_decl;
115827 + else
115828 + fndecl = gimple_call_fndecl(stmt);
115829 +
115830 + if (fndecl == NULL_TREE)
115831 + return NULL_TREE;
115832 +
115833 + return DECL_ORIGIN(fndecl);
115834 +}
115835 +
115836 +// e.g., 3.8.2, 64, arch/x86/ia32/ia32_signal.c copy_siginfo_from_user32(): compat_ptr() u32 max
115837 +static bool skip_asm(const_tree arg)
115838 +{
115839 + gimple def_stmt = get_def_stmt(arg);
115840 +
115841 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
115842 + return false;
115843 +
115844 + def_stmt = get_def_stmt(gimple_assign_rhs1(def_stmt));
115845 + return def_stmt && gimple_code(def_stmt) == GIMPLE_ASM;
115846 +}
115847 +
115848 +static void walk_use_def_phi(struct pointer_set_t *visited, struct interesting_node *cur_node, tree result)
115849 +{
115850 + gimple phi = get_def_stmt(result);
115851 + unsigned int i, n = gimple_phi_num_args(phi);
115852 +
115853 + pointer_set_insert(visited, phi);
115854 + for (i = 0; i < n; i++) {
115855 + tree arg = gimple_phi_arg_def(phi, i);
115856 +
115857 + walk_use_def(visited, cur_node, arg);
115858 + }
115859 +}
115860 +
115861 +static void walk_use_def_binary(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
115862 +{
115863 + gimple def_stmt = get_def_stmt(lhs);
115864 + tree rhs1, rhs2;
115865 +
115866 + rhs1 = gimple_assign_rhs1(def_stmt);
115867 + rhs2 = gimple_assign_rhs2(def_stmt);
115868 +
115869 + walk_use_def(visited, cur_node, rhs1);
115870 + walk_use_def(visited, cur_node, rhs2);
115871 +}
115872 +
115873 +static void insert_last_node(struct interesting_node *cur_node, tree node)
115874 +{
115875 + unsigned int i;
115876 + tree element;
115877 + enum tree_code code;
115878 +
115879 + gcc_assert(node != NULL_TREE);
115880 +
115881 + if (is_gimple_constant(node))
115882 + return;
115883 +
115884 + code = TREE_CODE(node);
115885 + if (code == VAR_DECL) {
115886 + node = DECL_ORIGIN(node);
115887 + code = TREE_CODE(node);
115888 + }
115889 +
115890 + if (code != PARM_DECL && code != FUNCTION_DECL && code != COMPONENT_REF)
115891 + return;
115892 +
115893 +#if BUILDING_GCC_VERSION <= 4007
115894 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, element) {
115895 +#else
115896 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, element) {
115897 +#endif
115898 + if (operand_equal_p(node, element, 0))
115899 + return;
115900 + }
115901 +
115902 +#if BUILDING_GCC_VERSION <= 4007
115903 + gcc_assert(VEC_length(tree, cur_node->last_nodes) < VEC_LEN);
115904 + VEC_safe_push(tree, gc, cur_node->last_nodes, node);
115905 +#else
115906 + gcc_assert(cur_node->last_nodes->length() < VEC_LEN);
115907 + vec_safe_push(cur_node->last_nodes, node);
115908 +#endif
115909 +}
115910 +
115911 +// a size_overflow asm stmt in the control flow doesn't stop the recursion
115912 +static void handle_asm_stmt(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs, const_gimple stmt)
115913 +{
115914 + if (!is_size_overflow_asm(stmt))
115915 + walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
115916 +}
115917 +
115918 +/* collect the parm_decls and fndecls (for checking a missing size_overflow attribute (ret or arg) or intentional_overflow)
115919 + * and component refs (for checking the intentional_overflow attribute).
115920 + */
115921 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
115922 +{
115923 + const_gimple def_stmt;
115924 +
115925 + if (TREE_CODE(lhs) != SSA_NAME) {
115926 + insert_last_node(cur_node, lhs);
115927 + return;
115928 + }
115929 +
115930 + def_stmt = get_def_stmt(lhs);
115931 + if (!def_stmt)
115932 + return;
115933 +
115934 + if (pointer_set_insert(visited, def_stmt))
115935 + return;
115936 +
115937 + switch (gimple_code(def_stmt)) {
115938 + case GIMPLE_NOP:
115939 + return walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
115940 + case GIMPLE_ASM:
115941 + return handle_asm_stmt(visited, cur_node, lhs, def_stmt);
115942 + case GIMPLE_CALL: {
115943 + tree fndecl = gimple_call_fndecl(def_stmt);
115944 +
115945 + if (fndecl == NULL_TREE)
115946 + return;
115947 + insert_last_node(cur_node, fndecl);
115948 + return;
115949 + }
115950 + case GIMPLE_PHI:
115951 + return walk_use_def_phi(visited, cur_node, lhs);
115952 + case GIMPLE_ASSIGN:
115953 + switch (gimple_num_ops(def_stmt)) {
115954 + case 2:
115955 + return walk_use_def(visited, cur_node, gimple_assign_rhs1(def_stmt));
115956 + case 3:
115957 + return walk_use_def_binary(visited, cur_node, lhs);
115958 + }
115959 + default:
115960 + debug_gimple_stmt((gimple)def_stmt);
115961 + error("%s: unknown gimple code", __func__);
115962 + gcc_unreachable();
115963 + }
115964 +}
115965 +
115966 +// Collect all the last nodes for checking the intentional_overflow and size_overflow attributes
115967 +static void set_last_nodes(struct interesting_node *cur_node)
115968 +{
115969 + struct pointer_set_t *visited;
115970 +
115971 + visited = pointer_set_create();
115972 + walk_use_def(visited, cur_node, cur_node->node);
115973 + pointer_set_destroy(visited);
115974 +}
115975 +
115976 +enum precond {
115977 + NO_ATTRIBUTE_SEARCH, NO_CHECK_INSERT, NONE
115978 +};
115979 +
115980 +/* 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.
115981 + * There is only missing size_overflow attribute checking if the intentional_overflow attribute is the mark_no type.
115982 + * Stmt duplication is unnecessary if there are no binary/ternary assignements or if the unary assignment isn't a cast.
115983 + * It skips the possible error codes too.
115984 + */
115985 +static enum precond check_preconditions(struct interesting_node *cur_node)
115986 +{
115987 + bool interesting_conditions[5] = {false, false, false, false, false};
115988 +
115989 + set_last_nodes(cur_node);
115990 +
115991 + check_intentional_attribute_ipa(cur_node);
115992 + if (cur_node->intentional_attr_decl == MARK_TURN_OFF || cur_node->intentional_attr_cur_fndecl == MARK_TURN_OFF)
115993 + return NO_ATTRIBUTE_SEARCH;
115994 +
115995 + search_interesting_conditions(cur_node, interesting_conditions);
115996 +
115997 + // error code: a phi, unary assign (not cast) and returns only
115998 + if (!interesting_conditions[NOT_UNARY] && interesting_conditions[PHI] && interesting_conditions[RET] && !interesting_conditions[CAST])
115999 + return NO_ATTRIBUTE_SEARCH;
116000 +
116001 + // error code: def_stmts trace back to a constant and there are no binary/ternary assigments
116002 + if (interesting_conditions[CAST] && interesting_conditions[FROM_CONST] && !interesting_conditions[NOT_UNARY])
116003 + return NO_ATTRIBUTE_SEARCH;
116004 +
116005 + // unnecessary overflow check
116006 + if (!interesting_conditions[CAST] && !interesting_conditions[NOT_UNARY])
116007 + return NO_CHECK_INSERT;
116008 +
116009 + if (cur_node->intentional_attr_cur_fndecl != MARK_NO)
116010 + return NO_CHECK_INSERT;
116011 +
116012 + return NONE;
116013 +}
116014 +
116015 +static tree cast_to_orig_type(struct visited *visited, gimple stmt, const_tree orig_node, tree new_node)
116016 +{
116017 + const_gimple assign;
116018 + tree orig_type = TREE_TYPE(orig_node);
116019 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
116020 +
116021 + assign = build_cast_stmt(visited, orig_type, new_node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
116022 + return gimple_assign_lhs(assign);
116023 +}
116024 +
116025 +static void change_orig_node(struct visited *visited, struct interesting_node *cur_node, tree new_node)
116026 +{
116027 + void (*set_rhs)(gimple, tree);
116028 + gimple stmt = cur_node->first_stmt;
116029 + const_tree orig_node = cur_node->node;
116030 +
116031 + switch (gimple_code(stmt)) {
116032 + case GIMPLE_RETURN:
116033 + gimple_return_set_retval(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
116034 + break;
116035 + case GIMPLE_CALL:
116036 + gimple_call_set_arg(stmt, cur_node->num - 1, cast_to_orig_type(visited, stmt, orig_node, new_node));
116037 + break;
116038 + case GIMPLE_ASSIGN:
116039 + switch (cur_node->num) {
116040 + case 1:
116041 + set_rhs = &gimple_assign_set_rhs1;
116042 + break;
116043 + case 2:
116044 + set_rhs = &gimple_assign_set_rhs2;
116045 + break;
116046 +#if BUILDING_GCC_VERSION >= 4006
116047 + case 3:
116048 + set_rhs = &gimple_assign_set_rhs3;
116049 + break;
116050 +#endif
116051 + default:
116052 + gcc_unreachable();
116053 + }
116054 +
116055 + set_rhs(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
116056 + break;
116057 + default:
116058 + debug_gimple_stmt(stmt);
116059 + gcc_unreachable();
116060 + }
116061 +
116062 + update_stmt(stmt);
116063 +}
116064 +
116065 +static struct visited *create_visited(void)
116066 +{
116067 + struct visited *new_node;
116068 +
116069 + new_node = (struct visited *)xmalloc(sizeof(*new_node));
116070 + new_node->stmts = pointer_set_create();
116071 + new_node->my_stmts = pointer_set_create();
116072 + new_node->skip_expr_casts = pointer_set_create();
116073 + new_node->no_cast_check = pointer_set_create();
116074 + return new_node;
116075 +}
116076 +
116077 +static void free_visited(struct visited *visited)
116078 +{
116079 + pointer_set_destroy(visited->stmts);
116080 + pointer_set_destroy(visited->my_stmts);
116081 + pointer_set_destroy(visited->skip_expr_casts);
116082 + pointer_set_destroy(visited->no_cast_check);
116083 +
116084 + free(visited);
116085 +}
116086 +
116087 +/* This function calls the main recursion function (expand) that duplicates the stmts. Before that it checks the intentional_overflow attribute and asm stmts,
116088 + * 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
116089 + * in the original stmt (first stmt) and it inserts the overflow check for the arg of the callee or for the return value.
116090 + */
116091 +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)
116092 +{
116093 + enum precond ret;
116094 + tree new_node, orig_node = cur_node->node;
116095 +
116096 + ret = check_preconditions(cur_node);
116097 + if (ret == NO_ATTRIBUTE_SEARCH)
116098 + return cnodes;
116099 +
116100 + cnodes = search_overflow_attribute(cnodes, cur_node);
116101 +
116102 + if (ret == NO_CHECK_INSERT)
116103 + return cnodes;
116104 +
116105 + new_node = expand(visited, caller_node, orig_node);
116106 + if (new_node == NULL_TREE)
116107 + return cnodes;
116108 +
116109 + change_orig_node(visited, cur_node, new_node);
116110 + check_size_overflow(caller_node, cur_node->first_stmt, TREE_TYPE(new_node), new_node, orig_node, BEFORE_STMT);
116111 +
116112 + return cnodes;
116113 +}
116114 +
116115 +// Check visited_fns interesting nodes.
116116 +static bool is_in_interesting_node(struct interesting_node *head, const_gimple first_stmt, const_tree node, unsigned int num)
116117 +{
116118 + struct interesting_node *cur;
116119 +
116120 + for (cur = head; cur; cur = cur->next) {
116121 + if (!operand_equal_p(node, cur->node, 0))
116122 + continue;
116123 + if (num != cur->num)
116124 + continue;
116125 + if (first_stmt == cur->first_stmt)
116126 + return true;
116127 + }
116128 + return false;
116129 +}
116130 +
116131 +/* Create an interesting node. The ipa pass starts to duplicate from these stmts.
116132 + 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
116133 + 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
116134 + the intentional_overflow attribute check. They are collected by set_last_nodes().
116135 + num: arg count of a call stmt or 0 when it is a ret
116136 + node: the recursion starts from here, it is a call arg or a return value
116137 + 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.
116138 + intentional_attr_decl: intentional_overflow attribute of the callee function
116139 + intentional_attr_cur_fndecl: intentional_overflow attribute of the caller function
116140 + intentional_mark_from_gimple: the intentional overflow type of size_overflow asm stmt from gimple if it exists
116141 + */
116142 +static struct interesting_node *create_new_interesting_node(struct interesting_node *head, gimple first_stmt, tree node, unsigned int num, gimple asm_stmt)
116143 +{
116144 + struct interesting_node *new_node;
116145 + tree fndecl;
116146 + enum gimple_code code;
116147 +
116148 + gcc_assert(node != NULL_TREE);
116149 + code = gimple_code(first_stmt);
116150 + gcc_assert(code == GIMPLE_CALL || code == GIMPLE_ASM || code == GIMPLE_ASSIGN || code == GIMPLE_RETURN);
116151 +
116152 + if (num == CANNOT_FIND_ARG)
116153 + return head;
116154 +
116155 + if (skip_types(node))
116156 + return head;
116157 +
116158 + if (skip_asm(node))
116159 + return head;
116160 +
116161 + if (is_gimple_call(first_stmt))
116162 + fndecl = gimple_call_fndecl(first_stmt);
116163 + else
116164 + fndecl = current_function_decl;
116165 +
116166 + if (fndecl == NULL_TREE)
116167 + return head;
116168 +
116169 + if (is_in_interesting_node(head, first_stmt, node, num))
116170 + return head;
116171 +
116172 + new_node = (struct interesting_node *)xmalloc(sizeof(*new_node));
116173 +
116174 + new_node->next = NULL;
116175 + new_node->first_stmt = first_stmt;
116176 +#if BUILDING_GCC_VERSION <= 4007
116177 + new_node->last_nodes = VEC_alloc(tree, gc, VEC_LEN);
116178 +#else
116179 + vec_alloc(new_node->last_nodes, VEC_LEN);
116180 +#endif
116181 + new_node->num = num;
116182 + new_node->node = node;
116183 + new_node->fndecl = fndecl;
116184 + new_node->intentional_attr_decl = MARK_NO;
116185 + new_node->intentional_attr_cur_fndecl = MARK_NO;
116186 + new_node->intentional_mark_from_gimple = asm_stmt;
116187 +
116188 + if (!head)
116189 + return new_node;
116190 +
116191 + new_node->next = head;
116192 + return new_node;
116193 +}
116194 +
116195 +/* 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).
116196 + * If the ret stmt is in the next cgraph node list then it's an interesting ret.
116197 + */
116198 +static struct interesting_node *handle_stmt_by_cgraph_nodes_ret(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
116199 +{
116200 + struct next_cgraph_node *cur_node;
116201 + tree ret = gimple_return_retval(stmt);
116202 +
116203 + if (ret == NULL_TREE)
116204 + return head;
116205 +
116206 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
116207 + if (!operand_equal_p(cur_node->callee_fndecl, DECL_ORIGIN(current_function_decl), 0))
116208 + continue;
116209 + if (cur_node->num == 0)
116210 + head = create_new_interesting_node(head, stmt, ret, 0, NOT_INTENTIONAL_ASM);
116211 + }
116212 +
116213 + return head;
116214 +}
116215 +
116216 +/* 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).
116217 + * If the call stmt is in the next cgraph node list then it's an interesting call.
116218 + */
116219 +static struct interesting_node *handle_stmt_by_cgraph_nodes_call(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
116220 +{
116221 + unsigned int argnum;
116222 + tree arg;
116223 + const_tree fndecl;
116224 + struct next_cgraph_node *cur_node;
116225 +
116226 + fndecl = gimple_call_fndecl(stmt);
116227 + if (fndecl == NULL_TREE)
116228 + return head;
116229 +
116230 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
116231 + if (!operand_equal_p(cur_node->callee_fndecl, fndecl, 0))
116232 + continue;
116233 + argnum = get_correct_arg_count(cur_node->num, fndecl);
116234 + gcc_assert(argnum != CANNOT_FIND_ARG);
116235 + if (argnum == 0)
116236 + continue;
116237 +
116238 + arg = gimple_call_arg(stmt, argnum - 1);
116239 + head = create_new_interesting_node(head, stmt, arg, argnum, NOT_INTENTIONAL_ASM);
116240 + }
116241 +
116242 + return head;
116243 +}
116244 +
116245 +static unsigned int check_ops(const_tree orig_node, const_tree node, unsigned int ret_count)
116246 +{
116247 + if (!operand_equal_p(orig_node, node, 0))
116248 + return WRONG_NODE;
116249 + if (skip_types(node))
116250 + return WRONG_NODE;
116251 + return ret_count;
116252 +}
116253 +
116254 +// Get the index of the rhs node in an assignment
116255 +static unsigned int get_assign_ops_count(const_gimple stmt, tree node)
116256 +{
116257 + const_tree rhs1, rhs2;
116258 + unsigned int ret;
116259 +
116260 + gcc_assert(stmt);
116261 + gcc_assert(is_gimple_assign(stmt));
116262 +
116263 + rhs1 = gimple_assign_rhs1(stmt);
116264 + gcc_assert(rhs1 != NULL_TREE);
116265 +
116266 + switch (gimple_num_ops(stmt)) {
116267 + case 2:
116268 + return check_ops(node, rhs1, 1);
116269 + case 3:
116270 + ret = check_ops(node, rhs1, 1);
116271 + if (ret != WRONG_NODE)
116272 + return ret;
116273 +
116274 + rhs2 = gimple_assign_rhs2(stmt);
116275 + gcc_assert(rhs2 != NULL_TREE);
116276 + return check_ops(node, rhs2, 2);
116277 + default:
116278 + gcc_unreachable();
116279 + }
116280 +}
116281 +
116282 +// Find the correct arg number of a call stmt. It is needed when the interesting function is a cloned function.
116283 +static unsigned int find_arg_number_gimple(const_tree arg, const_gimple stmt)
116284 +{
116285 + unsigned int i;
116286 +
116287 + if (gimple_call_fndecl(stmt) == NULL_TREE)
116288 + return CANNOT_FIND_ARG;
116289 +
116290 + for (i = 0; i < gimple_call_num_args(stmt); i++) {
116291 + tree node;
116292 +
116293 + node = gimple_call_arg(stmt, i);
116294 + if (!operand_equal_p(arg, node, 0))
116295 + continue;
116296 + if (!skip_types(node))
116297 + return i + 1;
116298 + }
116299 +
116300 + return CANNOT_FIND_ARG;
116301 +}
116302 +
116303 +/* starting from the size_overflow asm stmt collect interesting stmts. They can be
116304 + * any of return, call or assignment stmts (because of inlining).
116305 + */
116306 +static struct interesting_node *get_interesting_ret_or_call(struct pointer_set_t *visited, struct interesting_node *head, tree node, gimple intentional_asm)
116307 +{
116308 + use_operand_p use_p;
116309 + imm_use_iterator imm_iter;
116310 + unsigned int argnum;
116311 +
116312 + gcc_assert(TREE_CODE(node) == SSA_NAME);
116313 +
116314 + if (pointer_set_insert(visited, node))
116315 + return head;
116316 +
116317 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
116318 + gimple stmt = USE_STMT(use_p);
116319 +
116320 + if (stmt == NULL)
116321 + return head;
116322 + if (is_gimple_debug(stmt))
116323 + continue;
116324 +
116325 + switch (gimple_code(stmt)) {
116326 + case GIMPLE_CALL:
116327 + argnum = find_arg_number_gimple(node, stmt);
116328 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
116329 + break;
116330 + case GIMPLE_RETURN:
116331 + head = create_new_interesting_node(head, stmt, node, 0, intentional_asm);
116332 + break;
116333 + case GIMPLE_ASSIGN:
116334 + argnum = get_assign_ops_count(stmt, node);
116335 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
116336 + break;
116337 + case GIMPLE_PHI: {
116338 + tree result = gimple_phi_result(stmt);
116339 + head = get_interesting_ret_or_call(visited, head, result, intentional_asm);
116340 + break;
116341 + }
116342 + case GIMPLE_ASM:
116343 + if (gimple_asm_noutputs(stmt) != 0)
116344 + break;
116345 + if (!is_size_overflow_asm(stmt))
116346 + break;
116347 + head = create_new_interesting_node(head, stmt, node, 1, intentional_asm);
116348 + break;
116349 + case GIMPLE_COND:
116350 + case GIMPLE_SWITCH:
116351 + break;
116352 + default:
116353 + debug_gimple_stmt(stmt);
116354 + gcc_unreachable();
116355 + break;
116356 + }
116357 + }
116358 + return head;
116359 +}
116360 +
116361 +static void remove_size_overflow_asm(gimple stmt)
116362 +{
116363 + gimple_stmt_iterator gsi;
116364 + tree input, output;
116365 +
116366 + if (!is_size_overflow_asm(stmt))
116367 + return;
116368 +
116369 + if (gimple_asm_noutputs(stmt) == 0) {
116370 + gsi = gsi_for_stmt(stmt);
116371 + ipa_remove_stmt_references(cgraph_get_create_node(current_function_decl), stmt);
116372 + gsi_remove(&gsi, true);
116373 + return;
116374 + }
116375 +
116376 + input = gimple_asm_input_op(stmt, 0);
116377 + output = gimple_asm_output_op(stmt, 0);
116378 + replace_size_overflow_asm_with_assign(stmt, TREE_VALUE(output), TREE_VALUE(input));
116379 +}
116380 +
116381 +/* handle the size_overflow asm stmts from the gimple pass and collect the interesting stmts.
116382 + * If the asm stmt is a parm_decl kind (noutputs == 0) then remove it.
116383 + * If it is a simple asm stmt then replace it with an assignment from the asm input to the asm output.
116384 + */
116385 +static struct interesting_node *handle_stmt_by_size_overflow_asm(gimple stmt, struct interesting_node *head)
116386 +{
116387 + const_tree output;
116388 + struct pointer_set_t *visited;
116389 + gimple intentional_asm = NOT_INTENTIONAL_ASM;
116390 +
116391 + if (!is_size_overflow_asm(stmt))
116392 + return head;
116393 +
116394 + if (is_size_overflow_intentional_asm_yes(stmt) || is_size_overflow_intentional_asm_turn_off(stmt))
116395 + intentional_asm = stmt;
116396 +
116397 + gcc_assert(gimple_asm_ninputs(stmt) == 1);
116398 +
116399 + if (gimple_asm_noutputs(stmt) == 0 && is_size_overflow_intentional_asm_turn_off(stmt))
116400 + return head;
116401 +
116402 + if (gimple_asm_noutputs(stmt) == 0) {
116403 + const_tree input;
116404 +
116405 + if (!is_size_overflow_intentional_asm_turn_off(stmt))
116406 + return head;
116407 +
116408 + input = gimple_asm_input_op(stmt, 0);
116409 + remove_size_overflow_asm(stmt);
116410 + if (is_gimple_constant(TREE_VALUE(input)))
116411 + return head;
116412 + visited = pointer_set_create();
116413 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(input), intentional_asm);
116414 + pointer_set_destroy(visited);
116415 + return head;
116416 + }
116417 +
116418 + if (!is_size_overflow_intentional_asm_yes(stmt) && !is_size_overflow_intentional_asm_turn_off(stmt))
116419 + remove_size_overflow_asm(stmt);
116420 +
116421 + visited = pointer_set_create();
116422 + output = gimple_asm_output_op(stmt, 0);
116423 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(output), intentional_asm);
116424 + pointer_set_destroy(visited);
116425 + return head;
116426 +}
116427 +
116428 +/* Iterate over all the stmts of a function and look for the size_overflow asm stmts (they were created in the gimple pass)
116429 + * or a call stmt or a return stmt and store them in the interesting_node list
116430 + */
116431 +static struct interesting_node *collect_interesting_stmts(struct next_cgraph_node *next_node)
116432 +{
116433 + basic_block bb;
116434 + struct interesting_node *head = NULL;
116435 +
116436 + FOR_ALL_BB_FN(bb, cfun) {
116437 + gimple_stmt_iterator gsi;
116438 +
116439 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
116440 + enum gimple_code code;
116441 + gimple stmt = gsi_stmt(gsi);
116442 +
116443 + code = gimple_code(stmt);
116444 +
116445 + if (code == GIMPLE_ASM)
116446 + head = handle_stmt_by_size_overflow_asm(stmt, head);
116447 +
116448 + if (!next_node)
116449 + continue;
116450 + if (code == GIMPLE_CALL)
116451 + head = handle_stmt_by_cgraph_nodes_call(head, stmt, next_node);
116452 + if (code == GIMPLE_RETURN)
116453 + head = handle_stmt_by_cgraph_nodes_ret(head, stmt, next_node);
116454 + }
116455 + }
116456 + return head;
116457 +}
116458 +
116459 +static void free_interesting_node(struct interesting_node *head)
116460 +{
116461 + struct interesting_node *cur;
116462 +
116463 + while (head) {
116464 + cur = head->next;
116465 +#if BUILDING_GCC_VERSION <= 4007
116466 + VEC_free(tree, gc, head->last_nodes);
116467 +#else
116468 + vec_free(head->last_nodes);
116469 +#endif
116470 + free(head);
116471 + head = cur;
116472 + }
116473 +}
116474 +
116475 +static struct visited_fns *insert_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
116476 +{
116477 + struct visited_fns *new_visited_fns;
116478 +
116479 + new_visited_fns = (struct visited_fns *)xmalloc(sizeof(*new_visited_fns));
116480 + new_visited_fns->fndecl = cur_node->fndecl;
116481 + new_visited_fns->num = cur_node->num;
116482 + new_visited_fns->first_stmt = cur_node->first_stmt;
116483 + new_visited_fns->next = NULL;
116484 +
116485 + if (!head)
116486 + return new_visited_fns;
116487 +
116488 + new_visited_fns->next = head;
116489 + return new_visited_fns;
116490 +}
116491 +
116492 +/* 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
116493 + * it is a visited_fns function.
116494 + */
116495 +static bool is_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
116496 +{
116497 + struct visited_fns *cur;
116498 +
116499 + if (!head)
116500 + return false;
116501 +
116502 + for (cur = head; cur; cur = cur->next) {
116503 + if (cur_node->first_stmt != cur->first_stmt)
116504 + continue;
116505 + if (!operand_equal_p(cur_node->fndecl, cur->fndecl, 0))
116506 + continue;
116507 + if (cur_node->num == cur->num)
116508 + return true;
116509 + }
116510 + return false;
116511 +}
116512 +
116513 +static void free_next_cgraph_node(struct next_cgraph_node *head)
116514 +{
116515 + struct next_cgraph_node *cur;
116516 +
116517 + while (head) {
116518 + cur = head->next;
116519 + free(head);
116520 + head = cur;
116521 + }
116522 +}
116523 +
116524 +static void remove_all_size_overflow_asm(void)
116525 +{
116526 + basic_block bb;
116527 +
116528 + FOR_ALL_BB_FN(bb, cfun) {
116529 + gimple_stmt_iterator si;
116530 +
116531 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
116532 + remove_size_overflow_asm(gsi_stmt(si));
116533 + }
116534 +}
116535 +
116536 +/* Main recursive walk of the ipa pass: iterate over the collected interesting stmts in a function
116537 + * (they are interesting if they have an associated size_overflow asm stmt) and recursively walk
116538 + * the newly collected interesting functions (they are interesting if there is control flow between
116539 + * the interesting stmts and them).
116540 + */
116541 +static struct visited_fns *handle_function(struct cgraph_node *node, struct next_cgraph_node *next_node, struct visited_fns *visited_fns)
116542 +{
116543 + struct visited *visited;
116544 + struct interesting_node *head, *cur_node;
116545 + struct next_cgraph_node *cur_cnodes, *cnodes_head = NULL;
116546 +
116547 + set_current_function_decl(NODE_DECL(node));
116548 + call_count = 0;
116549 +
116550 + head = collect_interesting_stmts(next_node);
116551 +
116552 + visited = create_visited();
116553 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
116554 + if (is_visited_fns_function(visited_fns, cur_node))
116555 + continue;
116556 + cnodes_head = handle_interesting_stmt(visited, cnodes_head, cur_node, node);
116557 + visited_fns = insert_visited_fns_function(visited_fns, cur_node);
116558 + }
116559 +
116560 + free_visited(visited);
116561 + free_interesting_node(head);
116562 + remove_all_size_overflow_asm();
116563 + unset_current_function_decl();
116564 +
116565 + for (cur_cnodes = cnodes_head; cur_cnodes; cur_cnodes = cur_cnodes->next)
116566 + visited_fns = handle_function(cur_cnodes->current_function, cur_cnodes, visited_fns);
116567 +
116568 + free_next_cgraph_node(cnodes_head);
116569 + return visited_fns;
116570 +}
116571 +
116572 +static void free_visited_fns(struct visited_fns *head)
116573 +{
116574 + struct visited_fns *cur;
116575 +
116576 + while (head) {
116577 + cur = head->next;
116578 + free(head);
116579 + head = cur;
116580 + }
116581 +}
116582 +
116583 +// Main entry point of the ipa pass: erases the plf flag of all stmts and iterates over all the functions
116584 +unsigned int search_function(void)
116585 +{
116586 + struct cgraph_node *node;
116587 + struct visited_fns *visited_fns = NULL;
116588 +
116589 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
116590 + gcc_assert(cgraph_function_flags_ready);
116591 +#if BUILDING_GCC_VERSION <= 4007
116592 + gcc_assert(node->reachable);
116593 +#endif
116594 +
116595 + visited_fns = handle_function(node, NULL, visited_fns);
116596 + }
116597 +
116598 + free_visited_fns(visited_fns);
116599 + return 0;
116600 +}
116601 +
116602 +#if BUILDING_GCC_VERSION >= 4009
116603 +static const struct pass_data insert_size_overflow_check_data = {
116604 +#else
116605 +static struct ipa_opt_pass_d insert_size_overflow_check = {
116606 + .pass = {
116607 +#endif
116608 + .type = SIMPLE_IPA_PASS,
116609 + .name = "size_overflow",
116610 +#if BUILDING_GCC_VERSION >= 4008
116611 + .optinfo_flags = OPTGROUP_NONE,
116612 +#endif
116613 +#if BUILDING_GCC_VERSION >= 4009
116614 + .has_gate = false,
116615 + .has_execute = true,
116616 +#else
116617 + .gate = NULL,
116618 + .execute = search_function,
116619 + .sub = NULL,
116620 + .next = NULL,
116621 + .static_pass_number = 0,
116622 +#endif
116623 + .tv_id = TV_NONE,
116624 + .properties_required = 0,
116625 + .properties_provided = 0,
116626 + .properties_destroyed = 0,
116627 + .todo_flags_start = 0,
116628 + .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,
116629 +#if BUILDING_GCC_VERSION < 4009
116630 + },
116631 + .generate_summary = NULL,
116632 + .write_summary = NULL,
116633 + .read_summary = NULL,
116634 +#if BUILDING_GCC_VERSION >= 4006
116635 + .write_optimization_summary = NULL,
116636 + .read_optimization_summary = NULL,
116637 +#endif
116638 + .stmt_fixup = NULL,
116639 + .function_transform_todo_flags_start = 0,
116640 + .function_transform = NULL,
116641 + .variable_transform = NULL,
116642 +#endif
116643 +};
116644 +
116645 +#if BUILDING_GCC_VERSION >= 4009
116646 +namespace {
116647 +class insert_size_overflow_check : public ipa_opt_pass_d {
116648 +public:
116649 + insert_size_overflow_check() : ipa_opt_pass_d(insert_size_overflow_check_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
116650 + unsigned int execute() { return search_function(); }
116651 +};
116652 +}
116653 +#endif
116654 +
116655 +struct opt_pass *make_insert_size_overflow_check(void)
116656 +{
116657 +#if BUILDING_GCC_VERSION >= 4009
116658 + return new insert_size_overflow_check();
116659 +#else
116660 + return &insert_size_overflow_check.pass;
116661 +#endif
116662 +}
116663 +
116664 diff --git a/tools/gcc/size_overflow_plugin/intentional_overflow.c b/tools/gcc/size_overflow_plugin/intentional_overflow.c
116665 new file mode 100644
116666 index 0000000..d71d72a
116667 --- /dev/null
116668 +++ b/tools/gcc/size_overflow_plugin/intentional_overflow.c
116669 @@ -0,0 +1,736 @@
116670 +/*
116671 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
116672 + * Licensed under the GPL v2, or (at your option) v3
116673 + *
116674 + * Homepage:
116675 + * http://www.grsecurity.net/~ephox/overflow_plugin/
116676 + *
116677 + * Documentation:
116678 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
116679 + *
116680 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
116681 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
116682 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
116683 + *
116684 + * Usage:
116685 + * $ make
116686 + * $ make run
116687 + */
116688 +
116689 +#include "gcc-common.h"
116690 +#include "size_overflow.h"
116691 +
116692 +/* Get the param of the intentional_overflow attribute.
116693 + * * 0: MARK_NOT_INTENTIONAL
116694 + * * 1..MAX_PARAM: MARK_YES
116695 + * * -1: MARK_TURN_OFF
116696 + */
116697 +static tree get_attribute_param(const_tree decl)
116698 +{
116699 + const_tree attr;
116700 +
116701 + if (decl == NULL_TREE)
116702 + return NULL_TREE;
116703 +
116704 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(decl));
116705 + if (!attr || !TREE_VALUE(attr))
116706 + return NULL_TREE;
116707 +
116708 + return TREE_VALUE(attr);
116709 +}
116710 +
116711 +// MARK_TURN_OFF
116712 +bool is_turn_off_intentional_attr(const_tree decl)
116713 +{
116714 + const_tree param_head;
116715 +
116716 + param_head = get_attribute_param(decl);
116717 + if (param_head == NULL_TREE)
116718 + return false;
116719 +
116720 + if (TREE_INT_CST_HIGH(TREE_VALUE(param_head)) == -1)
116721 + return true;
116722 + return false;
116723 +}
116724 +
116725 +// MARK_NOT_INTENTIONAL
116726 +bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum)
116727 +{
116728 + const_tree param_head;
116729 +
116730 + if (argnum == 0)
116731 + return false;
116732 +
116733 + param_head = get_attribute_param(decl);
116734 + if (param_head == NULL_TREE)
116735 + return false;
116736 +
116737 + if (!TREE_INT_CST_LOW(TREE_VALUE(param_head)))
116738 + return true;
116739 + return false;
116740 +}
116741 +
116742 +// MARK_YES
116743 +bool is_yes_intentional_attr(const_tree decl, unsigned int argnum)
116744 +{
116745 + tree param, param_head;
116746 +
116747 + if (argnum == 0)
116748 + return false;
116749 +
116750 + param_head = get_attribute_param(decl);
116751 + for (param = param_head; param; param = TREE_CHAIN(param))
116752 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(param)))
116753 + return true;
116754 + return false;
116755 +}
116756 +
116757 +void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum)
116758 +{
116759 + location_t loc;
116760 +
116761 + if (caller_attr == MARK_NO || caller_attr == MARK_NOT_INTENTIONAL || caller_attr == MARK_TURN_OFF)
116762 + return;
116763 +
116764 + if (callee_attr == MARK_NOT_INTENTIONAL || callee_attr == MARK_YES)
116765 + return;
116766 +
116767 + loc = DECL_SOURCE_LOCATION(decl);
116768 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", DECL_NAME_POINTER(decl), argnum);
116769 +}
116770 +
116771 +// Get the field decl of a component ref for intentional_overflow checking
116772 +static const_tree search_field_decl(const_tree comp_ref)
116773 +{
116774 + const_tree field = NULL_TREE;
116775 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
116776 +
116777 + for (i = 0; i < len; i++) {
116778 + field = TREE_OPERAND(comp_ref, i);
116779 + if (TREE_CODE(field) == FIELD_DECL)
116780 + break;
116781 + }
116782 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
116783 + return field;
116784 +}
116785 +
116786 +/* Get the type of the intentional_overflow attribute of a node
116787 + * * MARK_TURN_OFF
116788 + * * MARK_YES
116789 + * * MARK_NO
116790 + * * MARK_NOT_INTENTIONAL
116791 + */
116792 +enum mark get_intentional_attr_type(const_tree node)
116793 +{
116794 + const_tree cur_decl;
116795 +
116796 + if (node == NULL_TREE)
116797 + return MARK_NO;
116798 +
116799 + switch (TREE_CODE(node)) {
116800 + case COMPONENT_REF:
116801 + cur_decl = search_field_decl(node);
116802 + if (is_turn_off_intentional_attr(cur_decl))
116803 + return MARK_TURN_OFF;
116804 + if (is_end_intentional_intentional_attr(cur_decl, 1))
116805 + return MARK_YES;
116806 + break;
116807 + case PARM_DECL: {
116808 + unsigned int argnum;
116809 +
116810 + cur_decl = DECL_ORIGIN(current_function_decl);
116811 + argnum = find_arg_number_tree(node, cur_decl);
116812 + if (argnum == CANNOT_FIND_ARG)
116813 + return MARK_NO;
116814 + if (is_yes_intentional_attr(cur_decl, argnum))
116815 + return MARK_YES;
116816 + if (is_end_intentional_intentional_attr(cur_decl, argnum))
116817 + return MARK_NOT_INTENTIONAL;
116818 + break;
116819 + }
116820 + case FUNCTION_DECL:
116821 + if (is_turn_off_intentional_attr(DECL_ORIGIN(node)))
116822 + return MARK_TURN_OFF;
116823 + break;
116824 + default:
116825 + break;
116826 + }
116827 + return MARK_NO;
116828 +}
116829 +
116830 +// Search for the intentional_overflow attribute on the last nodes
116831 +static enum mark search_last_nodes_intentional(struct interesting_node *cur_node)
116832 +{
116833 + unsigned int i;
116834 + tree last_node;
116835 + enum mark mark = MARK_NO;
116836 +
116837 +#if BUILDING_GCC_VERSION <= 4007
116838 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, last_node) {
116839 +#else
116840 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, last_node) {
116841 +#endif
116842 + mark = get_intentional_attr_type(last_node);
116843 + if (mark != MARK_NO)
116844 + break;
116845 + }
116846 + return mark;
116847 +}
116848 +
116849 +/* Check the intentional kind of size_overflow asm stmt (created by the gimple pass) and
116850 + * set the appropriate intentional_overflow type. Delete the asm stmt in the end.
116851 + */
116852 +static bool is_intentional_attribute_from_gimple(struct interesting_node *cur_node)
116853 +{
116854 + if (!cur_node->intentional_mark_from_gimple)
116855 + return false;
116856 +
116857 + if (is_size_overflow_intentional_asm_yes(cur_node->intentional_mark_from_gimple))
116858 + cur_node->intentional_attr_cur_fndecl = MARK_YES;
116859 + else
116860 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
116861 +
116862 + // skip param decls
116863 + if (gimple_asm_noutputs(cur_node->intentional_mark_from_gimple) == 0)
116864 + return true;
116865 + return true;
116866 +}
116867 +
116868 +/* Search intentional_overflow attribute on caller and on callee too.
116869 + * 0</MARK_YES: no dup, search size_overflow and intentional_overflow attributes
116870 + * 0/MARK_NOT_INTENTIONAL: no dup, search size_overflow attribute (int)
116871 + * -1/MARK_TURN_OFF: no dup, no search, current_function_decl -> no dup
116872 +*/
116873 +void check_intentional_attribute_ipa(struct interesting_node *cur_node)
116874 +{
116875 + const_tree fndecl;
116876 +
116877 + if (is_intentional_attribute_from_gimple(cur_node))
116878 + return;
116879 +
116880 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
116881 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
116882 + return;
116883 + }
116884 +
116885 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASM) {
116886 + cur_node->intentional_attr_cur_fndecl = MARK_NOT_INTENTIONAL;
116887 + return;
116888 + }
116889 +
116890 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASSIGN)
116891 + return;
116892 +
116893 + fndecl = get_interesting_orig_fndecl(cur_node->first_stmt, cur_node->num);
116894 + if (is_turn_off_intentional_attr(fndecl)) {
116895 + cur_node->intentional_attr_decl = MARK_TURN_OFF;
116896 + return;
116897 + }
116898 +
116899 + if (is_end_intentional_intentional_attr(fndecl, cur_node->num))
116900 + cur_node->intentional_attr_decl = MARK_NOT_INTENTIONAL;
116901 + else if (is_yes_intentional_attr(fndecl, cur_node->num))
116902 + cur_node->intentional_attr_decl = MARK_YES;
116903 +
116904 + cur_node->intentional_attr_cur_fndecl = search_last_nodes_intentional(cur_node);
116905 + print_missing_intentional(cur_node->intentional_attr_decl, cur_node->intentional_attr_cur_fndecl, cur_node->fndecl, cur_node->num);
116906 +}
116907 +
116908 +bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
116909 +{
116910 + const_tree rhs1, lhs, rhs1_type, lhs_type;
116911 + enum machine_mode lhs_mode, rhs_mode;
116912 + gimple def_stmt = get_def_stmt(no_const_rhs);
116913 +
116914 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
116915 + return false;
116916 +
116917 + rhs1 = gimple_assign_rhs1(def_stmt);
116918 + lhs = gimple_assign_lhs(def_stmt);
116919 + rhs1_type = TREE_TYPE(rhs1);
116920 + lhs_type = TREE_TYPE(lhs);
116921 + rhs_mode = TYPE_MODE(rhs1_type);
116922 + lhs_mode = TYPE_MODE(lhs_type);
116923 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
116924 + return false;
116925 +
116926 + return true;
116927 +}
116928 +
116929 +static unsigned int uses_num(tree node)
116930 +{
116931 + imm_use_iterator imm_iter;
116932 + use_operand_p use_p;
116933 + unsigned int num = 0;
116934 +
116935 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
116936 + gimple use_stmt = USE_STMT(use_p);
116937 +
116938 + if (use_stmt == NULL)
116939 + return num;
116940 + if (is_gimple_debug(use_stmt))
116941 + continue;
116942 + if (gimple_assign_cast_p(use_stmt) && is_size_overflow_type(gimple_assign_lhs(use_stmt)))
116943 + continue;
116944 + num++;
116945 + }
116946 + return num;
116947 +}
116948 +
116949 +static bool no_uses(tree node)
116950 +{
116951 + return !uses_num(node);
116952 +}
116953 +
116954 +// 3.8.5 mm/page-writeback.c __ilog2_u64(): ret, uint + uintmax; uint -> int; int max
116955 +bool is_const_plus_unsigned_signed_truncation(const_tree lhs)
116956 +{
116957 + tree rhs1, lhs_type, rhs_type, rhs2, not_const_rhs;
116958 + gimple def_stmt = get_def_stmt(lhs);
116959 +
116960 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
116961 + return false;
116962 +
116963 + rhs1 = gimple_assign_rhs1(def_stmt);
116964 + rhs_type = TREE_TYPE(rhs1);
116965 + lhs_type = TREE_TYPE(lhs);
116966 + if (TYPE_UNSIGNED(lhs_type) || !TYPE_UNSIGNED(rhs_type))
116967 + return false;
116968 + if (TYPE_MODE(lhs_type) != TYPE_MODE(rhs_type))
116969 + return false;
116970 +
116971 + def_stmt = get_def_stmt(rhs1);
116972 + if (!def_stmt || !is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 3)
116973 + return false;
116974 +
116975 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR)
116976 + return false;
116977 +
116978 + rhs1 = gimple_assign_rhs1(def_stmt);
116979 + rhs2 = gimple_assign_rhs2(def_stmt);
116980 + if (!is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
116981 + return false;
116982 +
116983 + if (is_gimple_constant(rhs2))
116984 + not_const_rhs = rhs1;
116985 + else
116986 + not_const_rhs = rhs2;
116987 +
116988 + return no_uses(not_const_rhs);
116989 +}
116990 +
116991 +static bool is_lt_signed_type_max(const_tree rhs)
116992 +{
116993 + const_tree new_type, type_max, type = TREE_TYPE(rhs);
116994 +
116995 + if (!TYPE_UNSIGNED(type))
116996 + return true;
116997 +
116998 + switch (TYPE_MODE(type)) {
116999 + case QImode:
117000 + new_type = intQI_type_node;
117001 + break;
117002 + case HImode:
117003 + new_type = intHI_type_node;
117004 + break;
117005 + case SImode:
117006 + new_type = intSI_type_node;
117007 + break;
117008 + case DImode:
117009 + new_type = intDI_type_node;
117010 + break;
117011 + default:
117012 + debug_tree((tree)type);
117013 + gcc_unreachable();
117014 + }
117015 +
117016 + type_max = TYPE_MAX_VALUE(new_type);
117017 + if (!tree_int_cst_lt(type_max, rhs))
117018 + return true;
117019 +
117020 + return false;
117021 +}
117022 +
117023 +static bool is_gt_zero(const_tree rhs)
117024 +{
117025 + const_tree type = TREE_TYPE(rhs);
117026 +
117027 + if (TYPE_UNSIGNED(type))
117028 + return true;
117029 +
117030 + if (!tree_int_cst_lt(rhs, integer_zero_node))
117031 + return true;
117032 +
117033 + return false;
117034 +}
117035 +
117036 +bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
117037 +{
117038 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
117039 + return false;
117040 + if (!is_gimple_constant(rhs))
117041 + return false;
117042 +
117043 + // If the const is between 0 and the max value of the signed type of the same bitsize then there is no intentional overflow
117044 + if (is_lt_signed_type_max(rhs) && is_gt_zero(rhs))
117045 + return false;
117046 +
117047 + return true;
117048 +}
117049 +
117050 +static tree change_assign_rhs(struct visited *visited, gimple stmt, const_tree orig_rhs, tree new_rhs)
117051 +{
117052 + gimple assign;
117053 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
117054 + tree origtype = TREE_TYPE(orig_rhs);
117055 +
117056 + gcc_assert(is_gimple_assign(stmt));
117057 +
117058 + assign = build_cast_stmt(visited, origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
117059 + pointer_set_insert(visited->my_stmts, assign);
117060 + return gimple_assign_lhs(assign);
117061 +}
117062 +
117063 +tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2)
117064 +{
117065 + tree new_rhs, orig_rhs;
117066 + void (*gimple_assign_set_rhs)(gimple, tree);
117067 + tree rhs1 = gimple_assign_rhs1(stmt);
117068 + tree rhs2 = gimple_assign_rhs2(stmt);
117069 + tree lhs = gimple_assign_lhs(stmt);
117070 +
117071 + if (!check_overflow)
117072 + return create_assign(visited, stmt, lhs, AFTER_STMT);
117073 +
117074 + if (change_rhs == NULL_TREE)
117075 + return create_assign(visited, stmt, lhs, AFTER_STMT);
117076 +
117077 + if (new_rhs2 == NULL_TREE) {
117078 + orig_rhs = rhs1;
117079 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
117080 + } else {
117081 + orig_rhs = rhs2;
117082 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
117083 + }
117084 +
117085 + check_size_overflow(caller_node, stmt, TREE_TYPE(change_rhs), change_rhs, orig_rhs, BEFORE_STMT);
117086 +
117087 + new_rhs = change_assign_rhs(visited, stmt, orig_rhs, change_rhs);
117088 + gimple_assign_set_rhs(stmt, new_rhs);
117089 + update_stmt(stmt);
117090 +
117091 + return create_assign(visited, stmt, lhs, AFTER_STMT);
117092 +}
117093 +
117094 +static bool is_subtraction_special(struct visited *visited, const_gimple stmt)
117095 +{
117096 + gimple rhs1_def_stmt, rhs2_def_stmt;
117097 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
117098 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
117099 + const_tree rhs1 = gimple_assign_rhs1(stmt);
117100 + const_tree rhs2 = gimple_assign_rhs2(stmt);
117101 +
117102 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
117103 + return false;
117104 +
117105 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
117106 +
117107 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
117108 + return false;
117109 +
117110 + rhs1_def_stmt = get_def_stmt(rhs1);
117111 + rhs2_def_stmt = get_def_stmt(rhs2);
117112 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
117113 + return false;
117114 +
117115 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
117116 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
117117 + rhs1_def_stmt_lhs = gimple_assign_lhs(rhs1_def_stmt);
117118 + rhs2_def_stmt_lhs = gimple_assign_lhs(rhs2_def_stmt);
117119 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
117120 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
117121 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
117122 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
117123 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
117124 + return false;
117125 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
117126 + return false;
117127 +
117128 + pointer_set_insert(visited->no_cast_check, rhs1_def_stmt);
117129 + pointer_set_insert(visited->no_cast_check, rhs2_def_stmt);
117130 + return true;
117131 +}
117132 +
117133 +static gimple create_binary_assign(struct visited *visited, enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
117134 +{
117135 + gimple assign;
117136 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
117137 + tree type = TREE_TYPE(rhs1);
117138 + tree lhs = create_new_var(type);
117139 +
117140 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
117141 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
117142 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
117143 +
117144 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
117145 + update_stmt(assign);
117146 + pointer_set_insert(visited->my_stmts, assign);
117147 + return assign;
117148 +}
117149 +
117150 +static tree cast_to_TI_type(struct visited *visited, gimple stmt, tree node)
117151 +{
117152 + gimple_stmt_iterator gsi;
117153 + gimple cast_stmt;
117154 + tree type = TREE_TYPE(node);
117155 +
117156 + if (types_compatible_p(type, intTI_type_node))
117157 + return node;
117158 +
117159 + gsi = gsi_for_stmt(stmt);
117160 + cast_stmt = build_cast_stmt(visited, intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
117161 + pointer_set_insert(visited->my_stmts, cast_stmt);
117162 + return gimple_assign_lhs(cast_stmt);
117163 +}
117164 +
117165 +static tree get_def_stmt_rhs(struct visited *visited, const_tree var)
117166 +{
117167 + tree rhs1, def_stmt_rhs1;
117168 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
117169 +
117170 + def_stmt = get_def_stmt(var);
117171 + if (!gimple_assign_cast_p(def_stmt))
117172 + return NULL_TREE;
117173 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && pointer_set_contains(visited->my_stmts, def_stmt) && gimple_assign_cast_p(def_stmt));
117174 +
117175 + rhs1 = gimple_assign_rhs1(def_stmt);
117176 + rhs1_def_stmt = get_def_stmt(rhs1);
117177 + if (!gimple_assign_cast_p(rhs1_def_stmt))
117178 + return rhs1;
117179 +
117180 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
117181 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
117182 +
117183 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
117184 + case GIMPLE_CALL:
117185 + case GIMPLE_NOP:
117186 + case GIMPLE_ASM:
117187 + case GIMPLE_PHI:
117188 + return def_stmt_rhs1;
117189 + case GIMPLE_ASSIGN:
117190 + return rhs1;
117191 + default:
117192 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
117193 + gcc_unreachable();
117194 + }
117195 +}
117196 +
117197 +tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs)
117198 +{
117199 + tree new_rhs1, new_rhs2;
117200 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
117201 + gimple assign, stmt = get_def_stmt(lhs);
117202 + tree rhs1 = gimple_assign_rhs1(stmt);
117203 + tree rhs2 = gimple_assign_rhs2(stmt);
117204 +
117205 + if (!is_subtraction_special(visited, stmt))
117206 + return NULL_TREE;
117207 +
117208 + new_rhs1 = expand(visited, caller_node, rhs1);
117209 + new_rhs2 = expand(visited, caller_node, rhs2);
117210 +
117211 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs1);
117212 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs2);
117213 +
117214 + if (new_rhs1_def_stmt_rhs1 == NULL_TREE || new_rhs2_def_stmt_rhs1 == NULL_TREE)
117215 + return NULL_TREE;
117216 +
117217 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
117218 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs1_def_stmt_rhs1);
117219 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs2_def_stmt_rhs1);
117220 + }
117221 +
117222 + assign = create_binary_assign(visited, MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
117223 + new_lhs = gimple_assign_lhs(assign);
117224 + check_size_overflow(caller_node, assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
117225 +
117226 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
117227 +}
117228 +
117229 +bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
117230 +{
117231 + const_gimple def_stmt;
117232 +
117233 + if (TREE_CODE(rhs) != SSA_NAME)
117234 + return false;
117235 +
117236 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
117237 + return false;
117238 +
117239 + def_stmt = get_def_stmt(rhs);
117240 + if (!is_gimple_assign(def_stmt) || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
117241 + return false;
117242 +
117243 + return true;
117244 +}
117245 +
117246 +/* e.g., drivers/acpi/acpica/utids.c acpi_ut_execute_CID()
117247 + * ((count - 1) * sizeof(struct acpi_pnp_dee_id_list) -> (count + fffffff) * 16
117248 + * fffffff * 16 > signed max -> truncate
117249 + */
117250 +static bool look_for_mult_and_add(const_gimple stmt)
117251 +{
117252 + const_tree res;
117253 + tree rhs1, rhs2, def_rhs1, def_rhs2, const_rhs, def_const_rhs;
117254 + const_gimple def_stmt;
117255 +
117256 + if (!stmt || gimple_code(stmt) == GIMPLE_NOP)
117257 + return false;
117258 + if (!is_gimple_assign(stmt))
117259 + return false;
117260 + if (gimple_assign_rhs_code(stmt) != MULT_EXPR)
117261 + return false;
117262 +
117263 + rhs1 = gimple_assign_rhs1(stmt);
117264 + rhs2 = gimple_assign_rhs2(stmt);
117265 + if (is_gimple_constant(rhs1)) {
117266 + const_rhs = rhs1;
117267 + def_stmt = get_def_stmt(rhs2);
117268 + } else if (is_gimple_constant(rhs2)) {
117269 + const_rhs = rhs2;
117270 + def_stmt = get_def_stmt(rhs1);
117271 + } else
117272 + return false;
117273 +
117274 + if (!is_gimple_assign(def_stmt))
117275 + return false;
117276 +
117277 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR && gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
117278 + return false;
117279 +
117280 + def_rhs1 = gimple_assign_rhs1(def_stmt);
117281 + def_rhs2 = gimple_assign_rhs2(def_stmt);
117282 + if (is_gimple_constant(def_rhs1))
117283 + def_const_rhs = def_rhs1;
117284 + else if (is_gimple_constant(def_rhs2))
117285 + def_const_rhs = def_rhs2;
117286 + else
117287 + return false;
117288 +
117289 + res = fold_binary_loc(gimple_location(def_stmt), MULT_EXPR, TREE_TYPE(const_rhs), const_rhs, def_const_rhs);
117290 + if (is_lt_signed_type_max(res) && is_gt_zero(res))
117291 + return false;
117292 + return true;
117293 +}
117294 +
117295 +enum intentional_overflow_type add_mul_intentional_overflow(const_gimple stmt)
117296 +{
117297 + const_gimple def_stmt_1, def_stmt_2;
117298 + const_tree rhs1, rhs2;
117299 + bool add_mul_rhs1, add_mul_rhs2;
117300 +
117301 + rhs1 = gimple_assign_rhs1(stmt);
117302 + def_stmt_1 = get_def_stmt(rhs1);
117303 + add_mul_rhs1 = look_for_mult_and_add(def_stmt_1);
117304 +
117305 + rhs2 = gimple_assign_rhs2(stmt);
117306 + def_stmt_2 = get_def_stmt(rhs2);
117307 + add_mul_rhs2 = look_for_mult_and_add(def_stmt_2);
117308 +
117309 + if (add_mul_rhs1)
117310 + return RHS1_INTENTIONAL_OVERFLOW;
117311 + if (add_mul_rhs2)
117312 + return RHS2_INTENTIONAL_OVERFLOW;
117313 + return NO_INTENTIONAL_OVERFLOW;
117314 +}
117315 +
117316 +static gimple get_dup_stmt(struct visited *visited, gimple stmt)
117317 +{
117318 + gimple my_stmt;
117319 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
117320 +
117321 + gsi_next(&gsi);
117322 + my_stmt = gsi_stmt(gsi);
117323 +
117324 + gcc_assert(pointer_set_contains(visited->my_stmts, my_stmt));
117325 + gcc_assert(gimple_assign_rhs_code(stmt) == gimple_assign_rhs_code(my_stmt));
117326 +
117327 + return my_stmt;
117328 +}
117329 +
117330 +/* unsigned type -> unary or binary assign (rhs1 or rhs2 is constant)
117331 + * unsigned type cast to signed type, unsigned type: no more uses
117332 + * e.g., lib/vsprintf.c:simple_strtol()
117333 + * _10 = (unsigned long int) _9
117334 + * _11 = -_10;
117335 + * _12 = (long int) _11; (_11_ no more uses)
117336 + */
117337 +static bool is_call_or_cast(gimple stmt)
117338 +{
117339 + return gimple_assign_cast_p(stmt) || is_gimple_call(stmt);
117340 +}
117341 +
117342 +static bool is_unsigned_cast_or_call_def_stmt(const_tree node)
117343 +{
117344 + const_tree rhs;
117345 + gimple def_stmt;
117346 +
117347 + if (node == NULL_TREE)
117348 + return true;
117349 + if (is_gimple_constant(node))
117350 + return true;
117351 +
117352 + def_stmt = get_def_stmt(node);
117353 + if (!def_stmt)
117354 + return false;
117355 +
117356 + if (is_call_or_cast(def_stmt))
117357 + return true;
117358 +
117359 + if (!is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 2)
117360 + return false;
117361 + rhs = gimple_assign_rhs1(def_stmt);
117362 + def_stmt = get_def_stmt(rhs);
117363 + if (!def_stmt)
117364 + return false;
117365 + return is_call_or_cast(def_stmt);
117366 +}
117367 +
117368 +void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt)
117369 +{
117370 + unsigned int use_num;
117371 + gimple so_stmt;
117372 + const_gimple def_stmt;
117373 + const_tree rhs1, rhs2;
117374 + tree rhs = gimple_assign_rhs1(stmt);
117375 + tree lhs_type = TREE_TYPE(gimple_assign_lhs(stmt));
117376 + const_tree rhs_type = TREE_TYPE(rhs);
117377 +
117378 + if (!(TYPE_UNSIGNED(rhs_type) && !TYPE_UNSIGNED(lhs_type)))
117379 + return;
117380 + if (GET_MODE_BITSIZE(TYPE_MODE(rhs_type)) != GET_MODE_BITSIZE(TYPE_MODE(lhs_type)))
117381 + return;
117382 + use_num = uses_num(rhs);
117383 + if (use_num != 1)
117384 + return;
117385 +
117386 + def_stmt = get_def_stmt(rhs);
117387 + if (!def_stmt)
117388 + return;
117389 + if (!is_gimple_assign(def_stmt))
117390 + return;
117391 +
117392 + rhs1 = gimple_assign_rhs1(def_stmt);
117393 + if (!is_unsigned_cast_or_call_def_stmt(rhs1))
117394 + return;
117395 +
117396 + rhs2 = gimple_assign_rhs2(def_stmt);
117397 + if (!is_unsigned_cast_or_call_def_stmt(rhs2))
117398 + return;
117399 + if (gimple_num_ops(def_stmt) == 3 && !is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
117400 + return;
117401 +
117402 + so_stmt = get_dup_stmt(visited, stmt);
117403 + create_up_and_down_cast(visited, so_stmt, lhs_type, gimple_assign_rhs1(so_stmt));
117404 +}
117405 +
117406 diff --git a/tools/gcc/size_overflow_plugin/misc.c b/tools/gcc/size_overflow_plugin/misc.c
117407 new file mode 100644
117408 index 0000000..4bddad2
117409 --- /dev/null
117410 +++ b/tools/gcc/size_overflow_plugin/misc.c
117411 @@ -0,0 +1,203 @@
117412 +/*
117413 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
117414 + * Licensed under the GPL v2, or (at your option) v3
117415 + *
117416 + * Homepage:
117417 + * http://www.grsecurity.net/~ephox/overflow_plugin/
117418 + *
117419 + * Documentation:
117420 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
117421 + *
117422 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
117423 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
117424 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
117425 + *
117426 + * Usage:
117427 + * $ make
117428 + * $ make run
117429 + */
117430 +
117431 +#include "gcc-common.h"
117432 +#include "size_overflow.h"
117433 +
117434 +void set_current_function_decl(tree fndecl)
117435 +{
117436 + gcc_assert(fndecl != NULL_TREE);
117437 +
117438 + push_cfun(DECL_STRUCT_FUNCTION(fndecl));
117439 + calculate_dominance_info(CDI_DOMINATORS);
117440 + current_function_decl = fndecl;
117441 +}
117442 +
117443 +void unset_current_function_decl(void)
117444 +{
117445 + free_dominance_info(CDI_DOMINATORS);
117446 + pop_cfun();
117447 + current_function_decl = NULL_TREE;
117448 +}
117449 +
117450 +static bool is_bool(const_tree node)
117451 +{
117452 + const_tree type;
117453 +
117454 + if (node == NULL_TREE)
117455 + return false;
117456 +
117457 + type = TREE_TYPE(node);
117458 + if (!INTEGRAL_TYPE_P(type))
117459 + return false;
117460 + if (TREE_CODE(type) == BOOLEAN_TYPE)
117461 + return true;
117462 + if (TYPE_PRECISION(type) == 1)
117463 + return true;
117464 + return false;
117465 +}
117466 +
117467 +bool skip_types(const_tree var)
117468 +{
117469 + tree type;
117470 + enum tree_code code;
117471 +
117472 + if (is_gimple_constant(var))
117473 + return true;
117474 +
117475 + switch (TREE_CODE(var)) {
117476 + case ADDR_EXPR:
117477 +#if BUILDING_GCC_VERSION >= 4006
117478 + case MEM_REF:
117479 +#endif
117480 + case ARRAY_REF:
117481 + case BIT_FIELD_REF:
117482 + case INDIRECT_REF:
117483 + case TARGET_MEM_REF:
117484 + case COMPONENT_REF:
117485 + case VAR_DECL:
117486 + case VIEW_CONVERT_EXPR:
117487 + return true;
117488 + default:
117489 + break;
117490 + }
117491 +
117492 + code = TREE_CODE(var);
117493 + gcc_assert(code == SSA_NAME || code == PARM_DECL);
117494 +
117495 + type = TREE_TYPE(var);
117496 + switch (TREE_CODE(type)) {
117497 + case INTEGER_TYPE:
117498 + case ENUMERAL_TYPE:
117499 + return false;
117500 + case BOOLEAN_TYPE:
117501 + return is_bool(var);
117502 + default:
117503 + return true;
117504 + }
117505 +}
117506 +
117507 +gimple get_def_stmt(const_tree node)
117508 +{
117509 + gcc_assert(node != NULL_TREE);
117510 +
117511 + if (skip_types(node))
117512 + return NULL;
117513 +
117514 + if (TREE_CODE(node) != SSA_NAME)
117515 + return NULL;
117516 + return SSA_NAME_DEF_STMT(node);
117517 +}
117518 +
117519 +tree create_new_var(tree type)
117520 +{
117521 + tree new_var = create_tmp_var(type, "cicus");
117522 +
117523 + add_referenced_var(new_var);
117524 + return new_var;
117525 +}
117526 +
117527 +static bool skip_cast(tree dst_type, const_tree rhs, bool force)
117528 +{
117529 + const_gimple def_stmt = get_def_stmt(rhs);
117530 +
117531 + if (force)
117532 + return false;
117533 +
117534 + if (is_gimple_constant(rhs))
117535 + return false;
117536 +
117537 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
117538 + return false;
117539 +
117540 + if (!types_compatible_p(dst_type, TREE_TYPE(rhs)))
117541 + return false;
117542 +
117543 + // DI type can be on 32 bit (from create_assign) but overflow type stays DI
117544 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
117545 + return false;
117546 +
117547 + return true;
117548 +}
117549 +
117550 +tree cast_a_tree(tree type, tree var)
117551 +{
117552 + gcc_assert(type != NULL_TREE);
117553 + gcc_assert(var != NULL_TREE);
117554 + gcc_assert(fold_convertible_p(type, var));
117555 +
117556 + return fold_convert(type, var);
117557 +}
117558 +
117559 +gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force)
117560 +{
117561 + gimple assign, def_stmt;
117562 +
117563 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
117564 + gcc_assert(!is_gimple_constant(rhs));
117565 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
117566 + gcc_unreachable();
117567 +
117568 + def_stmt = get_def_stmt(rhs);
117569 + if (def_stmt && gimple_code(def_stmt) != GIMPLE_NOP && skip_cast(dst_type, rhs, force) && pointer_set_contains(visited->my_stmts, def_stmt))
117570 + return def_stmt;
117571 +
117572 + if (lhs == CREATE_NEW_VAR)
117573 + lhs = create_new_var(dst_type);
117574 +
117575 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
117576 +
117577 + if (!gsi_end_p(*gsi)) {
117578 + location_t loc = gimple_location(gsi_stmt(*gsi));
117579 + gimple_set_location(assign, loc);
117580 + }
117581 +
117582 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
117583 +
117584 + if (before)
117585 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
117586 + else
117587 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
117588 + update_stmt(assign);
117589 + return assign;
117590 +}
117591 +
117592 +bool is_size_overflow_type(const_tree var)
117593 +{
117594 + const char *name;
117595 + const_tree type_name, type;
117596 +
117597 + if (var == NULL_TREE)
117598 + return false;
117599 +
117600 + type = TREE_TYPE(var);
117601 + type_name = TYPE_NAME(type);
117602 + if (type_name == NULL_TREE)
117603 + return false;
117604 +
117605 + if (DECL_P(type_name))
117606 + name = DECL_NAME_POINTER(type_name);
117607 + else
117608 + name = IDENTIFIER_POINTER(type_name);
117609 +
117610 + if (!strncmp(name, "size_overflow_type", 18))
117611 + return true;
117612 + return false;
117613 +}
117614 +
117615 diff --git a/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
117616 new file mode 100644
117617 index 0000000..7c9e6d1
117618 --- /dev/null
117619 +++ b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
117620 @@ -0,0 +1,138 @@
117621 +/*
117622 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
117623 + * Licensed under the GPL v2, or (at your option) v3
117624 + *
117625 + * Homepage:
117626 + * http://www.grsecurity.net/~ephox/overflow_plugin/
117627 + *
117628 + * Documentation:
117629 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
117630 + *
117631 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
117632 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
117633 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
117634 + *
117635 + * Usage:
117636 + * $ make
117637 + * $ make run
117638 + */
117639 +
117640 +#include "gcc-common.h"
117641 +#include "size_overflow.h"
117642 +
117643 +bool skip_expr_on_double_type(const_gimple stmt)
117644 +{
117645 + enum tree_code code = gimple_assign_rhs_code(stmt);
117646 +
117647 + switch (code) {
117648 + case RSHIFT_EXPR:
117649 + case TRUNC_DIV_EXPR:
117650 + case CEIL_DIV_EXPR:
117651 + case FLOOR_DIV_EXPR:
117652 + case ROUND_DIV_EXPR:
117653 + case EXACT_DIV_EXPR:
117654 + case RDIV_EXPR:
117655 + case TRUNC_MOD_EXPR:
117656 + case CEIL_MOD_EXPR:
117657 + case FLOOR_MOD_EXPR:
117658 + case ROUND_MOD_EXPR:
117659 + return true;
117660 + default:
117661 + return false;
117662 + }
117663 +}
117664 +
117665 +void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs)
117666 +{
117667 + const_tree orig_rhs1;
117668 + tree down_lhs, new_lhs, dup_type = TREE_TYPE(rhs);
117669 + gimple down_cast, up_cast;
117670 + gimple_stmt_iterator gsi = gsi_for_stmt(use_stmt);
117671 +
117672 + down_cast = build_cast_stmt(visited, orig_type, rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
117673 + down_lhs = gimple_assign_lhs(down_cast);
117674 +
117675 + gsi = gsi_for_stmt(use_stmt);
117676 + up_cast = build_cast_stmt(visited, dup_type, down_lhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
117677 + new_lhs = gimple_assign_lhs(up_cast);
117678 +
117679 + orig_rhs1 = gimple_assign_rhs1(use_stmt);
117680 + if (operand_equal_p(orig_rhs1, rhs, 0))
117681 + gimple_assign_set_rhs1(use_stmt, new_lhs);
117682 + else
117683 + gimple_assign_set_rhs2(use_stmt, new_lhs);
117684 + update_stmt(use_stmt);
117685 +
117686 + pointer_set_insert(visited->my_stmts, up_cast);
117687 + pointer_set_insert(visited->my_stmts, down_cast);
117688 + pointer_set_insert(visited->skip_expr_casts, up_cast);
117689 + pointer_set_insert(visited->skip_expr_casts, down_cast);
117690 +}
117691 +
117692 +static tree get_proper_unsigned_half_type(const_tree node)
117693 +{
117694 + tree new_type, type;
117695 +
117696 + gcc_assert(is_size_overflow_type(node));
117697 +
117698 + type = TREE_TYPE(node);
117699 + switch (TYPE_MODE(type)) {
117700 + case HImode:
117701 + new_type = unsigned_intQI_type_node;
117702 + break;
117703 + case SImode:
117704 + new_type = unsigned_intHI_type_node;
117705 + break;
117706 + case DImode:
117707 + new_type = unsigned_intSI_type_node;
117708 + break;
117709 + case TImode:
117710 + new_type = unsigned_intDI_type_node;
117711 + break;
117712 + default:
117713 + gcc_unreachable();
117714 + }
117715 +
117716 + if (TYPE_QUALS(type) != 0)
117717 + return build_qualified_type(new_type, TYPE_QUALS(type));
117718 + return new_type;
117719 +}
117720 +
117721 +static void insert_cast_rhs(struct visited *visited, gimple stmt, tree rhs)
117722 +{
117723 + tree type;
117724 +
117725 + if (rhs == NULL_TREE)
117726 + return;
117727 + if (!is_size_overflow_type(rhs))
117728 + return;
117729 +
117730 + type = get_proper_unsigned_half_type(rhs);
117731 + if (is_gimple_constant(rhs))
117732 + return;
117733 + create_up_and_down_cast(visited, stmt, type, rhs);
117734 +}
117735 +
117736 +static void insert_cast(struct visited *visited, gimple stmt, tree rhs)
117737 +{
117738 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && !is_size_overflow_type(rhs))
117739 + return;
117740 + gcc_assert(is_size_overflow_type(rhs));
117741 + insert_cast_rhs(visited, stmt, rhs);
117742 +}
117743 +
117744 +void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type)
117745 +{
117746 + tree rhs1, rhs2;
117747 +
117748 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS1_INTENTIONAL_OVERFLOW) {
117749 + rhs1 = gimple_assign_rhs1(stmt);
117750 + insert_cast(visited, stmt, rhs1);
117751 + }
117752 +
117753 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS2_INTENTIONAL_OVERFLOW) {
117754 + rhs2 = gimple_assign_rhs2(stmt);
117755 + insert_cast(visited, stmt, rhs2);
117756 + }
117757 +}
117758 +
117759 diff --git a/tools/gcc/size_overflow_plugin/size_overflow.h b/tools/gcc/size_overflow_plugin/size_overflow.h
117760 new file mode 100644
117761 index 0000000..e5b4e50
117762 --- /dev/null
117763 +++ b/tools/gcc/size_overflow_plugin/size_overflow.h
117764 @@ -0,0 +1,127 @@
117765 +#ifndef SIZE_OVERFLOW_H
117766 +#define SIZE_OVERFLOW_H
117767 +
117768 +#define CREATE_NEW_VAR NULL_TREE
117769 +#define CANNOT_FIND_ARG 32
117770 +#define MAX_PARAM 31
117771 +#define BEFORE_STMT true
117772 +#define AFTER_STMT false
117773 +
117774 +#define TURN_OFF_ASM_STR "# size_overflow MARK_TURN_OFF "
117775 +#define YES_ASM_STR "# size_overflow MARK_YES "
117776 +#define OK_ASM_STR "# size_overflow "
117777 +
117778 +enum mark {
117779 + MARK_NO, MARK_YES, MARK_NOT_INTENTIONAL, MARK_TURN_OFF
117780 +};
117781 +
117782 +enum intentional_overflow_type {
117783 + NO_INTENTIONAL_OVERFLOW, RHS1_INTENTIONAL_OVERFLOW, RHS2_INTENTIONAL_OVERFLOW
117784 +};
117785 +
117786 +struct visited {
117787 + struct pointer_set_t *stmts;
117788 + struct pointer_set_t *my_stmts;
117789 + struct pointer_set_t *skip_expr_casts;
117790 + struct pointer_set_t *no_cast_check;
117791 +};
117792 +
117793 +// size_overflow_plugin.c
117794 +extern tree report_size_overflow_decl;
117795 +extern tree size_overflow_type_HI;
117796 +extern tree size_overflow_type_SI;
117797 +extern tree size_overflow_type_DI;
117798 +extern tree size_overflow_type_TI;
117799 +
117800 +
117801 +// size_overflow_plugin_hash.c
117802 +struct size_overflow_hash {
117803 + const struct size_overflow_hash * const next;
117804 + const char * const name;
117805 + const unsigned int param;
117806 +};
117807 +
117808 +struct interesting_node {
117809 + struct interesting_node *next;
117810 + gimple first_stmt;
117811 + const_tree fndecl;
117812 + tree node;
117813 +#if BUILDING_GCC_VERSION <= 4007
117814 + VEC(tree, gc) *last_nodes;
117815 +#else
117816 + vec<tree, va_gc> *last_nodes;
117817 +#endif
117818 + unsigned int num;
117819 + enum mark intentional_attr_decl;
117820 + enum mark intentional_attr_cur_fndecl;
117821 + gimple intentional_mark_from_gimple;
117822 +};
117823 +
117824 +extern bool is_size_overflow_asm(const_gimple stmt);
117825 +extern unsigned int get_function_num(const_tree node, const_tree orig_fndecl);
117826 +extern unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl);
117827 +extern bool is_missing_function(const_tree orig_fndecl, unsigned int num);
117828 +extern bool is_a_return_check(const_tree node);
117829 +extern const struct size_overflow_hash *get_function_hash(const_tree fndecl);
117830 +extern unsigned int find_arg_number_tree(const_tree arg, const_tree func);
117831 +
117832 +
117833 +// size_overflow_debug.c
117834 +extern struct opt_pass *make_dump_pass(void);
117835 +
117836 +
117837 +// intentional_overflow.c
117838 +extern enum mark get_intentional_attr_type(const_tree node);
117839 +extern bool is_size_overflow_intentional_asm_yes(const_gimple stmt);
117840 +extern bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt);
117841 +extern bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum);
117842 +extern bool is_yes_intentional_attr(const_tree decl, unsigned int argnum);
117843 +extern bool is_turn_off_intentional_attr(const_tree decl);
117844 +extern void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum);
117845 +extern void check_intentional_attribute_ipa(struct interesting_node *cur_node);
117846 +extern bool is_a_cast_and_const_overflow(const_tree no_const_rhs);
117847 +extern bool is_const_plus_unsigned_signed_truncation(const_tree lhs);
117848 +extern bool is_a_constant_overflow(const_gimple stmt, const_tree rhs);
117849 +extern tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2);
117850 +extern tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs);
117851 +extern bool is_a_neg_overflow(const_gimple stmt, const_tree rhs);
117852 +extern enum intentional_overflow_type add_mul_intentional_overflow(const_gimple def_stmt);
117853 +extern void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt);
117854 +
117855 +
117856 +// insert_size_overflow_check_ipa.c
117857 +extern unsigned int search_function(void);
117858 +extern unsigned int call_count;
117859 +extern struct opt_pass *make_insert_size_overflow_check(void);
117860 +extern const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum);
117861 +
117862 +
117863 +// insert_size_overflow_asm.c
117864 +extern struct opt_pass *make_insert_size_overflow_asm_pass(void);
117865 +
117866 +
117867 +// misc.c
117868 +extern void set_current_function_decl(tree fndecl);
117869 +extern void unset_current_function_decl(void);
117870 +extern gimple get_def_stmt(const_tree node);
117871 +extern tree create_new_var(tree type);
117872 +extern gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force);
117873 +extern bool skip_types(const_tree var);
117874 +extern tree cast_a_tree(tree type, tree var);
117875 +extern bool is_size_overflow_type(const_tree var);
117876 +
117877 +
117878 +// insert_size_overflow_check_core.c
117879 +extern tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs);
117880 +extern void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
117881 +extern tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
117882 +extern tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before);
117883 +
117884 +
117885 +// remove_unnecessary_dup.c
117886 +extern struct opt_pass *make_remove_unnecessary_dup_pass(void);
117887 +extern void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type);
117888 +extern bool skip_expr_on_double_type(const_gimple stmt);
117889 +extern void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs);
117890 +
117891 +#endif
117892 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_debug.c b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
117893 new file mode 100644
117894 index 0000000..4378111
117895 --- /dev/null
117896 +++ b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
117897 @@ -0,0 +1,116 @@
117898 +/*
117899 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
117900 + * Licensed under the GPL v2, or (at your option) v3
117901 + *
117902 + * Homepage:
117903 + * http://www.grsecurity.net/~ephox/overflow_plugin/
117904 + *
117905 + * Documentation:
117906 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
117907 + *
117908 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
117909 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
117910 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
117911 + *
117912 + * Usage:
117913 + * $ make
117914 + * $ make run
117915 + */
117916 +
117917 +#include "gcc-common.h"
117918 +
117919 +static unsigned int dump_functions(void)
117920 +{
117921 + struct cgraph_node *node;
117922 +
117923 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
117924 + basic_block bb;
117925 +
117926 + push_cfun(DECL_STRUCT_FUNCTION(NODE_DECL(node)));
117927 + current_function_decl = NODE_DECL(node);
117928 +
117929 + fprintf(stderr, "-----------------------------------------\n%s\n-----------------------------------------\n", DECL_NAME_POINTER(current_function_decl));
117930 +
117931 + FOR_ALL_BB_FN(bb, cfun) {
117932 + gimple_stmt_iterator si;
117933 +
117934 + fprintf(stderr, "<bb %u>:\n", bb->index);
117935 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
117936 + debug_gimple_stmt(gsi_stmt(si));
117937 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
117938 + debug_gimple_stmt(gsi_stmt(si));
117939 + fprintf(stderr, "\n");
117940 + }
117941 +
117942 + fprintf(stderr, "-------------------------------------------------------------------------\n");
117943 +
117944 + pop_cfun();
117945 + current_function_decl = NULL_TREE;
117946 + }
117947 +
117948 + fprintf(stderr, "###############################################################################\n");
117949 +
117950 + return 0;
117951 +}
117952 +
117953 +#if BUILDING_GCC_VERSION >= 4009
117954 +static const struct pass_data dump_pass_data = {
117955 +#else
117956 +static struct ipa_opt_pass_d dump_pass = {
117957 + .pass = {
117958 +#endif
117959 + .type = SIMPLE_IPA_PASS,
117960 + .name = "dump",
117961 +#if BUILDING_GCC_VERSION >= 4008
117962 + .optinfo_flags = OPTGROUP_NONE,
117963 +#endif
117964 +#if BUILDING_GCC_VERSION >= 4009
117965 + .has_gate = false,
117966 + .has_execute = true,
117967 +#else
117968 + .gate = NULL,
117969 + .execute = dump_functions,
117970 + .sub = NULL,
117971 + .next = NULL,
117972 + .static_pass_number = 0,
117973 +#endif
117974 + .tv_id = TV_NONE,
117975 + .properties_required = 0,
117976 + .properties_provided = 0,
117977 + .properties_destroyed = 0,
117978 + .todo_flags_start = 0,
117979 + .todo_flags_finish = 0,
117980 +#if BUILDING_GCC_VERSION < 4009
117981 + },
117982 + .generate_summary = NULL,
117983 + .write_summary = NULL,
117984 + .read_summary = NULL,
117985 +#if BUILDING_GCC_VERSION >= 4006
117986 + .write_optimization_summary = NULL,
117987 + .read_optimization_summary = NULL,
117988 +#endif
117989 + .stmt_fixup = NULL,
117990 + .function_transform_todo_flags_start = 0,
117991 + .function_transform = NULL,
117992 + .variable_transform = NULL,
117993 +#endif
117994 +};
117995 +
117996 +#if BUILDING_GCC_VERSION >= 4009
117997 +namespace {
117998 +class dump_pass : public ipa_opt_pass_d {
117999 +public:
118000 + dump_pass() : ipa_opt_pass_d(dump_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
118001 + unsigned int execute() { return dump_functions(); }
118002 +};
118003 +}
118004 +#endif
118005 +
118006 +struct opt_pass *make_dump_pass(void)
118007 +{
118008 +#if BUILDING_GCC_VERSION >= 4009
118009 + return new dump_pass();
118010 +#else
118011 + return &dump_pass.pass;
118012 +#endif
118013 +}
118014 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash.data b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
118015 new file mode 100644
118016 index 0000000..f527934
118017 --- /dev/null
118018 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
118019 @@ -0,0 +1,5911 @@
118020 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
118021 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
118022 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
118023 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
118024 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
118025 +padzero_55 padzero 1 55 &sel_read_policyvers_55
118026 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
118027 +__skb_to_sgvec_72 __skb_to_sgvec 0 72 NULL
118028 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
118029 +load_msg_95 load_msg 2 95 NULL
118030 +ipath_verbs_send_117 ipath_verbs_send 5-3 117 NULL
118031 +init_q_132 init_q 4 132 NULL
118032 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
118033 +hva_to_gfn_memslot_149 hva_to_gfn_memslot 0-1 149 NULL
118034 +ping_v6_sendmsg_152 ping_v6_sendmsg 4 152 NULL
118035 +ext4_ext_get_actual_len_153 ext4_ext_get_actual_len 0 153 NULL nohasharray
118036 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 &ext4_ext_get_actual_len_153
118037 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
118038 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
118039 +obd_proc_jobid_var_seq_write_199 obd_proc_jobid_var_seq_write 3 199 NULL
118040 +ll_xattr_cache_seq_write_250 ll_xattr_cache_seq_write 3 250 NULL
118041 +br_port_info_size_268 br_port_info_size 0 268 NULL
118042 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
118043 +SYSC_connect_304 SYSC_connect 3 304 NULL
118044 +syslog_print_307 syslog_print 2 307 NULL
118045 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
118046 +mlx5_core_access_reg_361 mlx5_core_access_reg 3-5 361 NULL
118047 +aio_read_events_ring_410 aio_read_events_ring 3-0 410 NULL
118048 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
118049 +snd_ca0106_ptr_read_467 snd_ca0106_ptr_read 0 467 NULL
118050 +cfs_trace_set_debug_mb_usrstr_486 cfs_trace_set_debug_mb_usrstr 2 486 NULL
118051 +nvme_trans_modesel_data_488 nvme_trans_modesel_data 4 488 NULL
118052 +iwl_dbgfs_protection_mode_write_502 iwl_dbgfs_protection_mode_write 3 502 NULL
118053 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
118054 +ocfs2_validate_meta_ecc_bhs_527 ocfs2_validate_meta_ecc_bhs 0 527 NULL
118055 +zlib_deflate_workspacesize_537 zlib_deflate_workspacesize 0-1-2 537 NULL
118056 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
118057 +sco_sock_setsockopt_552 sco_sock_setsockopt 5 552 NULL
118058 +lpfc_nlp_state_name_556 lpfc_nlp_state_name 2 556 NULL
118059 +snd_aw2_saa7146_get_hw_ptr_playback_558 snd_aw2_saa7146_get_hw_ptr_playback 0 558 NULL
118060 +start_isoc_chain_565 start_isoc_chain 2 565 NULL nohasharray
118061 +dev_hard_header_565 dev_hard_header 0 565 &start_isoc_chain_565
118062 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
118063 +btrfs_stack_file_extent_offset_607 btrfs_stack_file_extent_offset 0 607 NULL
118064 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
118065 +fuse_request_alloc_nofs_617 fuse_request_alloc_nofs 1 617 NULL
118066 +ptlrpc_lprocfs_nrs_seq_write_621 ptlrpc_lprocfs_nrs_seq_write 3 621 NULL
118067 +viafb_dfpl_proc_write_627 viafb_dfpl_proc_write 3 627 NULL
118068 +ceph_osdc_new_request_635 ceph_osdc_new_request 6 635 NULL
118069 +cfs_hash_bkt_size_643 cfs_hash_bkt_size 0 643 NULL
118070 +unlink_queued_645 unlink_queued 4 645 NULL
118071 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
118072 +nvif_notify_new_671 nvif_notify_new 6 671 NULL
118073 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
118074 +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
118075 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
118076 +dvb_video_write_754 dvb_video_write 3 754 NULL
118077 +cfs_trace_allocate_string_buffer_781 cfs_trace_allocate_string_buffer 2 781 NULL
118078 +ath6kl_disconnect_timeout_write_794 ath6kl_disconnect_timeout_write 3 794 NULL
118079 +if_writecmd_815 if_writecmd 2 815 NULL
118080 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
118081 +error_state_read_859 error_state_read 6 859 NULL
118082 +lustre_init_msg_v2_864 lustre_init_msg_v2 2 864 NULL
118083 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
118084 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
118085 +snd_pcm_action_single_905 snd_pcm_action_single 0 905 NULL
118086 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
118087 +__nodes_weight_956 __nodes_weight 2-0 956 NULL
118088 +bnx2x_fill_fw_str_968 bnx2x_fill_fw_str 3 968 NULL
118089 +usnic_ib_qp_grp_dump_hdr_989 usnic_ib_qp_grp_dump_hdr 2 989 NULL
118090 +readreg_1017 readreg 0-1 1017 NULL
118091 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
118092 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
118093 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
118094 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
118095 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
118096 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
118097 +nfs4_init_nonuniform_client_string_1097 nfs4_init_nonuniform_client_string 3 1097 NULL
118098 +__arch_hweight8_1105 __arch_hweight8 0 1105 NULL
118099 +utf8s_to_utf16s_1115 utf8s_to_utf16s 0 1115 NULL
118100 +cfg80211_report_obss_beacon_1133 cfg80211_report_obss_beacon 3 1133 NULL
118101 +i2400m_rx_ctl_1157 i2400m_rx_ctl 4 1157 NULL
118102 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
118103 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
118104 +pstore_ftrace_knob_write_1198 pstore_ftrace_knob_write 3 1198 NULL
118105 +i2400m_rx_ctl_ack_1199 i2400m_rx_ctl_ack 3 1199 NULL
118106 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
118107 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
118108 +lov_ost_pool_init_1215 lov_ost_pool_init 2 1215 NULL
118109 +kernfs_file_direct_read_1238 kernfs_file_direct_read 3 1238 NULL
118110 +acpi_battery_write_alarm_1240 acpi_battery_write_alarm 3 1240 NULL
118111 +drm_primary_helper_create_plane_1262 drm_primary_helper_create_plane 3 1262 NULL
118112 +ocfs2_extend_file_1266 ocfs2_extend_file 3 1266 NULL
118113 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
118114 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
118115 +SyS_flistxattr_1287 SyS_flistxattr 3 1287 NULL
118116 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
118117 +posix_acl_xattr_set_1301 posix_acl_xattr_set 4 1301 NULL
118118 +ffs_1322 ffs 0 1322 NULL
118119 +qlcnic_pci_sriov_configure_1327 qlcnic_pci_sriov_configure 2 1327 NULL
118120 +btrfs_submit_compressed_write_1347 btrfs_submit_compressed_write 5 1347 NULL
118121 +bond_verify_device_path_1352 bond_verify_device_path 3 1352 NULL
118122 +snd_pcm_lib_write1_1358 snd_pcm_lib_write1 0-3 1358 NULL
118123 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
118124 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
118125 +ocfs2_prepare_inode_for_write_1372 ocfs2_prepare_inode_for_write 3 1372 NULL
118126 +xpcs_reg_addr_read_1381 xpcs_reg_addr_read 3 1381 NULL
118127 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
118128 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
118129 +SYSC_io_getevents_1392 SYSC_io_getevents 3 1392 NULL
118130 +cfs_trace_copyout_string_1416 cfs_trace_copyout_string 2 1416 NULL
118131 +init_rs_internal_1436 init_rs_internal 1 1436 NULL
118132 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
118133 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
118134 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
118135 +SYSC_syslog_1477 SYSC_syslog 3 1477 NULL
118136 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
118137 +fpregs_set_1497 fpregs_set 4 1497 NULL
118138 +tomoyo_round2_1518 tomoyo_round2 0 1518 NULL
118139 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
118140 +ath6kl_init_get_fwcaps_1557 ath6kl_init_get_fwcaps 3 1557 NULL
118141 +ffs_mutex_lock_1564 ffs_mutex_lock 0 1564 NULL
118142 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
118143 +ipath_ht_handle_hwerrors_1592 ipath_ht_handle_hwerrors 3 1592 NULL
118144 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
118145 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
118146 +v9fs_fid_xattr_get_1618 v9fs_fid_xattr_get 0 1618 NULL
118147 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
118148 +mei_cl_recv_1665 mei_cl_recv 3 1665 NULL
118149 +rmap_add_1677 rmap_add 3 1677 NULL
118150 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
118151 +iwl_dbgfs_d0i3_refs_read_1705 iwl_dbgfs_d0i3_refs_read 3 1705 NULL
118152 +pdu_write_u_1710 pdu_write_u 3 1710 NULL
118153 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
118154 +btrfs_dir_data_len_1714 btrfs_dir_data_len 0 1714 NULL
118155 +internal_create_group_1733 internal_create_group 0 1733 NULL
118156 +dev_irnet_read_1741 dev_irnet_read 3 1741 NULL
118157 +usb_ep_align_maybe_1743 usb_ep_align_maybe 0-3 1743 NULL
118158 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
118159 +cosa_write_1774 cosa_write 3 1774 NULL
118160 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
118161 +__nodelist_scnprintf_1815 __nodelist_scnprintf 2-0 1815 NULL
118162 +sb_issue_zeroout_1884 sb_issue_zeroout 3 1884 NULL
118163 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
118164 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
118165 +SyS_add_key_1900 SyS_add_key 4 1900 NULL
118166 +uhid_char_read_1920 uhid_char_read 3 1920 NULL
118167 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
118168 +azx_get_position_1927 azx_get_position 0 1927 NULL
118169 +bdev_erase_1933 bdev_erase 3 1933 NULL
118170 +ext3_fiemap_1936 ext3_fiemap 4 1936 NULL
118171 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL nohasharray
118172 +nvif_object_sclass_1940 nvif_object_sclass 3 1940 &cyttsp_probe_1940
118173 +ieee80211_if_fmt_dot11MeshConfirmTimeout_1945 ieee80211_if_fmt_dot11MeshConfirmTimeout 3 1945 NULL
118174 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
118175 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
118176 +gpio_power_write_1991 gpio_power_write 3 1991 NULL
118177 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
118178 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
118179 +ocfs2_global_qinit_alloc_2018 ocfs2_global_qinit_alloc 0 2018 NULL
118180 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
118181 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
118182 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
118183 +ocfs2_expand_inline_dir_2063 ocfs2_expand_inline_dir 3 2063 NULL
118184 +__generic_copy_from_user_intel_2073 __generic_copy_from_user_intel 0-3 2073 NULL
118185 +diva_set_driver_dbg_mask_2077 diva_set_driver_dbg_mask 0 2077 NULL
118186 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
118187 +xgmac_reg_value_read_2095 xgmac_reg_value_read 3 2095 NULL
118188 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
118189 +audit_expand_2098 audit_expand 0 2098 NULL
118190 +__set_print_fmt_2106 __set_print_fmt 0 2106 NULL
118191 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
118192 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
118193 +btrfs_file_extent_inline_len_2116 btrfs_file_extent_inline_len 0 2116 NULL
118194 +enable_read_2117 enable_read 3 2117 NULL
118195 +pcf50633_write_block_2124 pcf50633_write_block 2-3 2124 NULL
118196 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
118197 +iov_iter_count_2152 iov_iter_count 0 2152 NULL
118198 +__copy_to_user_ll_2157 __copy_to_user_ll 0-3 2157 NULL
118199 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
118200 +bio_integrity_alloc_2194 bio_integrity_alloc 3 2194 NULL
118201 +picolcd_debug_reset_write_2195 picolcd_debug_reset_write 3 2195 NULL
118202 +u32_array_read_2219 u32_array_read 3 2219 NULL nohasharray
118203 +mei_dbgfs_read_meclients_2219 mei_dbgfs_read_meclients 3 2219 &u32_array_read_2219
118204 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
118205 +netlbl_secattr_catmap_walk_2255 netlbl_secattr_catmap_walk 0-2 2255 NULL
118206 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
118207 +do_update_counters_2259 do_update_counters 4 2259 NULL
118208 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
118209 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
118210 +sr_read_cmd_2299 sr_read_cmd 5 2299 NULL
118211 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
118212 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
118213 +hfsplus_find_init_2318 hfsplus_find_init 0 2318 NULL nohasharray
118214 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 &hfsplus_find_init_2318
118215 +dice_hwdep_read_2326 dice_hwdep_read 3 2326 NULL
118216 +__erst_read_to_erange_2341 __erst_read_to_erange 0 2341 NULL
118217 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
118218 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
118219 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
118220 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
118221 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
118222 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
118223 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
118224 +raid1_size_2419 raid1_size 0-2 2419 NULL
118225 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
118226 +wiphy_new_2482 wiphy_new 2 2482 NULL
118227 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
118228 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
118229 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
118230 +ext4_get_inode_loc_2516 ext4_get_inode_loc 0 2516 NULL
118231 +batadv_tvlv_container_list_size_2524 batadv_tvlv_container_list_size 0 2524 NULL
118232 +smk_write_syslog_2529 smk_write_syslog 3 2529 NULL
118233 +__ceph_setxattr_2532 __ceph_setxattr 4 2532 NULL
118234 +sfw_create_rpc_2562 sfw_create_rpc 4 2562 NULL
118235 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
118236 +pcm_sanity_check_2574 pcm_sanity_check 0 2574 NULL
118237 +mdc_max_rpcs_in_flight_seq_write_2594 mdc_max_rpcs_in_flight_seq_write 3 2594 NULL
118238 +slot_bytes_2609 slot_bytes 0 2609 NULL
118239 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
118240 +switch_status_2629 switch_status 5 2629 NULL
118241 +_proc_do_string_2632 _proc_do_string 2 2632 NULL
118242 +tcp_xmit_size_goal_2661 tcp_xmit_size_goal 2 2661 NULL
118243 +osc_build_ppga_2670 osc_build_ppga 2 2670 NULL
118244 +ffs_ep0_read_2672 ffs_ep0_read 3 2672 NULL
118245 +oti6858_write_2692 oti6858_write 4 2692 NULL
118246 +nfc_llcp_send_ui_frame_2702 nfc_llcp_send_ui_frame 5 2702 NULL
118247 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
118248 +lprocfs_stats_counter_size_2708 lprocfs_stats_counter_size 0 2708 NULL
118249 +xfs_readdir_2767 xfs_readdir 3 2767 NULL
118250 +fsl_edma_alloc_desc_2769 fsl_edma_alloc_desc 2 2769 NULL
118251 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
118252 +set_msr_hyperv_pw_2785 set_msr_hyperv_pw 3 2785 NULL
118253 +device_add_attrs_2789 device_add_attrs 0 2789 NULL
118254 +iwl_dbgfs_clear_ucode_statistics_write_2804 iwl_dbgfs_clear_ucode_statistics_write 3 2804 NULL
118255 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
118256 +vb2_dc_get_userptr_2829 vb2_dc_get_userptr 2-3 2829 NULL
118257 +sock_create_2838 sock_create 0 2838 NULL
118258 +wait_for_avail_2847 wait_for_avail 0 2847 NULL
118259 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
118260 +irnet_ctrl_read_2863 irnet_ctrl_read 4 2863 NULL
118261 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
118262 +nla_padlen_2883 nla_padlen 1 2883 NULL
118263 +cmm_write_2896 cmm_write 3 2896 NULL
118264 +osc_import_seq_write_2923 osc_import_seq_write 3 2923 NULL
118265 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
118266 +nes_read_indexed_2946 nes_read_indexed 0 2946 NULL
118267 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
118268 +i40e_dbg_prep_dump_buf_2951 i40e_dbg_prep_dump_buf 2 2951 NULL
118269 +set_fast_connectable_2952 set_fast_connectable 4 2952 NULL
118270 +free_area_init_core_2962 free_area_init_core 2-3 2962 NULL
118271 +bio_setup_sector_2970 bio_setup_sector 3 2970 NULL
118272 +do_strnlen_user_2976 do_strnlen_user 0-2 2976 NULL
118273 +p9_nr_pages_2992 p9_nr_pages 0-2 2992 NULL
118274 +lov_stripetype_seq_write_3013 lov_stripetype_seq_write 3 3013 NULL
118275 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
118276 +depth_write_3021 depth_write 3 3021 NULL
118277 +snd_azf3328_codec_inl_3022 snd_azf3328_codec_inl 0 3022 NULL
118278 +nvme_split_and_submit_3027 nvme_split_and_submit 3 3027 NULL
118279 +kvm_unmap_hva_3028 kvm_unmap_hva 2 3028 NULL
118280 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
118281 +lpfc_idiag_mbxacc_write_3038 lpfc_idiag_mbxacc_write 3 3038 NULL nohasharray
118282 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 &lpfc_idiag_mbxacc_write_3038
118283 +nr_free_buffer_pages_3044 nr_free_buffer_pages 0 3044 NULL
118284 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
118285 +qp_alloc_ppn_set_3068 qp_alloc_ppn_set 2-4 3068 NULL
118286 +__blk_end_bidi_request_3070 __blk_end_bidi_request 3-4 3070 NULL
118287 +hfsplus_asc2uni_3071 hfsplus_asc2uni 0 3071 NULL nohasharray
118288 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 &hfsplus_asc2uni_3071
118289 +read_file_antenna_diversity_3077 read_file_antenna_diversity 3 3077 NULL
118290 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
118291 +rb_alloc_3102 rb_alloc 1 3102 NULL
118292 +ufshcd_get_rsp_upiu_result_3114 ufshcd_get_rsp_upiu_result 0 3114 NULL
118293 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
118294 +print_time_3132 print_time 0 3132 NULL
118295 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
118296 +CIFSSMBSetPosixACL_3154 CIFSSMBSetPosixACL 5 3154 NULL
118297 +uv_num_possible_blades_3177 uv_num_possible_blades 0 3177 NULL
118298 +pkcs7_sig_note_signature_3178 pkcs7_sig_note_signature 5 3178 NULL
118299 +uinput_ioctl_handler_3181 uinput_ioctl_handler 2 3181 NULL nohasharray
118300 +uvc_video_stats_dump_3181 uvc_video_stats_dump 3 3181 &uinput_ioctl_handler_3181
118301 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
118302 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
118303 +alloc_context_3194 alloc_context 1 3194 NULL
118304 +shmem_pread_slow_3198 shmem_pread_slow 3-2 3198 NULL
118305 +codec_reg_write_file_3204 codec_reg_write_file 3 3204 NULL
118306 +SyS_sendto_3219 SyS_sendto 6 3219 NULL
118307 +btrfs_prealloc_file_range_3227 btrfs_prealloc_file_range 3 3227 NULL
118308 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
118309 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
118310 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
118311 +ext3_xattr_find_entry_3237 ext3_xattr_find_entry 0 3237 NULL
118312 +key_key_read_3241 key_key_read 3 3241 NULL
118313 +__ilog2_u64_3284 __ilog2_u64 0 3284 NULL
118314 +ieee80211_if_write_beacon_loss_3296 ieee80211_if_write_beacon_loss 3 3296 NULL
118315 +cgroup_name_3300 cgroup_name 3 3300 NULL
118316 +__iovec_copy_from_user_inatomic_3314 __iovec_copy_from_user_inatomic 0-4-3 3314 NULL
118317 +_iwl_dbgfs_d3_sram_write_3315 _iwl_dbgfs_d3_sram_write 3 3315 NULL
118318 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
118319 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
118320 +sysfs_create_group_3339 sysfs_create_group 0 3339 NULL
118321 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
118322 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
118323 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
118324 +scnprintf_3360 scnprintf 0-2 3360 NULL
118325 +sr_read_3366 sr_read 3 3366 NULL
118326 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
118327 +isdn_readbchan_3401 isdn_readbchan 0-5 3401 NULL
118328 +mei_io_cb_alloc_resp_buf_3414 mei_io_cb_alloc_resp_buf 2 3414 NULL
118329 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
118330 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
118331 +SyS_msgsnd_3436 SyS_msgsnd 3 3436 NULL
118332 +softsynth_write_3455 softsynth_write 3 3455 NULL
118333 +snd_pcm_lib_readv_transfer_3464 snd_pcm_lib_readv_transfer 5-4-2 3464 NULL
118334 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
118335 +xfrm_migrate_msgsize_3496 xfrm_migrate_msgsize 1 3496 NULL
118336 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL
118337 +SyS_semtimedop_3532 SyS_semtimedop 3 3532 NULL
118338 +SyS_readv_3539 SyS_readv 3 3539 NULL
118339 +btrfs_dir_name_len_3549 btrfs_dir_name_len 0 3549 NULL
118340 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
118341 +evtchn_read_3569 evtchn_read 3 3569 NULL
118342 +ll_track_ppid_seq_write_3582 ll_track_ppid_seq_write 3 3582 NULL
118343 +vc_resize_3585 vc_resize 3-2 3585 NULL
118344 +kvm_mmu_notifier_change_pte_3596 kvm_mmu_notifier_change_pte 3 3596 NULL
118345 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
118346 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
118347 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
118348 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
118349 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
118350 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
118351 +_iwl_dbgfs_tx_flush_write_3675 _iwl_dbgfs_tx_flush_write 3 3675 NULL
118352 +snd_m3_assp_read_3703 snd_m3_assp_read 0 3703 NULL
118353 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
118354 +msm_otg_mode_write_3788 msm_otg_mode_write 3 3788 NULL
118355 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
118356 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
118357 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
118358 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
118359 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
118360 +get_fd_set_3866 get_fd_set 1 3866 NULL
118361 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
118362 +efivarfs_file_read_3893 efivarfs_file_read 3 3893 NULL
118363 +nvram_write_3894 nvram_write 3 3894 NULL
118364 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
118365 +comedi_buf_read_n_available_3899 comedi_buf_read_n_available 0 3899 NULL
118366 +vcs_write_3910 vcs_write 3 3910 NULL
118367 +SyS_move_pages_3920 SyS_move_pages 2 3920 NULL
118368 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
118369 +brcmf_debugfs_fws_stats_read_3947 brcmf_debugfs_fws_stats_read 3 3947 NULL
118370 +mite_bytes_written_to_memory_lb_3987 mite_bytes_written_to_memory_lb 0 3987 NULL
118371 +copy_from_user_atomic_iovec_3990 copy_from_user_atomic_iovec 0-4 3990 NULL
118372 +do_add_counters_3992 do_add_counters 3 3992 NULL
118373 +userspace_status_4004 userspace_status 4 4004 NULL
118374 +xfs_check_block_4005 xfs_check_block 4 4005 NULL nohasharray
118375 +mei_write_4005 mei_write 3 4005 &xfs_check_block_4005
118376 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
118377 +blk_end_request_4024 blk_end_request 3 4024 NULL
118378 +ext4_xattr_find_entry_4025 ext4_xattr_find_entry 0 4025 NULL
118379 +mtip_hw_read_registers_4037 mtip_hw_read_registers 3 4037 NULL
118380 +read_file_queues_4078 read_file_queues 3 4078 NULL
118381 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
118382 +C_SYSC_rt_sigpending_4114 C_SYSC_rt_sigpending 2 4114 NULL
118383 +tm6000_read_4151 tm6000_read 3 4151 NULL
118384 +mpt_raid_phys_disk_get_num_paths_4155 mpt_raid_phys_disk_get_num_paths 0 4155 NULL
118385 +msg_bits_4158 msg_bits 0-3-4 4158 NULL
118386 +get_alua_req_4166 get_alua_req 3 4166 NULL
118387 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
118388 +read_file_bool_4180 read_file_bool 3 4180 NULL
118389 +lstcon_test_add_4190 lstcon_test_add 10 4190 NULL
118390 +vring_new_virtqueue_4199 vring_new_virtqueue 2 4199 NULL
118391 +f1x_determine_channel_4202 f1x_determine_channel 2 4202 NULL
118392 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
118393 +__snd_gf1_read_addr_4210 __snd_gf1_read_addr 0 4210 NULL
118394 +ath6kl_force_roam_write_4282 ath6kl_force_roam_write 3 4282 NULL
118395 +goldfish_audio_write_4284 goldfish_audio_write 3 4284 NULL
118396 +get_connectors_for_crtc_4291 get_connectors_for_crtc 0 4291 NULL
118397 +__usbnet_read_cmd_4299 __usbnet_read_cmd 7 4299 NULL
118398 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
118399 +count_strings_4315 count_strings 0 4315 NULL
118400 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
118401 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
118402 +ima_eventdigest_init_common_4338 ima_eventdigest_init_common 2 4338 NULL
118403 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 0-3 4365 NULL nohasharray
118404 +lookup_string_4365 lookup_string 0 4365 &__copy_from_user_inatomic_4365
118405 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
118406 +access_process_vm_4412 access_process_vm 0 4412 NULL nohasharray
118407 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 &access_process_vm_4412
118408 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
118409 +rtw_android_get_rssi_4421 rtw_android_get_rssi 0 4421 NULL
118410 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
118411 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
118412 +snd_seq_expand_var_event_4481 snd_seq_expand_var_event 5-0 4481 NULL
118413 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
118414 +set_link_security_4502 set_link_security 4 4502 NULL
118415 +ll_max_readahead_per_file_mb_seq_write_4531 ll_max_readahead_per_file_mb_seq_write 3 4531 NULL
118416 +tty_register_device_4544 tty_register_device 2 4544 NULL
118417 +fsl_edma_prep_slave_sg_4555 fsl_edma_prep_slave_sg 3 4555 NULL
118418 +btrfs_file_extent_inline_item_len_4575 btrfs_file_extent_inline_item_len 0 4575 NULL
118419 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
118420 +bch_alloc_4593 bch_alloc 1 4593 NULL
118421 +ll_rw_extents_stats_seq_write_4633 ll_rw_extents_stats_seq_write 3 4633 NULL
118422 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
118423 +nve0_gpio_intr_mask_4665 nve0_gpio_intr_mask 4-3 4665 NULL
118424 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
118425 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
118426 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
118427 +kone_receive_4690 kone_receive 4 4690 NULL
118428 +hash_netportnet6_expire_4702 hash_netportnet6_expire 4 4702 NULL
118429 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
118430 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
118431 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
118432 +ll_rw_offset_stats_seq_write_4736 ll_rw_offset_stats_seq_write 3 4736 NULL nohasharray
118433 +bitmap_startwrite_4736 bitmap_startwrite 2 4736 &ll_rw_offset_stats_seq_write_4736
118434 +lu_buf_alloc_4753 lu_buf_alloc 2 4753 NULL
118435 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
118436 +create_subvol_4791 create_subvol 4 4791 NULL
118437 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
118438 +C_SYSC_setsockopt_4806 C_SYSC_setsockopt 5 4806 NULL
118439 +repair_io_failure_4815 repair_io_failure 4-3 4815 NULL
118440 +scsi_end_request_4839 scsi_end_request 3-4 4839 NULL
118441 +comedi_buf_write_free_4847 comedi_buf_write_free 2 4847 NULL
118442 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
118443 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
118444 +ocfs2_defrag_extent_4873 ocfs2_defrag_extent 2 4873 NULL
118445 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
118446 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
118447 +ieee80211_if_fmt_ave_beacon_4941 ieee80211_if_fmt_ave_beacon 3 4941 NULL
118448 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
118449 +ath10k_read_chip_id_4969 ath10k_read_chip_id 3 4969 NULL
118450 +skb_network_header_len_4971 skb_network_header_len 0 4971 NULL
118451 +ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval_4976 ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval 3 4976 NULL
118452 +compat_SyS_ipc_5000 compat_SyS_ipc 3 5000 NULL
118453 +do_mincore_5018 do_mincore 0-2-1 5018 NULL
118454 +cfg80211_rx_mgmt_5056 cfg80211_rx_mgmt 5 5056 NULL
118455 +ocfs2_check_range_for_holes_5066 ocfs2_check_range_for_holes 3-2 5066 NULL
118456 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
118457 +snd_emu10k1_ptr20_read_5087 snd_emu10k1_ptr20_read 0 5087 NULL
118458 +get_random_bytes_5091 get_random_bytes 2 5091 NULL nohasharray
118459 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3-4-0 5091 &get_random_bytes_5091 nohasharray
118460 +blk_rq_sectors_5091 blk_rq_sectors 0 5091 &kfifo_copy_from_user_5091
118461 +sound_write_5102 sound_write 3 5102 NULL
118462 +i40e_dbg_netdev_ops_write_5117 i40e_dbg_netdev_ops_write 3 5117 NULL
118463 +qib_7220_handle_hwerrors_5142 qib_7220_handle_hwerrors 3 5142 NULL
118464 +bucket_table_alloc_5149 bucket_table_alloc 1 5149 NULL
118465 +__uwb_addr_print_5161 __uwb_addr_print 2 5161 NULL
118466 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
118467 +acpi_pcc_get_sqty_5176 acpi_pcc_get_sqty 0 5176 NULL
118468 +trf7970a_read_cont_5179 trf7970a_read_cont 4 5179 NULL
118469 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
118470 +dwc2_hcd_urb_alloc_5217 dwc2_hcd_urb_alloc 2 5217 NULL
118471 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
118472 +xgmac_reg_addr_read_5278 xgmac_reg_addr_read 3 5278 NULL
118473 +usb_descriptor_fillbuf_5302 usb_descriptor_fillbuf 0 5302 NULL
118474 +r592_write_fifo_pio_5315 r592_write_fifo_pio 3 5315 NULL
118475 +sbc_get_write_same_sectors_5317 sbc_get_write_same_sectors 0 5317 NULL
118476 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
118477 +uinput_ioctl_5342 uinput_ioctl 2 5342 NULL
118478 +cq_free_res_5355 cq_free_res 5 5355 NULL
118479 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
118480 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
118481 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
118482 +ll_xattr_cache_refill_5468 ll_xattr_cache_refill 0 5468 NULL
118483 +kernfs_fop_write_5471 kernfs_fop_write 3 5471 NULL
118484 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
118485 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
118486 +tty_write_5494 tty_write 3 5494 NULL
118487 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL nohasharray
118488 +ieee80211_if_fmt_last_beacon_5498 ieee80211_if_fmt_last_beacon 3 5498 &tomoyo_update_domain_5498
118489 +__max_nr_grant_frames_5505 __max_nr_grant_frames 0 5505 NULL
118490 +ieee80211_if_fmt_auto_open_plinks_5534 ieee80211_if_fmt_auto_open_plinks 3 5534 NULL
118491 +get_entry_msg_len_5552 get_entry_msg_len 0 5552 NULL
118492 +le_readq_5557 le_readq 0 5557 NULL
118493 +inw_5558 inw 0 5558 NULL
118494 +bioset_create_5580 bioset_create 1 5580 NULL
118495 +oz_ep_alloc_5587 oz_ep_alloc 1 5587 NULL
118496 +SYSC_fsetxattr_5639 SYSC_fsetxattr 4 5639 NULL
118497 +ext4_xattr_get_5661 ext4_xattr_get 0 5661 NULL
118498 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
118499 +get_arg_5694 get_arg 3 5694 NULL
118500 +subbuf_read_actor_5708 subbuf_read_actor 3 5708 NULL
118501 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
118502 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
118503 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
118504 +nvme_trans_bdev_char_page_5797 nvme_trans_bdev_char_page 3 5797 NULL
118505 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
118506 +nv50_disp_pioc_create__5812 nv50_disp_pioc_create_ 5 5812 NULL
118507 +ceph_x_encrypt_buflen_5829 ceph_x_encrypt_buflen 0-1 5829 NULL
118508 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
118509 +setup_req_5848 setup_req 3 5848 NULL
118510 +ria_page_count_5849 ria_page_count 0 5849 NULL
118511 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
118512 +uinput_compat_ioctl_5861 uinput_compat_ioctl 2 5861 NULL
118513 +config_buf_5862 config_buf 0 5862 NULL nohasharray
118514 +ufshcd_check_query_response_5862 ufshcd_check_query_response 0 5862 &config_buf_5862
118515 +lprocfs_fid_width_seq_write_5889 lprocfs_fid_width_seq_write 3 5889 NULL
118516 +port_show_regs_5904 port_show_regs 3 5904 NULL
118517 +rbd_segment_length_5907 rbd_segment_length 0-3-2 5907 NULL
118518 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
118519 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
118520 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
118521 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
118522 +ll_statahead_one_5962 ll_statahead_one 3 5962 NULL
118523 +__apu_get_register_5967 __apu_get_register 0 5967 NULL
118524 +ieee80211_if_fmt_rc_rateidx_mask_5ghz_5971 ieee80211_if_fmt_rc_rateidx_mask_5ghz 3 5971 NULL
118525 +SyS_semop_5980 SyS_semop 3 5980 NULL
118526 +btrfs_item_offset_6019 btrfs_item_offset 0 6019 NULL
118527 +alloc_msg_6072 alloc_msg 1 6072 NULL
118528 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
118529 +_random_read_6098 _random_read 3 6098 NULL
118530 +ipmi_addr_length_6110 ipmi_addr_length 0 6110 NULL nohasharray
118531 +force_static_address_read_6110 force_static_address_read 3 6110 &ipmi_addr_length_6110
118532 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
118533 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
118534 +ieee80211_if_fmt_beacon_timeout_6153 ieee80211_if_fmt_beacon_timeout 3 6153 NULL
118535 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
118536 +maybe_insert_hole_6167 maybe_insert_hole 3 6167 NULL
118537 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
118538 +SyS_setgroups_6182 SyS_setgroups 1 6182 NULL
118539 +snd_efw_command_get_phys_meters_6190 snd_efw_command_get_phys_meters 3 6190 NULL
118540 +mxt_show_instance_6207 mxt_show_instance 2-0 6207 NULL
118541 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
118542 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
118543 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
118544 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
118545 +of_gpio_count_6270 of_gpio_count 0 6270 NULL
118546 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
118547 +snd_hda_override_conn_list_6282 snd_hda_override_conn_list 3-0 6282 NULL nohasharray
118548 +xenbus_file_write_6282 xenbus_file_write 3 6282 &snd_hda_override_conn_list_6282
118549 +posix_acl_fix_xattr_to_user_6283 posix_acl_fix_xattr_to_user 2 6283 NULL
118550 +serial_port_in_6291 serial_port_in 0 6291 NULL
118551 +qlcnic_sriov_alloc_bc_msg_6309 qlcnic_sriov_alloc_bc_msg 2 6309 NULL
118552 +hfsplus_direct_IO_6313 hfsplus_direct_IO 4 6313 NULL
118553 +SyS_mincore_6329 SyS_mincore 2-1 6329 NULL nohasharray
118554 +hfa384x_inw_6329 hfa384x_inw 0 6329 &SyS_mincore_6329
118555 +fuse_get_req_for_background_6337 fuse_get_req_for_background 2 6337 NULL
118556 +ucs2_strnlen_6342 ucs2_strnlen 0 6342 NULL
118557 +regcache_sync_block_raw_6350 regcache_sync_block_raw 5-4 6350 NULL
118558 +mei_dbgfs_read_devstate_6352 mei_dbgfs_read_devstate 3 6352 NULL
118559 +arch_gnttab_valloc_6372 arch_gnttab_valloc 2 6372 NULL
118560 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL nohasharray
118561 +sync_fence_alloc_6378 sync_fence_alloc 1 6378 &osd_req_read_sg_kern_6378
118562 +posix_acl_fix_xattr_userns_6420 posix_acl_fix_xattr_userns 4 6420 NULL
118563 +add_transaction_credits_6422 add_transaction_credits 2-3 6422 NULL
118564 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
118565 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
118566 +C_SYSC_vmsplice_6470 C_SYSC_vmsplice 3 6470 NULL
118567 +ieee80211_if_fmt_dot11MeshMaxRetries_6476 ieee80211_if_fmt_dot11MeshMaxRetries 3 6476 NULL
118568 +qp_memcpy_from_queue_6479 qp_memcpy_from_queue 5-4 6479 NULL
118569 +cipso_v4_map_lvl_hton_6490 cipso_v4_map_lvl_hton 0 6490 NULL
118570 +dbg_intr_buf_6501 dbg_intr_buf 2 6501 NULL
118571 +mei_read_6507 mei_read 3 6507 NULL
118572 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
118573 +wdm_read_6549 wdm_read 3 6549 NULL
118574 +dm_stats_create_6551 dm_stats_create 4-2-3 6551 NULL
118575 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
118576 +SyS_semtimedop_6563 SyS_semtimedop 3 6563 NULL
118577 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
118578 +xfs_do_div_6649 xfs_do_div 0-2 6649 NULL
118579 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
118580 +btrfs_lookup_csums_range_6696 btrfs_lookup_csums_range 2-3 6696 NULL
118581 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
118582 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
118583 +mpeg_read_6708 mpeg_read 3 6708 NULL
118584 +ibmpex_query_sensor_count_6709 ibmpex_query_sensor_count 0 6709 NULL
118585 +check_clk_sync_6717 check_clk_sync 2 6717 NULL
118586 +video_proc_write_6724 video_proc_write 3 6724 NULL
118587 +posix_acl_xattr_count_6725 posix_acl_xattr_count 0-1 6725 NULL
118588 +kobject_add_varg_6781 kobject_add_varg 0 6781 NULL
118589 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
118590 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
118591 +zone_spanned_pages_in_node_6787 zone_spanned_pages_in_node 0-3-4 6787 NULL
118592 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
118593 +ll_xattr_cache_find_6798 ll_xattr_cache_find 0 6798 NULL
118594 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
118595 +lbs_rdrf_write_6826 lbs_rdrf_write 3 6826 NULL
118596 +calc_pages_for_6838 calc_pages_for 0-1-2 6838 NULL
118597 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
118598 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
118599 +perf_output_sample_ustack_6868 perf_output_sample_ustack 2 6868 NULL
118600 +dio_complete_6879 dio_complete 0-3-2 6879 NULL
118601 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL nohasharray
118602 +ieee80211_if_fmt_path_refresh_time_6888 ieee80211_if_fmt_path_refresh_time 3 6888 &raw_seticmpfilter_6888
118603 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
118604 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 NULL nohasharray
118605 +spi_show_regs_6911 spi_show_regs 3 6911 &proc_sessionid_read_6911 nohasharray
118606 +acm_alloc_minor_6911 acm_alloc_minor 0 6911 &spi_show_regs_6911
118607 +__kfifo_dma_in_finish_r_6913 __kfifo_dma_in_finish_r 2-3 6913 NULL
118608 +do_msgrcv_6921 do_msgrcv 3 6921 NULL
118609 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
118610 +ipath_verbs_send_dma_6929 ipath_verbs_send_dma 6 6929 NULL
118611 +qsfp_cks_6945 qsfp_cks 2-0 6945 NULL
118612 +tg3_nvram_write_block_unbuffered_6955 tg3_nvram_write_block_unbuffered 3 6955 NULL
118613 +pch_uart_hal_read_6961 pch_uart_hal_read 0 6961 NULL
118614 +i40e_dbg_dump_write_6973 i40e_dbg_dump_write 3 6973 NULL nohasharray
118615 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 &i40e_dbg_dump_write_6973
118616 +lustre_pack_reply_6982 lustre_pack_reply 2 6982 NULL
118617 +request_key_async_6990 request_key_async 4 6990 NULL
118618 +tpl_write_6998 tpl_write 3 6998 NULL
118619 +cipso_v4_gentag_enum_7006 cipso_v4_gentag_enum 0 7006 NULL
118620 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
118621 +ld_usb_write_7022 ld_usb_write 3 7022 NULL
118622 +wimax_msg_7030 wimax_msg 4 7030 NULL
118623 +ceph_kvmalloc_7033 ceph_kvmalloc 1 7033 NULL
118624 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
118625 +snd_pcm_oss_bytes_7051 snd_pcm_oss_bytes 2 7051 NULL
118626 +nouveau_device_create__7063 nouveau_device_create_ 7 7063 NULL
118627 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
118628 +event_enable_read_7074 event_enable_read 3 7074 NULL
118629 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL nohasharray
118630 +tipc_send_packet_7091 tipc_send_packet 4 7091 &beacon_interval_read_7091
118631 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
118632 +osc_resend_count_seq_write_7120 osc_resend_count_seq_write 3 7120 NULL
118633 +qib_format_hwerrors_7133 qib_format_hwerrors 5 7133 NULL
118634 +kvm_mmu_notifier_test_young_7139 kvm_mmu_notifier_test_young 3 7139 NULL
118635 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
118636 +hdlc_loop_7255 hdlc_loop 0 7255 NULL
118637 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL nohasharray
118638 +kimage_alloc_init_7282 kimage_alloc_init 3 7282 &rx_rate_rx_frames_per_rates_read_7282
118639 +get_string_7302 get_string 0 7302 NULL
118640 +pci_vpd_info_field_size_7324 pci_vpd_info_field_size 0 7324 NULL
118641 +mgmt_control_7349 mgmt_control 3 7349 NULL
118642 +at_est2timeout_7365 at_est2timeout 0-1 7365 NULL
118643 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
118644 +ath10k_read_fw_stats_7387 ath10k_read_fw_stats 3 7387 NULL
118645 +hweight_long_7388 hweight_long 0-1 7388 NULL
118646 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
118647 +_ore_add_stripe_unit_7399 _ore_add_stripe_unit 6-3 7399 NULL
118648 +audmux_read_file_7400 audmux_read_file 3 7400 NULL
118649 +readb_7401 readb 0 7401 NULL
118650 +tipc_recvmsg_7402 tipc_recvmsg 4 7402 NULL
118651 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
118652 +__copy_to_user_nocheck_7443 __copy_to_user_nocheck 0-3 7443 NULL
118653 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
118654 +SYSC_setgroups_7454 SYSC_setgroups 1 7454 NULL
118655 +rt2x00debug_read_queue_stats_7455 rt2x00debug_read_queue_stats 3 7455 NULL
118656 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
118657 +garp_request_join_7471 garp_request_join 4 7471 NULL nohasharray
118658 +ReadHSCX_7471 ReadHSCX 0 7471 &garp_request_join_7471
118659 +snd_pcm_lib_read1_7491 snd_pcm_lib_read1 0-3 7491 NULL
118660 +ahash_instance_headroom_7509 ahash_instance_headroom 0 7509 NULL nohasharray
118661 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 &ahash_instance_headroom_7509
118662 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
118663 +ath10k_read_htt_stats_mask_7557 ath10k_read_htt_stats_mask 3 7557 NULL
118664 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
118665 +netvsc_get_slots_7565 netvsc_get_slots 0 7565 NULL
118666 +cfs_cpt_num_estimate_7571 cfs_cpt_num_estimate 0 7571 NULL
118667 +groups_alloc_7614 groups_alloc 1 7614 NULL nohasharray
118668 +create_dir_7614 create_dir 0 7614 &groups_alloc_7614
118669 +_rtw_zmalloc_7636 _rtw_zmalloc 1 7636 NULL
118670 +fault_inject_write_7662 fault_inject_write 3 7662 NULL
118671 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 NULL
118672 +acpi_ns_get_pathname_length_7699 acpi_ns_get_pathname_length 0 7699 NULL
118673 +dev_write_7708 dev_write 3 7708 NULL
118674 +pci_raw_set_power_state_7729 pci_raw_set_power_state 0 7729 NULL
118675 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
118676 +iwl_dbgfs_bt_cmd_read_7770 iwl_dbgfs_bt_cmd_read 3 7770 NULL
118677 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
118678 +__videobuf_read_start_7782 __videobuf_read_start 0 7782 NULL
118679 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
118680 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
118681 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL nohasharray
118682 +lustre_packed_msg_size_7792 lustre_packed_msg_size 0 7792 &diva_os_copy_from_user_7792
118683 +seq_buf_alloc_7828 seq_buf_alloc 1 7828 NULL
118684 +cfs_trace_dump_debug_buffer_usrstr_7861 cfs_trace_dump_debug_buffer_usrstr 2 7861 NULL
118685 +tipc_alloc_entry_7875 tipc_alloc_entry 2 7875 NULL
118686 +config_desc_7878 config_desc 0 7878 NULL
118687 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
118688 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
118689 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
118690 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
118691 +integrity_digsig_verify_7956 integrity_digsig_verify 3 7956 NULL
118692 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
118693 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
118694 +vcs_read_8017 vcs_read 3 8017 NULL
118695 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
118696 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
118697 +spi_write_then_read_8073 spi_write_then_read 5-3 8073 NULL
118698 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 NULL
118699 +venus_lookup_8121 venus_lookup 4 8121 NULL
118700 +ieee80211_if_fmt_num_buffered_multicast_8127 ieee80211_if_fmt_num_buffered_multicast 3 8127 NULL
118701 +xfs_file_fallocate_8150 xfs_file_fallocate 3-4 8150 NULL
118702 +ufshcd_wait_for_dev_cmd_8168 ufshcd_wait_for_dev_cmd 0 8168 NULL
118703 +__sk_mem_schedule_8185 __sk_mem_schedule 2 8185 NULL
118704 +ieee80211_if_fmt_dot11MeshHoldingTimeout_8187 ieee80211_if_fmt_dot11MeshHoldingTimeout 3 8187 NULL
118705 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
118706 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
118707 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
118708 +play_iframe_8219 play_iframe 3 8219 NULL
118709 +kvm_mmu_page_set_gfn_8225 kvm_mmu_page_set_gfn 2 8225 NULL
118710 +sctp_ssnmap_size_8228 sctp_ssnmap_size 0-1-2 8228 NULL
118711 +check_xattr_ref_inode_8244 check_xattr_ref_inode 0 8244 NULL
118712 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
118713 +init_cdev_8274 init_cdev 1 8274 NULL
118714 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
118715 +qib_decode_7220_err_8315 qib_decode_7220_err 3 8315 NULL
118716 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
118717 +rtw_cfg80211_rx_action_8329 rtw_cfg80211_rx_action 3 8329 NULL
118718 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
118719 +ieee80211_if_fmt_ht_opmode_8347 ieee80211_if_fmt_ht_opmode 3 8347 NULL
118720 +generic_write_sync_8358 generic_write_sync 0 8358 NULL
118721 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
118722 +ath6kl_lrssi_roam_write_8362 ath6kl_lrssi_roam_write 3 8362 NULL
118723 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
118724 +zd_rf_scnprint_id_8406 zd_rf_scnprint_id 0-3 8406 NULL
118725 +smk_write_change_rule_8411 smk_write_change_rule 3 8411 NULL nohasharray
118726 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 &smk_write_change_rule_8411
118727 +roccat_common2_sysfs_read_8431 roccat_common2_sysfs_read 6 8431 NULL
118728 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
118729 +fore200e_chunk_alloc_8501 fore200e_chunk_alloc 4-3 8501 NULL
118730 +batadv_tt_len_8502 batadv_tt_len 0-1 8502 NULL
118731 +dev_config_8506 dev_config 3 8506 NULL
118732 +ACL_to_cifs_posix_8509 ACL_to_cifs_posix 3 8509 NULL
118733 +nouveau_platform_device_create__8514 nouveau_platform_device_create_ 2 8514 NULL
118734 +opticon_process_data_packet_8524 opticon_process_data_packet 3 8524 NULL
118735 +user_on_off_8552 user_on_off 2 8552 NULL
118736 +profile_remove_8556 profile_remove 3 8556 NULL
118737 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
118738 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
118739 +tower_write_8580 tower_write 3 8580 NULL
118740 +cfs_cpt_number_8618 cfs_cpt_number 0 8618 NULL
118741 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
118742 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
118743 +scsi_dma_map_8632 scsi_dma_map 0 8632 NULL
118744 +fuse_send_write_pages_8636 fuse_send_write_pages 5-0 8636 NULL
118745 +mlx5_vzalloc_8663 mlx5_vzalloc 1 8663 NULL
118746 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
118747 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
118748 +bpf_prog_size_8685 bpf_prog_size 0 8685 NULL
118749 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
118750 +skb_frag_size_8695 skb_frag_size 0 8695 NULL
118751 +arcfb_write_8702 arcfb_write 3 8702 NULL
118752 +i_size_read_8703 i_size_read 0 8703 NULL nohasharray
118753 +init_header_8703 init_header 0 8703 &i_size_read_8703
118754 +ufshcd_get_tr_ocs_8706 ufshcd_get_tr_ocs 0 8706 NULL
118755 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
118756 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
118757 +tracing_max_lat_write_8728 tracing_max_lat_write 3 8728 NULL
118758 +jffs2_acl_count_8729 jffs2_acl_count 0-1 8729 NULL
118759 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
118760 +compound_order_8750 compound_order 0 8750 NULL
118761 +yurex_write_8761 yurex_write 3 8761 NULL
118762 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
118763 +kstrtoint_from_user_8778 kstrtoint_from_user 2 8778 NULL
118764 +paging32_prefetch_gpte_8783 paging32_prefetch_gpte 4 8783 NULL
118765 +ext4_try_to_write_inline_data_8785 ext4_try_to_write_inline_data 4-3 8785 NULL
118766 +__bitmap_weight_8796 __bitmap_weight 0-2 8796 NULL
118767 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
118768 +SyS_llistxattr_8824 SyS_llistxattr 3 8824 NULL
118769 +ll_xattr_cache_get_8829 ll_xattr_cache_get 0 8829 NULL
118770 +get_queue_depth_8833 get_queue_depth 0 8833 NULL
118771 +dvb_ringbuffer_pkt_next_8834 dvb_ringbuffer_pkt_next 0-2 8834 NULL
118772 +usb_ep_queue_8839 usb_ep_queue 0 8839 NULL
118773 +iwl_rx_packet_len_8854 iwl_rx_packet_len 0 8854 NULL
118774 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
118775 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
118776 +xgmac_reg_value_write_8860 xgmac_reg_value_write 3 8860 NULL
118777 +radeon_drm_ioctl_8875 radeon_drm_ioctl 2 8875 NULL
118778 +compressed_bio_size_8887 compressed_bio_size 0-2 8887 NULL
118779 +ab3100_get_set_reg_8890 ab3100_get_set_reg 3 8890 NULL nohasharray
118780 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 &ab3100_get_set_reg_8890
118781 +sdio_max_byte_size_8907 sdio_max_byte_size 0 8907 NULL
118782 +sysfs_merge_group_8917 sysfs_merge_group 0 8917 NULL
118783 +write_file_ani_8918 write_file_ani 3 8918 NULL
118784 +layout_commit_8926 layout_commit 3 8926 NULL
118785 +cp2112_hid_get_8933 cp2112_hid_get 4 8933 NULL
118786 +adjust_priv_size_8935 adjust_priv_size 0-1 8935 NULL
118787 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
118788 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
118789 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
118790 +qib_qsfp_dump_8966 qib_qsfp_dump 0-3 8966 NULL
118791 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
118792 +seq_open_net_8968 seq_open_net 4 8968 NULL nohasharray
118793 +vol_cdev_read_8968 vol_cdev_read 3 8968 &seq_open_net_8968
118794 +bio_integrity_get_tag_8974 bio_integrity_get_tag 3 8974 NULL
118795 +sony_register_touchpad_8981 sony_register_touchpad 2 8981 NULL
118796 +jbd2_journal_blocks_per_page_9004 jbd2_journal_blocks_per_page 0 9004 NULL
118797 +il_dbgfs_clear_ucode_stats_write_9016 il_dbgfs_clear_ucode_stats_write 3 9016 NULL
118798 +snd_emu10k1_ptr_read_9026 snd_emu10k1_ptr_read 0-2 9026 NULL
118799 +fd_ioctl_9028 fd_ioctl 3 9028 NULL
118800 +nla_put_9042 nla_put 3 9042 NULL
118801 +sta_tx_latency_stat_header_9050 sta_tx_latency_stat_header 0-3-4 9050 NULL
118802 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
118803 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
118804 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
118805 +create_queues_9088 create_queues 2-3 9088 NULL
118806 +nvkm_output_create__9091 nvkm_output_create_ 6 9091 NULL
118807 +ftdi_prepare_write_buffer_9093 ftdi_prepare_write_buffer 3 9093 NULL
118808 +adxl34x_spi_read_block_9108 adxl34x_spi_read_block 3 9108 NULL
118809 +gfn_to_rmap_9110 gfn_to_rmap 3-2 9110 NULL nohasharray
118810 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 &gfn_to_rmap_9110
118811 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
118812 +vb2_dma_sg_alloc_9157 vb2_dma_sg_alloc 2 9157 NULL
118813 +dbg_command_buf_9165 dbg_command_buf 2 9165 NULL
118814 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
118815 +count_leading_zeros_9183 count_leading_zeros 0 9183 NULL
118816 +altera_swap_ir_9194 altera_swap_ir 2 9194 NULL
118817 +snd_m3_get_pointer_9206 snd_m3_get_pointer 0 9206 NULL
118818 +iwl_dbgfs_frame_stats_read_9211 iwl_dbgfs_frame_stats_read 3 9211 NULL
118819 +card_send_command_9215 card_send_command 3 9215 NULL
118820 +virtqueue_add_9217 virtqueue_add 4-5 9217 NULL
118821 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
118822 +l2cap_create_connless_pdu_9222 l2cap_create_connless_pdu 3 9222 NULL
118823 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
118824 +hfsplus_bnode_read_u16_9262 hfsplus_bnode_read_u16 0 9262 NULL
118825 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
118826 +flakey_status_9274 flakey_status 5 9274 NULL
118827 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
118828 +ceph_sync_setxattr_9310 ceph_sync_setxattr 4 9310 NULL
118829 +__blockdev_direct_IO_9321 __blockdev_direct_IO 0-6 9321 NULL
118830 +ieee80211_if_fmt_txpower_9334 ieee80211_if_fmt_txpower 3 9334 NULL
118831 +nvme_trans_fmt_get_parm_header_9340 nvme_trans_fmt_get_parm_header 2 9340 NULL
118832 +ocfs2_orphan_for_truncate_9342 ocfs2_orphan_for_truncate 4 9342 NULL
118833 +ll_direct_rw_pages_9361 ll_direct_rw_pages 0 9361 NULL
118834 +sta_beacon_loss_count_read_9370 sta_beacon_loss_count_read 3 9370 NULL
118835 +virtqueue_add_outbuf_9395 virtqueue_add_outbuf 3 9395 NULL
118836 +read_9397 read 3 9397 NULL
118837 +hash_ipportip4_expire_9415 hash_ipportip4_expire 4 9415 NULL
118838 +btrfs_drop_extents_9423 btrfs_drop_extents 4 9423 NULL
118839 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
118840 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
118841 +ieee80211_if_fmt_fwded_unicast_9454 ieee80211_if_fmt_fwded_unicast 3 9454 NULL
118842 +get_registers_9470 get_registers 4 9470 NULL nohasharray
118843 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 &get_registers_9470
118844 +crypt_status_9492 crypt_status 5 9492 NULL
118845 +lbs_threshold_write_9502 lbs_threshold_write 5 9502 NULL
118846 +lp_write_9511 lp_write 3 9511 NULL
118847 +mext_calc_swap_extents_9517 mext_calc_swap_extents 4 9517 NULL
118848 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
118849 +ll_max_read_ahead_whole_mb_seq_write_9528 ll_max_read_ahead_whole_mb_seq_write 3 9528 NULL
118850 +read_file_dma_9530 read_file_dma 3 9530 NULL
118851 +iwl_dbgfs_bf_params_read_9542 iwl_dbgfs_bf_params_read 3 9542 NULL
118852 +il_dbgfs_missed_beacon_write_9546 il_dbgfs_missed_beacon_write 3 9546 NULL
118853 +compat_SyS_pwritev64_9548 compat_SyS_pwritev64 3 9548 NULL
118854 +fw_node_create_9559 fw_node_create 2 9559 NULL
118855 +kobj_map_9566 kobj_map 2-3 9566 NULL
118856 +f2fs_read_data_pages_9574 f2fs_read_data_pages 4 9574 NULL
118857 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5-6 9605 NULL
118858 +lov_ost_pool_add_9626 lov_ost_pool_add 3 9626 NULL
118859 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
118860 +ceph_copy_user_to_page_vector_9635 ceph_copy_user_to_page_vector 4-3 9635 NULL
118861 +acpi_ex_insert_into_field_9638 acpi_ex_insert_into_field 3 9638 NULL
118862 +ll_checksum_seq_write_9648 ll_checksum_seq_write 3 9648 NULL
118863 +ocfs2_xattr_get_rec_9652 ocfs2_xattr_get_rec 0 9652 NULL
118864 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
118865 +tipc_port_mcast_xmit_9663 tipc_port_mcast_xmit 4 9663 NULL
118866 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
118867 +dns_query_9676 dns_query 3 9676 NULL
118868 +qib_7322_handle_hwerrors_9678 qib_7322_handle_hwerrors 3 9678 NULL
118869 +__erst_read_from_storage_9690 __erst_read_from_storage 0 9690 NULL
118870 +lowpan_control_write_9699 lowpan_control_write 3 9699 NULL
118871 +vx_transfer_end_9701 vx_transfer_end 0 9701 NULL
118872 +fuse_iter_npages_9705 fuse_iter_npages 0 9705 NULL nohasharray
118873 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 &fuse_iter_npages_9705
118874 +cfg80211_tx_mlme_mgmt_9715 cfg80211_tx_mlme_mgmt 3 9715 NULL
118875 +parse_uac2_sample_rate_range_9718 parse_uac2_sample_rate_range 0 9718 NULL
118876 +btrfs_stack_file_extent_num_bytes_9720 btrfs_stack_file_extent_num_bytes 0 9720 NULL
118877 +SYSC_ppoll_9721 SYSC_ppoll 2 9721 NULL
118878 +nla_get_u8_9736 nla_get_u8 0 9736 NULL
118879 +ieee80211_if_fmt_num_mcast_sta_9738 ieee80211_if_fmt_num_mcast_sta 3 9738 NULL
118880 +ddb_input_read_9743 ddb_input_read 3-0 9743 NULL
118881 +regmap_multi_reg_write_bypassed_9751 regmap_multi_reg_write_bypassed 3 9751 NULL nohasharray
118882 +sta_last_ack_signal_read_9751 sta_last_ack_signal_read 3 9751 &regmap_multi_reg_write_bypassed_9751
118883 +btrfs_super_root_9763 btrfs_super_root 0 9763 NULL
118884 +copy_page_from_iter_bvec_9767 copy_page_from_iter_bvec 0-3 9767 NULL
118885 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
118886 +kvm_age_hva_9795 kvm_age_hva 2 9795 NULL
118887 +bio_alloc_map_data_9798 bio_alloc_map_data 1 9798 NULL
118888 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 NULL nohasharray
118889 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 &ieee80211_if_read_state_9813
118890 +compat_SyS_vmsplice_9828 compat_SyS_vmsplice 3 9828 NULL
118891 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
118892 +f1x_translate_sysaddr_to_cs_9868 f1x_translate_sysaddr_to_cs 2 9868 NULL
118893 +wil_read_file_ioblob_9878 wil_read_file_ioblob 3 9878 NULL
118894 +bm_register_write_9893 bm_register_write 3 9893 NULL nohasharray
118895 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 &bm_register_write_9893
118896 +snd_gf1_pcm_playback_copy_9895 snd_gf1_pcm_playback_copy 3-5 9895 NULL
118897 +nonpaging_page_fault_9908 nonpaging_page_fault 2 9908 NULL
118898 +iwl_dbgfs_prph_reg_read_9928 iwl_dbgfs_prph_reg_read 3 9928 NULL
118899 +root_nfs_parse_options_9937 root_nfs_parse_options 3 9937 NULL
118900 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
118901 +read_file_misc_9948 read_file_misc 3 9948 NULL
118902 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
118903 +SyS_gethostname_9964 SyS_gethostname 2 9964 NULL
118904 +get_free_serial_index_9969 get_free_serial_index 0 9969 NULL
118905 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
118906 +SYSC_move_pages_9986 SYSC_move_pages 2 9986 NULL
118907 +ceph_oloc_oid_to_pg_10003 ceph_oloc_oid_to_pg 0 10003 NULL
118908 +aat2870_dump_reg_10019 aat2870_dump_reg 0 10019 NULL
118909 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
118910 +get_elem_size_10110 get_elem_size 0-2 10110 NULL nohasharray
118911 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 &get_elem_size_10110
118912 +gfs2_meta_read_10112 gfs2_meta_read 0 10112 NULL
118913 +SyS_migrate_pages_10134 SyS_migrate_pages 2 10134 NULL
118914 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
118915 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL nohasharray
118916 +tracing_nsecs_write_10157 tracing_nsecs_write 3 10157 &rx_out_of_mem_read_10157
118917 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
118918 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
118919 +kstrtol_from_user_10168 kstrtol_from_user 2 10168 NULL
118920 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
118921 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
118922 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
118923 +lmv_hsm_req_count_10245 lmv_hsm_req_count 0 10245 NULL
118924 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
118925 +__qlcnic_pci_sriov_enable_10281 __qlcnic_pci_sriov_enable 2 10281 NULL
118926 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
118927 +nvif_object_new_10300 nvif_object_new 5 10300 NULL
118928 +read_emulate_10310 read_emulate 2-4 10310 NULL
118929 +read_file_spectral_count_10320 read_file_spectral_count 3 10320 NULL
118930 +compat_SyS_writev_10327 compat_SyS_writev 3 10327 NULL
118931 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
118932 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
118933 +whci_add_cap_10350 whci_add_cap 0 10350 NULL
118934 +dbAllocAny_10354 dbAllocAny 0 10354 NULL
118935 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
118936 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
118937 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
118938 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
118939 +fwtty_rx_10434 fwtty_rx 3 10434 NULL
118940 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
118941 +hash_ipportip6_expire_10478 hash_ipportip6_expire 4 10478 NULL
118942 +nouveau_pwr_create__10483 nouveau_pwr_create_ 4 10483 NULL
118943 +ext4_itable_unused_count_10501 ext4_itable_unused_count 0 10501 NULL
118944 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
118945 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
118946 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
118947 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
118948 +qlcnic_pci_sriov_enable_10519 qlcnic_pci_sriov_enable 2 10519 NULL
118949 +kstrtouint_from_user_10536 kstrtouint_from_user 2 10536 NULL nohasharray
118950 +snd_pcm_lib_read_10536 snd_pcm_lib_read 0-3 10536 &kstrtouint_from_user_10536
118951 +ext4_write_begin_10576 ext4_write_begin 3-4 10576 NULL
118952 +scrub_remap_extent_10588 scrub_remap_extent 2 10588 NULL
118953 +otp_read_10594 otp_read 2-4-5 10594 NULL
118954 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
118955 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
118956 +fq_alloc_node_10633 fq_alloc_node 1 10633 NULL
118957 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
118958 +efx_max_tx_len_10662 efx_max_tx_len 0-2 10662 NULL
118959 +parport_write_10669 parport_write 0 10669 NULL
118960 +edge_write_10692 edge_write 4 10692 NULL
118961 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL nohasharray
118962 +inl_10708 inl 0 10708 &selinux_inode_setxattr_10708
118963 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 NULL nohasharray
118964 +shash_async_setkey_10720 shash_async_setkey 3 10720 &pvr2_ioread_read_10720
118965 +spi_sync_10731 spi_sync 0 10731 NULL
118966 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL nohasharray
118967 +apu_get_register_10737 apu_get_register 0 10737 &sctp_getsockopt_maxseg_10737
118968 +SyS_io_getevents_10756 SyS_io_getevents 3 10756 NULL
118969 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
118970 +rd_build_prot_space_10761 rd_build_prot_space 2-3 10761 NULL
118971 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
118972 +__qp_memcpy_to_queue_10779 __qp_memcpy_to_queue 2-4 10779 NULL
118973 +diva_set_trace_filter_10820 diva_set_trace_filter 0-1 10820 NULL
118974 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
118975 +ext4_direct_IO_10843 ext4_direct_IO 4 10843 NULL
118976 +ida_get_new_above_10853 ida_get_new_above 0 10853 NULL
118977 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
118978 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
118979 +wiidebug_drm_write_10879 wiidebug_drm_write 3 10879 NULL
118980 +get_scq_10897 get_scq 2 10897 NULL
118981 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
118982 +lprocfs_wr_atomic_10912 lprocfs_wr_atomic 3 10912 NULL
118983 +__copy_from_user_10918 __copy_from_user 0-3 10918 NULL
118984 +kobject_add_10919 kobject_add 0 10919 NULL
118985 +ar9003_dump_modal_eeprom_10959 ar9003_dump_modal_eeprom 3-2-0 10959 NULL
118986 +ci_port_test_write_10962 ci_port_test_write 3 10962 NULL
118987 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
118988 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
118989 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
118990 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
118991 +SetLineNumber_11023 SetLineNumber 0 11023 NULL
118992 +nouveau_gpio_create__11048 nouveau_gpio_create_ 4 11048 NULL
118993 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
118994 +insert_inline_extent_backref_11063 insert_inline_extent_backref 8 11063 NULL
118995 +xfs_collapse_file_space_11075 xfs_collapse_file_space 2-3 11075 NULL
118996 +tcp_send_mss_11079 tcp_send_mss 0 11079 NULL
118997 +count_argc_11083 count_argc 0 11083 NULL
118998 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
118999 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
119000 +page_offset_11120 page_offset 0 11120 NULL
119001 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 NULL
119002 +alloc_alien_cache_11127 alloc_alien_cache 2 11127 NULL
119003 +snd_gf1_pcm_playback_silence_11172 snd_gf1_pcm_playback_silence 3-4 11172 NULL
119004 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
119005 +comedi_alloc_spriv_11234 comedi_alloc_spriv 2 11234 NULL
119006 +of_irq_count_11253 of_irq_count 0 11253 NULL
119007 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
119008 +ath6kl_power_params_write_11274 ath6kl_power_params_write 3 11274 NULL
119009 +SYSC_getrandom_11294 SYSC_getrandom 2 11294 NULL
119010 +tipc_msg_build_11304 tipc_msg_build 3-4-5 11304 NULL
119011 +__proc_daemon_file_11305 __proc_daemon_file 5 11305 NULL
119012 +ext4_xattr_check_names_11314 ext4_xattr_check_names 0 11314 NULL
119013 +bcache_dev_sectors_dirty_add_11315 bcache_dev_sectors_dirty_add 3-4 11315 NULL
119014 +sk_filter_size_11316 sk_filter_size 0 11316 NULL nohasharray
119015 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 &sk_filter_size_11316
119016 +construct_key_11329 construct_key 3 11329 NULL nohasharray
119017 +__kfifo_out_peek_11329 __kfifo_out_peek 0-3 11329 &construct_key_11329
119018 +next_segment_11330 next_segment 0-2-1 11330 NULL
119019 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
119020 +ext4_get_inline_size_11349 ext4_get_inline_size 0 11349 NULL
119021 +sel_write_create_11353 sel_write_create 3 11353 NULL nohasharray
119022 +nl80211_send_mgmt_11353 nl80211_send_mgmt 7 11353 &sel_write_create_11353
119023 +of_get_available_child_count_11361 of_get_available_child_count 0 11361 NULL
119024 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
119025 +tcf_register_action_11381 tcf_register_action 2 11381 NULL nohasharray
119026 +nft_value_dump_11381 nft_value_dump 3 11381 &tcf_register_action_11381
119027 +isku_sysfs_read_keys_capslock_11392 isku_sysfs_read_keys_capslock 6 11392 NULL
119028 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
119029 +lprocfs_wr_evict_client_11402 lprocfs_wr_evict_client 3 11402 NULL
119030 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
119031 +str_to_user_11411 str_to_user 2 11411 NULL
119032 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
119033 +ath6kl_wmi_test_rx_11414 ath6kl_wmi_test_rx 3 11414 NULL
119034 +adis16480_show_firmware_revision_11417 adis16480_show_firmware_revision 3 11417 NULL
119035 +trace_options_read_11419 trace_options_read 3 11419 NULL
119036 +i40e_dbg_command_write_11421 i40e_dbg_command_write 3 11421 NULL
119037 +bttv_read_11432 bttv_read 3 11432 NULL
119038 +create_zero_mask_11453 create_zero_mask 0-1 11453 NULL
119039 +ufshcd_change_queue_depth_11477 ufshcd_change_queue_depth 2 11477 NULL
119040 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 NULL nohasharray
119041 +pci_set_power_state_11479 pci_set_power_state 0 11479 &sca3000_read_first_n_hw_rb_11479
119042 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
119043 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
119044 +ll_direct_IO_26_seg_11518 ll_direct_IO_26_seg 0 11518 NULL
119045 +twl_direction_in_11527 twl_direction_in 2 11527 NULL
119046 +skb_cow_data_11565 skb_cow_data 0 11565 NULL
119047 +lpfc_idiag_ctlacc_write_11576 lpfc_idiag_ctlacc_write 3 11576 NULL
119048 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
119049 +batadv_iv_ogm_orig_add_if_11586 batadv_iv_ogm_orig_add_if 2 11586 NULL
119050 +snd_pcm_action_11589 snd_pcm_action 0 11589 NULL
119051 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
119052 +batadv_iv_ogm_orig_del_if_11604 batadv_iv_ogm_orig_del_if 2 11604 NULL
119053 +SYSC_mq_timedsend_11607 SYSC_mq_timedsend 3 11607 NULL
119054 +C_SYSC_migrate_pages_11618 C_SYSC_migrate_pages 2 11618 NULL
119055 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
119056 +nla_total_size_11658 nla_total_size 0-1 11658 NULL
119057 +srpc_create_client_rpc_11664 srpc_create_client_rpc 3 11664 NULL nohasharray
119058 +slab_ksize_11664 slab_ksize 0 11664 &srpc_create_client_rpc_11664
119059 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
119060 +compat_SyS_msgsnd_11675 compat_SyS_msgsnd 3 11675 NULL
119061 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
119062 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
119063 +split_11691 split 2 11691 NULL
119064 +compat_SyS_keyctl_11695 compat_SyS_keyctl 4 11695 NULL nohasharray
119065 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 &compat_SyS_keyctl_11695
119066 +blk_rq_cur_bytes_11723 blk_rq_cur_bytes 0 11723 NULL
119067 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
119068 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
119069 +ieee80211_get_num_supported_channels_11768 ieee80211_get_num_supported_channels 0 11768 NULL
119070 +tipc_sendmsg_11769 tipc_sendmsg 4 11769 NULL
119071 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
119072 +btrfs_key_blockptr_11786 btrfs_key_blockptr 0 11786 NULL
119073 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
119074 +umc_device_register_11824 umc_device_register 0 11824 NULL
119075 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
119076 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
119077 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
119078 +unix_stream_connect_11844 unix_stream_connect 3 11844 NULL
119079 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
119080 +l2cap_chan_send_11878 l2cap_chan_send 3 11878 NULL
119081 +ieee80211_rx_bss_info_11887 ieee80211_rx_bss_info 3 11887 NULL
119082 +mdc_rename_11899 mdc_rename 4-6 11899 NULL
119083 +xstateregs_get_11906 xstateregs_get 4 11906 NULL
119084 +ti_write_11916 ti_write 4 11916 NULL
119085 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
119086 +bitmap_remap_11929 bitmap_remap 5 11929 NULL
119087 +atomic_sub_return_11939 atomic_sub_return 0-1 11939 NULL
119088 +r1_sync_page_io_11963 r1_sync_page_io 3 11963 NULL
119089 +f1x_swap_interleaved_region_11970 f1x_swap_interleaved_region 0-2 11970 NULL
119090 +read_and_add_raw_conns_11987 read_and_add_raw_conns 0 11987 NULL
119091 +ftdi_elan_total_command_size_12045 ftdi_elan_total_command_size 0 12045 NULL
119092 +ieee80211_if_read_user_power_level_12050 ieee80211_if_read_user_power_level 3 12050 NULL
119093 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
119094 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
119095 +batadv_tt_global_size_mod_12085 batadv_tt_global_size_mod 3 12085 NULL
119096 +rtw_malloc2d_12102 rtw_malloc2d 1-2-3 12102 NULL
119097 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
119098 +set_powered_12129 set_powered 4 12129 NULL
119099 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
119100 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
119101 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
119102 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
119103 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
119104 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
119105 +fnic_reset_stats_write_12177 fnic_reset_stats_write 3 12177 NULL
119106 +LNetEQAlloc_12178 LNetEQAlloc 1 12178 NULL
119107 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
119108 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
119109 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
119110 +snd_pcm_kernel_ioctl_12219 snd_pcm_kernel_ioctl 0 12219 NULL
119111 +fuse_get_req_12221 fuse_get_req 2 12221 NULL nohasharray
119112 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 &fuse_get_req_12221
119113 +__alloc_bootmem_low_nopanic_12235 __alloc_bootmem_low_nopanic 1 12235 NULL
119114 +usnic_ib_qp_grp_dump_rows_12239 usnic_ib_qp_grp_dump_rows 3 12239 NULL
119115 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
119116 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
119117 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
119118 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
119119 +roundup_to_multiple_of_64_12288 roundup_to_multiple_of_64 0-1 12288 NULL nohasharray
119120 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 &roundup_to_multiple_of_64_12288
119121 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
119122 +usnic_transport_sock_to_str_12322 usnic_transport_sock_to_str 2-0 12322 NULL
119123 +ufshcd_copy_query_response_12324 ufshcd_copy_query_response 0 12324 NULL
119124 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
119125 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
119126 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
119127 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
119128 +write_file_dump_12391 write_file_dump 3 12391 NULL nohasharray
119129 +btrfs_file_extent_ram_bytes_12391 btrfs_file_extent_ram_bytes 0 12391 &write_file_dump_12391 nohasharray
119130 +populate_dir_12391 populate_dir 0 12391 &btrfs_file_extent_ram_bytes_12391
119131 +hbucket_elem_add_12416 hbucket_elem_add 3 12416 NULL
119132 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
119133 +cfs_array_alloc_12441 cfs_array_alloc 1-2 12441 NULL
119134 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
119135 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
119136 +fnic_trace_ctrl_read_12497 fnic_trace_ctrl_read 3 12497 NULL
119137 +__ceph_osdc_start_request_12502 __ceph_osdc_start_request 0 12502 NULL
119138 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
119139 +nvkm_event_init_12565 nvkm_event_init 3-2 12565 NULL
119140 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
119141 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
119142 +_iwl_dbgfs_prph_reg_write_12597 _iwl_dbgfs_prph_reg_write 3 12597 NULL
119143 +tlbflush_write_file_12598 tlbflush_write_file 3 12598 NULL
119144 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
119145 +sdhci_pltfm_init_12627 sdhci_pltfm_init 3 12627 NULL
119146 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
119147 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
119148 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
119149 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
119150 +rtw_android_get_link_speed_12655 rtw_android_get_link_speed 0 12655 NULL
119151 +ocfs2_read_block_12659 ocfs2_read_block 0 12659 NULL
119152 +lustre_pack_request_v2_12665 lustre_pack_request_v2 2 12665 NULL
119153 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
119154 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
119155 +ext4_writepage_trans_blocks_12674 ext4_writepage_trans_blocks 0 12674 NULL
119156 +iwl_dbgfs_calib_disabled_write_12707 iwl_dbgfs_calib_disabled_write 3 12707 NULL
119157 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
119158 +ivtv_write_12721 ivtv_write 3 12721 NULL
119159 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
119160 +__mei_cl_async_send_12737 __mei_cl_async_send 3 12737 NULL
119161 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
119162 +listxattr_12769 listxattr 3 12769 NULL
119163 +sctp_ssnmap_init_12772 sctp_ssnmap_init 2-3 12772 NULL
119164 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
119165 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
119166 +SyS_add_key_12834 SyS_add_key 4 12834 NULL
119167 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
119168 +spidev_sync_12842 spidev_sync 0 12842 NULL
119169 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
119170 +ath9k_dump_4k_modal_eeprom_12883 ath9k_dump_4k_modal_eeprom 3-2 12883 NULL
119171 +get_leb_cnt_12892 get_leb_cnt 0-2 12892 NULL
119172 +get_virtual_node_size_12908 get_virtual_node_size 0 12908 NULL
119173 +rds_pages_in_vec_12922 rds_pages_in_vec 0 12922 NULL
119174 +do_inode_permission_12946 do_inode_permission 0 12946 NULL
119175 +bm_status_write_12964 bm_status_write 3 12964 NULL
119176 +raid56_parity_recover_12987 raid56_parity_recover 5 12987 NULL
119177 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
119178 +sk_peek_offset_12991 sk_peek_offset 0 12991 NULL
119179 +bset_prev_bytes_13020 bset_prev_bytes 0 13020 NULL
119180 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
119181 +ocfs2_write_begin_13045 ocfs2_write_begin 3-4 13045 NULL
119182 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL nohasharray
119183 +ptlrpc_lprocfs_threads_min_seq_write_13060 ptlrpc_lprocfs_threads_min_seq_write 3 13060 &__dn_setsockopt_13060
119184 +ufshcd_compose_upiu_13076 ufshcd_compose_upiu 0 13076 NULL
119185 +xattr_getsecurity_13090 xattr_getsecurity 0 13090 NULL
119186 +ttm_dma_pool_alloc_new_pages_13105 ttm_dma_pool_alloc_new_pages 3 13105 NULL
119187 +SyS_msgrcv_13109 SyS_msgrcv 3 13109 NULL
119188 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
119189 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
119190 +blk_update_request_13146 blk_update_request 3 13146 NULL
119191 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
119192 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
119193 +ucs2_strlen_13178 ucs2_strlen 0 13178 NULL
119194 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
119195 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
119196 +comedi_read_13199 comedi_read 3 13199 NULL
119197 +hash_ipport4_expire_13201 hash_ipport4_expire 4 13201 NULL
119198 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
119199 +svm_msrpm_offset_13220 svm_msrpm_offset 0-1 13220 NULL
119200 +fnic_trace_ctrl_write_13229 fnic_trace_ctrl_write 3 13229 NULL
119201 +_iwl_dbgfs_disable_power_off_write_13243 _iwl_dbgfs_disable_power_off_write 3 13243 NULL
119202 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
119203 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
119204 +bio_integrity_trim_13259 bio_integrity_trim 3-2 13259 NULL
119205 +simple_attr_write_13260 simple_attr_write 3 13260 NULL
119206 +pmcraid_notify_aen_13274 pmcraid_notify_aen 3 13274 NULL
119207 +nvkm_ltc_create__13275 nvkm_ltc_create_ 4 13275 NULL
119208 +il4965_stats_flag_13281 il4965_stats_flag 0-3 13281 NULL
119209 +lpfc_idiag_mbxacc_get_setup_13282 lpfc_idiag_mbxacc_get_setup 0 13282 NULL
119210 +nvkm_i2c_pad_create__13292 nvkm_i2c_pad_create_ 5 13292 NULL
119211 +sd_major_13294 sd_major 0-1 13294 NULL
119212 +read_file_phy_err_13318 read_file_phy_err 3 13318 NULL
119213 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
119214 +round_event_name_len_13348 round_event_name_len 0 13348 NULL
119215 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
119216 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
119217 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
119218 +ext4_meta_trans_blocks_13380 ext4_meta_trans_blocks 0-3-2 13380 NULL
119219 +lov_mds_md_size_13388 lov_mds_md_size 0-1 13388 NULL nohasharray
119220 +dis_bypass_write_13388 dis_bypass_write 3 13388 &lov_mds_md_size_13388
119221 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
119222 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL
119223 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 7-8-9 13443 NULL
119224 +sb_init_dio_done_wq_13482 sb_init_dio_done_wq 0 13482 NULL
119225 +data_read_13494 data_read 3 13494 NULL nohasharray
119226 +ext_prop_data_store_13494 ext_prop_data_store 3 13494 &data_read_13494
119227 +ocfs2_align_bytes_to_blocks_13512 ocfs2_align_bytes_to_blocks 0-2 13512 NULL
119228 +core_status_13515 core_status 4 13515 NULL
119229 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
119230 +bm_init_13529 bm_init 2 13529 NULL
119231 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
119232 +ieee80211_if_read_ap_power_level_13558 ieee80211_if_read_ap_power_level 3 13558 NULL
119233 +hash_net4_expire_13559 hash_net4_expire 4 13559 NULL
119234 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
119235 +cache_write_13589 cache_write 3 13589 NULL
119236 +Rd_Indx_13602 Rd_Indx 3-2 13602 NULL
119237 +wm8994_bulk_write_13615 wm8994_bulk_write 2-3 13615 NULL
119238 +pmcraid_get_minor_13619 pmcraid_get_minor 0 13619 NULL
119239 +packet_snd_13634 packet_snd 3 13634 NULL
119240 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
119241 +cache_downcall_13666 cache_downcall 3 13666 NULL
119242 +usb_get_string_13693 usb_get_string 0 13693 NULL
119243 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
119244 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
119245 +udf_direct_IO_13765 udf_direct_IO 4 13765 NULL
119246 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
119247 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
119248 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
119249 +random_read_13815 random_read 3 13815 NULL
119250 +mutex_lock_interruptible_nested_13817 mutex_lock_interruptible_nested 0 13817 NULL
119251 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
119252 +___mei_cl_send_13821 ___mei_cl_send 3 13821 NULL
119253 +qce_ahash_hmac_setkey_13837 qce_ahash_hmac_setkey 3 13837 NULL
119254 +enc_pools_insert_13849 enc_pools_insert 3 13849 NULL
119255 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
119256 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL
119257 +qp_memcpy_to_queue_13886 qp_memcpy_to_queue 5-2 13886 NULL
119258 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
119259 +cfg80211_inform_bss_width_13933 cfg80211_inform_bss_width 9 13933 NULL
119260 +ext3_xattr_block_get_13936 ext3_xattr_block_get 0 13936 NULL
119261 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL nohasharray
119262 +ocfs2_xa_value_truncate_13940 ocfs2_xa_value_truncate 2 13940 &ieee80211_if_read_dot11MeshForwarding_13940
119263 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
119264 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
119265 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL
119266 +osc_grant_shrink_interval_seq_write_13952 osc_grant_shrink_interval_seq_write 3 13952 NULL
119267 +snd_pcm_plug_slave_size_13967 snd_pcm_plug_slave_size 0-2 13967 NULL
119268 +qcam_read_13977 qcam_read 3 13977 NULL
119269 +dsp_read_13980 dsp_read 2 13980 NULL
119270 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
119271 +sddr09_write_data_14014 sddr09_write_data 3 14014 NULL
119272 +btrfs_get_blocks_direct_14016 btrfs_get_blocks_direct 2 14016 NULL
119273 +dmi_format_ids_14018 dmi_format_ids 2 14018 NULL
119274 +iscsi_create_flashnode_conn_14022 iscsi_create_flashnode_conn 4 14022 NULL
119275 +pci_add_ext_cap_save_buffer_14032 pci_add_ext_cap_save_buffer 3 14032 NULL
119276 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
119277 +ieee80211_if_fmt_aid_14055 ieee80211_if_fmt_aid 3 14055 NULL
119278 +ovs_nla_alloc_flow_actions_14056 ovs_nla_alloc_flow_actions 1 14056 NULL
119279 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
119280 +lov_stripeoffset_seq_write_14078 lov_stripeoffset_seq_write 3 14078 NULL
119281 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
119282 +ext4_journal_blocks_per_page_14127 ext4_journal_blocks_per_page 0 14127 NULL
119283 +isku_sysfs_read_light_14140 isku_sysfs_read_light 6 14140 NULL
119284 +em_canid_change_14150 em_canid_change 3 14150 NULL
119285 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
119286 +midi_alloc_ep_req_14159 midi_alloc_ep_req 2 14159 NULL
119287 +print_input_mask_14168 print_input_mask 3-0 14168 NULL
119288 +ocfs2_xattr_value_truncate_14183 ocfs2_xattr_value_truncate 3 14183 NULL
119289 +datafab_read_data_14186 datafab_read_data 4 14186 NULL
119290 +hfsplus_brec_find_14200 hfsplus_brec_find 0 14200 NULL
119291 +alloc_async_14208 alloc_async 1 14208 NULL
119292 +ath6kl_regread_write_14220 ath6kl_regread_write 3 14220 NULL
119293 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
119294 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4 14244 NULL
119295 +btrfs_token_file_extent_ram_bytes_14247 btrfs_token_file_extent_ram_bytes 0 14247 NULL
119296 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
119297 +rr_status_14293 rr_status 5 14293 NULL
119298 +read_default_ldt_14302 read_default_ldt 2 14302 NULL nohasharray
119299 +lustre_pack_reply_flags_14302 lustre_pack_reply_flags 2 14302 &read_default_ldt_14302
119300 +oo_objects_14319 oo_objects 0 14319 NULL
119301 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
119302 +alloc_tx_struct_14349 alloc_tx_struct 1 14349 NULL
119303 +hash_ipportnet4_expire_14354 hash_ipportnet4_expire 4 14354 NULL
119304 +snd_pcm_lib_readv_14363 snd_pcm_lib_readv 0-3 14363 NULL
119305 +lowpan_read_14369 lowpan_read 3 14369 NULL
119306 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
119307 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
119308 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
119309 +get_kcore_size_14425 get_kcore_size 0 14425 NULL
119310 +_iwl_dbgfs_sram_write_14439 _iwl_dbgfs_sram_write 3 14439 NULL
119311 +block_size_14443 block_size 0 14443 NULL
119312 +lmv_user_md_size_14456 lmv_user_md_size 0-1 14456 NULL
119313 +snd_emu10k1_proc_spdif_status_14457 snd_emu10k1_proc_spdif_status 4-5 14457 NULL
119314 +ath10k_write_htt_stats_mask_14458 ath10k_write_htt_stats_mask 3 14458 NULL
119315 +lustre_msg_size_v2_14470 lustre_msg_size_v2 0-1 14470 NULL
119316 +dma_transfer_size_14473 dma_transfer_size 0 14473 NULL
119317 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
119318 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
119319 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
119320 +dataflash_read_user_otp_14536 dataflash_read_user_otp 3-2 14536 NULL nohasharray
119321 +ep0_write_14536 ep0_write 3 14536 &dataflash_read_user_otp_14536
119322 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
119323 +qp_host_alloc_queue_14566 qp_host_alloc_queue 1 14566 NULL
119324 +SyS_setdomainname_14569 SyS_setdomainname 2 14569 NULL
119325 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
119326 +ceph_osdc_alloc_request_14597 ceph_osdc_alloc_request 3 14597 NULL
119327 +ufshcd_compose_dev_cmd_14626 ufshcd_compose_dev_cmd 0 14626 NULL
119328 +dbJoin_14644 dbJoin 0 14644 NULL
119329 +profile_replace_14652 profile_replace 3 14652 NULL
119330 +usnic_vnic_dump_14662 usnic_vnic_dump 3 14662 NULL
119331 +min_bytes_needed_14675 min_bytes_needed 0 14675 NULL
119332 +nvme_trans_log_info_exceptions_14677 nvme_trans_log_info_exceptions 3 14677 NULL
119333 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
119334 +ieee80211_if_fmt_rc_rateidx_mask_2ghz_14683 ieee80211_if_fmt_rc_rateidx_mask_2ghz 3 14683 NULL
119335 +SyS_fsetxattr_14702 SyS_fsetxattr 4 14702 NULL
119336 +persistent_ram_ecc_string_14704 persistent_ram_ecc_string 0 14704 NULL
119337 +u_audio_playback_14709 u_audio_playback 3 14709 NULL
119338 +rtw_cbuf_alloc_14710 rtw_cbuf_alloc 1 14710 NULL
119339 +vfd_write_14717 vfd_write 3 14717 NULL
119340 +__blk_end_request_14729 __blk_end_request 3 14729 NULL
119341 +raid1_resize_14740 raid1_resize 2 14740 NULL
119342 +i915_error_state_buf_init_14742 i915_error_state_buf_init 2 14742 NULL
119343 +btrfs_inode_extref_name_len_14752 btrfs_inode_extref_name_len 0 14752 NULL
119344 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
119345 +regmap_range_read_file_14775 regmap_range_read_file 3 14775 NULL
119346 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
119347 +keys_proc_write_14792 keys_proc_write 3 14792 NULL
119348 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
119349 +__kfifo_in_14797 __kfifo_in 3-0 14797 NULL nohasharray
119350 +ttm_page_pool_free_14797 ttm_page_pool_free 2-0 14797 &__kfifo_in_14797
119351 +hpet_readl_14801 hpet_readl 0 14801 NULL nohasharray
119352 +snd_als300_gcr_read_14801 snd_als300_gcr_read 0 14801 &hpet_readl_14801
119353 +do_tune_cpucache_14828 do_tune_cpucache 2 14828 NULL
119354 +mrp_attr_create_14853 mrp_attr_create 3 14853 NULL
119355 +lcd_write_14857 lcd_write 3 14857 NULL
119356 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
119357 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
119358 +SYSC_readv_14901 SYSC_readv 3 14901 NULL
119359 +netlbl_catmap_walk_14902 netlbl_catmap_walk 0-2 14902 NULL
119360 +__arch_hweight64_14923 __arch_hweight64 0 14923 NULL nohasharray
119361 +qp_memcpy_to_queue_iov_14923 qp_memcpy_to_queue_iov 5-2 14923 &__arch_hweight64_14923 nohasharray
119362 +ptlrpc_prep_req_pool_14923 ptlrpc_prep_req_pool 4 14923 &qp_memcpy_to_queue_iov_14923
119363 +ocfs2_expand_nonsparse_inode_14936 ocfs2_expand_nonsparse_inode 3-4 14936 NULL
119364 +queue_cnt_14951 queue_cnt 0 14951 NULL
119365 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
119366 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
119367 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
119368 +setkey_14987 setkey 3 14987 NULL nohasharray
119369 +gpio_twl4030_write_14987 gpio_twl4030_write 1 14987 &setkey_14987
119370 +sctp_setsockopt_default_sndinfo_15011 sctp_setsockopt_default_sndinfo 3 15011 NULL
119371 +blk_integrity_tuple_size_15027 blk_integrity_tuple_size 0 15027 NULL
119372 +read_file_node_aggr_15040 read_file_node_aggr 3 15040 NULL
119373 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
119374 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
119375 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
119376 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5-0 15072 NULL
119377 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
119378 +smscore_load_firmware_family2_15086 smscore_load_firmware_family2 3 15086 NULL
119379 +compat_SyS_pwritev_15118 compat_SyS_pwritev 3 15118 NULL
119380 +hex_dump_to_buffer_15121 hex_dump_to_buffer 6 15121 NULL
119381 +start_port_15124 start_port 0 15124 NULL
119382 +ipwireless_ppp_mru_15153 ipwireless_ppp_mru 0 15153 NULL
119383 +SYSC_setdomainname_15180 SYSC_setdomainname 2 15180 NULL
119384 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
119385 +mtt_alloc_res_15211 mtt_alloc_res 5 15211 NULL
119386 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
119387 +iwl_dbgfs_sram_write_15239 iwl_dbgfs_sram_write 3 15239 NULL
119388 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
119389 +wacom_led_putimage_15264 wacom_led_putimage 4 15264 NULL
119390 +simple_strtol_15273 simple_strtol 0 15273 NULL
119391 +fw_realloc_buffer_15280 fw_realloc_buffer 2 15280 NULL
119392 +kovaplus_sysfs_read_15337 kovaplus_sysfs_read 6 15337 NULL
119393 +ioread16_15342 ioread16 0 15342 NULL
119394 +ept_prefetch_gpte_15348 ept_prefetch_gpte 4 15348 NULL
119395 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
119396 +graph_depth_read_15371 graph_depth_read 3 15371 NULL
119397 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
119398 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
119399 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
119400 +get_modalias_15406 get_modalias 2 15406 NULL
119401 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4-0 15423 NULL
119402 +tcp_mtu_to_mss_15438 tcp_mtu_to_mss 2-0 15438 NULL
119403 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
119404 +memweight_15450 memweight 2 15450 NULL
119405 +__clone_and_map_data_bio_15498 __clone_and_map_data_bio 3 15498 NULL
119406 +zd_chip_is_zd1211b_15518 zd_chip_is_zd1211b 0 15518 NULL
119407 +ifx_spi_write_15531 ifx_spi_write 3 15531 NULL
119408 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
119409 +xfrm_state_mtu_15548 xfrm_state_mtu 0-2 15548 NULL
119410 +persistent_status_15574 persistent_status 4 15574 NULL
119411 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
119412 +vme_user_write_15587 vme_user_write 3 15587 NULL
119413 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
119414 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
119415 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
119416 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &tomoyo_scan_bprm_15642 nohasharray
119417 +sk_memory_allocated_add_15642 sk_memory_allocated_add 2 15642 &pipeline_hs_tx_stat_fifo_int_read_15642
119418 +joydev_handle_JSIOCSBTNMAP_15643 joydev_handle_JSIOCSBTNMAP 3 15643 NULL
119419 +fs_path_add_15648 fs_path_add 3 15648 NULL
119420 +xsd_read_15653 xsd_read 3 15653 NULL
119421 +unix_bind_15668 unix_bind 3 15668 NULL
119422 +dm_read_15674 dm_read 3 15674 NULL nohasharray
119423 +SyS_connect_15674 SyS_connect 3 15674 &dm_read_15674
119424 +uinput_str_to_user_15695 uinput_str_to_user 3 15695 NULL
119425 +__sk_migrate_realloc_15709 __sk_migrate_realloc 3 15709 NULL
119426 +tracing_snapshot_write_15719 tracing_snapshot_write 3 15719 NULL
119427 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
119428 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
119429 +gnttab_expand_15817 gnttab_expand 1 15817 NULL nohasharray
119430 +nameseq_list_15817 nameseq_list 3-0 15817 &gnttab_expand_15817
119431 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
119432 +table_size_15851 table_size 0-1-2 15851 NULL
119433 +write_file_tx99_15856 write_file_tx99 3 15856 NULL
119434 +media_entity_init_15870 media_entity_init 2-4 15870 NULL
119435 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
119436 +parse_audio_stream_data_15937 parse_audio_stream_data 3 15937 NULL
119437 +power_read_15939 power_read 3 15939 NULL
119438 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
119439 +snd_pcm_lib_read_transfer_15952 snd_pcm_lib_read_transfer 5-2-4 15952 NULL
119440 +memblock_virt_alloc_try_nid_15954 memblock_virt_alloc_try_nid 1 15954 NULL
119441 +smk_read_ptrace_15974 smk_read_ptrace 3 15974 NULL
119442 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
119443 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
119444 +read_file_spectral_period_16057 read_file_spectral_period 3 16057 NULL
119445 +SYSC_kexec_file_load_16058 SYSC_kexec_file_load 3 16058 NULL
119446 +si5351_msynth_params_address_16062 si5351_msynth_params_address 0-1 16062 NULL
119447 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
119448 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 NULL nohasharray
119449 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 &isr_hw_pm_mode_changes_read_16110
119450 +udelay_test_write_16111 udelay_test_write 3 16111 NULL
119451 +snd_dma_pointer_16126 snd_dma_pointer 0-2 16126 NULL
119452 +fsm_init_16134 fsm_init 2 16134 NULL
119453 +ext4_xattr_block_get_16148 ext4_xattr_block_get 0 16148 NULL
119454 +optimal_reclaimed_pages_16172 optimal_reclaimed_pages 0 16172 NULL
119455 +mapping_level_16188 mapping_level 2-0 16188 NULL
119456 +i40e_allocate_virt_mem_d_16191 i40e_allocate_virt_mem_d 3 16191 NULL
119457 +ath10k_htt_rx_ring_size_16201 ath10k_htt_rx_ring_size 0 16201 NULL
119458 +cipso_v4_map_cat_rng_hton_16203 cipso_v4_map_cat_rng_hton 0 16203 NULL
119459 +SyS_pselect6_16210 SyS_pselect6 1 16210 NULL
119460 +create_table_16213 create_table 2 16213 NULL
119461 +ath9k_hw_ar9287_dump_eeprom_16224 ath9k_hw_ar9287_dump_eeprom 5-4 16224 NULL
119462 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
119463 +BcmGetSectionValStartOffset_16235 BcmGetSectionValStartOffset 0 16235 NULL
119464 +lov_prep_brw_set_16246 lov_prep_brw_set 3 16246 NULL
119465 +i40e_dbg_dump_read_16247 i40e_dbg_dump_read 3 16247 NULL
119466 +il_dbgfs_disable_ht40_write_16249 il_dbgfs_disable_ht40_write 3 16249 NULL
119467 +SyS_fgetxattr_16254 SyS_fgetxattr 4 16254 NULL
119468 +reiserfs_acl_count_16265 reiserfs_acl_count 0-1 16265 NULL
119469 +ocfs2_xattr_bucket_value_truncate_16279 ocfs2_xattr_bucket_value_truncate 4 16279 NULL
119470 +nand_bch_init_16280 nand_bch_init 3-2 16280 NULL nohasharray
119471 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 &nand_bch_init_16280
119472 +account_16283 account 0-4-2 16283 NULL nohasharray
119473 +mirror_status_16283 mirror_status 5 16283 &account_16283
119474 +jumpshot_read_data_16287 jumpshot_read_data 4 16287 NULL
119475 +mo_xattr_get_16288 mo_xattr_get 0 16288 NULL
119476 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
119477 +rbd_segment_offset_16293 rbd_segment_offset 0-2 16293 NULL
119478 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
119479 +kvm_handle_hva_range_16312 kvm_handle_hva_range 3-2 16312 NULL
119480 +sysfs_create_groups_16360 sysfs_create_groups 0 16360 NULL
119481 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
119482 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
119483 +nv50_pioc_create_16389 nv50_pioc_create 5 16389 NULL
119484 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
119485 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
119486 +__bio_add_page_16435 __bio_add_page 0-4 16435 NULL
119487 +cmdline_store_16442 cmdline_store 4 16442 NULL
119488 +copy_from_user_bvec_16447 copy_from_user_bvec 0-4 16447 NULL
119489 +btrfs_truncate_inode_items_16452 btrfs_truncate_inode_items 4 16452 NULL
119490 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
119491 +req_capsule_get_size_16467 req_capsule_get_size 0 16467 NULL
119492 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
119493 +KEY_OFFSET_16504 KEY_OFFSET 0 16504 NULL
119494 +snd_interval_max_16529 snd_interval_max 0 16529 NULL
119495 +raid10_resize_16537 raid10_resize 2 16537 NULL
119496 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
119497 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
119498 +lustre_msg_hdr_size_v2_16589 lustre_msg_hdr_size_v2 0-1 16589 NULL
119499 +compat_SyS_migrate_pages_16618 compat_SyS_migrate_pages 2 16618 NULL
119500 +rtw_set_wpa_ie_16633 rtw_set_wpa_ie 3 16633 NULL
119501 +btrfs_get_token_32_16651 btrfs_get_token_32 0 16651 NULL
119502 +__wa_populate_dto_urb_16699 __wa_populate_dto_urb 3-4 16699 NULL
119503 +_iwl_dbgfs_bt_force_ant_write_16701 _iwl_dbgfs_bt_force_ant_write 3 16701 NULL
119504 +__proc_lnet_buffers_16717 __proc_lnet_buffers 5 16717 NULL
119505 +__copy_to_user_swizzled_16748 __copy_to_user_swizzled 3-4 16748 NULL
119506 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
119507 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
119508 +i2o_parm_issue_16790 i2o_parm_issue 0 16790 NULL
119509 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
119510 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
119511 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
119512 +hfsplus_min_io_size_16859 hfsplus_min_io_size 0 16859 NULL
119513 +alloc_idx_lebs_16872 alloc_idx_lebs 2 16872 NULL
119514 +carl9170_debugfs_ampdu_state_read_16873 carl9170_debugfs_ampdu_state_read 3 16873 NULL
119515 +st_write_16874 st_write 3 16874 NULL
119516 +__kfifo_peek_n_16877 __kfifo_peek_n 0 16877 NULL
119517 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 NULL nohasharray
119518 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 &psb_unlocked_ioctl_16926
119519 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
119520 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
119521 +svcxdr_dupstr_16963 svcxdr_dupstr 3 16963 NULL
119522 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
119523 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
119524 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
119525 +C_SYSC_keyctl_17041 C_SYSC_keyctl 4 17041 NULL
119526 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
119527 +__arch_hweight32_17060 __arch_hweight32 0 17060 NULL
119528 +sddr55_read_data_17072 sddr55_read_data 4 17072 NULL
119529 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
119530 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
119531 +carl9170_debugfs_mem_usage_read_17084 carl9170_debugfs_mem_usage_read 3 17084 NULL
119532 +entry_length_17093 entry_length 0 17093 NULL
119533 +write_mem_17114 write_mem 3 17114 NULL
119534 +pvr2_hdw_state_report_17121 pvr2_hdw_state_report 3 17121 NULL
119535 +do_blockdev_direct_IO_17143 do_blockdev_direct_IO 0-6 17143 NULL
119536 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
119537 +jumpshot_write_data_17151 jumpshot_write_data 4 17151 NULL
119538 +mxt_upload_cfg_mem_17157 mxt_upload_cfg_mem 4 17157 NULL
119539 +sep_read_17161 sep_read 3 17161 NULL
119540 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
119541 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
119542 +UniStrnlen_17169 UniStrnlen 0 17169 NULL
119543 +access_remote_vm_17189 access_remote_vm 0 17189 NULL nohasharray
119544 +iwl_dbgfs_txfifo_flush_write_17189 iwl_dbgfs_txfifo_flush_write 3 17189 &access_remote_vm_17189
119545 +driver_state_read_17194 driver_state_read 3 17194 NULL nohasharray
119546 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 &driver_state_read_17194
119547 +sync_request_17208 sync_request 2 17208 NULL
119548 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
119549 +lprocfs_read_frac_helper_17261 lprocfs_read_frac_helper 0 17261 NULL
119550 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
119551 +alloc_ep_17269 alloc_ep 1 17269 NULL
119552 +pg_read_17276 pg_read 3 17276 NULL
119553 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
119554 +hmac_sha256_17278 hmac_sha256 2 17278 NULL
119555 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
119556 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
119557 +__ptlrpc_request_bufs_pack_17298 __ptlrpc_request_bufs_pack 4 17298 NULL
119558 +ieee80211_if_fmt_dot11MeshForwarding_17301 ieee80211_if_fmt_dot11MeshForwarding 3 17301 NULL
119559 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
119560 +gnttab_map_frames_v2_17314 gnttab_map_frames_v2 2 17314 NULL
119561 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
119562 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
119563 +mdc_import_seq_write_17409 mdc_import_seq_write 3 17409 NULL
119564 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
119565 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
119566 +libcfs_ipif_enumerate_17445 libcfs_ipif_enumerate 0 17445 NULL
119567 +nla_get_u32_17455 nla_get_u32 0 17455 NULL
119568 +__ref_totlen_17461 __ref_totlen 0 17461 NULL
119569 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
119570 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
119571 +copy_page_from_iter_17512 copy_page_from_iter 3-0 17512 NULL
119572 +reiserfs_direct_IO_17513 reiserfs_direct_IO 4 17513 NULL
119573 +lbs_highrssi_write_17515 lbs_highrssi_write 3 17515 NULL
119574 +qp_free_res_17541 qp_free_res 5 17541 NULL
119575 +__copy_to_user_17551 __copy_to_user 0-3 17551 NULL
119576 +copy_from_user_17559 copy_from_user 3-0 17559 NULL
119577 +hash_netport4_expire_17573 hash_netport4_expire 4 17573 NULL
119578 +wil_write_file_rxon_17581 wil_write_file_rxon 3 17581 NULL
119579 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
119580 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
119581 +osst_execute_17607 osst_execute 7-6 17607 NULL
119582 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
119583 +dma_map_page_17628 dma_map_page 0 17628 NULL
119584 +twl4030_set_gpio_direction_17645 twl4030_set_gpio_direction 1 17645 NULL
119585 +SYSC_migrate_pages_17657 SYSC_migrate_pages 2 17657 NULL
119586 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
119587 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
119588 +venus_rename_17707 venus_rename 4-5 17707 NULL
119589 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
119590 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
119591 +nv92_gpio_intr_mask_17773 nv92_gpio_intr_mask 4-3 17773 NULL
119592 +shrink_slab_node_17794 shrink_slab_node 3 17794 NULL
119593 +lpuart_copy_rx_to_tty_17801 lpuart_copy_rx_to_tty 3 17801 NULL
119594 +gnet_stats_copy_app_17821 gnet_stats_copy_app 3 17821 NULL
119595 +cipso_v4_gentag_rbm_17836 cipso_v4_gentag_rbm 0 17836 NULL
119596 +em28xx_audio_ep_packet_size_17844 em28xx_audio_ep_packet_size 0 17844 NULL
119597 +dm_stats_message_17863 dm_stats_message 5 17863 NULL
119598 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
119599 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
119600 +virtio_cread32_17873 virtio_cread32 0 17873 NULL
119601 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
119602 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL nohasharray
119603 +i40e_align_l2obj_base_17878 i40e_align_l2obj_base 0-1 17878 &orinoco_set_key_17878
119604 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
119605 +ieee80211_if_fmt_dot11MeshMaxPeerLinks_17883 ieee80211_if_fmt_dot11MeshMaxPeerLinks 3 17883 NULL
119606 +ieee80211_if_fmt_dot11MeshHWMPRootMode_17890 ieee80211_if_fmt_dot11MeshHWMPRootMode 3 17890 NULL
119607 +dev_pm_opp_get_opp_count_17911 dev_pm_opp_get_opp_count 0 17911 NULL
119608 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
119609 +tipc_port_iovec_rcv_17921 tipc_port_iovec_rcv 3 17921 NULL
119610 +scsi_bufflen_17933 scsi_bufflen 0 17933 NULL
119611 +__mutex_lock_check_stamp_17947 __mutex_lock_check_stamp 0 17947 NULL
119612 +beacon_interval_write_17952 beacon_interval_write 3 17952 NULL
119613 +calc_nr_buckets_17976 calc_nr_buckets 0 17976 NULL
119614 +ext4_ext_calc_credits_for_single_extent_17983 ext4_ext_calc_credits_for_single_extent 0-2 17983 NULL
119615 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
119616 +gnttab_max_grant_frames_17993 gnttab_max_grant_frames 0 17993 NULL
119617 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
119618 +o2hb_highest_node_18034 o2hb_highest_node 0 18034 NULL
119619 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
119620 +__btrfs_drop_extents_18049 __btrfs_drop_extents 5 18049 NULL
119621 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
119622 +lua_sysfs_read_18062 lua_sysfs_read 6 18062 NULL
119623 +fpregs_get_18066 fpregs_get 4 18066 NULL
119624 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
119625 +SYSC_pselect6_18076 SYSC_pselect6 1 18076 NULL
119626 +SYSC_semtimedop_18091 SYSC_semtimedop 3 18091 NULL
119627 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
119628 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
119629 +svc_getnl_18120 svc_getnl 0 18120 NULL
119630 +paging32_gpte_to_gfn_lvl_18131 paging32_gpte_to_gfn_lvl 0-2-1 18131 NULL
119631 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
119632 +enable_ints_write_18170 enable_ints_write 3 18170 NULL
119633 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
119634 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
119635 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
119636 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
119637 +fill_ext_prop_18233 fill_ext_prop 0 18233 NULL
119638 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
119639 +alloc_trace_uprobe_18247 alloc_trace_uprobe 3 18247 NULL
119640 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
119641 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
119642 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
119643 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
119644 +bio_phys_segments_18281 bio_phys_segments 0 18281 NULL nohasharray
119645 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 &bio_phys_segments_18281
119646 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
119647 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
119648 +um_idi_write_18293 um_idi_write 3 18293 NULL
119649 +nouveau_disp_create__18305 nouveau_disp_create_ 4-7 18305 NULL
119650 +lustre_msg_hdr_size_18308 lustre_msg_hdr_size 2 18308 NULL
119651 +class_add_profile_18315 class_add_profile 1-3-5 18315 NULL
119652 +csio_mem_read_18319 csio_mem_read 3 18319 NULL
119653 +alloc_and_copy_string_18321 alloc_and_copy_string 2 18321 NULL
119654 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
119655 +bio_integrity_advance_18324 bio_integrity_advance 2 18324 NULL
119656 +copy_page_to_iter_18345 copy_page_to_iter 0-3 18345 NULL
119657 +lcd_proc_write_18351 lcd_proc_write 3 18351 NULL
119658 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
119659 +SyS_process_vm_readv_18366 SyS_process_vm_readv 3-5 18366 NULL
119660 +ep_io_18367 ep_io 0 18367 NULL
119661 +qib_user_sdma_num_pages_18371 qib_user_sdma_num_pages 0 18371 NULL
119662 +__ceph_getxattr_18386 __ceph_getxattr 0 18386 NULL
119663 +ci_role_write_18388 ci_role_write 3 18388 NULL
119664 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
119665 +adis16136_show_serial_18402 adis16136_show_serial 3 18402 NULL
119666 +nvif_device_init_18418 nvif_device_init 6 18418 NULL
119667 +memblock_virt_alloc_node_nopanic_18431 memblock_virt_alloc_node_nopanic 1 18431 NULL
119668 +iscsi_create_flashnode_sess_18433 iscsi_create_flashnode_sess 4 18433 NULL
119669 +snd_hda_get_connections_18437 snd_hda_get_connections 0 18437 NULL
119670 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
119671 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
119672 +pci_vpd_lrdt_size_18479 pci_vpd_lrdt_size 0 18479 NULL nohasharray
119673 +mite_bytes_in_transit_18479 mite_bytes_in_transit 0 18479 &pci_vpd_lrdt_size_18479
119674 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
119675 +btrfs_fiemap_18501 btrfs_fiemap 3 18501 NULL
119676 +__copy_user_zeroing_intel_18510 __copy_user_zeroing_intel 0-3 18510 NULL
119677 +snd_vx_inb_18514 snd_vx_inb 0 18514 NULL
119678 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
119679 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 9 18530 NULL
119680 +tipc_send2port_18531 tipc_send2port 4 18531 NULL
119681 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
119682 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
119683 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
119684 +debug_output_18575 debug_output 3 18575 NULL
119685 +filemap_fdatawait_range_18600 filemap_fdatawait_range 0 18600 NULL nohasharray
119686 +slabinfo_write_18600 slabinfo_write 3 18600 &filemap_fdatawait_range_18600
119687 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
119688 +from_buffer_18625 from_buffer 3 18625 NULL
119689 +kmalloc_kernel_18641 kmalloc_kernel 1 18641 NULL
119690 +snd_pcm_oss_write3_18657 snd_pcm_oss_write3 0-3 18657 NULL
119691 +ieee80211_if_fmt_rssi_threshold_18664 ieee80211_if_fmt_rssi_threshold 3 18664 NULL
119692 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 NULL
119693 +fnic_stats_debugfs_read_18688 fnic_stats_debugfs_read 3 18688 NULL
119694 +echo_client_prep_commit_18693 echo_client_prep_commit 8 18693 NULL
119695 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
119696 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
119697 +blk_rq_bytes_18715 blk_rq_bytes 0 18715 NULL
119698 +nfs4_init_callback_netid_18717 nfs4_init_callback_netid 3 18717 NULL
119699 +snd_als4k_gcr_read_addr_18741 snd_als4k_gcr_read_addr 0 18741 NULL
119700 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
119701 +__erst_read_to_erange_from_nvram_18748 __erst_read_to_erange_from_nvram 0 18748 NULL
119702 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
119703 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
119704 +SyS_lsetxattr_18776 SyS_lsetxattr 4 18776 NULL
119705 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
119706 +fence_context_alloc_18792 fence_context_alloc 1 18792 NULL
119707 +dm_stats_print_18815 dm_stats_print 7 18815 NULL
119708 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
119709 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
119710 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
119711 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
119712 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
119713 +devm_mdiobus_alloc_size_18902 devm_mdiobus_alloc_size 2 18902 NULL
119714 +tracing_thresh_write_18909 tracing_thresh_write 3 18909 NULL
119715 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
119716 +ieee80211_rx_mgmt_disassoc_18927 ieee80211_rx_mgmt_disassoc 3 18927 NULL
119717 +snapshot_write_next_18937 snapshot_write_next 0 18937 NULL
119718 +__nla_reserve_18974 __nla_reserve 3 18974 NULL
119719 +layout_in_gaps_19006 layout_in_gaps 2 19006 NULL
119720 +huge_page_size_19008 huge_page_size 0 19008 NULL
119721 +hash_netport6_expire_19013 hash_netport6_expire 4 19013 NULL
119722 +sysfs_create_dir_ns_19033 sysfs_create_dir_ns 0 19033 NULL
119723 +revalidate_19043 revalidate 2 19043 NULL
119724 +afs_vnode_store_data_19048 afs_vnode_store_data 2-3-4-5 19048 NULL
119725 +osc_pinger_recov_seq_write_19056 osc_pinger_recov_seq_write 3 19056 NULL
119726 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
119727 +ceph_create_snap_context_19082 ceph_create_snap_context 1 19082 NULL
119728 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
119729 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
119730 +skb_gro_offset_19123 skb_gro_offset 0 19123 NULL
119731 +cma_bitmap_maxno_19135 cma_bitmap_maxno 0 19135 NULL
119732 +snd_als4k_iobase_readl_19136 snd_als4k_iobase_readl 0 19136 NULL
119733 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
119734 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
119735 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
119736 +read_extent_buffer_to_user_19189 read_extent_buffer_to_user 4-3 19189 NULL
119737 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
119738 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 0-3 19214 NULL
119739 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
119740 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
119741 +snd_mask_max_19224 snd_mask_max 0 19224 NULL
119742 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
119743 +ucma_query_19260 ucma_query 4 19260 NULL
119744 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
119745 +batadv_tt_save_orig_buffer_19288 batadv_tt_save_orig_buffer 4 19288 NULL nohasharray
119746 +cfg80211_rx_unprot_mlme_mgmt_19288 cfg80211_rx_unprot_mlme_mgmt 3 19288 &batadv_tt_save_orig_buffer_19288
119747 +qc_capture_19298 qc_capture 3 19298 NULL
119748 +ocfs2_prepare_inode_for_refcount_19303 ocfs2_prepare_inode_for_refcount 4-3 19303 NULL
119749 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
119750 +debug_read_19322 debug_read 3 19322 NULL
119751 +lbs_host_sleep_write_19332 lbs_host_sleep_write 3 19332 NULL nohasharray
119752 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 &lbs_host_sleep_write_19332
119753 +closure_sub_19359 closure_sub 2 19359 NULL
119754 +firmware_data_write_19360 firmware_data_write 6-5 19360 NULL
119755 +read_zero_19366 read_zero 3 19366 NULL
119756 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
119757 +sync_fill_pt_info_19397 sync_fill_pt_info 0 19397 NULL
119758 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
119759 +hid_hw_raw_request_19408 hid_hw_raw_request 0 19408 NULL
119760 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
119761 +SyS_sched_getaffinity_19444 SyS_sched_getaffinity 2 19444 NULL
119762 +xfrm_alg_auth_len_19454 xfrm_alg_auth_len 0 19454 NULL
119763 +gnet_stats_copy_19458 gnet_stats_copy 4 19458 NULL
119764 +gp2ap020a00f_get_thresh_reg_19468 gp2ap020a00f_get_thresh_reg 0 19468 NULL
119765 +sky2_read16_19475 sky2_read16 0 19475 NULL
119766 +__read_status_pciv2_19492 __read_status_pciv2 0 19492 NULL
119767 +kstrtoll_from_user_19500 kstrtoll_from_user 2 19500 NULL
119768 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
119769 +batadv_tvlv_container_register_19520 batadv_tvlv_container_register 5 19520 NULL
119770 +ttm_dma_page_pool_free_19527 ttm_dma_page_pool_free 2-0 19527 NULL
119771 +cfc_write_array_to_buffer_19529 cfc_write_array_to_buffer 3 19529 NULL
119772 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
119773 +gfn_to_index_19558 gfn_to_index 0-1-3-2 19558 NULL
119774 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
119775 +nfsd_read_19568 nfsd_read 5 19568 NULL
119776 +ieee80211_key_alloc_19575 ieee80211_key_alloc 3 19575 NULL
119777 +bm_status_read_19583 bm_status_read 3 19583 NULL
119778 +load_xattr_datum_19594 load_xattr_datum 0 19594 NULL
119779 +drbg_sec_strength_19604 drbg_sec_strength 0 19604 NULL
119780 +__mei_cl_recv_19636 __mei_cl_recv 3 19636 NULL
119781 +parser_init_19651 parser_init 2 19651 NULL
119782 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
119783 +memblock_virt_alloc_low_nopanic_19714 memblock_virt_alloc_low_nopanic 1 19714 NULL
119784 +read_reg_19723 read_reg 0 19723 NULL
119785 +wm8350_block_write_19727 wm8350_block_write 2-3 19727 NULL
119786 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
119787 +snd_es1968_get_dma_ptr_19747 snd_es1968_get_dma_ptr 0 19747 NULL
119788 +p9_client_read_19750 p9_client_read 5-0 19750 NULL
119789 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
119790 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
119791 +jffs2_acl_from_medium_19762 jffs2_acl_from_medium 2 19762 NULL
119792 +readhscx_19769 readhscx 0 19769 NULL
119793 +ath10k_write_htt_max_amsdu_ampdu_19820 ath10k_write_htt_max_amsdu_ampdu 3 19820 NULL
119794 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
119795 +vfs_getxattr_19832 vfs_getxattr 0 19832 NULL
119796 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
119797 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
119798 +__nla_put_19857 __nla_put 3 19857 NULL
119799 +mrp_request_join_19882 mrp_request_join 4 19882 NULL
119800 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
119801 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
119802 +mangle_name_19923 mangle_name 0 19923 NULL
119803 +cgroup_task_count_19930 cgroup_task_count 0 19930 NULL
119804 +guest_read_tsc_19931 guest_read_tsc 0 19931 NULL
119805 +azx_get_pos_lpib_19933 azx_get_pos_lpib 0 19933 NULL
119806 +v4l2_ctrl_new_19942 v4l2_ctrl_new 8-12 19942 NULL
119807 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
119808 +cfg80211_rx_assoc_resp_19944 cfg80211_rx_assoc_resp 4 19944 NULL
119809 +ll_xattr_cache_list_19954 ll_xattr_cache_list 0 19954 NULL
119810 +get_jack_mode_name_19976 get_jack_mode_name 4 19976 NULL
119811 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
119812 +rtw_set_wps_probe_resp_19989 rtw_set_wps_probe_resp 3 19989 NULL
119813 +lustre_pack_request_19992 lustre_pack_request 3 19992 NULL
119814 +find_overflow_devnum_19995 find_overflow_devnum 0 19995 NULL
119815 +diva_um_idi_read_20003 diva_um_idi_read 0 20003 NULL
119816 +lov_stripe_md_size_20009 lov_stripe_md_size 0-1 20009 NULL nohasharray
119817 +event_trigger_write_20009 event_trigger_write 3 20009 &lov_stripe_md_size_20009
119818 +tree_mod_log_eb_move_20011 tree_mod_log_eb_move 5 20011 NULL
119819 +SYSC_fgetxattr_20027 SYSC_fgetxattr 4 20027 NULL
119820 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
119821 +iwl_mvm_power_mac_dbgfs_read_20067 iwl_mvm_power_mac_dbgfs_read 0-4 20067 NULL
119822 +target_message_20072 target_message 2 20072 NULL
119823 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
119824 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
119825 +aat2870_reg_write_file_20086 aat2870_reg_write_file 3 20086 NULL
119826 +team_options_register_20091 team_options_register 3 20091 NULL
119827 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
119828 +root_nfs_copy_20111 root_nfs_copy 3 20111 NULL
119829 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
119830 +ext4_ext_direct_IO_20165 ext4_ext_direct_IO 4 20165 NULL
119831 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
119832 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
119833 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
119834 +crystalhd_map_dio_20181 crystalhd_map_dio 3 20181 NULL
119835 +pvr2_ctrl_value_to_sym_20229 pvr2_ctrl_value_to_sym 5 20229 NULL
119836 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
119837 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
119838 +btrfs_header_nritems_20296 btrfs_header_nritems 0 20296 NULL
119839 +r10_sync_page_io_20307 r10_sync_page_io 3 20307 NULL
119840 +dm_get_reserved_bio_based_ios_20315 dm_get_reserved_bio_based_ios 0 20315 NULL
119841 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
119842 +vx_send_msg_nolock_20322 vx_send_msg_nolock 0 20322 NULL
119843 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
119844 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
119845 +handle_arr_calc_size_20355 handle_arr_calc_size 0-1 20355 NULL
119846 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
119847 +snd_nm256_readl_20394 snd_nm256_readl 0 20394 NULL
119848 +SyS_get_mempolicy_20399 SyS_get_mempolicy 3 20399 NULL nohasharray
119849 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 &SyS_get_mempolicy_20399
119850 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
119851 +read_buf_20469 read_buf 2 20469 NULL
119852 +bio_trim_20472 bio_trim 2 20472 NULL
119853 +btrfs_get_32_20476 btrfs_get_32 0 20476 NULL
119854 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
119855 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
119856 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
119857 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
119858 +venus_create_20555 venus_create 4 20555 NULL
119859 +btrfs_super_log_root_20565 btrfs_super_log_root 0 20565 NULL
119860 +crypto_ahash_reqsize_20569 crypto_ahash_reqsize 0 20569 NULL
119861 +kvm_test_age_hva_20593 kvm_test_age_hva 2 20593 NULL
119862 +set_secure_conn_20596 set_secure_conn 4 20596 NULL
119863 +sync_timeline_create_20601 sync_timeline_create 2 20601 NULL
119864 +lirc_write_20604 lirc_write 3 20604 NULL
119865 +qib_qsfp_write_20614 qib_qsfp_write 0-4-2 20614 NULL
119866 +snd_pcm_oss_prepare_20641 snd_pcm_oss_prepare 0 20641 NULL
119867 +get_extent_skip_holes_20642 get_extent_skip_holes 2 20642 NULL
119868 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3-4 20646 NULL
119869 +cpulist_scnprintf_20648 cpulist_scnprintf 2-0 20648 NULL
119870 +oz_add_farewell_20652 oz_add_farewell 5 20652 NULL
119871 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
119872 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL
119873 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 0-4 20682 NULL
119874 +cpumask_size_20683 cpumask_size 0 20683 NULL
119875 +btrfs_node_blockptr_20685 btrfs_node_blockptr 0 20685 NULL
119876 +xpcs_reg_addr_write_20694 xpcs_reg_addr_write 3 20694 NULL
119877 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
119878 +__maestro_read_20700 __maestro_read 0 20700 NULL
119879 +cipso_v4_gentag_rng_20703 cipso_v4_gentag_rng 0 20703 NULL
119880 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
119881 +hfs_direct_IO_20714 hfs_direct_IO 4 20714 NULL
119882 +ocfs2_read_xattr_bucket_20722 ocfs2_read_xattr_bucket 0 20722 NULL
119883 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
119884 +fb_prepare_logo_20743 fb_prepare_logo 0 20743 NULL
119885 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
119886 +ocfs2_align_bytes_to_clusters_20754 ocfs2_align_bytes_to_clusters 2 20754 NULL
119887 +brcmf_p2p_escan_20763 brcmf_p2p_escan 2 20763 NULL
119888 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
119889 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
119890 +edid_write_20797 edid_write 3 20797 NULL
119891 +lowpan_write_20800 lowpan_write 3 20800 NULL
119892 +strndup_user_20819 strndup_user 2 20819 NULL
119893 +tipc_msg_build_20825 tipc_msg_build 3 20825 NULL
119894 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
119895 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
119896 +p9_tag_alloc_20845 p9_tag_alloc 3 20845 NULL
119897 +nvme_trans_supported_vpd_pages_20847 nvme_trans_supported_vpd_pages 4 20847 NULL
119898 +get_name_20855 get_name 4 20855 NULL
119899 +iwl_dbgfs_pm_params_read_20866 iwl_dbgfs_pm_params_read 3 20866 NULL
119900 +snd_pcm_capture_avail_20867 snd_pcm_capture_avail 0 20867 NULL
119901 +srq_free_res_20868 srq_free_res 5 20868 NULL
119902 +cfs_cpt_table_create_20884 cfs_cpt_table_create 1 20884 NULL
119903 +req_capsule_filled_sizes_20888 req_capsule_filled_sizes 0 20888 NULL
119904 +rb_simple_write_20890 rb_simple_write 3 20890 NULL
119905 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
119906 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
119907 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
119908 +lbs_rdbbp_write_20918 lbs_rdbbp_write 3 20918 NULL
119909 +htable_bits_20933 htable_bits 0 20933 NULL
119910 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
119911 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
119912 +rsxx_cram_read_20957 rsxx_cram_read 3 20957 NULL
119913 +nfs_map_name_to_uid_20962 nfs_map_name_to_uid 3 20962 NULL
119914 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
119915 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
119916 +qib_verbs_send_20999 qib_verbs_send 5-3 20999 NULL
119917 +btrfs_inode_ref_name_len_21024 btrfs_inode_ref_name_len 0 21024 NULL
119918 +arch_gnttab_init_21030 arch_gnttab_init 1 21030 NULL
119919 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
119920 +srp_change_queue_depth_21038 srp_change_queue_depth 2 21038 NULL
119921 +fsl_edma_prep_dma_cyclic_21042 fsl_edma_prep_dma_cyclic 4-3 21042 NULL
119922 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
119923 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
119924 +qdisc_get_default_21072 qdisc_get_default 2 21072 NULL
119925 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
119926 +bl_add_page_to_bio_21094 bl_add_page_to_bio 2 21094 NULL nohasharray
119927 +multipath_status_21094 multipath_status 5 21094 &bl_add_page_to_bio_21094
119928 +rate_control_pid_events_read_21099 rate_control_pid_events_read 3 21099 NULL
119929 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
119930 +_efx_mcdi_rpc_async_21119 _efx_mcdi_rpc_async 4-5 21119 NULL
119931 +i2400m_rx_trace_21127 i2400m_rx_trace 3 21127 NULL
119932 +mei_dbgfs_read_active_21172 mei_dbgfs_read_active 3 21172 NULL
119933 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
119934 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
119935 +scsi_execute_req_flags_21215 scsi_execute_req_flags 5 21215 NULL
119936 +get_numpages_21227 get_numpages 0-1-2 21227 NULL
119937 +input_ff_create_21240 input_ff_create 2 21240 NULL
119938 +cfg80211_notify_new_peer_candidate_21242 cfg80211_notify_new_peer_candidate 4 21242 NULL
119939 +fru_length_21257 fru_length 0 21257 NULL
119940 +rtw_set_wps_beacon_21262 rtw_set_wps_beacon 3 21262 NULL
119941 +ocfs2_blocks_for_bytes_21268 ocfs2_blocks_for_bytes 0-2 21268 NULL
119942 +drm_universal_plane_init_21296 drm_universal_plane_init 6 21296 NULL
119943 +do_msg_fill_21307 do_msg_fill 3 21307 NULL
119944 +add_res_range_21310 add_res_range 4 21310 NULL
119945 +get_zeroed_page_21322 get_zeroed_page 0 21322 NULL
119946 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
119947 +read_file_bool_bmps_21344 read_file_bool_bmps 3 21344 NULL
119948 +azx_get_delay_from_lpib_21348 azx_get_delay_from_lpib 3 21348 NULL
119949 +gfs2_ea_get_copy_21353 gfs2_ea_get_copy 0 21353 NULL
119950 +allocate_cmdlines_buffer_21355 allocate_cmdlines_buffer 1 21355 NULL
119951 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
119952 +SYSC_rt_sigpending_21379 SYSC_rt_sigpending 2 21379 NULL
119953 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
119954 +insert_ptr_21386 insert_ptr 6 21386 NULL
119955 +diva_get_driver_dbg_mask_21399 diva_get_driver_dbg_mask 0 21399 NULL
119956 +snd_m3_inw_21406 snd_m3_inw 0 21406 NULL
119957 +usnic_ib_dump_vf_hdr_21423 usnic_ib_dump_vf_hdr 3 21423 NULL
119958 +snapshot_read_next_21426 snapshot_read_next 0 21426 NULL
119959 +tcp_bound_to_half_wnd_21429 tcp_bound_to_half_wnd 0-2 21429 NULL
119960 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
119961 +nouveau_clock_create__21449 nouveau_clock_create_ 8 21449 NULL
119962 +__ertm_hdr_size_21450 __ertm_hdr_size 0 21450 NULL
119963 +mei_nfc_send_21477 mei_nfc_send 3 21477 NULL
119964 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
119965 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
119966 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
119967 +cipso_v4_map_cat_enum_hton_21540 cipso_v4_map_cat_enum_hton 0 21540 NULL
119968 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
119969 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
119970 +xfs_buf_read_uncached_21585 xfs_buf_read_uncached 3 21585 NULL
119971 +snd_es18xx_mixer_read_21586 snd_es18xx_mixer_read 0 21586 NULL
119972 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
119973 +filemap_get_page_21606 filemap_get_page 2 21606 NULL
119974 +ocfs2_refcount_cow_hunk_21630 ocfs2_refcount_cow_hunk 3-4 21630 NULL
119975 +__jfs_getxattr_21631 __jfs_getxattr 0 21631 NULL
119976 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
119977 +ocfs2_xattr_get_nolock_21678 ocfs2_xattr_get_nolock 0 21678 NULL
119978 +regmap_register_patch_21681 regmap_register_patch 3 21681 NULL
119979 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1 21687 NULL
119980 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
119981 +unix_skb_len_21722 unix_skb_len 0 21722 NULL
119982 +lprocfs_wr_import_21728 lprocfs_wr_import 3 21728 NULL
119983 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
119984 +usbat_flash_read_data_21762 usbat_flash_read_data 4 21762 NULL
119985 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
119986 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
119987 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
119988 +_iwl_dbgfs_sta_drain_write_21837 _iwl_dbgfs_sta_drain_write 3 21837 NULL
119989 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
119990 +lpfc_idiag_extacc_avail_get_21865 lpfc_idiag_extacc_avail_get 0-3 21865 NULL
119991 +brcms_debugfs_hardware_read_21867 brcms_debugfs_hardware_read 3 21867 NULL
119992 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
119993 +ldlm_lock_create_21888 ldlm_lock_create 7 21888 NULL
119994 +__btrfs_direct_write_21894 __btrfs_direct_write 3 21894 NULL
119995 +dbAllocCtl_21911 dbAllocCtl 0 21911 NULL
119996 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
119997 +twl_i2c_write_u16_21953 twl_i2c_write_u16 3 21953 NULL
119998 +__build_xattrs_21979 __build_xattrs 0 21979 NULL
119999 +SYSC_prctl_21980 SYSC_prctl 4 21980 NULL
120000 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 0-3 22001 NULL nohasharray
120001 +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
120002 +regcache_sync_block_raw_flush_22021 regcache_sync_block_raw_flush 3-4 22021 NULL
120003 +btrfs_get_16_22023 btrfs_get_16 0 22023 NULL
120004 +_sp2d_min_pg_22032 _sp2d_min_pg 0 22032 NULL
120005 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
120006 +ieee80211_if_fmt_dropped_frames_ttl_22054 ieee80211_if_fmt_dropped_frames_ttl 3 22054 NULL
120007 +btrfs_reloc_clone_csums_22077 btrfs_reloc_clone_csums 2-3 22077 NULL
120008 +mem_rw_22085 mem_rw 3 22085 NULL
120009 +kstrtos32_from_user_22087 kstrtos32_from_user 2 22087 NULL
120010 +rt2x00debug_read_crypto_stats_22109 rt2x00debug_read_crypto_stats 3 22109 NULL
120011 +snd_hda_codec_read_22130 snd_hda_codec_read 0 22130 NULL
120012 +SyS_sched_setaffinity_22148 SyS_sched_setaffinity 2 22148 NULL
120013 +do_tcp_sendpages_22155 do_tcp_sendpages 4 22155 NULL
120014 +nve0_aux_mask_22158 nve0_aux_mask 2 22158 NULL
120015 +__kfifo_alloc_22173 __kfifo_alloc 3 22173 NULL
120016 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
120017 +mem_write_22232 mem_write 3 22232 NULL
120018 +p9_virtio_zc_request_22240 p9_virtio_zc_request 6-5 22240 NULL
120019 +prepare_to_wait_event_22247 prepare_to_wait_event 0 22247 NULL
120020 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
120021 +ping_common_sendmsg_22261 ping_common_sendmsg 5 22261 NULL
120022 +add_res_tree_22263 add_res_tree 7 22263 NULL
120023 +queue_max_sectors_22280 queue_max_sectors 0 22280 NULL
120024 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL nohasharray
120025 +pci_vpd_srdt_size_22300 pci_vpd_srdt_size 0 22300 &__tun_chr_ioctl_22300
120026 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
120027 +lov_setstripe_22307 lov_setstripe 2 22307 NULL
120028 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
120029 +C_SYSC_msgrcv_22320 C_SYSC_msgrcv 3 22320 NULL
120030 +atomic_read_22342 atomic_read 0 22342 NULL
120031 +ll_lazystatfs_seq_write_22353 ll_lazystatfs_seq_write 3 22353 NULL
120032 +snd_pcm_alsa_frames_22363 snd_pcm_alsa_frames 2 22363 NULL
120033 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
120034 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
120035 +zoran_write_22404 zoran_write 3 22404 NULL
120036 +queue_reply_22416 queue_reply 3 22416 NULL
120037 +__set_enter_print_fmt_22431 __set_enter_print_fmt 0 22431 NULL
120038 +queue_max_segments_22441 queue_max_segments 0 22441 NULL
120039 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
120040 +ecryptfs_write_22488 ecryptfs_write 4-3 22488 NULL
120041 +qib_user_sdma_alloc_header_22490 qib_user_sdma_alloc_header 2 22490 NULL
120042 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
120043 +mutex_lock_interruptible_22505 mutex_lock_interruptible 0 22505 NULL
120044 +trim_no_bitmap_22524 trim_no_bitmap 4-3 22524 NULL
120045 +ocfs2_read_extent_block_22550 ocfs2_read_extent_block 0 22550 NULL
120046 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
120047 +dbFindCtl_22587 dbFindCtl 0 22587 NULL
120048 +cfs_expr_list_values_22600 cfs_expr_list_values 0 22600 NULL
120049 +snapshot_read_22601 snapshot_read 3 22601 NULL
120050 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
120051 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
120052 +wl1271_rx_filter_get_fields_size_22638 wl1271_rx_filter_get_fields_size 0 22638 NULL
120053 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
120054 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
120055 +compat_SyS_msgrcv_22661 compat_SyS_msgrcv 3 22661 NULL
120056 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
120057 +bch_dump_read_22685 bch_dump_read 3 22685 NULL
120058 +reg_umr_22686 reg_umr 5 22686 NULL
120059 +SYSC_vmsplice_22697 SYSC_vmsplice 3 22697 NULL
120060 +nr_cpusets_22705 nr_cpusets 0 22705 NULL
120061 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
120062 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4-0 22735 NULL
120063 +ceph_decode_32_22738 ceph_decode_32 0 22738 NULL nohasharray
120064 +__mei_cl_send_22738 __mei_cl_send 3 22738 &ceph_decode_32_22738
120065 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
120066 +qlcnic_sriov_init_22762 qlcnic_sriov_init 2 22762 NULL
120067 +print_frame_22769 print_frame 0 22769 NULL
120068 +ftrace_arch_read_dyn_info_22773 ftrace_arch_read_dyn_info 0 22773 NULL
120069 +vnic_dev_get_res_count_22791 vnic_dev_get_res_count 0 22791 NULL
120070 +__generic_copy_to_user_intel_22806 __generic_copy_to_user_intel 0-3 22806 NULL
120071 +create_attr_set_22861 create_attr_set 1 22861 NULL
120072 +hash_ip6_expire_22867 hash_ip6_expire 4 22867 NULL
120073 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
120074 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
120075 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
120076 +ion_handle_test_kernel_22900 ion_handle_test_kernel 4-3 22900 NULL nohasharray
120077 +policy_emit_config_values_22900 policy_emit_config_values 3 22900 &ion_handle_test_kernel_22900
120078 +nfs4_acl_bytes_22915 nfs4_acl_bytes 0-1 22915 NULL
120079 +__set_xattr_22923 __set_xattr 0 22923 NULL
120080 +xstateregs_set_22932 xstateregs_set 4 22932 NULL
120081 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
120082 +alloc_sglist_22960 alloc_sglist 2-3 22960 NULL
120083 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
120084 +vme_get_size_22964 vme_get_size 0 22964 NULL
120085 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
120086 +cached_dev_cache_miss_22979 cached_dev_cache_miss 4 22979 NULL
120087 +usb_get_langid_22983 usb_get_langid 0 22983 NULL
120088 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
120089 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
120090 +cifs_local_to_utf16_bytes_23025 cifs_local_to_utf16_bytes 0 23025 NULL
120091 +ocfs2_refcount_cow_xattr_23029 ocfs2_refcount_cow_xattr 6-7 23029 NULL
120092 +st_status_23032 st_status 5 23032 NULL
120093 +nv50_disp_chan_create__23056 nv50_disp_chan_create_ 5 23056 NULL
120094 +comedi_buf_write_n_available_23057 comedi_buf_write_n_available 0 23057 NULL
120095 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
120096 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
120097 +mei_cl_send_23068 mei_cl_send 3 23068 NULL
120098 +kvm_mmu_gva_to_gpa_write_23075 kvm_mmu_gva_to_gpa_write 0 23075 NULL
120099 +raw_sendmsg_23078 raw_sendmsg 4 23078 NULL
120100 +get_user_hdr_len_23079 get_user_hdr_len 0 23079 NULL
120101 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
120102 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
120103 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
120104 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
120105 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
120106 +bset_tree_bytes_23111 bset_tree_bytes 0 23111 NULL nohasharray
120107 +nl80211_send_rx_auth_23111 nl80211_send_rx_auth 4 23111 &bset_tree_bytes_23111
120108 +__clear_user_23118 __clear_user 0-2 23118 NULL
120109 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
120110 +ata_scsi_change_queue_depth_23126 ata_scsi_change_queue_depth 2 23126 NULL
120111 +read_file_ani_23161 read_file_ani 3 23161 NULL
120112 +usblp_write_23178 usblp_write 3 23178 NULL
120113 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
120114 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
120115 +tipc_sendmcast_23214 tipc_sendmcast 4 23214 NULL
120116 +nft_hash_tbl_alloc_23224 nft_hash_tbl_alloc 1 23224 NULL
120117 +tty_buffer_request_room_23228 tty_buffer_request_room 2-0 23228 NULL
120118 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL nohasharray
120119 +__read_status_pci_23229 __read_status_pci 0 23229 &xlog_get_bp_23229
120120 +ft1000_read_dpram_mag_32_23232 ft1000_read_dpram_mag_32 0 23232 NULL
120121 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
120122 +__gfn_to_rmap_23240 __gfn_to_rmap 1-2 23240 NULL
120123 +nv50_ram_create__23241 nv50_ram_create_ 4 23241 NULL
120124 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
120125 +uwb_dev_addr_print_23282 uwb_dev_addr_print 2 23282 NULL
120126 +ec_i2c_count_message_23285 ec_i2c_count_message 0-2 23285 NULL
120127 +diva_get_trace_filter_23286 diva_get_trace_filter 0 23286 NULL
120128 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
120129 +__aa_kvmalloc_23320 __aa_kvmalloc 1 23320 NULL
120130 +page_readlink_23346 page_readlink 3 23346 NULL
120131 +kmem_zalloc_large_23351 kmem_zalloc_large 1 23351 NULL
120132 +get_dst_timing_23358 get_dst_timing 0 23358 NULL
120133 +fd_setup_write_same_buf_23369 fd_setup_write_same_buf 3 23369 NULL
120134 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
120135 +ocfs2_zero_tail_23447 ocfs2_zero_tail 3 23447 NULL
120136 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
120137 +__ata_change_queue_depth_23484 __ata_change_queue_depth 3 23484 NULL
120138 +linear_conf_23485 linear_conf 2 23485 NULL
120139 +event_filter_read_23494 event_filter_read 3 23494 NULL
120140 +lustre_acl_xattr_merge2ext_23502 lustre_acl_xattr_merge2ext 2 23502 NULL
120141 +devm_iio_device_alloc_23511 devm_iio_device_alloc 2 23511 NULL
120142 +__proc_cpt_table_23516 __proc_cpt_table 5 23516 NULL
120143 +hash_ipmark6_expire_23518 hash_ipmark6_expire 4 23518 NULL
120144 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
120145 +tcp_current_mss_23552 tcp_current_mss 0 23552 NULL
120146 +btrfs_super_bytenr_23561 btrfs_super_bytenr 0 23561 NULL
120147 +venus_symlink_23570 venus_symlink 6-4 23570 NULL
120148 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
120149 +xfpregs_get_23586 xfpregs_get 4 23586 NULL
120150 +snd_interval_min_23590 snd_interval_min 0 23590 NULL
120151 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
120152 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
120153 +sInW_23663 sInW 0 23663 NULL
120154 +SyS_connect_23669 SyS_connect 3 23669 NULL
120155 +cx18_read_23699 cx18_read 3 23699 NULL
120156 +at_get_23708 at_get 0 23708 NULL
120157 +get_conn_info_23723 get_conn_info 4 23723 NULL
120158 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
120159 +__kfifo_max_r_23768 __kfifo_max_r 0-2-1 23768 NULL
120160 +__build_packet_message_23778 __build_packet_message 4-10 23778 NULL
120161 +security_inode_getxattr_23781 security_inode_getxattr 0 23781 NULL
120162 +cfg80211_inform_bss_width_frame_23782 cfg80211_inform_bss_width_frame 5 23782 NULL
120163 +mpt_free_res_23793 mpt_free_res 5 23793 NULL
120164 +map_write_23795 map_write 3 23795 NULL
120165 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
120166 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
120167 +lustre_msg_buflen_23827 lustre_msg_buflen 0 23827 NULL
120168 +pgdat_end_pfn_23842 pgdat_end_pfn 0 23842 NULL
120169 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
120170 +p54_init_common_23850 p54_init_common 1 23850 NULL
120171 +bin_to_hex_dup_23853 bin_to_hex_dup 2 23853 NULL
120172 +ocfs2_xattr_get_clusters_23857 ocfs2_xattr_get_clusters 0 23857 NULL
120173 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
120174 +tipc_snprintf_23893 tipc_snprintf 2-0 23893 NULL
120175 +iov_iter_get_pages_alloc_23903 iov_iter_get_pages_alloc 3-0 23903 NULL
120176 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL nohasharray
120177 +ieee80211_if_read_hw_queues_23911 ieee80211_if_read_hw_queues 3 23911 &add_new_gdb_meta_bg_23911
120178 +f2fs_getxattr_23917 f2fs_getxattr 0 23917 NULL
120179 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 NULL nohasharray
120180 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 &ipath_reg_phys_mr_23918
120181 +kvm_read_guest_23928 kvm_read_guest 4-2 23928 NULL
120182 +uvc_endpoint_max_bpi_23944 uvc_endpoint_max_bpi 0 23944 NULL
120183 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
120184 +size_roundup_power2_23958 size_roundup_power2 0-1 23958 NULL
120185 +sddr55_write_data_23983 sddr55_write_data 4 23983 NULL
120186 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
120187 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
120188 +give_pages_24021 give_pages 3 24021 NULL
120189 +adis16400_show_serial_number_24037 adis16400_show_serial_number 3 24037 NULL
120190 +hmac_setkey_24043 hmac_setkey 3 24043 NULL
120191 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
120192 +iwl_dbgfs_low_latency_read_24062 iwl_dbgfs_low_latency_read 3 24062 NULL
120193 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
120194 +C_SYSC_process_vm_writev_24102 C_SYSC_process_vm_writev 3-5 24102 NULL
120195 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
120196 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
120197 +lov_brw_24122 lov_brw 4 24122 NULL
120198 +mpu401_read_24126 mpu401_read 3 24126 NULL
120199 +_picolcd_flash_write_24134 _picolcd_flash_write 4 24134 NULL
120200 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
120201 +SyS_sethostname_24150 SyS_sethostname 2 24150 NULL
120202 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
120203 +adu_read_24177 adu_read 3 24177 NULL
120204 +safe_prepare_write_buffer_24187 safe_prepare_write_buffer 3 24187 NULL
120205 +nv94_aux_24197 nv94_aux 3-6 24197 NULL
120206 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
120207 +tcpprobe_sprint_24222 tcpprobe_sprint 0-2 24222 NULL
120208 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 3-2-1 24224 NULL nohasharray
120209 +mei_amthif_read_24224 mei_amthif_read 4 24224 &pcpu_embed_first_chunk_24224
120210 +pci_num_vf_24235 pci_num_vf 0 24235 NULL
120211 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
120212 +em28xx_alloc_urbs_24260 em28xx_alloc_urbs 4-6 24260 NULL
120213 +calculate_sizes_24273 calculate_sizes 2 24273 NULL
120214 +thin_status_24278 thin_status 5 24278 NULL
120215 +msg_size_24288 msg_size 0 24288 NULL
120216 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
120217 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
120218 +si476x_radio_read_acf_blob_24336 si476x_radio_read_acf_blob 3 24336 NULL
120219 +C_SYSC_pwritev_24345 C_SYSC_pwritev 3 24345 NULL
120220 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
120221 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
120222 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
120223 +btrfs_item_size_nr_24367 btrfs_item_size_nr 0 24367 NULL
120224 +igetword_24373 igetword 0 24373 NULL
120225 +mpt_alloc_res_24387 mpt_alloc_res 5 24387 NULL
120226 +osc_cur_grant_bytes_seq_write_24396 osc_cur_grant_bytes_seq_write 3 24396 NULL
120227 +getxattr_24398 getxattr 4 24398 NULL nohasharray
120228 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 &getxattr_24398
120229 +blk_update_bidi_request_24415 blk_update_bidi_request 3-4 24415 NULL
120230 +nvme_trans_log_supp_pages_24418 nvme_trans_log_supp_pages 3 24418 NULL
120231 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
120232 +xenbus_file_read_24427 xenbus_file_read 3 24427 NULL
120233 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
120234 +copy_and_ioctl_24434 copy_and_ioctl 4 24434 NULL
120235 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
120236 +smk_user_access_24440 smk_user_access 3 24440 NULL nohasharray
120237 +rtw_set_wps_assoc_resp_24440 rtw_set_wps_assoc_resp 3 24440 &smk_user_access_24440
120238 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
120239 +lbs_highsnr_write_24460 lbs_highsnr_write 3 24460 NULL
120240 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
120241 +dut_mode_read_24489 dut_mode_read 3 24489 NULL
120242 +read_file_spec_scan_ctl_24491 read_file_spec_scan_ctl 3 24491 NULL
120243 +pd_video_read_24510 pd_video_read 3 24510 NULL
120244 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
120245 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
120246 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
120247 +write_cache_pages_24562 write_cache_pages 0 24562 NULL
120248 +SyS_pselect6_24582 SyS_pselect6 1 24582 NULL
120249 +udf_compute_nr_groups_24594 udf_compute_nr_groups 0 24594 NULL
120250 +sensor_hub_get_physical_device_count_24605 sensor_hub_get_physical_device_count 0 24605 NULL nohasharray
120251 +lov_alloc_memmd_24605 lov_alloc_memmd 2 24605 &sensor_hub_get_physical_device_count_24605
120252 +SyS_poll_24620 SyS_poll 2 24620 NULL
120253 +context_alloc_24645 context_alloc 3 24645 NULL
120254 +blk_rq_err_bytes_24650 blk_rq_err_bytes 0 24650 NULL
120255 +datafab_write_data_24696 datafab_write_data 4 24696 NULL
120256 +intelfbhw_get_p1p2_24703 intelfbhw_get_p1p2 2 24703 NULL
120257 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
120258 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
120259 +get_dma_residue_24749 get_dma_residue 0 24749 NULL
120260 +ocfs2_cow_file_pos_24751 ocfs2_cow_file_pos 3 24751 NULL
120261 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
120262 +ocfs2_read_blocks_24777 ocfs2_read_blocks 0 24777 NULL
120263 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
120264 +cache_read_24790 cache_read 3 24790 NULL
120265 +user_regset_copyout_24796 user_regset_copyout 7 24796 NULL
120266 +kvm_read_guest_virt_helper_24804 kvm_read_guest_virt_helper 3-1 24804 NULL
120267 +ath6kl_fwlog_mask_write_24810 ath6kl_fwlog_mask_write 3 24810 NULL
120268 +snd_als4k_gcr_read_24840 snd_als4k_gcr_read 0 24840 NULL
120269 +snd_pcm_lib_buffer_bytes_24865 snd_pcm_lib_buffer_bytes 0 24865 NULL
120270 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
120271 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
120272 +queues_read_24877 queues_read 3 24877 NULL
120273 +iov_iter_npages_bvec_24905 iov_iter_npages_bvec 0-2 24905 NULL
120274 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
120275 +xpcs_reg_value_write_24922 xpcs_reg_value_write 3 24922 NULL
120276 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL
120277 +ocfs2_fiemap_24949 ocfs2_fiemap 4-3 24949 NULL
120278 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
120279 +twl_i2c_write_u8_24976 twl_i2c_write_u8 3 24976 NULL
120280 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
120281 +info_debugfs_read_helper_24988 info_debugfs_read_helper 0 24988 NULL
120282 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
120283 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
120284 +ni_660x_num_counters_25031 ni_660x_num_counters 0 25031 NULL
120285 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
120286 +load_unaligned_zeropad_25050 load_unaligned_zeropad 0 25050 NULL
120287 +btrfs_stack_key_blockptr_25058 btrfs_stack_key_blockptr 0 25058 NULL
120288 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
120289 +ll_track_pid_seq_write_25068 ll_track_pid_seq_write 3 25068 NULL
120290 +SYSC_listxattr_25072 SYSC_listxattr 3 25072 NULL
120291 +ima_appraise_measurement_25093 ima_appraise_measurement 6 25093 NULL
120292 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
120293 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
120294 +kvm_mmu_notifier_change_pte_25169 kvm_mmu_notifier_change_pte 3 25169 NULL
120295 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
120296 +security_socket_post_create_25221 security_socket_post_create 0 25221 NULL
120297 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
120298 +stripe_status_25259 stripe_status 5 25259 NULL
120299 +snd_pcm_start_25273 snd_pcm_start 0 25273 NULL
120300 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
120301 +vfs_writev_25278 vfs_writev 3 25278 NULL
120302 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
120303 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 NULL
120304 +rng_buffer_size_25348 rng_buffer_size 0 25348 NULL
120305 +SYSC_kexec_load_25361 SYSC_kexec_load 2 25361 NULL
120306 +unix_mkname_25368 unix_mkname 0-2 25368 NULL
120307 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
120308 +vsp1_entity_init_25407 vsp1_entity_init 3 25407 NULL
120309 +mcp795_rtcc_read_25415 mcp795_rtcc_read 4 25415 NULL
120310 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
120311 +ipath_decode_err_25468 ipath_decode_err 3 25468 NULL
120312 +crypto_hash_digestsize_25469 crypto_hash_digestsize 0 25469 NULL
120313 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4-0 25502 NULL
120314 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
120315 +mxt_obj_size_25510 mxt_obj_size 0 25510 NULL
120316 +sb_permission_25523 sb_permission 0 25523 NULL
120317 +ext3_get_inode_loc_25542 ext3_get_inode_loc 0 25542 NULL
120318 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
120319 +wimax_addr_scnprint_25548 wimax_addr_scnprint 2 25548 NULL
120320 +ht_print_chan_25556 ht_print_chan 0-3-4 25556 NULL
120321 +skb_tailroom_25567 skb_tailroom 0 25567 NULL
120322 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
120323 +copy_user_generic_25611 copy_user_generic 0 25611 NULL
120324 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
120325 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL nohasharray
120326 +__get_user_pages_25628 __get_user_pages 0 25628 &befs_utf2nls_25628
120327 +__direct_map_25647 __direct_map 6-5 25647 NULL
120328 +aircable_prepare_write_buffer_25669 aircable_prepare_write_buffer 3 25669 NULL
120329 +lpfc_idiag_cmd_get_25672 lpfc_idiag_cmd_get 2 25672 NULL
120330 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
120331 +prom_early_alloc_25692 prom_early_alloc 1 25692 NULL
120332 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
120333 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
120334 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 NULL nohasharray
120335 +sel_write_context_25726 sel_write_context 3 25726 &__alloc_bootmem_low_node_25726
120336 +xgbe_common_read_25743 xgbe_common_read 2 25743 NULL
120337 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
120338 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
120339 +sg_read_25799 sg_read 3 25799 NULL
120340 +system_enable_read_25815 system_enable_read 3 25815 NULL
120341 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
120342 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
120343 +parport_read_25855 parport_read 0 25855 NULL
120344 +xfs_dir2_sf_hdr_size_25858 xfs_dir2_sf_hdr_size 0 25858 NULL
120345 +key_attr_size_25865 key_attr_size 0 25865 NULL
120346 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
120347 +run_delalloc_nocow_25896 run_delalloc_nocow 3-4 25896 NULL
120348 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
120349 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
120350 +nvme_trans_mode_page_create_25908 nvme_trans_mode_page_create 7-4 25908 NULL
120351 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
120352 +rcname_read_25919 rcname_read 3 25919 NULL
120353 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
120354 +key_flags_read_25931 key_flags_read 3 25931 NULL
120355 +copy_play_buf_25932 copy_play_buf 3 25932 NULL
120356 +flush_25957 flush 2 25957 NULL
120357 +_regmap_multi_reg_write_25967 _regmap_multi_reg_write 3 25967 NULL
120358 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
120359 +lustre_msg_buflen_v2_25997 lustre_msg_buflen_v2 0 25997 NULL
120360 +SyS_process_vm_readv_26019 SyS_process_vm_readv 3-5 26019 NULL
120361 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
120362 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
120363 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
120364 +pri_wm_latency_write_26063 pri_wm_latency_write 3 26063 NULL
120365 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
120366 +i8042_pnp_id_to_string_26108 i8042_pnp_id_to_string 3 26108 NULL
120367 +read_sb_page_26119 read_sb_page 5 26119 NULL
120368 +ath9k_hw_name_26146 ath9k_hw_name 3 26146 NULL
120369 +copy_oldmem_page_26164 copy_oldmem_page 3 26164 NULL
120370 +gfs2_xattr_acl_get_26166 gfs2_xattr_acl_get 0 26166 NULL nohasharray
120371 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 &gfs2_xattr_acl_get_26166
120372 +disk_devt_26180 disk_devt 0 26180 NULL
120373 +ieee80211_if_fmt_dot11MeshTTL_26198 ieee80211_if_fmt_dot11MeshTTL 3 26198 NULL
120374 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
120375 +mce_write_26201 mce_write 3 26201 NULL
120376 +mwifiex_regrdwr_write_26225 mwifiex_regrdwr_write 3 26225 NULL
120377 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
120378 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
120379 +genwqe_ffdc_buff_size_26263 genwqe_ffdc_buff_size 0 26263 NULL
120380 +crypto_ctxsize_26278 crypto_ctxsize 0 26278 NULL
120381 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
120382 +snd_pcm_plug_client_channels_buf_26309 snd_pcm_plug_client_channels_buf 0-3 26309 NULL
120383 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
120384 +check_can_nocow_26336 check_can_nocow 2 26336 NULL
120385 +snd_vx_check_reg_bit_26344 snd_vx_check_reg_bit 0 26344 NULL
120386 +ocfs2_duplicate_clusters_by_page_26357 ocfs2_duplicate_clusters_by_page 6-3 26357 NULL
120387 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
120388 +invalidate_inode_pages2_range_26403 invalidate_inode_pages2_range 0 26403 NULL
120389 +ntty_write_26404 ntty_write 3 26404 NULL
120390 +firmware_store_26408 firmware_store 4 26408 NULL
120391 +pagemap_read_26441 pagemap_read 3 26441 NULL
120392 +tower_read_26461 tower_read 3 26461 NULL nohasharray
120393 +enc_pools_add_pages_26461 enc_pools_add_pages 1 26461 &tower_read_26461
120394 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
120395 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
120396 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
120397 +read_vmcore_26501 read_vmcore 3 26501 NULL
120398 +uhid_char_write_26502 uhid_char_write 3 26502 NULL
120399 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 4-3 26507 NULL
120400 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
120401 +alloc_ep_req_26521 alloc_ep_req 3-2 26521 NULL
120402 +SyS_rt_sigpending_26538 SyS_rt_sigpending 2 26538 NULL
120403 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
120404 +dio_new_bio_26562 dio_new_bio 0 26562 NULL
120405 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL
120406 +kernfs_name_locked_26617 kernfs_name_locked 3 26617 NULL
120407 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
120408 +amdtp_stream_get_max_payload_26645 amdtp_stream_get_max_payload 0 26645 NULL
120409 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL
120410 +nouveau_volt_create__26654 nouveau_volt_create_ 4 26654 NULL
120411 +cipso_v4_map_cat_rbm_hton_26680 cipso_v4_map_cat_rbm_hton 0 26680 NULL
120412 +flowinfo_read_26683 flowinfo_read 3 26683 NULL
120413 +sysfs_add_file_26716 sysfs_add_file 0 26716 NULL
120414 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
120415 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
120416 +bos_desc_26752 bos_desc 0 26752 NULL
120417 +snd_hda_get_raw_connections_26762 snd_hda_get_raw_connections 0 26762 NULL
120418 +dma_map_single_attrs_26779 dma_map_single_attrs 0 26779 NULL
120419 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
120420 +cipso_v4_genopt_26812 cipso_v4_genopt 0 26812 NULL
120421 +iwl_trans_read_mem32_26825 iwl_trans_read_mem32 0 26825 NULL
120422 +smk_write_load_26829 smk_write_load 3 26829 NULL
120423 +scnprint_id_26842 scnprint_id 3-0 26842 NULL
120424 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
120425 +ss_alloc_ep_req_26848 ss_alloc_ep_req 2 26848 NULL
120426 +tipc_conn_sendmsg_26867 tipc_conn_sendmsg 5 26867 NULL
120427 +ath6kl_create_qos_write_26879 ath6kl_create_qos_write 3 26879 NULL
120428 +svc_print_xprts_26881 svc_print_xprts 0 26881 NULL
120429 +skb_zerocopy_headlen_26910 skb_zerocopy_headlen 0 26910 NULL
120430 +hhf_zalloc_26912 hhf_zalloc 1 26912 NULL
120431 +cfg80211_process_auth_26916 cfg80211_process_auth 3 26916 NULL
120432 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
120433 +brcmf_usb_dl_cmd_26931 brcmf_usb_dl_cmd 4 26931 NULL
120434 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
120435 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 NULL nohasharray
120436 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 &sctp_setsockopt_adaptation_layer_26935
120437 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
120438 +do_trimming_26952 do_trimming 3 26952 NULL nohasharray
120439 +extract_entropy_user_26952 extract_entropy_user 3 26952 &do_trimming_26952
120440 +do_direct_IO_26979 do_direct_IO 0 26979 NULL
120441 +lustre_msg_size_26995 lustre_msg_size 2 26995 NULL
120442 +sc16is7xx_port_read_27051 sc16is7xx_port_read 0 27051 NULL
120443 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
120444 +ext4_convert_unwritten_extents_27064 ext4_convert_unwritten_extents 4-3 27064 NULL
120445 +snd_pcm_lib_period_bytes_27071 snd_pcm_lib_period_bytes 0 27071 NULL
120446 +paravirt_read_msr_27077 paravirt_read_msr 0 27077 NULL
120447 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
120448 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL nohasharray
120449 +ath9k_hw_4k_dump_eeprom_27089 ath9k_hw_4k_dump_eeprom 5-4 27089 &btmrvl_hscmd_write_27089
120450 +__devcgroup_inode_permission_27108 __devcgroup_inode_permission 0 27108 NULL
120451 +drbd_get_capacity_27141 drbd_get_capacity 0 27141 NULL
120452 +pms_capture_27142 pms_capture 4 27142 NULL
120453 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
120454 +wil_write_file_wmi_27150 wil_write_file_wmi 3 27150 NULL
120455 +snd_compr_calc_avail_27165 snd_compr_calc_avail 0 27165 NULL
120456 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
120457 +write_kmem_27225 write_kmem 3 27225 NULL nohasharray
120458 +svcxdr_tmpalloc_27225 svcxdr_tmpalloc 2 27225 &write_kmem_27225
120459 +dbAllocAG_27228 dbAllocAG 0 27228 NULL
120460 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
120461 +ll_track_gid_seq_write_27267 ll_track_gid_seq_write 3 27267 NULL
120462 +comedi_alloc_devpriv_27272 comedi_alloc_devpriv 2 27272 NULL
120463 +get_rx_fifo_content_27283 get_rx_fifo_content 0 27283 NULL
120464 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
120465 +virtqueue_add_inbuf_27312 virtqueue_add_inbuf 3 27312 NULL
120466 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3-0 27332 NULL
120467 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
120468 +iwl_dbgfs_csr_write_27363 iwl_dbgfs_csr_write 3 27363 NULL
120469 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
120470 +seq_read_27411 seq_read 3 27411 NULL
120471 +ib_dma_map_sg_27413 ib_dma_map_sg 0 27413 NULL
120472 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
120473 +ocfs2_refcount_cal_cow_clusters_27422 ocfs2_refcount_cal_cow_clusters 3-4 27422 NULL
120474 +cypress_write_27423 cypress_write 4 27423 NULL
120475 +sddr09_read_data_27447 sddr09_read_data 3 27447 NULL
120476 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
120477 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
120478 +ip_set_get_h32_27498 ip_set_get_h32 0 27498 NULL
120479 +btrfs_get_64_27499 btrfs_get_64 0 27499 NULL
120480 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
120481 +oti_alloc_cookies_27510 oti_alloc_cookies 2 27510 NULL
120482 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
120483 +snd_sonicvibes_getdmaa_27552 snd_sonicvibes_getdmaa 0 27552 NULL
120484 +SyS_fgetxattr_27571 SyS_fgetxattr 4 27571 NULL
120485 +sco_sock_recvmsg_27572 sco_sock_recvmsg 4 27572 NULL
120486 +libipw_alloc_txb_27579 libipw_alloc_txb 1 27579 NULL
120487 +C_SYSC_mbind_27636 C_SYSC_mbind 5 27636 NULL
120488 +ocfs2_xattr_ibody_get_27642 ocfs2_xattr_ibody_get 0 27642 NULL nohasharray
120489 +read_flush_procfs_27642 read_flush_procfs 3 27642 &ocfs2_xattr_ibody_get_27642 nohasharray
120490 +nl80211_send_connect_result_27642 nl80211_send_connect_result 5-7 27642 &read_flush_procfs_27642
120491 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
120492 +btrfs_fallocate_27647 btrfs_fallocate 3-4 27647 NULL
120493 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
120494 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
120495 +ocfs2_extend_dir_27695 ocfs2_extend_dir 4 27695 NULL
120496 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
120497 +evm_write_key_27715 evm_write_key 3 27715 NULL
120498 +ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol_27722 ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol 3 27722 NULL
120499 +xfs_dir2_block_sfsize_27727 xfs_dir2_block_sfsize 0 27727 NULL
120500 +load_scode_27738 load_scode 2 27738 NULL
120501 +SyS_setsockopt_27759 SyS_setsockopt 5 27759 NULL
120502 +transport_init_session_tags_27776 transport_init_session_tags 1-2 27776 NULL
120503 +__lov_setstripe_27782 __lov_setstripe 2 27782 NULL
120504 +twl4030_set_gpio_dataout_27792 twl4030_set_gpio_dataout 1 27792 NULL
120505 +SyS_readv_27804 SyS_readv 3 27804 NULL
120506 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
120507 +hpt374_read_freq_27828 hpt374_read_freq 0 27828 NULL
120508 +init_header_complete_27833 init_header_complete 0 27833 NULL
120509 +read_profile_27859 read_profile 3 27859 NULL
120510 +sky2_pci_read16_27863 sky2_pci_read16 0 27863 NULL
120511 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
120512 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
120513 +i915_error_object_create_sized_27919 i915_error_object_create_sized 4 27919 NULL
120514 +check_mapped_name_27943 check_mapped_name 3 27943 NULL
120515 +bio_next_split_27961 bio_next_split 2 27961 NULL nohasharray
120516 +tracing_clock_write_27961 tracing_clock_write 3 27961 &bio_next_split_27961
120517 +tipc_media_addr_printf_27971 tipc_media_addr_printf 2 27971 NULL
120518 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 NULL nohasharray
120519 +device_register_27972 device_register 0 27972 &mic_rx_pkts_read_27972
120520 +compat_SyS_set_mempolicy_27975 compat_SyS_set_mempolicy 3 27975 NULL
120521 +pci_enable_device_flags_27977 pci_enable_device_flags 0 27977 NULL
120522 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
120523 +seq_get_buf_28006 seq_get_buf 0 28006 NULL
120524 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
120525 +powercap_register_zone_28028 powercap_register_zone 6 28028 NULL
120526 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
120527 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2-4 28053 NULL
120528 +pool_status_28055 pool_status 5 28055 NULL
120529 +init_rs_non_canonical_28059 init_rs_non_canonical 1 28059 NULL
120530 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
120531 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
120532 +acpi_gsb_i2c_write_bytes_28082 acpi_gsb_i2c_write_bytes 4 28082 NULL
120533 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
120534 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
120535 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
120536 +m25p80_read_reg_28132 m25p80_read_reg 4 28132 NULL
120537 +video_read_28148 video_read 3 28148 NULL
120538 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
120539 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
120540 +vread_28173 vread 0-3 28173 NULL
120541 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
120542 +counter_free_res_28187 counter_free_res 5 28187 NULL
120543 +read_disk_sb_28188 read_disk_sb 2 28188 NULL
120544 +nvkm_output_dp_create__28192 nvkm_output_dp_create_ 6 28192 NULL
120545 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
120546 +__qp_memcpy_from_queue_28220 __qp_memcpy_from_queue 3-4 28220 NULL
120547 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL
120548 +amd_nb_num_28228 amd_nb_num 0 28228 NULL
120549 +usemap_size_28281 usemap_size 0 28281 NULL
120550 +inline_xattr_size_28285 inline_xattr_size 0 28285 NULL
120551 +dma_map_sg_attrs_28289 dma_map_sg_attrs 0 28289 NULL
120552 +SyS_ppoll_28290 SyS_ppoll 2 28290 NULL
120553 +kstrtos16_from_user_28300 kstrtos16_from_user 2 28300 NULL
120554 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
120555 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
120556 +xpcs_mmd_read_28331 xpcs_mmd_read 3 28331 NULL
120557 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
120558 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
120559 +snapshot_write_28351 snapshot_write 3 28351 NULL
120560 +xfs_iomap_write_unwritten_28365 xfs_iomap_write_unwritten 3-2 28365 NULL
120561 +batadv_handle_tt_response_28370 batadv_handle_tt_response 4 28370 NULL
120562 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
120563 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
120564 +bypass_pwup_write_28416 bypass_pwup_write 3 28416 NULL
120565 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
120566 +__videobuf_mmap_setup_28421 __videobuf_mmap_setup 0 28421 NULL
120567 +ksocknal_alloc_tx_28426 ksocknal_alloc_tx 2 28426 NULL
120568 +hid_hw_output_report_28429 hid_hw_output_report 0 28429 NULL
120569 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
120570 +snd_emu10k1_efx_read_28452 snd_emu10k1_efx_read 2 28452 NULL
120571 +key_mic_failures_read_28457 key_mic_failures_read 3 28457 NULL
120572 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
120573 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
120574 +sh_irda_init_iobuf_28527 sh_irda_init_iobuf 2 28527 NULL nohasharray
120575 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 &sh_irda_init_iobuf_28527
120576 +early_init_dt_alloc_memory_arch_28528 early_init_dt_alloc_memory_arch 1 28528 NULL
120577 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
120578 +run_delalloc_range_28545 run_delalloc_range 3-4 28545 NULL nohasharray
120579 +aio_read_events_28545 aio_read_events 3 28545 &run_delalloc_range_28545 nohasharray
120580 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 &aio_read_events_28545
120581 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
120582 +asymmetric_verify_28567 asymmetric_verify 3 28567 NULL
120583 +oxygen_read32_28582 oxygen_read32 0 28582 NULL
120584 +task_cgroup_path_28599 task_cgroup_path 3 28599 NULL
120585 +extract_entropy_28604 extract_entropy 5-3 28604 NULL
120586 +xgbe_common_write_28609 xgbe_common_write 2 28609 NULL
120587 +kfifo_unused_28612 kfifo_unused 0 28612 NULL
120588 +snd_nm256_capture_copy_28622 snd_nm256_capture_copy 5-3 28622 NULL
120589 +setup_usemap_28636 setup_usemap 3-4 28636 NULL
120590 +qib_handle_6120_hwerrors_28642 qib_handle_6120_hwerrors 3 28642 NULL
120591 +p9_fcall_alloc_28652 p9_fcall_alloc 1 28652 NULL
120592 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
120593 +SyS_setgroups16_28686 SyS_setgroups16 1 28686 NULL
120594 +kvm_mmu_get_page_28692 kvm_mmu_get_page 2 28692 NULL
120595 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
120596 +spi_execute_28736 spi_execute 5 28736 NULL
120597 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
120598 +read_file_btcoex_28743 read_file_btcoex 3 28743 NULL
120599 +max_hw_blocks_28748 max_hw_blocks 0 28748 NULL
120600 +nv50_dmac_create_28762 nv50_dmac_create 5 28762 NULL
120601 +rpc_pipe_generic_upcall_28766 rpc_pipe_generic_upcall 4 28766 NULL
120602 +ath6kl_get_num_reg_28780 ath6kl_get_num_reg 0 28780 NULL
120603 +sel_write_member_28800 sel_write_member 3 28800 NULL
120604 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
120605 +kernel_tree_alloc_28833 kernel_tree_alloc 1 28833 NULL
120606 +parser_init_byteStream_28841 parser_init_byteStream 2 28841 NULL
120607 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
120608 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
120609 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
120610 +da9055_group_write_28904 da9055_group_write 2-3 28904 NULL
120611 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
120612 +iwl_dbgfs_sleep_level_override_write_28925 iwl_dbgfs_sleep_level_override_write 3 28925 NULL
120613 +push_rx_28939 push_rx 3 28939 NULL
120614 +mxuport_prepare_write_buffer_28943 mxuport_prepare_write_buffer 3 28943 NULL
120615 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3-4 28963 NULL
120616 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
120617 +hash_net6_expire_28979 hash_net6_expire 4 28979 NULL
120618 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
120619 +bin_uuid_28999 bin_uuid 3 28999 NULL
120620 +fd_execute_rw_29004 fd_execute_rw 3 29004 NULL
120621 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
120622 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
120623 +btrfs_root_bytenr_29058 btrfs_root_bytenr 0 29058 NULL
120624 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
120625 +lpfc_idiag_extacc_drivr_get_29067 lpfc_idiag_extacc_drivr_get 0-3 29067 NULL
120626 +sctp_getsockopt_assoc_stats_29074 sctp_getsockopt_assoc_stats 2 29074 NULL
120627 +iwl_dbgfs_log_event_write_29088 iwl_dbgfs_log_event_write 3 29088 NULL
120628 +ccp_init_dm_workarea_29097 ccp_init_dm_workarea 3 29097 NULL
120629 +__compat_sys_preadv64_29103 __compat_sys_preadv64 3 29103 NULL
120630 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
120631 +snprintf_29125 snprintf 0 29125 NULL
120632 +iov_shorten_29130 iov_shorten 0 29130 NULL
120633 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
120634 +kvm_mmu_notifier_clear_flush_young_29154 kvm_mmu_notifier_clear_flush_young 3 29154 NULL
120635 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
120636 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL
120637 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
120638 +nvme_trans_copy_from_user_29227 nvme_trans_copy_from_user 3 29227 NULL
120639 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
120640 +evdev_handle_get_val_29242 evdev_handle_get_val 5-6 29242 NULL
120641 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
120642 +rbd_osd_req_create_29260 rbd_osd_req_create 3 29260 NULL
120643 +mwifiex_hscfg_write_29262 mwifiex_hscfg_write 3 29262 NULL
120644 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
120645 +ext4_fiemap_29296 ext4_fiemap 4 29296 NULL
120646 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
120647 +__fuse_get_req_29315 __fuse_get_req 2 29315 NULL
120648 +lprocfs_write_helper_29323 lprocfs_write_helper 2 29323 NULL
120649 +kvm_handle_hva_29326 kvm_handle_hva 2 29326 NULL
120650 +obd_proc_jobid_name_seq_write_29332 obd_proc_jobid_name_seq_write 3 29332 NULL
120651 +tun_put_user_29337 tun_put_user 5 29337 NULL
120652 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
120653 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
120654 +read_file_tx99_power_29405 read_file_tx99_power 3 29405 NULL
120655 +mempool_create_29437 mempool_create 1 29437 NULL
120656 +crypto_ahash_alignmask_29445 crypto_ahash_alignmask 0 29445 NULL
120657 +p9_client_prepare_req_29448 p9_client_prepare_req 3 29448 NULL
120658 +validate_scan_freqs_29462 validate_scan_freqs 0 29462 NULL
120659 +SyS_flistxattr_29474 SyS_flistxattr 3 29474 NULL
120660 +do_register_entry_29478 do_register_entry 4 29478 NULL
120661 +simple_strtoul_29480 simple_strtoul 0 29480 NULL
120662 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
120663 +btrfs_file_extent_disk_bytenr_29505 btrfs_file_extent_disk_bytenr 0 29505 NULL
120664 +usnic_vnic_spec_dump_29508 usnic_vnic_spec_dump 2 29508 NULL
120665 +write_file_regidx_29517 write_file_regidx 3 29517 NULL
120666 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
120667 +mic_vringh_copy_29531 mic_vringh_copy 4 29531 NULL
120668 +ftrace_write_29551 ftrace_write 3 29551 NULL
120669 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
120670 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
120671 +kvm_read_guest_virt_system_29569 kvm_read_guest_virt_system 4-2 29569 NULL
120672 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
120673 +iwl_dbgfs_missed_beacon_write_29586 iwl_dbgfs_missed_beacon_write 3 29586 NULL
120674 +pvr2_hdw_report_unlocked_29589 pvr2_hdw_report_unlocked 4-0 29589 NULL
120675 +dio_set_defer_completion_29599 dio_set_defer_completion 0 29599 NULL
120676 +slots_per_page_29601 slots_per_page 0 29601 NULL
120677 +osc_cached_mb_seq_write_29610 osc_cached_mb_seq_write 3 29610 NULL
120678 +lstcon_rpc_init_29623 lstcon_rpc_init 4 29623 NULL
120679 +nla_get_u16_29624 nla_get_u16 0 29624 NULL
120680 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
120681 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL nohasharray
120682 +spmi_controller_alloc_29654 spmi_controller_alloc 2 29654 &sctp_make_abort_user_29654
120683 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
120684 +lustre_posix_acl_xattr_2ext_29693 lustre_posix_acl_xattr_2ext 2 29693 NULL
120685 +posix_acl_from_xattr_29708 posix_acl_from_xattr 3 29708 NULL
120686 +probes_write_29711 probes_write 3 29711 NULL
120687 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
120688 +xfs_new_eof_29737 xfs_new_eof 2 29737 NULL
120689 +std_nic_write_29752 std_nic_write 3 29752 NULL
120690 +static_key_count_29771 static_key_count 0 29771 NULL
120691 +dbAlloc_29794 dbAlloc 0 29794 NULL
120692 +tcp_sendpage_29829 tcp_sendpage 4 29829 NULL
120693 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
120694 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
120695 +count_partial_29850 count_partial 0 29850 NULL
120696 +write_file_bool_bmps_29870 write_file_bool_bmps 3 29870 NULL
120697 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
120698 +crypto_aead_alignmask_29885 crypto_aead_alignmask 0 29885 NULL
120699 +rtw_cfg80211_indicate_sta_assoc_29897 rtw_cfg80211_indicate_sta_assoc 3 29897 NULL
120700 +nv94_gpio_intr_mask_29907 nv94_gpio_intr_mask 4-3 29907 NULL
120701 +lov_ost_pool_extend_29914 lov_ost_pool_extend 2 29914 NULL
120702 +write_file_queue_29922 write_file_queue 3 29922 NULL
120703 +__btrfs_getxattr_29947 __btrfs_getxattr 0 29947 NULL nohasharray
120704 +ipv6_recv_error_29947 ipv6_recv_error 3 29947 &__btrfs_getxattr_29947
120705 +dev_mem_write_30028 dev_mem_write 3 30028 NULL
120706 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
120707 +sysfs_add_file_mode_ns_30038 sysfs_add_file_mode_ns 0 30038 NULL
120708 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 0-4 30040 NULL
120709 +drp_wmove_30043 drp_wmove 4 30043 NULL
120710 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
120711 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
120712 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
120713 +defragment_dma_buffer_30113 defragment_dma_buffer 0 30113 NULL
120714 +spi_async_locked_30117 spi_async_locked 0 30117 NULL
120715 +u_memcpya_30139 u_memcpya 3-2 30139 NULL
120716 +dbg_port_buf_30145 dbg_port_buf 2 30145 NULL
120717 +elfcorehdr_read_30159 elfcorehdr_read 2 30159 NULL
120718 +alloc_switch_ctx_30165 alloc_switch_ctx 2 30165 NULL
120719 +expand_inode_data_30169 expand_inode_data 3-2 30169 NULL
120720 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
120721 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
120722 +__genwqe_readq_30197 __genwqe_readq 0 30197 NULL
120723 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
120724 +SyS_semop_30227 SyS_semop 3 30227 NULL
120725 +bitmap_file_set_bit_30228 bitmap_file_set_bit 2 30228 NULL
120726 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
120727 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL
120728 +compat_readv_30273 compat_readv 3 30273 NULL
120729 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
120730 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
120731 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
120732 +osc_contention_seconds_seq_write_30305 osc_contention_seconds_seq_write 3 30305 NULL
120733 +ext4_acl_from_disk_30320 ext4_acl_from_disk 2 30320 NULL
120734 +i8254_read_30330 i8254_read 0 30330 NULL
120735 +resource_from_user_30341 resource_from_user 3 30341 NULL
120736 +o2nm_this_node_30342 o2nm_this_node 0 30342 NULL
120737 +kstrtou32_from_user_30361 kstrtou32_from_user 2 30361 NULL
120738 +pvscsi_change_queue_depth_30365 pvscsi_change_queue_depth 2 30365 NULL
120739 +C_SYSC_readv_30369 C_SYSC_readv 3 30369 NULL
120740 +blkdev_issue_zeroout_30392 blkdev_issue_zeroout 3 30392 NULL
120741 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
120742 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
120743 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
120744 +lstcon_session_info_30425 lstcon_session_info 6 30425 NULL
120745 +enable_write_30456 enable_write 3 30456 NULL
120746 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
120747 +urandom_read_30462 urandom_read 3 30462 NULL
120748 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
120749 +adu_write_30487 adu_write 3 30487 NULL
120750 +dtim_interval_write_30489 dtim_interval_write 3 30489 NULL
120751 +batadv_send_tt_request_30493 batadv_send_tt_request 5 30493 NULL
120752 +memblock_virt_alloc_node_30515 memblock_virt_alloc_node 1 30515 NULL
120753 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
120754 +debug_debug2_read_30526 debug_debug2_read 3 30526 NULL nohasharray
120755 +set_config_30526 set_config 0 30526 &debug_debug2_read_30526
120756 +xfs_sb_version_hasftype_30559 xfs_sb_version_hasftype 0 30559 NULL
120757 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
120758 +set_le_30581 set_le 4 30581 NULL
120759 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
120760 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
120761 +SyS_msgrcv_30611 SyS_msgrcv 3 30611 NULL
120762 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
120763 +ieee80211_if_read_dot11MeshAwakeWindowDuration_30631 ieee80211_if_read_dot11MeshAwakeWindowDuration 3 30631 NULL
120764 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
120765 +mlx5_ib_alloc_fast_reg_page_list_30638 mlx5_ib_alloc_fast_reg_page_list 2 30638 NULL
120766 +SyS_listxattr_30647 SyS_listxattr 3 30647 NULL
120767 +jffs2_flash_read_30667 jffs2_flash_read 0 30667 NULL
120768 +ni_ai_fifo_read_30681 ni_ai_fifo_read 3 30681 NULL
120769 +sst_hsw_get_dsp_position_30691 sst_hsw_get_dsp_position 0 30691 NULL
120770 +get_pages_alloc_iovec_30699 get_pages_alloc_iovec 3-0 30699 NULL
120771 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
120772 +lbs_wrbbp_write_30712 lbs_wrbbp_write 3 30712 NULL
120773 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
120774 +snd_nm256_playback_silence_30727 snd_nm256_playback_silence 4-3 30727 NULL
120775 +snapshot_status_30744 snapshot_status 5 30744 NULL
120776 +fuse_direct_IO_30753 fuse_direct_IO 4 30753 NULL
120777 +fuse_conn_limit_write_30777 fuse_conn_limit_write 3 30777 NULL
120778 +__bio_alloc_30787 __bio_alloc 3 30787 NULL
120779 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
120780 +get_kobj_path_length_30831 get_kobj_path_length 0 30831 NULL
120781 +ath10k_write_fw_dbglog_30835 ath10k_write_fw_dbglog 3 30835 NULL
120782 +of_gpio_named_count_30841 of_gpio_named_count 0 30841 NULL
120783 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
120784 +wd_autoreset_write_30862 wd_autoreset_write 3 30862 NULL
120785 +ieee80211_if_fmt_dropped_frames_no_route_30884 ieee80211_if_fmt_dropped_frames_no_route 3 30884 NULL
120786 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
120787 +usnic_debugfs_buildinfo_read_30928 usnic_debugfs_buildinfo_read 3 30928 NULL
120788 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
120789 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
120790 +huge_page_mask_30981 huge_page_mask 0 30981 NULL
120791 +read_file_bt_ant_diversity_30983 read_file_bt_ant_diversity 3 30983 NULL
120792 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
120793 +ima_eventsig_init_31022 ima_eventsig_init 5 31022 NULL
120794 +template_fmt_size_31033 template_fmt_size 0 31033 NULL
120795 +stride_pg_count_31053 stride_pg_count 0-3-2-1-4-5 31053 NULL
120796 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
120797 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
120798 +proc_gid_map_write_31093 proc_gid_map_write 3 31093 NULL
120799 +depth_read_31112 depth_read 3 31112 NULL
120800 +hash_ipportnet6_expire_31118 hash_ipportnet6_expire 4 31118 NULL
120801 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
120802 +size_inside_page_31141 size_inside_page 0 31141 NULL
120803 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
120804 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
120805 +r592_read_fifo_pio_31198 r592_read_fifo_pio 3 31198 NULL
120806 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
120807 +cpumask_weight_31215 cpumask_weight 0 31215 NULL
120808 +__read_reg_31216 __read_reg 0 31216 NULL
120809 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
120810 +tcp_recvmsg_31238 tcp_recvmsg 4 31238 NULL
120811 +cyy_readb_31240 cyy_readb 0 31240 NULL
120812 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
120813 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
120814 +hash_netportnet4_expire_31290 hash_netportnet4_expire 4 31290 NULL
120815 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
120816 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
120817 +command_file_write_31318 command_file_write 3 31318 NULL
120818 +hwerr_crcbits_31334 hwerr_crcbits 4 31334 NULL
120819 +_regmap_raw_multi_reg_write_31336 _regmap_raw_multi_reg_write 3 31336 NULL
120820 +em28xx_init_usb_xfer_31337 em28xx_init_usb_xfer 4-6 31337 NULL
120821 +outlen_write_31358 outlen_write 3 31358 NULL
120822 +ieee80211_rx_mgmt_auth_31366 ieee80211_rx_mgmt_auth 3 31366 NULL
120823 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
120824 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3-2 31374 NULL
120825 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
120826 +inb_31388 inb 0 31388 NULL
120827 +mp_ioapic_pin_count_31393 mp_ioapic_pin_count 0 31393 NULL
120828 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
120829 +_sp2d_max_pg_31422 _sp2d_max_pg 0 31422 NULL
120830 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
120831 +snd_aw2_saa7146_get_hw_ptr_capture_31431 snd_aw2_saa7146_get_hw_ptr_capture 0 31431 NULL
120832 +transport_alloc_session_tags_31449 transport_alloc_session_tags 2-3 31449 NULL
120833 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
120834 +xfs_btree_get_numrecs_31477 xfs_btree_get_numrecs 0 31477 NULL
120835 +alg_setkey_31485 alg_setkey 3 31485 NULL
120836 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
120837 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
120838 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
120839 +hidraw_write_31536 hidraw_write 3 31536 NULL
120840 +usbvision_read_31555 usbvision_read 3 31555 NULL
120841 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
120842 +get_max_inline_xattr_value_size_31578 get_max_inline_xattr_value_size 0 31578 NULL
120843 +osst_write_31581 osst_write 3 31581 NULL
120844 +snd_compr_get_avail_31584 snd_compr_get_avail 0 31584 NULL
120845 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
120846 +memblock_virt_alloc_nopanic_31617 memblock_virt_alloc_nopanic 1 31617 NULL nohasharray
120847 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 &memblock_virt_alloc_nopanic_31617
120848 +usnic_ib_dump_vf_31623 usnic_ib_dump_vf 3 31623 NULL
120849 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
120850 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
120851 +xfer_secondary_pool_31661 xfer_secondary_pool 2 31661 NULL
120852 +__lgread_31668 __lgread 4 31668 NULL
120853 +copy_from_user_nmi_31672 copy_from_user_nmi 3-0 31672 NULL
120854 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
120855 +fst_recover_rx_error_31687 fst_recover_rx_error 3 31687 NULL
120856 +rs_pretty_print_rate_31727 rs_pretty_print_rate 0 31727 NULL
120857 +lu_buf_check_and_grow_31735 lu_buf_check_and_grow 2 31735 NULL nohasharray
120858 +utf16s_to_utf8s_31735 utf16s_to_utf8s 0 31735 &lu_buf_check_and_grow_31735
120859 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3-2 31741 NULL
120860 +input_abs_get_max_31742 input_abs_get_max 0 31742 NULL nohasharray
120861 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 &input_abs_get_max_31742
120862 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
120863 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
120864 +SyS_lsetxattr_31766 SyS_lsetxattr 4 31766 NULL
120865 +usblp_cache_device_id_string_31790 usblp_cache_device_id_string 0 31790 NULL
120866 +get_count_order_31800 get_count_order 0 31800 NULL
120867 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
120868 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
120869 +data_write_31805 data_write 3 31805 NULL
120870 +SyS_msgsnd_31814 SyS_msgsnd 3 31814 NULL
120871 +strnlen_user_31815 strnlen_user 0-2 31815 NULL
120872 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
120873 +clone_bio_31854 clone_bio 4-3 31854 NULL
120874 +SyS_ppoll_31855 SyS_ppoll 2 31855 NULL
120875 +iwl_dbgfs_disable_ht40_write_31876 iwl_dbgfs_disable_ht40_write 3 31876 NULL
120876 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
120877 +ddb_output_write_31902 ddb_output_write 3-0 31902 NULL
120878 +xattr_permission_31907 xattr_permission 0 31907 NULL
120879 +lu_buf_realloc_31915 lu_buf_realloc 2 31915 NULL
120880 +new_dir_31919 new_dir 3 31919 NULL
120881 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
120882 +era_status_31934 era_status 5 31934 NULL
120883 +SYSC_sethostname_31940 SYSC_sethostname 2 31940 NULL
120884 +read_mem_31942 read_mem 3 31942 NULL
120885 +ext4_zero_range_31944 ext4_zero_range 3-2 31944 NULL
120886 +vb2_write_31948 vb2_write 3 31948 NULL
120887 +pvr2_ctrl_get_valname_31951 pvr2_ctrl_get_valname 4 31951 NULL
120888 +regcache_rbtree_sync_31964 regcache_rbtree_sync 2 31964 NULL
120889 +iwl_rx_packet_payload_len_31965 iwl_rx_packet_payload_len 0 31965 NULL
120890 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
120891 +iblock_execute_rw_31982 iblock_execute_rw 3 31982 NULL nohasharray
120892 +vx_read_status_31982 vx_read_status 0 31982 &iblock_execute_rw_31982
120893 +find_next_zero_bit_31990 find_next_zero_bit 0 31990 NULL
120894 +lustre_acl_xattr_merge2posix_31992 lustre_acl_xattr_merge2posix 2 31992 NULL
120895 +sysfs_create_file_31996 sysfs_create_file 0 31996 NULL
120896 +calc_hmac_32010 calc_hmac 3 32010 NULL
120897 +aead_len_32021 aead_len 0 32021 NULL
120898 +sci_dma_rx_push_32029 sci_dma_rx_push 2 32029 NULL
120899 +stk_read_32038 stk_read 3 32038 NULL
120900 +SYSC_llistxattr_32061 SYSC_llistxattr 3 32061 NULL
120901 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
120902 +cow_file_range_inline_32091 cow_file_range_inline 3 32091 NULL
120903 +kiblnd_alloc_pages_32092 kiblnd_alloc_pages 3 32092 NULL
120904 +bio_alloc_32095 bio_alloc 2 32095 NULL
120905 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
120906 +disk_status_32120 disk_status 4 32120 NULL
120907 +kobject_add_internal_32133 kobject_add_internal 0 32133 NULL
120908 +venus_link_32165 venus_link 5 32165 NULL
120909 +ocfs2_direct_IO_32168 ocfs2_direct_IO 4 32168 NULL
120910 +do_writepages_32173 do_writepages 0 32173 NULL
120911 +del_ptr_32197 del_ptr 4 32197 NULL
120912 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
120913 +riva_get_cmap_len_32218 riva_get_cmap_len 0 32218 NULL
120914 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
120915 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
120916 +ocfs2_xattr_find_entry_32260 ocfs2_xattr_find_entry 0 32260 NULL
120917 +kvm_set_spte_hva_32312 kvm_set_spte_hva 2 32312 NULL
120918 +cas_calc_tabort_32316 cas_calc_tabort 0 32316 NULL
120919 +SyS_select_32319 SyS_select 1 32319 NULL
120920 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
120921 +nl80211_send_mlme_event_32337 nl80211_send_mlme_event 4 32337 NULL
120922 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
120923 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL nohasharray
120924 +rx_streaming_always_write_32357 rx_streaming_always_write 3 32357 &dispatch_ioctl_32357
120925 +sel_read_initcon_32362 sel_read_initcon 3 32362 NULL nohasharray
120926 +ReadHDLCPCI_32362 ReadHDLCPCI 0 32362 &sel_read_initcon_32362
120927 +ll_setxattr_common_32398 ll_setxattr_common 4 32398 NULL
120928 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
120929 +vmci_qp_alloc_32405 vmci_qp_alloc 5-3 32405 NULL
120930 +cache_status_32462 cache_status 5 32462 NULL
120931 +fill_readbuf_32464 fill_readbuf 3 32464 NULL
120932 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
120933 +bypass_pwoff_write_32499 bypass_pwoff_write 3 32499 NULL
120934 +mdc_pinger_recov_seq_write_32510 mdc_pinger_recov_seq_write 3 32510 NULL
120935 +ctrl_std_val_to_sym_32516 ctrl_std_val_to_sym 5 32516 NULL
120936 +disconnect_32521 disconnect 4 32521 NULL
120937 +qsfp_read_32522 qsfp_read 0-2-4 32522 NULL
120938 +ilo_read_32531 ilo_read 3 32531 NULL
120939 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
120940 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
120941 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
120942 +osc_iocontrol_32565 osc_iocontrol 3 32565 NULL
120943 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
120944 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
120945 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
120946 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
120947 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
120948 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
120949 +xpcs_reg_value_read_32644 xpcs_reg_value_read 3 32644 NULL
120950 +kvmalloc_32646 kvmalloc 1 32646 NULL
120951 +ib_sg_dma_len_32649 ib_sg_dma_len 0 32649 NULL
120952 +generic_readlink_32654 generic_readlink 3 32654 NULL
120953 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
120954 +compat_SyS_preadv_32679 compat_SyS_preadv 3 32679 NULL
120955 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
120956 +rt2x00debug_read_queue_dump_32712 rt2x00debug_read_queue_dump 3 32712 NULL
120957 +_xfs_buf_get_pages_32715 _xfs_buf_get_pages 2 32715 NULL
120958 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
120959 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
120960 +vmci_transport_dgram_dequeue_32775 vmci_transport_dgram_dequeue 4 32775 NULL
120961 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
120962 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
120963 +sta_tx_latency_stat_read_32862 sta_tx_latency_stat_read 3 32862 NULL
120964 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
120965 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 NULL nohasharray
120966 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 &cifs_writedata_alloc_32880
120967 +vp702x_usb_inout_cmd_32884 vp702x_usb_inout_cmd 4-6 32884 NULL
120968 +visorchannel_dump_section_32893 visorchannel_dump_section 4 32893 NULL
120969 +tipc_link_iovec_xmit_fast_32913 tipc_link_iovec_xmit_fast 3 32913 NULL nohasharray
120970 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 &tipc_link_iovec_xmit_fast_32913
120971 +zlib_inflate_workspacesize_32927 zlib_inflate_workspacesize 0 32927 NULL
120972 +rmap_recycle_32938 rmap_recycle 3 32938 NULL
120973 +ptlrpc_prep_bulk_imp_32997 ptlrpc_prep_bulk_imp 2 32997 NULL
120974 +compat_filldir_32999 compat_filldir 3 32999 NULL
120975 +SyS_syslog_33007 SyS_syslog 3 33007 NULL
120976 +br_multicast_set_hash_max_33012 br_multicast_set_hash_max 2 33012 NULL
120977 +write_file_bt_ant_diversity_33019 write_file_bt_ant_diversity 3 33019 NULL
120978 +mic_virtio_copy_to_user_33048 mic_virtio_copy_to_user 3 33048 NULL
120979 +SYSC_lgetxattr_33049 SYSC_lgetxattr 4 33049 NULL
120980 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
120981 +ebt_compat_match_offset_33053 ebt_compat_match_offset 0-2 33053 NULL
120982 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
120983 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
120984 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
120985 +alloc_tio_33077 alloc_tio 3 33077 NULL
120986 +acl_permission_check_33083 acl_permission_check 0 33083 NULL
120987 +f2fs_llseek_33098 f2fs_llseek 2 33098 NULL
120988 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
120989 +SyS_poll_33152 SyS_poll 2 33152 NULL
120990 +_pci_add_cap_save_buffer_33153 _pci_add_cap_save_buffer 4 33153 NULL
120991 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
120992 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 3-2 33204 NULL
120993 +pp_read_33210 pp_read 3 33210 NULL
120994 +snd_pcm_plug_client_size_33267 snd_pcm_plug_client_size 0-2 33267 NULL
120995 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
120996 +sync_pt_create_33282 sync_pt_create 2 33282 NULL
120997 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
120998 +isku_sysfs_read_keys_easyzone_33318 isku_sysfs_read_keys_easyzone 6 33318 NULL
120999 +vx_send_irq_dsp_33329 vx_send_irq_dsp 0 33329 NULL
121000 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
121001 +lov_stripesize_seq_write_33353 lov_stripesize_seq_write 3 33353 NULL
121002 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
121003 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
121004 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
121005 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
121006 +scsi_varlen_cdb_length_33385 scsi_varlen_cdb_length 0 33385 NULL
121007 +nvc0_ram_create__33391 nvc0_ram_create_ 5 33391 NULL
121008 +ocfs2_allocate_unwritten_extents_33394 ocfs2_allocate_unwritten_extents 3-2 33394 NULL
121009 +cfs_trace_copyin_string_33396 cfs_trace_copyin_string 4 33396 NULL
121010 +snd_pcm_capture_ioctl1_33408 snd_pcm_capture_ioctl1 0 33408 NULL
121011 +hash_netiface6_expire_33421 hash_netiface6_expire 4 33421 NULL
121012 +dis_tap_write_33426 dis_tap_write 3 33426 NULL
121013 +message_stats_list_33440 message_stats_list 5 33440 NULL
121014 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
121015 +create_entry_33479 create_entry 2 33479 NULL
121016 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
121017 +res_counter_read_33499 res_counter_read 4 33499 NULL
121018 +hash_netnet4_expire_33500 hash_netnet4_expire 4 33500 NULL
121019 +fb_read_33506 fb_read 3 33506 NULL
121020 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
121021 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
121022 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
121023 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
121024 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL nohasharray
121025 +osc_max_rpcs_in_flight_seq_write_33539 osc_max_rpcs_in_flight_seq_write 3 33539 &tomoyo_read_self_33539
121026 +count_subheaders_33591 count_subheaders 0 33591 NULL
121027 +scsi_execute_33596 scsi_execute 5 33596 NULL
121028 +comedi_buf_write_n_allocated_33604 comedi_buf_write_n_allocated 0 33604 NULL
121029 +xt_compat_target_offset_33608 xt_compat_target_offset 0 33608 NULL
121030 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 NULL nohasharray
121031 +usb_gstrings_attach_33615 usb_gstrings_attach 3 33615 &il_dbgfs_qos_read_33615
121032 +stride_page_count_33641 stride_page_count 2 33641 NULL
121033 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
121034 +inw_p_33668 inw_p 0 33668 NULL
121035 +arp_hdr_len_33671 arp_hdr_len 0 33671 NULL
121036 +i2c_hid_alloc_buffers_33673 i2c_hid_alloc_buffers 2 33673 NULL
121037 +nv50_disp_dmac_create__33696 nv50_disp_dmac_create_ 6 33696 NULL
121038 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 NULL
121039 +tipc_link_stats_33716 tipc_link_stats 3 33716 NULL
121040 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
121041 +write_file_spectral_count_33723 write_file_spectral_count 3 33723 NULL
121042 +read_file_node_recv_33729 read_file_node_recv 3 33729 NULL
121043 +__mutex_lock_interruptible_slowpath_33735 __mutex_lock_interruptible_slowpath 0 33735 NULL
121044 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
121045 +hashtab_create_33769 hashtab_create 3 33769 NULL
121046 +__btrfs_free_reserved_extent_33782 __btrfs_free_reserved_extent 2 33782 NULL
121047 +if_sdio_read_rx_len_33800 if_sdio_read_rx_len 0 33800 NULL
121048 +filter_write_33819 filter_write 3 33819 NULL
121049 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
121050 +scrub_setup_recheck_block_33831 scrub_setup_recheck_block 5-4 33831 NULL
121051 +ext4_journal_extend_33835 ext4_journal_extend 2 33835 NULL
121052 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
121053 +azx_get_pos_posbuf_33867 azx_get_pos_posbuf 0 33867 NULL
121054 +get_user_pages_33908 get_user_pages 0 33908 NULL
121055 +sg_nents_33909 sg_nents 0 33909 NULL
121056 +ath6kl_roam_mode_write_33912 ath6kl_roam_mode_write 3 33912 NULL
121057 +queue_logical_block_size_33918 queue_logical_block_size 0 33918 NULL
121058 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
121059 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
121060 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
121061 +rs_sta_dbgfs_drv_tx_stats_read_33946 rs_sta_dbgfs_drv_tx_stats_read 3 33946 NULL
121062 +__proc_dump_kernel_33954 __proc_dump_kernel 5 33954 NULL
121063 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
121064 +lbs_lowrssi_write_34025 lbs_lowrssi_write 3 34025 NULL
121065 +ppp_write_34034 ppp_write 3 34034 NULL
121066 +tty_insert_flip_string_34042 tty_insert_flip_string 3-0 34042 NULL
121067 +bm_page_io_async_34050 bm_page_io_async 2 34050 NULL
121068 +calc_linear_pos_34067 calc_linear_pos 0-4 34067 NULL
121069 +memcg_update_all_caches_34068 memcg_update_all_caches 1 34068 NULL
121070 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
121071 +__irq_domain_add_34101 __irq_domain_add 2 34101 NULL
121072 +proc_scsi_host_write_34107 proc_scsi_host_write 3 34107 NULL
121073 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
121074 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2-0 34135 NULL
121075 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
121076 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
121077 +skb_to_sgvec_34171 skb_to_sgvec 0 34171 NULL
121078 +rsi_debug_zone_write_34206 rsi_debug_zone_write 3 34206 NULL
121079 +ext4_da_write_begin_34215 ext4_da_write_begin 3-4 34215 NULL
121080 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
121081 +device_private_init_34279 device_private_init 0 34279 NULL
121082 +xgmac_reg_addr_write_34284 xgmac_reg_addr_write 3 34284 NULL
121083 +ext4_get_groups_count_34324 ext4_get_groups_count 0 34324 NULL
121084 +pcpu_need_to_extend_34326 pcpu_need_to_extend 0 34326 NULL nohasharray
121085 +iov_iter_single_seg_count_34326 iov_iter_single_seg_count 0 34326 &pcpu_need_to_extend_34326
121086 +proc_thread_self_readlink_34357 proc_thread_self_readlink 3 34357 NULL
121087 +crypto_ablkcipher_ivsize_34363 crypto_ablkcipher_ivsize 0 34363 NULL nohasharray
121088 +sync_page_io_34363 sync_page_io 3 34363 &crypto_ablkcipher_ivsize_34363
121089 +rngapi_reset_34366 rngapi_reset 3 34366 NULL
121090 +ea_read_34378 ea_read 0 34378 NULL nohasharray
121091 +_iwl_dbgfs_low_latency_write_34378 _iwl_dbgfs_low_latency_write 3 34378 &ea_read_34378
121092 +fuse_send_read_34379 fuse_send_read 0-4 34379 NULL
121093 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
121094 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
121095 +read_rbu_image_type_34387 read_rbu_image_type 6 34387 NULL
121096 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 NULL nohasharray
121097 +iwl_calib_set_34400 iwl_calib_set 3 34400 &ivtv_read_pos_34400
121098 +wd_exp_mode_write_34407 wd_exp_mode_write 3 34407 NULL
121099 +nl80211_send_disassoc_34424 nl80211_send_disassoc 4 34424 NULL
121100 +security_socket_create_34439 security_socket_create 0 34439 NULL
121101 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
121102 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
121103 +skcipher_sndbuf_34476 skcipher_sndbuf 0 34476 NULL
121104 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
121105 +security_inode_permission_34488 security_inode_permission 0 34488 NULL
121106 +SyS_pwritev_34494 SyS_pwritev 3 34494 NULL
121107 +qp_alloc_res_34496 qp_alloc_res 5 34496 NULL
121108 +lu_buf_check_and_alloc_34505 lu_buf_check_and_alloc 2 34505 NULL
121109 +ext4_fallocate_34537 ext4_fallocate 4-3 34537 NULL nohasharray
121110 +tracing_stats_read_34537 tracing_stats_read 3 34537 &ext4_fallocate_34537
121111 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4-0 34547 NULL
121112 +dbBackSplit_34561 dbBackSplit 0 34561 NULL
121113 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
121114 +ext4_ind_direct_IO_34574 ext4_ind_direct_IO 4 34574 NULL
121115 +lov_stripecount_seq_write_34582 lov_stripecount_seq_write 3 34582 NULL
121116 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
121117 +inet6_ifla6_size_34591 inet6_ifla6_size 0 34591 NULL
121118 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL nohasharray
121119 +cw1200_queue_init_34599 cw1200_queue_init 4 34599 &ceph_msgpool_init_34599
121120 +bio_integrity_bytes_34602 bio_integrity_bytes 2 34602 NULL
121121 +__jffs2_ref_totlen_34609 __jffs2_ref_totlen 0 34609 NULL
121122 +__cfg80211_disconnected_34622 __cfg80211_disconnected 3 34622 NULL
121123 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
121124 +kvm_set_spte_hva_34671 kvm_set_spte_hva 2 34671 NULL
121125 +sleep_auth_write_34676 sleep_auth_write 3 34676 NULL
121126 +f2fs_direct_IO_34685 f2fs_direct_IO 4 34685 NULL
121127 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
121128 +batadv_tvlv_realloc_packet_buff_34688 batadv_tvlv_realloc_packet_buff 3-4 34688 NULL
121129 +port_print_34704 port_print 3 34704 NULL
121130 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
121131 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
121132 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
121133 +lsm_alloc_plain_34755 lsm_alloc_plain 1 34755 NULL
121134 +bootmode_store_34762 bootmode_store 4 34762 NULL
121135 +device_add_34766 device_add 0 34766 NULL
121136 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
121137 +ext3_direct_IO_34798 ext3_direct_IO 4 34798 NULL
121138 +SYSC_keyctl_34800 SYSC_keyctl 4 34800 NULL
121139 +can_nocow_extent_34801 can_nocow_extent 2 34801 NULL
121140 +drbd_get_max_capacity_34804 drbd_get_max_capacity 0 34804 NULL
121141 +ll_setxattr_34806 ll_setxattr 4 34806 NULL
121142 +file_page_index_34820 file_page_index 0-2 34820 NULL
121143 +bio_segments_34832 bio_segments 0 34832 NULL
121144 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
121145 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
121146 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
121147 +usb_serial_generic_prepare_write_buffer_34857 usb_serial_generic_prepare_write_buffer 3 34857 NULL
121148 +ieee80211_if_read_txpower_34871 ieee80211_if_read_txpower 3 34871 NULL
121149 +msg_print_text_34889 msg_print_text 0 34889 NULL
121150 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
121151 +si476x_radio_read_rsq_primary_blob_34916 si476x_radio_read_rsq_primary_blob 3 34916 NULL
121152 +btrfs_super_chunk_root_34925 btrfs_super_chunk_root 0 34925 NULL nohasharray
121153 +__inode_permission_34925 __inode_permission 0 34925 &btrfs_super_chunk_root_34925
121154 +sec_flags2str_34933 sec_flags2str 3 34933 NULL
121155 +snd_info_entry_read_34938 snd_info_entry_read 3 34938 NULL
121156 +compat_SyS_kexec_load_34947 compat_SyS_kexec_load 2 34947 NULL
121157 +do_add_page_to_bio_34974 do_add_page_to_bio 2-10 34974 NULL
121158 +sdebug_change_qdepth_34994 sdebug_change_qdepth 2 34994 NULL
121159 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
121160 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
121161 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
121162 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
121163 +hwdep_read_locked_35037 hwdep_read_locked 3 35037 NULL
121164 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
121165 +__kfifo_uint_must_check_helper_35097 __kfifo_uint_must_check_helper 0-1 35097 NULL
121166 +capi_write_35104 capi_write 3 35104 NULL nohasharray
121167 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
121168 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
121169 +ceph_osdc_start_request_35122 ceph_osdc_start_request 0 35122 NULL
121170 +addrs_per_inode_35151 addrs_per_inode 0 35151 NULL
121171 +message_stats_print_35158 message_stats_print 6 35158 NULL
121172 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
121173 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
121174 +compat_SyS_pselect6_35203 compat_SyS_pselect6 1 35203 NULL
121175 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
121176 +striped_read_35218 striped_read 0-2 35218 NULL nohasharray
121177 +security_key_getsecurity_35218 security_key_getsecurity 0 35218 &striped_read_35218
121178 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
121179 +kimage_file_prepare_segments_35232 kimage_file_prepare_segments 5 35232 NULL
121180 +set_fd_set_35249 set_fd_set 1 35249 NULL
121181 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
121182 +dis_disc_write_35265 dis_disc_write 3 35265 NULL
121183 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
121184 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
121185 +i2o_block_end_request_35282 i2o_block_end_request 3 35282 NULL
121186 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
121187 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3 35311 NULL nohasharray
121188 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 &__btrfs_buffered_write_35311
121189 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
121190 +sta_tx_latency_stat_write_35323 sta_tx_latency_stat_write 3 35323 NULL
121191 +ieee80211_if_fmt_ap_power_level_35347 ieee80211_if_fmt_ap_power_level 3 35347 NULL
121192 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
121193 +ieee80211_rx_mgmt_deauth_35351 ieee80211_rx_mgmt_deauth 3 35351 NULL
121194 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
121195 +read_kmem_35372 read_kmem 3 35372 NULL
121196 +SyS_getxattr_35408 SyS_getxattr 4 35408 NULL
121197 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
121198 +iwl_dbgfs_drv_rx_stats_read_35430 iwl_dbgfs_drv_rx_stats_read 3 35430 NULL
121199 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
121200 +efx_mcdi_rpc_async_quiet_35460 efx_mcdi_rpc_async_quiet 4-5 35460 NULL
121201 +macvtap_do_read_35475 macvtap_do_read 3 35475 NULL
121202 +fiemap_prepare_and_copy_exts_35494 fiemap_prepare_and_copy_exts 5 35494 NULL
121203 +btrfs_prealloc_file_range_trans_35500 btrfs_prealloc_file_range_trans 4 35500 NULL
121204 +async_setkey_35521 async_setkey 3 35521 NULL
121205 +__filemap_fdatawrite_range_35528 __filemap_fdatawrite_range 0 35528 NULL
121206 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
121207 +pstore_mkfile_35536 pstore_mkfile 7 35536 NULL
121208 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
121209 +ocfs2_write_zero_page_35539 ocfs2_write_zero_page 3 35539 NULL
121210 +ibnl_put_attr_35541 ibnl_put_attr 3 35541 NULL
121211 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
121212 +C_SYSC_kexec_load_35565 C_SYSC_kexec_load 2 35565 NULL
121213 +ext4_blocks_for_truncate_35579 ext4_blocks_for_truncate 0 35579 NULL
121214 +ext2_acl_from_disk_35580 ext2_acl_from_disk 2 35580 NULL
121215 +spk_msg_set_35586 spk_msg_set 3 35586 NULL
121216 +kernel_readv_35617 kernel_readv 3 35617 NULL
121217 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
121218 +ptlrpcd_steal_rqset_35637 ptlrpcd_steal_rqset 0 35637 NULL
121219 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
121220 +rdmaltWithLock_35669 rdmaltWithLock 0 35669 NULL
121221 +SYSC_pwritev_35690 SYSC_pwritev 3 35690 NULL
121222 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
121223 +md_super_write_35703 md_super_write 4 35703 NULL
121224 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
121225 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
121226 +alloc_netdev_mqs_35806 alloc_netdev_mqs 1 35806 NULL
121227 +pvr2_hdw_cpufw_get_35824 pvr2_hdw_cpufw_get 0-4-2 35824 NULL
121228 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
121229 +vx_query_hbuffer_size_35859 vx_query_hbuffer_size 0 35859 NULL
121230 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
121231 +kvm_dirty_bitmap_bytes_35886 kvm_dirty_bitmap_bytes 0 35886 NULL
121232 +ieee80211_if_fmt_dot11MeshRetryTimeout_35890 ieee80211_if_fmt_dot11MeshRetryTimeout 3 35890 NULL
121233 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
121234 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
121235 +rbio_nr_pages_35916 rbio_nr_pages 0-1-2 35916 NULL
121236 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
121237 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
121238 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
121239 +generic_ocp_read_35974 generic_ocp_read 3 35974 NULL nohasharray
121240 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 &generic_ocp_read_35974
121241 +acl_alloc_35979 acl_alloc 1 35979 NULL
121242 +device_add_class_symlinks_35985 device_add_class_symlinks 0 35985 NULL
121243 +write_file_antenna_35998 write_file_antenna 3 35998 NULL nohasharray
121244 +kuc_alloc_35998 kuc_alloc 1 35998 &write_file_antenna_35998
121245 +lov_mds_md_max_stripe_count_36008 lov_mds_md_max_stripe_count 0-1 36008 NULL
121246 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
121247 +__videobuf_alloc_36031 __videobuf_alloc 1 36031 NULL
121248 +account_shadowed_36048 account_shadowed 2 36048 NULL
121249 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
121250 +write_emulate_36065 write_emulate 2-4 36065 NULL
121251 +stack_max_size_write_36068 stack_max_size_write 3 36068 NULL
121252 +radeon_vm_num_pdes_36070 radeon_vm_num_pdes 0 36070 NULL
121253 +ieee80211_if_fmt_peer_36071 ieee80211_if_fmt_peer 3 36071 NULL
121254 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
121255 +snd_pcm_plug_read_transfer_36080 snd_pcm_plug_read_transfer 0-3 36080 NULL
121256 +mtip_hw_read_device_status_36082 mtip_hw_read_device_status 3 36082 NULL
121257 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
121258 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
121259 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
121260 +twl_set_36154 twl_set 2 36154 NULL
121261 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
121262 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
121263 +SyS_kexec_load_36176 SyS_kexec_load 2 36176 NULL
121264 +ramoops_init_przs_36199 ramoops_init_przs 4 36199 NULL
121265 +SYSC_sched_getaffinity_36208 SYSC_sched_getaffinity 2 36208 NULL
121266 +SYSC_process_vm_readv_36216 SYSC_process_vm_readv 3-5 36216 NULL
121267 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
121268 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
121269 +SYSC_getxattr_36242 SYSC_getxattr 4 36242 NULL
121270 +vmsplice_to_user_36245 vmsplice_to_user 3 36245 NULL nohasharray
121271 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 &vmsplice_to_user_36245
121272 +cfs_hash_buckets_realloc_36276 cfs_hash_buckets_realloc 4 36276 NULL
121273 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
121274 +crypto_shash_digestsize_36284 crypto_shash_digestsize 0 36284 NULL
121275 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
121276 +cfg80211_rx_mlme_mgmt_36306 cfg80211_rx_mlme_mgmt 3 36306 NULL
121277 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
121278 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL nohasharray
121279 +__compat_sys_pwritev64_36328 __compat_sys_pwritev64 3 36328 &fat_compat_ioctl_filldir_36328
121280 +lc_create_36332 lc_create 4 36332 NULL
121281 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
121282 +isku_sysfs_read_key_mask_36343 isku_sysfs_read_key_mask 6 36343 NULL
121283 +ath6kl_regwrite_write_36351 ath6kl_regwrite_write 3 36351 NULL
121284 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL
121285 +to_sector_36361 to_sector 0-1 36361 NULL
121286 +tunables_read_36385 tunables_read 3 36385 NULL
121287 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
121288 +sierra_write_36402 sierra_write 4 36402 NULL
121289 +SyS_sethostname_36417 SyS_sethostname 2 36417 NULL
121290 +soc_pcm_codec_params_fixup_36434 soc_pcm_codec_params_fixup 2 36434 NULL
121291 +ReadW6692B_36445 ReadW6692B 0 36445 NULL
121292 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
121293 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
121294 +SyS_process_vm_writev_36476 SyS_process_vm_writev 3-5 36476 NULL
121295 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
121296 +ds1343_nvram_write_36489 ds1343_nvram_write 5-6 36489 NULL
121297 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 NULL nohasharray
121298 +ip6_append_data_36490 ip6_append_data 4 36490 &tx_tx_checksum_result_read_36490
121299 +cmd_loop_36491 cmd_loop 0 36491 NULL
121300 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
121301 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
121302 +_iwl_dbgfs_fw_nmi_write_36515 _iwl_dbgfs_fw_nmi_write 3 36515 NULL
121303 +get_param_l_36518 get_param_l 0 36518 NULL
121304 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
121305 +crypto_aead_authsize_36537 crypto_aead_authsize 0 36537 NULL
121306 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
121307 +__kfifo_to_user_36555 __kfifo_to_user 3-0 36555 NULL
121308 +btrfs_get_token_64_36572 btrfs_get_token_64 0 36572 NULL
121309 +__erst_read_36579 __erst_read 0 36579 NULL
121310 +put_cmsg_36589 put_cmsg 4 36589 NULL
121311 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
121312 +vxge_config_vpaths_36636 vxge_config_vpaths 0 36636 NULL
121313 +convert_extent_item_v0_36645 convert_extent_item_v0 4 36645 NULL
121314 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
121315 +lpfc_idiag_extacc_alloc_get_36648 lpfc_idiag_extacc_alloc_get 0-3 36648 NULL
121316 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
121317 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
121318 +xillybus_read_36678 xillybus_read 3 36678 NULL
121319 +gsmtty_write_36702 gsmtty_write 3 36702 NULL
121320 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4-0 36740 NULL
121321 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
121322 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
121323 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
121324 +i40e_init_lan_hmc_36796 i40e_init_lan_hmc 5-4-3-2 36796 NULL
121325 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
121326 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
121327 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
121328 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
121329 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
121330 +cm_write_36858 cm_write 3 36858 NULL
121331 +tipc_link_iovec_long_xmit_36871 tipc_link_iovec_long_xmit 3 36871 NULL nohasharray
121332 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 &tipc_link_iovec_long_xmit_36871
121333 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
121334 +raid56_parity_write_36877 raid56_parity_write 5 36877 NULL
121335 +__btrfs_map_block_36883 __btrfs_map_block 3 36883 NULL
121336 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
121337 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
121338 +il4965_rs_sta_dbgfs_scale_table_write_36979 il4965_rs_sta_dbgfs_scale_table_write 3 36979 NULL
121339 +drbd_new_dev_size_36998 drbd_new_dev_size 0-3 36998 NULL
121340 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
121341 +setxattr_37006 setxattr 4 37006 NULL
121342 +ec_i2c_xfer_37029 ec_i2c_xfer 3 37029 NULL
121343 +ieee80211_chsw_switch_vifs_37030 ieee80211_chsw_switch_vifs 2 37030 NULL
121344 +command_file_read_37038 command_file_read 3 37038 NULL
121345 +figure_loop_size_37051 figure_loop_size 2-3 37051 NULL
121346 +qp_broker_create_37053 qp_broker_create 6-5 37053 NULL nohasharray
121347 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 &qp_broker_create_37053
121348 +_iwl_dbgfs_bcast_filters_macs_write_37069 _iwl_dbgfs_bcast_filters_macs_write 3 37069 NULL
121349 +SYSC_setxattr_37078 SYSC_setxattr 4 37078 NULL
121350 +parse_command_37079 parse_command 2 37079 NULL
121351 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
121352 +tun_get_user_37094 tun_get_user 5 37094 NULL
121353 +has_wrprotected_page_37123 has_wrprotected_page 3-2 37123 NULL
121354 +snd_hda_get_conn_list_37132 snd_hda_get_conn_list 0 37132 NULL
121355 +mtt_free_res_37144 mtt_free_res 5 37144 NULL
121356 +msg_word_37164 msg_word 0 37164 NULL
121357 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
121358 +forced_ps_write_37209 forced_ps_write 3 37209 NULL
121359 +crypto_shash_descsize_37212 crypto_shash_descsize 0 37212 NULL
121360 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2-0 37213 NULL
121361 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
121362 +__do_replace_37227 __do_replace 5 37227 NULL
121363 +iwl_dbgfs_d3_sram_read_37237 iwl_dbgfs_d3_sram_read 3 37237 NULL
121364 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL nohasharray
121365 +__btrfs_inc_extent_ref_37238 __btrfs_inc_extent_ref 7 37238 &rx_filter_dup_filter_read_37238
121366 +exofs_max_io_pages_37263 exofs_max_io_pages 0-2 37263 NULL
121367 +_iwl_dbgfs_fw_restart_write_37270 _iwl_dbgfs_fw_restart_write 3 37270 NULL
121368 +ieee80211_if_read_power_mode_37305 ieee80211_if_read_power_mode 3 37305 NULL
121369 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
121370 +tipc_send_37315 tipc_send 3 37315 NULL
121371 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL nohasharray
121372 +bnx2x_vf_fill_fw_str_37327 bnx2x_vf_fill_fw_str 3 37327 &l2cap_create_connless_pdu_37327
121373 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
121374 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
121375 +security_inode_getsecurity_37354 security_inode_getsecurity 0 37354 NULL
121376 +seek_firmware_37372 seek_firmware 2 37372 NULL
121377 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
121378 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
121379 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4-0 37428 NULL
121380 +iwl_print_last_event_logs_37433 iwl_print_last_event_logs 0-7-9 37433 NULL
121381 +fru_alloc_37442 fru_alloc 1 37442 NULL
121382 +tcp_established_options_37450 tcp_established_options 0 37450 NULL
121383 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
121384 +get_est_timing_37484 get_est_timing 0 37484 NULL
121385 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
121386 +bitmap_dirty_bits_37503 bitmap_dirty_bits 2 37503 NULL
121387 +osc_active_seq_write_37514 osc_active_seq_write 3 37514 NULL
121388 +bdev_writeseg_37519 bdev_writeseg 2-3 37519 NULL
121389 +xz_dec_test_write_37527 xz_dec_test_write 3 37527 NULL
121390 +fault_inject_read_37534 fault_inject_read 3 37534 NULL
121391 +hdr_size_37536 hdr_size 0 37536 NULL
121392 +extent_map_end_37550 extent_map_end 0 37550 NULL
121393 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL
121394 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
121395 +qla2x00_debounce_register_37597 qla2x00_debounce_register 0 37597 NULL
121396 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
121397 +SYSC_mbind_37622 SYSC_mbind 5 37622 NULL
121398 +SyS_mbind_37638 SyS_mbind 5 37638 NULL
121399 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
121400 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 NULL nohasharray
121401 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 &vmw_framebuffer_dmabuf_dirty_37661
121402 +SYSC_get_mempolicy_37664 SYSC_get_mempolicy 3 37664 NULL
121403 +__wa_seg_calculate_isoc_frame_count_37672 __wa_seg_calculate_isoc_frame_count 0 37672 NULL
121404 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
121405 +tracing_saved_cmdlines_size_write_37684 tracing_saved_cmdlines_size_write 3 37684 NULL
121406 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
121407 +nametbl_header_37698 nametbl_header 2-0 37698 NULL
121408 +__le32_to_cpup_37702 __le32_to_cpup 0 37702 NULL
121409 +dynamic_ps_timeout_write_37713 dynamic_ps_timeout_write 3 37713 NULL
121410 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
121411 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
121412 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
121413 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
121414 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
121415 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
121416 +nvkm_notify_init_37806 nvkm_notify_init 6 37806 NULL
121417 +ocrdma_alloc_frmr_page_list_37815 ocrdma_alloc_frmr_page_list 2 37815 NULL
121418 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
121419 +android_get_p2p_addr_37832 android_get_p2p_addr 0 37832 NULL
121420 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
121421 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
121422 +btrfs_leaf_data_37869 btrfs_leaf_data 0 37869 NULL
121423 +btrfs_stack_file_extent_disk_bytenr_37888 btrfs_stack_file_extent_disk_bytenr 0 37888 NULL
121424 +_rtw_malloc_37928 _rtw_malloc 1 37928 NULL nohasharray
121425 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 &_rtw_malloc_37928
121426 +read_rbu_packet_size_37939 read_rbu_packet_size 6 37939 NULL
121427 +write_file_bool_37957 write_file_bool 3 37957 NULL
121428 +fifo_alloc_37961 fifo_alloc 1 37961 NULL
121429 +rds_rdma_extra_size_37990 rds_rdma_extra_size 0 37990 NULL
121430 +persistent_ram_old_size_37997 persistent_ram_old_size 0 37997 NULL
121431 +vfs_readv_38011 vfs_readv 3 38011 NULL
121432 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
121433 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL nohasharray
121434 +klsi_105_prepare_write_buffer_38044 klsi_105_prepare_write_buffer 3 38044 &il_dbgfs_chain_noise_read_38044
121435 +parser_init_guts_38046 parser_init_guts 2 38046 NULL
121436 +SyS_llistxattr_38048 SyS_llistxattr 3 38048 NULL
121437 +sysfs_do_create_link_38051 sysfs_do_create_link 0 38051 NULL
121438 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
121439 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
121440 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
121441 +cifs_send_async_read_38077 cifs_send_async_read 2 38077 NULL
121442 +xfs_buf_readahead_map_38081 xfs_buf_readahead_map 3 38081 NULL
121443 +uwb_mac_addr_print_38085 uwb_mac_addr_print 2 38085 NULL
121444 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
121445 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
121446 +ep0_read_38095 ep0_read 3 38095 NULL
121447 +osc_checksum_seq_write_38096 osc_checksum_seq_write 3 38096 NULL nohasharray
121448 +sk_wmem_schedule_38096 sk_wmem_schedule 2 38096 &osc_checksum_seq_write_38096
121449 +o2hb_read_slots_38105 o2hb_read_slots 2 38105 NULL
121450 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
121451 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
121452 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 3-4-0 38153 NULL
121453 +btrfs_extent_same_38163 btrfs_extent_same 3-2-5 38163 NULL
121454 +kvm_clear_guest_38164 kvm_clear_guest 3-2 38164 NULL
121455 +cdev_add_38176 cdev_add 2-3 38176 NULL
121456 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
121457 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
121458 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
121459 +ceph_decode_16_38239 ceph_decode_16 0 38239 NULL
121460 +_ipw_read_reg32_38245 _ipw_read_reg32 0 38245 NULL
121461 +nvkm_dmaobj_create__38250 nvkm_dmaobj_create_ 6 38250 NULL
121462 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 NULL nohasharray
121463 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 &mthca_alloc_icm_table_38268 nohasharray
121464 +SYSC_msgrcv_38268 SYSC_msgrcv 3 38268 &ieee80211_if_read_auto_open_plinks_38268
121465 +xfs_bmbt_to_bmdr_38275 xfs_bmbt_to_bmdr 3 38275 NULL nohasharray
121466 +xfs_bmdr_to_bmbt_38275 xfs_bmdr_to_bmbt 5 38275 &xfs_bmbt_to_bmdr_38275
121467 +ftdi_process_packet_38281 ftdi_process_packet 4 38281 NULL
121468 +C_SYSC_pselect6_38296 C_SYSC_pselect6 1 38296 NULL
121469 +ucma_query_path_38305 ucma_query_path 3 38305 NULL
121470 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
121471 +ida_simple_get_38326 ida_simple_get 0 38326 NULL
121472 +__snd_gf1_look8_38333 __snd_gf1_look8 0 38333 NULL
121473 +usb_ext_prop_put_name_38352 usb_ext_prop_put_name 0-3 38352 NULL
121474 +btrfs_file_extent_disk_num_bytes_38363 btrfs_file_extent_disk_num_bytes 0 38363 NULL
121475 +xfs_free_file_space_38383 xfs_free_file_space 2-3 38383 NULL
121476 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
121477 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
121478 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
121479 +iov_iter_npages_iovec_38448 iov_iter_npages_iovec 0-2 38448 NULL
121480 +kvm_write_guest_38454 kvm_write_guest 4-2 38454 NULL
121481 +videobuf_waiton_38459 videobuf_waiton 0 38459 NULL
121482 +_iwl_dbgfs_scan_ant_rxchain_write_38479 _iwl_dbgfs_scan_ant_rxchain_write 3 38479 NULL
121483 +blk_end_bidi_request_38482 blk_end_bidi_request 3-4 38482 NULL
121484 +dev_names_read_38509 dev_names_read 3 38509 NULL
121485 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
121486 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
121487 +ubifs_idx_node_sz_38546 ubifs_idx_node_sz 0-2 38546 NULL
121488 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
121489 +kuc_len_38557 kuc_len 0-1 38557 NULL
121490 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
121491 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
121492 +_ipw_read32_38565 _ipw_read32 0 38565 NULL
121493 +snd_nm256_playback_copy_38567 snd_nm256_playback_copy 5-3 38567 NULL
121494 +copy_ctl_value_to_user_38587 copy_ctl_value_to_user 4 38587 NULL
121495 +rd_allocate_sgl_table_38607 rd_allocate_sgl_table 3 38607 NULL
121496 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
121497 +write_enabled_file_bool_38630 write_enabled_file_bool 3 38630 NULL
121498 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
121499 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
121500 +qp_broker_alloc_38646 qp_broker_alloc 6-5 38646 NULL
121501 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
121502 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
121503 +ufshcd_read_sdev_qdepth_38676 ufshcd_read_sdev_qdepth 0 38676 NULL
121504 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
121505 +tracing_nsecs_read_38689 tracing_nsecs_read 3 38689 NULL
121506 +rbio_add_io_page_38700 rbio_add_io_page 6 38700 NULL
121507 +w83977af_sir_interrupt_38738 w83977af_sir_interrupt 0 38738 NULL
121508 +udf_readpages_38761 udf_readpages 4 38761 NULL
121509 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
121510 +bcache_device_init_38781 bcache_device_init 3 38781 NULL
121511 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
121512 +do_pci_enable_device_38802 do_pci_enable_device 0 38802 NULL
121513 +err_decode_38804 err_decode 2 38804 NULL
121514 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
121515 +direct_entry_38836 direct_entry 3 38836 NULL
121516 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
121517 +interfaces_38859 interfaces 2 38859 NULL
121518 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
121519 +il_dbgfs_sram_write_38942 il_dbgfs_sram_write 3 38942 NULL
121520 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
121521 +usb_maxpacket_38977 usb_maxpacket 0 38977 NULL nohasharray
121522 +C_SYSC_preadv64_38977 C_SYSC_preadv64 3 38977 &usb_maxpacket_38977
121523 +OSDSetBlock_38986 OSDSetBlock 2-4 38986 NULL
121524 +bio_clone_range_38997 bio_clone_range 2 38997 NULL
121525 +lpfc_idiag_extacc_write_38998 lpfc_idiag_extacc_write 3 38998 NULL
121526 +get_nodes_39012 get_nodes 3 39012 NULL
121527 +twl6030_interrupt_unmask_39013 twl6030_interrupt_unmask 2 39013 NULL
121528 +force_sc_support_read_39014 force_sc_support_read 3 39014 NULL
121529 +__blkdev_issue_zeroout_39020 __blkdev_issue_zeroout 3 39020 NULL
121530 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
121531 +do_write_kmem_39051 do_write_kmem 0-1-3 39051 NULL
121532 +tomoyo_truncate_39105 tomoyo_truncate 0 39105 NULL
121533 +__kfifo_to_user_r_39123 __kfifo_to_user_r 5-3 39123 NULL
121534 +ea_foreach_39133 ea_foreach 0 39133 NULL
121535 +generic_permission_39150 generic_permission 0 39150 NULL
121536 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
121537 +ath9k_hw_ar9003_dump_eeprom_39156 ath9k_hw_ar9003_dump_eeprom 5-4 39156 NULL
121538 +echo_client_kbrw_39170 echo_client_kbrw 6 39170 NULL
121539 +ext3_xattr_check_names_39174 ext3_xattr_check_names 0 39174 NULL
121540 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
121541 +qcam_read_bytes_39205 qcam_read_bytes 0 39205 NULL
121542 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
121543 +SyS_getrandom_39235 SyS_getrandom 2 39235 NULL
121544 +posix_acl_to_xattr_39237 posix_acl_to_xattr 0 39237 NULL
121545 +snd_pcm_capture_forward_39248 snd_pcm_capture_forward 2 39248 NULL
121546 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
121547 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
121548 +i915_error_state_read_39254 i915_error_state_read 3 39254 NULL
121549 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
121550 +_iwl_dbgfs_pm_params_write_39325 _iwl_dbgfs_pm_params_write 3 39325 NULL
121551 +__cfg80211_connect_result_39326 __cfg80211_connect_result 4-6 39326 NULL
121552 +insert_reserved_file_extent_39327 insert_reserved_file_extent 3 39327 NULL
121553 +wimax_msg_alloc_39343 wimax_msg_alloc 4 39343 NULL
121554 +ide_complete_rq_39354 ide_complete_rq 3 39354 NULL
121555 +do_write_log_from_user_39362 do_write_log_from_user 3-0 39362 NULL
121556 +vortex_wtdma_getlinearpos_39371 vortex_wtdma_getlinearpos 0 39371 NULL
121557 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
121558 +fnic_trace_debugfs_read_39380 fnic_trace_debugfs_read 3 39380 NULL
121559 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
121560 +__send_to_port_39386 __send_to_port 3 39386 NULL
121561 +user_power_read_39414 user_power_read 3 39414 NULL
121562 +hash_ipmark4_expire_39419 hash_ipmark4_expire 4 39419 NULL
121563 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
121564 +mic_desc_size_39464 mic_desc_size 0 39464 NULL
121565 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
121566 +usif_ioctl_39481 usif_ioctl 3 39481 NULL
121567 +ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries_39499 ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries 3 39499 NULL
121568 +cl_req_alloc_39523 cl_req_alloc 4 39523 NULL
121569 +int_proc_write_39542 int_proc_write 3 39542 NULL
121570 +pp_write_39554 pp_write 3 39554 NULL
121571 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
121572 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
121573 +memblock_virt_alloc_internal_39600 memblock_virt_alloc_internal 1 39600 NULL
121574 +ext_depth_39607 ext_depth 0 39607 NULL
121575 +batadv_tt_tvlv_generate_39615 batadv_tt_tvlv_generate 4 39615 NULL
121576 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
121577 +sdio_readb_39618 sdio_readb 0 39618 NULL
121578 +set_dev_class_39645 set_dev_class 4 39645 NULL
121579 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
121580 +tcp_try_rmem_schedule_39657 tcp_try_rmem_schedule 3 39657 NULL
121581 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
121582 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
121583 +hsc_msg_len_get_39673 hsc_msg_len_get 0 39673 NULL
121584 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
121585 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
121586 +adt7316_spi_multi_read_39765 adt7316_spi_multi_read 3 39765 NULL
121587 +security_inode_listsecurity_39812 security_inode_listsecurity 0 39812 NULL
121588 +snd_pcm_oss_writev3_39818 snd_pcm_oss_writev3 3 39818 NULL
121589 +get_priv_size_39828 get_priv_size 0-1 39828 NULL
121590 +netlbl_catmap_walkrng_39885 netlbl_catmap_walkrng 0-2 39885 NULL
121591 +pkt_add_39897 pkt_add 3 39897 NULL
121592 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
121593 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
121594 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
121595 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
121596 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 NULL nohasharray
121597 +exofs_read_kern_39921 exofs_read_kern 6 39921 &oom_score_adj_read_39921
121598 +__spi_async_39932 __spi_async 0 39932 NULL
121599 +__get_order_39935 __get_order 0 39935 NULL
121600 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL
121601 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3-0 39955 NULL
121602 +lstcon_group_list_39958 lstcon_group_list 2 39958 NULL
121603 +bio_chain_clone_range_39967 bio_chain_clone_range 3 39967 NULL
121604 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
121605 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
121606 +lustre_pack_reply_v2_39978 lustre_pack_reply_v2 2 39978 NULL
121607 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
121608 +fw_device_op_read_39990 fw_device_op_read 3 39990 NULL
121609 +server_name2svname_39998 server_name2svname 4 39998 NULL
121610 +xen_hvm_config_40018 xen_hvm_config 2 40018 NULL
121611 +ivtvfb_write_40023 ivtvfb_write 3 40023 NULL
121612 +disc_pwup_write_40027 disc_pwup_write 3 40027 NULL
121613 +ea_foreach_i_40028 ea_foreach_i 0 40028 NULL
121614 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
121615 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 NULL nohasharray
121616 +add_tty_40055 add_tty 1 40055 &l2cap_create_iframe_pdu_40055
121617 +atomic_xchg_40070 atomic_xchg 0 40070 NULL
121618 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
121619 +dwc2_max_desc_num_40132 dwc2_max_desc_num 0 40132 NULL
121620 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
121621 +ath10k_write_simulate_fw_crash_40143 ath10k_write_simulate_fw_crash 3 40143 NULL
121622 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
121623 +pt_write_40159 pt_write 3 40159 NULL
121624 +scsi_sg_count_40182 scsi_sg_count 0 40182 NULL
121625 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
121626 +allocate_probes_40204 allocate_probes 1 40204 NULL
121627 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
121628 +compress_file_range_40225 compress_file_range 3-4 40225 NULL
121629 +ocrdma_dbgfs_ops_read_40232 ocrdma_dbgfs_ops_read 3 40232 NULL
121630 +osst_read_40237 osst_read 3 40237 NULL
121631 +lpage_info_slot_40243 lpage_info_slot 1-3 40243 NULL
121632 +ocfs2_zero_extend_get_range_40248 ocfs2_zero_extend_get_range 4-3 40248 NULL
121633 +of_get_child_count_40254 of_get_child_count 0 40254 NULL nohasharray
121634 +fsl_edma_prep_dma_cyclic_40254 fsl_edma_prep_dma_cyclic 3-4 40254 &of_get_child_count_40254
121635 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
121636 +ext2_fiemap_40271 ext2_fiemap 4 40271 NULL
121637 +usbnet_read_cmd_40275 usbnet_read_cmd 7 40275 NULL
121638 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
121639 +tracing_thresh_read_40295 tracing_thresh_read 3 40295 NULL
121640 +SyS_bind_40303 SyS_bind 3 40303 NULL
121641 +ib_get_mad_data_offset_40336 ib_get_mad_data_offset 0 40336 NULL
121642 +mmio_read_40348 mmio_read 4 40348 NULL
121643 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
121644 +ocfs2_check_range_for_refcount_40365 ocfs2_check_range_for_refcount 3-2 40365 NULL
121645 +get_chars_40373 get_chars 3 40373 NULL
121646 +fb_prepare_extra_logos_40429 fb_prepare_extra_logos 0-2 40429 NULL
121647 +proc_write_driver_40432 proc_write_driver 3 40432 NULL
121648 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
121649 +zd_usb_scnprint_id_40459 zd_usb_scnprint_id 0-3 40459 NULL
121650 +gp2ap020a00f_write_event_threshold_40461 gp2ap020a00f_write_event_threshold 2 40461 NULL
121651 +SyS_writev_40467 SyS_writev 3 40467 NULL
121652 +SyS_select_40473 SyS_select 1 40473 NULL
121653 +afs_fs_store_data_40484 afs_fs_store_data 3-4-5-6 40484 NULL
121654 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
121655 +devcgroup_inode_permission_40492 devcgroup_inode_permission 0 40492 NULL
121656 +__ethtool_get_sset_count_40511 __ethtool_get_sset_count 0 40511 NULL
121657 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
121658 +ixgbe_dbg_reg_ops_read_40540 ixgbe_dbg_reg_ops_read 3 40540 NULL
121659 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
121660 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
121661 +get_priv_descr_and_size_40612 get_priv_descr_and_size 0 40612 NULL
121662 +twl4030_kpwrite_u8_40665 twl4030_kpwrite_u8 3 40665 NULL
121663 +__cfg80211_roamed_40668 __cfg80211_roamed 4-6 40668 NULL
121664 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
121665 +fops_read_40672 fops_read 3 40672 NULL
121666 +idr_get_empty_slot_40674 idr_get_empty_slot 0 40674 NULL
121667 +alloc_rbio_40676 alloc_rbio 4 40676 NULL
121668 +videobuf_dma_init_user_locked_40678 videobuf_dma_init_user_locked 4-3 40678 NULL
121669 +pci_enable_resources_40680 pci_enable_resources 0 40680 NULL
121670 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
121671 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
121672 +lnet_new_text_buf_40717 lnet_new_text_buf 1 40717 NULL
121673 +ip_skb_dst_mtu_40718 ip_skb_dst_mtu 0 40718 NULL
121674 +of_pdt_build_one_prop_40735 of_pdt_build_one_prop 5 40735 NULL
121675 +fuse_readpages_40737 fuse_readpages 4 40737 NULL
121676 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
121677 +security_inode_listxattr_40752 security_inode_listxattr 0 40752 NULL
121678 +card_send_command_40757 card_send_command 3 40757 NULL
121679 +ad1889_readl_40765 ad1889_readl 0 40765 NULL
121680 +pg_write_40766 pg_write 3 40766 NULL
121681 +kernfs_fop_read_40770 kernfs_fop_read 3 40770 NULL
121682 +show_list_40775 show_list 3-0 40775 NULL
121683 +kfifo_out_copy_r_40784 kfifo_out_copy_r 0-3 40784 NULL
121684 +bitmap_weight_40791 bitmap_weight 0-2 40791 NULL
121685 +pyra_sysfs_read_40795 pyra_sysfs_read 6 40795 NULL
121686 +rtw_add_beacon_40801 rtw_add_beacon 3-5 40801 NULL
121687 +add_action_40811 add_action 4 40811 NULL
121688 +nl80211_send_roamed_40825 nl80211_send_roamed 5-7 40825 NULL
121689 +nilfs_mdt_init_40849 nilfs_mdt_init 3 40849 NULL
121690 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
121691 +read_file_queue_40895 read_file_queue 3 40895 NULL
121692 +waiters_read_40902 waiters_read 3 40902 NULL
121693 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
121694 +gfs2_ea_find_40913 gfs2_ea_find 0 40913 NULL
121695 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
121696 +snd_vx_create_40948 snd_vx_create 4 40948 NULL
121697 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
121698 +ima_appraise_measurement_40978 ima_appraise_measurement 6 40978 NULL
121699 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
121700 +iwl_dbgfs_scan_ant_rxchain_read_40999 iwl_dbgfs_scan_ant_rxchain_read 3 40999 NULL
121701 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
121702 +get_pages_alloc_bvec_41012 get_pages_alloc_bvec 0-3 41012 NULL
121703 +__proc_dobitmasks_41029 __proc_dobitmasks 5 41029 NULL
121704 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
121705 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
121706 +ocfs2_xattr_index_block_find_41040 ocfs2_xattr_index_block_find 0 41040 NULL
121707 +lprocfs_write_frac_helper_41050 lprocfs_write_frac_helper 2 41050 NULL
121708 +vfs_listxattr_41062 vfs_listxattr 0 41062 NULL nohasharray
121709 +beacon_filtering_write_41062 beacon_filtering_write 3 41062 &vfs_listxattr_41062
121710 +sc_only_mode_read_41076 sc_only_mode_read 3 41076 NULL
121711 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
121712 +nvme_map_user_pages_41093 nvme_map_user_pages 4-3 41093 NULL nohasharray
121713 +roccat_read_41093 roccat_read 3 41093 &nvme_map_user_pages_41093
121714 +dma_attach_41094 dma_attach 5-6 41094 NULL
121715 +provide_user_output_41105 provide_user_output 3 41105 NULL
121716 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
121717 +ath10k_read_wmi_services_41112 ath10k_read_wmi_services 3 41112 NULL
121718 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
121719 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
121720 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
121721 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
121722 +nfs_page_array_len_41219 nfs_page_array_len 0-2-1 41219 NULL
121723 +cfg80211_process_disassoc_41231 cfg80211_process_disassoc 3 41231 NULL
121724 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
121725 +erst_read_41260 erst_read 0 41260 NULL
121726 +alloc_context_41283 alloc_context 1 41283 NULL
121727 +of_count_phandle_with_args_41291 of_count_phandle_with_args 0 41291 NULL
121728 +virtscsi_change_queue_depth_41327 virtscsi_change_queue_depth 2 41327 NULL
121729 +o2hb_setup_one_bio_41341 o2hb_setup_one_bio 4 41341 NULL
121730 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
121731 +rtw_android_set_block_41347 rtw_android_set_block 0 41347 NULL
121732 +ceph_do_getattr_41349 ceph_do_getattr 0 41349 NULL
121733 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
121734 +kmp_init_41373 kmp_init 2 41373 NULL
121735 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
121736 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
121737 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
121738 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
121739 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
121740 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
121741 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 6-4 41442 NULL
121742 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
121743 +se_io_cb_41461 se_io_cb 3 41461 NULL
121744 +layout_leb_in_gaps_41470 layout_leb_in_gaps 0 41470 NULL
121745 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
121746 +bl_alloc_init_bio_41478 bl_alloc_init_bio 1 41478 NULL
121747 +kvm_unmap_hva_range_41484 kvm_unmap_hva_range 3-2 41484 NULL
121748 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
121749 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
121750 +xfrm_hash_new_size_41505 xfrm_hash_new_size 0-1 41505 NULL
121751 +SyS_preadv_41523 SyS_preadv 3 41523 NULL
121752 +dm_get_reserved_rq_based_ios_41529 dm_get_reserved_rq_based_ios 0 41529 NULL
121753 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
121754 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
121755 +nr_status_frames_41559 nr_status_frames 0-1 41559 NULL nohasharray
121756 +si476x_radio_fops_read_41559 si476x_radio_fops_read 3 41559 &nr_status_frames_41559
121757 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
121758 +nfsd_readv_41585 nfsd_readv 4 41585 NULL
121759 +batadv_tvlv_container_ogm_append_41588 batadv_tvlv_container_ogm_append 4 41588 NULL
121760 +tcp_hdrlen_41610 tcp_hdrlen 0 41610 NULL
121761 +lbs_bcnmiss_write_41613 lbs_bcnmiss_write 3 41613 NULL nohasharray
121762 +usb_endpoint_maxp_41613 usb_endpoint_maxp 0 41613 &lbs_bcnmiss_write_41613
121763 +a2mp_send_41615 a2mp_send 4 41615 NULL
121764 +lstcon_batch_list_41627 lstcon_batch_list 2 41627 NULL
121765 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
121766 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
121767 +get_std_timing_41654 get_std_timing 0 41654 NULL
121768 +ieee80211_if_fmt_bssid_41677 ieee80211_if_fmt_bssid 3 41677 NULL
121769 +fill_pcm_stream_name_41685 fill_pcm_stream_name 2 41685 NULL
121770 +lov_unpackmd_41701 lov_unpackmd 4 41701 NULL
121771 +connector_write_41709 connector_write 3 41709 NULL
121772 +fillonedir_41746 fillonedir 3 41746 NULL
121773 +iwl_dbgfs_bt_notif_read_41794 iwl_dbgfs_bt_notif_read 3 41794 NULL
121774 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
121775 +ptlrpc_new_bulk_41804 ptlrpc_new_bulk 1 41804 NULL
121776 +rtw_android_get_macaddr_41812 rtw_android_get_macaddr 0 41812 NULL
121777 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
121778 +kimage_file_alloc_init_41827 kimage_file_alloc_init 5 41827 NULL
121779 +copy_page_to_iter_bvec_41830 copy_page_to_iter_bvec 0-3 41830 NULL
121780 +ixgbe_dbg_netdev_ops_read_41839 ixgbe_dbg_netdev_ops_read 3 41839 NULL
121781 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
121782 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
121783 +pci_map_single_41869 pci_map_single 0 41869 NULL
121784 +usb_gadget_get_string_41871 usb_gadget_get_string 0 41871 NULL
121785 +v_APCI3120_InterruptDmaMoveBlock16bit_41914 v_APCI3120_InterruptDmaMoveBlock16bit 4 41914 NULL
121786 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
121787 +ext4_da_write_inline_data_begin_41935 ext4_da_write_inline_data_begin 4-3 41935 NULL
121788 +sci_rxfill_41945 sci_rxfill 0 41945 NULL
121789 +read_gssp_41947 read_gssp 3 41947 NULL
121790 +ocfs2_xattr_bucket_get_name_value_41949 ocfs2_xattr_bucket_get_name_value 0 41949 NULL
121791 +portnames_read_41958 portnames_read 3 41958 NULL
121792 +dst_mtu_41969 dst_mtu 0 41969 NULL
121793 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
121794 +pool_allocate_42012 pool_allocate 3 42012 NULL
121795 +spidev_sync_read_42014 spidev_sync_read 0 42014 NULL
121796 +rs_sta_dbgfs_scale_table_write_42017 rs_sta_dbgfs_scale_table_write 3 42017 NULL
121797 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
121798 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
121799 +alloc_trace_kprobe_42041 alloc_trace_kprobe 6 42041 NULL
121800 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
121801 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
121802 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
121803 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
121804 +ufshcd_dev_cmd_completion_42080 ufshcd_dev_cmd_completion 0 42080 NULL
121805 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
121806 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
121807 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
121808 +dw_dma_cyclic_prep_42113 dw_dma_cyclic_prep 3-4 42113 NULL
121809 +blk_ioctl_zeroout_42160 blk_ioctl_zeroout 3 42160 NULL
121810 +mmc_align_data_size_42161 mmc_align_data_size 0-2 42161 NULL
121811 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
121812 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
121813 +write_file_beacon_42185 write_file_beacon 3 42185 NULL
121814 +get_znodes_to_commit_42201 get_znodes_to_commit 0 42201 NULL
121815 +blockdev_direct_IO_42235 blockdev_direct_IO 5 42235 NULL nohasharray
121816 +pla_ocp_read_42235 pla_ocp_read 3 42235 &blockdev_direct_IO_42235
121817 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
121818 +find_last_bit_42260 find_last_bit 0 42260 NULL
121819 +__pcpu_size_to_slot_42271 __pcpu_size_to_slot 0 42271 NULL
121820 +__tty_buffer_request_room_42276 __tty_buffer_request_room 2-0 42276 NULL
121821 +snd_pcm_hw_param_value_max_42280 snd_pcm_hw_param_value_max 0 42280 NULL
121822 +__cpus_weight_42299 __cpus_weight 2-0 42299 NULL
121823 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
121824 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
121825 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
121826 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
121827 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
121828 +tcp_sync_mss_42330 tcp_sync_mss 2-0 42330 NULL
121829 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
121830 +drbd_md_last_sector_42378 drbd_md_last_sector 0 42378 NULL
121831 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
121832 +msnd_fifo_read_42406 msnd_fifo_read 0-3 42406 NULL
121833 +krng_get_random_42420 krng_get_random 3 42420 NULL
121834 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
121835 +spr_wm_latency_write_42441 spr_wm_latency_write 3 42441 NULL
121836 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
121837 +snd_pcm_action_group_42452 snd_pcm_action_group 0 42452 NULL
121838 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
121839 +kuc_free_42455 kuc_free 2 42455 NULL
121840 +cp2112_gpio_get_42467 cp2112_gpio_get 2 42467 NULL
121841 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
121842 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
121843 +bypass_write_42498 bypass_write 3 42498 NULL
121844 +SyS_mincore_42511 SyS_mincore 1-2 42511 NULL
121845 +kvm_write_wall_clock_42520 kvm_write_wall_clock 2 42520 NULL
121846 +dio_bio_complete_42524 dio_bio_complete 0 42524 NULL
121847 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
121848 +dbAllocNear_42546 dbAllocNear 0 42546 NULL
121849 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 NULL
121850 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
121851 +iwl_print_event_log_42566 iwl_print_event_log 0-7-5 42566 NULL
121852 +xfrm_new_hash_mask_42579 xfrm_new_hash_mask 0-1 42579 NULL
121853 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
121854 +ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout_42635 ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout 3 42635 NULL
121855 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
121856 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
121857 +parport_pc_compat_write_block_pio_42644 parport_pc_compat_write_block_pio 3 42644 NULL
121858 +_regmap_raw_write_42652 _regmap_raw_write 4-2 42652 NULL
121859 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
121860 +vb2_read_42703 vb2_read 3 42703 NULL
121861 +read_status_42722 read_status 0 42722 NULL
121862 +iwl_mvm_coex_dump_mbox_old_42727 iwl_mvm_coex_dump_mbox_old 4-3-0 42727 NULL
121863 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
121864 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
121865 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
121866 +dpm_sysfs_add_42756 dpm_sysfs_add 0 42756 NULL
121867 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
121868 +snd_midi_event_decode_42780 snd_midi_event_decode 0 42780 NULL
121869 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL nohasharray
121870 +isku_sysfs_read_info_42781 isku_sysfs_read_info 6 42781 &cryptd_hash_setkey_42781
121871 +elfcorehdr_read_notes_42786 elfcorehdr_read_notes 2 42786 NULL
121872 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
121873 +ntfs_attr_extend_allocation_42796 ntfs_attr_extend_allocation 0 42796 NULL
121874 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
121875 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
121876 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
121877 +set_arg_42824 set_arg 3 42824 NULL
121878 +si476x_radio_read_rsq_blob_42827 si476x_radio_read_rsq_blob 3 42827 NULL
121879 +ocfs2_clusters_for_bytes_42872 ocfs2_clusters_for_bytes 0-2 42872 NULL
121880 +nvme_trans_unit_serial_page_42879 nvme_trans_unit_serial_page 4 42879 NULL
121881 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
121882 +hd_end_request_42904 hd_end_request 2 42904 NULL
121883 +sta_last_rx_rate_read_42909 sta_last_rx_rate_read 3 42909 NULL
121884 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
121885 +vx_reset_chk_42946 vx_reset_chk 0 42946 NULL
121886 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
121887 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL nohasharray
121888 +rtw_os_xmit_resource_alloc_42990 rtw_os_xmit_resource_alloc 3 42990 &nfs_idmap_get_desc_42990
121889 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
121890 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
121891 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
121892 +nfs_map_group_to_gid_43082 nfs_map_group_to_gid 3 43082 NULL
121893 +_xfer_secondary_pool_43089 _xfer_secondary_pool 2 43089 NULL
121894 +sysfs_create_file_ns_43103 sysfs_create_file_ns 0 43103 NULL
121895 +ieee80211_if_fmt_drop_unencrypted_43107 ieee80211_if_fmt_drop_unencrypted 3 43107 NULL
121896 +calculate_node_totalpages_43118 calculate_node_totalpages 2-3 43118 NULL
121897 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
121898 +cfs_cpt_table_alloc_43159 cfs_cpt_table_alloc 1 43159 NULL
121899 +usb_string_sub_43164 usb_string_sub 0 43164 NULL
121900 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
121901 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
121902 +ext4_xattr_ibody_get_43200 ext4_xattr_ibody_get 0 43200 NULL
121903 +uio_write_43202 uio_write 3 43202 NULL
121904 +iso_callback_43208 iso_callback 3 43208 NULL
121905 +ath10k_p2p_calc_noa_ie_len_43209 ath10k_p2p_calc_noa_ie_len 0 43209 NULL
121906 +f2fs_acl_from_disk_43210 f2fs_acl_from_disk 2 43210 NULL
121907 +atomic_long_add_return_43217 atomic_long_add_return 1 43217 NULL
121908 +gfs2_direct_IO_43220 gfs2_direct_IO 4 43220 NULL
121909 +batadv_tt_tvlv_unicast_handler_v1_43239 batadv_tt_tvlv_unicast_handler_v1 5 43239 NULL
121910 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
121911 +ide_end_rq_43269 ide_end_rq 4 43269 NULL
121912 +evtchn_write_43278 evtchn_write 3 43278 NULL nohasharray
121913 +parport_pc_ecp_write_block_pio_43278 parport_pc_ecp_write_block_pio 3 43278 &evtchn_write_43278
121914 +filemap_write_and_wait_range_43279 filemap_write_and_wait_range 0 43279 NULL
121915 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
121916 +mmu_set_spte_43327 mmu_set_spte 7-6 43327 NULL
121917 +__ext4_get_inode_loc_43332 __ext4_get_inode_loc 0 43332 NULL
121918 +xenfb_write_43412 xenfb_write 3 43412 NULL
121919 +ext4_xattr_check_names_43422 ext4_xattr_check_names 0 43422 NULL
121920 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL
121921 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
121922 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
121923 +usemap_size_43443 usemap_size 0-2-1 43443 NULL nohasharray
121924 +usb_string_43443 usb_string 0 43443 &usemap_size_43443
121925 +get_vm_area_size_43444 get_vm_area_size 0 43444 NULL
121926 +fs_path_prepare_for_add_43453 fs_path_prepare_for_add 2 43453 NULL
121927 +nvme_trans_device_id_page_43466 nvme_trans_device_id_page 4 43466 NULL
121928 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
121929 +ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime_43505 ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime 3 43505 NULL
121930 +ll_direct_IO_26_43530 ll_direct_IO_26 4 43530 NULL
121931 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
121932 +read_events_43534 read_events 3 43534 NULL
121933 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
121934 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
121935 +request_resource_43548 request_resource 0 43548 NULL
121936 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
121937 +handle_frequent_errors_43599 handle_frequent_errors 4 43599 NULL
121938 +lpfc_idiag_drbacc_read_reg_43606 lpfc_idiag_drbacc_read_reg 0-3 43606 NULL
121939 +proc_read_43614 proc_read 3 43614 NULL
121940 +disable_dma_on_even_43618 disable_dma_on_even 0 43618 NULL
121941 +alloc_thread_groups_43625 alloc_thread_groups 2 43625 NULL
121942 +random_write_43656 random_write 3 43656 NULL
121943 +bio_integrity_tag_43658 bio_integrity_tag 3 43658 NULL
121944 +ext4_acl_count_43659 ext4_acl_count 0-1 43659 NULL
121945 +write_file_tx99_power_43670 write_file_tx99_power 3 43670 NULL
121946 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4 43679 NULL
121947 +max77693_bulk_write_43698 max77693_bulk_write 2-3 43698 NULL
121948 +nvkm_connector_create__43711 nvkm_connector_create_ 6 43711 NULL
121949 +fuse_send_read_43725 fuse_send_read 4-0 43725 NULL
121950 +drbd_md_first_sector_43729 drbd_md_first_sector 0 43729 NULL
121951 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
121952 +__alloc_alien_cache_43734 __alloc_alien_cache 2 43734 NULL
121953 +fuse_conn_congestion_threshold_write_43736 fuse_conn_congestion_threshold_write 3 43736 NULL
121954 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
121955 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
121956 +ocfs2_xattr_get_value_outside_43787 ocfs2_xattr_get_value_outside 0 43787 NULL nohasharray
121957 +byte_pos_43787 byte_pos 0 43787 &ocfs2_xattr_get_value_outside_43787
121958 +btrfs_copy_from_user_43806 btrfs_copy_from_user 0-3-1 43806 NULL
121959 +ieee80211_if_fmt_element_ttl_43825 ieee80211_if_fmt_element_ttl 3 43825 NULL
121960 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
121961 +read_flush_43851 read_flush 3 43851 NULL
121962 +pm860x_bulk_write_43875 pm860x_bulk_write 2-3 43875 NULL
121963 +ec_dbgfs_cmd_write_43895 ec_dbgfs_cmd_write 3 43895 NULL
121964 +SendString_43928 SendString 3 43928 NULL
121965 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
121966 +__get_required_blob_size_43980 __get_required_blob_size 0-3-2 43980 NULL
121967 +nla_reserve_43984 nla_reserve 3 43984 NULL
121968 +__clkdev_alloc_43990 __clkdev_alloc 1 43990 NULL
121969 +kvm_read_guest_virt_43992 kvm_read_guest_virt 4-2 43992 NULL nohasharray
121970 +scsi_command_size_43992 scsi_command_size 0 43992 &kvm_read_guest_virt_43992 nohasharray
121971 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 &scsi_command_size_43992
121972 +emit_flags_44006 emit_flags 4-3 44006 NULL
121973 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
121974 +fru_strlen_44046 fru_strlen 0 44046 NULL
121975 +ath9k_def_dump_modal_eeprom_44078 ath9k_def_dump_modal_eeprom 3-2-0 44078 NULL
121976 +SYSC_add_key_44079 SYSC_add_key 4 44079 NULL
121977 +pci_msix_vec_count_44093 pci_msix_vec_count 0 44093 NULL
121978 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
121979 +skb_frag_dma_map_44112 skb_frag_dma_map 0 44112 NULL
121980 +nouveau_clock_create__44116 nouveau_clock_create_ 6 44116 NULL
121981 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL
121982 +SyS_process_vm_writev_44129 SyS_process_vm_writev 3-5 44129 NULL
121983 +tracing_resize_saved_cmdlines_44140 tracing_resize_saved_cmdlines 1 44140 NULL
121984 +ttm_get_pages_44142 ttm_get_pages 2 44142 NULL
121985 +scsi_get_resid_44147 scsi_get_resid 0 44147 NULL
121986 +ocfs2_xattr_bucket_find_44174 ocfs2_xattr_bucket_find 0 44174 NULL
121987 +SYSC_set_mempolicy_44176 SYSC_set_mempolicy 3 44176 NULL
121988 +readreg_ipac_44186 readreg_ipac 0 44186 NULL
121989 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
121990 +btrfs_item_offset_nr_44220 btrfs_item_offset_nr 0 44220 NULL
121991 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
121992 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
121993 +sigma_action_write_regmap_44240 sigma_action_write_regmap 3 44240 NULL
121994 +device_create_file_44285 device_create_file 0 44285 NULL
121995 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
121996 +bitmap_scnprintf_44318 bitmap_scnprintf 0-2 44318 NULL
121997 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
121998 +ccp_init_data_44324 ccp_init_data 5 44324 NULL
121999 +rs_init_44327 rs_init 1 44327 NULL
122000 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 NULL nohasharray
122001 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 &nfs_fscache_get_super_cookie_44355
122002 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
122003 +mtip_hw_read_flags_44396 mtip_hw_read_flags 3 44396 NULL
122004 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
122005 +strlcpy_44400 strlcpy 3 44400 NULL
122006 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
122007 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
122008 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
122009 +mic_virtio_copy_to_user_44472 mic_virtio_copy_to_user 3-4 44472 NULL
122010 +write_file_debug_44476 write_file_debug 3 44476 NULL
122011 +btrfs_chunk_item_size_44478 btrfs_chunk_item_size 0-1 44478 NULL
122012 +sdio_align_size_44489 sdio_align_size 0-2 44489 NULL
122013 +bio_advance_44496 bio_advance 2 44496 NULL
122014 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
122015 +ac_register_board_44504 ac_register_board 3 44504 NULL
122016 +security_getprocattr_44505 security_getprocattr 0 44505 NULL nohasharray
122017 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 &security_getprocattr_44505
122018 +spidev_write_44510 spidev_write 3 44510 NULL
122019 +SyS_io_getevents_44519 SyS_io_getevents 3 44519 NULL
122020 +ieee80211_rx_mgmt_assoc_resp_44525 ieee80211_rx_mgmt_assoc_resp 3 44525 NULL
122021 +comm_write_44537 comm_write 3 44537 NULL
122022 +dgrp_config_proc_write_44571 dgrp_config_proc_write 3 44571 NULL
122023 +l2cap_sock_memcpy_fromiovec_cb_44573 l2cap_sock_memcpy_fromiovec_cb 4 44573 NULL
122024 +nouveau_perfmon_create__44602 nouveau_perfmon_create_ 4 44602 NULL
122025 +xpcs_mmd_write_44633 xpcs_mmd_write 3 44633 NULL
122026 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
122027 +mpi_resize_44674 mpi_resize 2 44674 NULL
122028 +sysfs_create_link_44685 sysfs_create_link 0 44685 NULL
122029 +ts_read_44687 ts_read 3 44687 NULL
122030 +lov_emerg_alloc_44698 lov_emerg_alloc 1 44698 NULL
122031 +C_SYSC_select_44701 C_SYSC_select 1 44701 NULL
122032 +__generic_block_fiemap_44713 __generic_block_fiemap 4 44713 NULL nohasharray
122033 +xfer_to_user_44713 xfer_to_user 3 44713 &__generic_block_fiemap_44713
122034 +nft_hash_tbl_size_44724 nft_hash_tbl_size 0 44724 NULL
122035 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
122036 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
122037 +fib_count_nexthops_44730 fib_count_nexthops 0 44730 NULL
122038 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
122039 +bch_bio_max_sectors_44755 bch_bio_max_sectors 0 44755 NULL
122040 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
122041 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
122042 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4-0 44769 NULL
122043 +handsfree_ramp_44777 handsfree_ramp 2 44777 NULL
122044 +irq_domain_add_legacy_44781 irq_domain_add_legacy 4-2 44781 NULL
122045 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
122046 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
122047 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
122048 +force_static_address_write_44819 force_static_address_write 3 44819 NULL
122049 +mei_cl_read_start_44824 mei_cl_read_start 2 44824 NULL
122050 +rmap_write_protect_44833 rmap_write_protect 2 44833 NULL
122051 +sisusb_write_44834 sisusb_write 3 44834 NULL
122052 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
122053 +qib_verbs_send_dma_44850 qib_verbs_send_dma 6 44850 NULL
122054 +copydesc_user_44855 copydesc_user 3 44855 NULL
122055 +set_advertising_44870 set_advertising 4 44870 NULL
122056 +init_rs_44873 init_rs 1 44873 NULL
122057 +skb_availroom_44883 skb_availroom 0 44883 NULL
122058 +do_tty_write_44896 do_tty_write 5 44896 NULL
122059 +regmap_spi_read_44921 regmap_spi_read 3-5 44921 NULL
122060 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
122061 +bytepos_delta_45017 bytepos_delta 0 45017 NULL
122062 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
122063 +dm_kvzalloc_45025 dm_kvzalloc 1 45025 NULL
122064 +sysfs_do_create_link_sd_45057 sysfs_do_create_link_sd 0 45057 NULL
122065 +sel_write_user_45060 sel_write_user 3 45060 NULL
122066 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
122067 +lnet_expand1tb_45102 lnet_expand1tb 6 45102 NULL
122068 +snd_card_new_45104 snd_card_new 5 45104 NULL
122069 +kvm_mmu_page_get_gfn_45110 kvm_mmu_page_get_gfn 0-2 45110 NULL
122070 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
122071 +usbdev_read_45114 usbdev_read 3 45114 NULL
122072 +send_to_tty_45141 send_to_tty 3 45141 NULL
122073 +cfs_trace_daemon_command_usrstr_45147 cfs_trace_daemon_command_usrstr 2 45147 NULL
122074 +gen_bitmask_string_45149 gen_bitmask_string 6 45149 NULL
122075 +device_write_45156 device_write 3 45156 NULL nohasharray
122076 +ocfs2_remove_inode_range_45156 ocfs2_remove_inode_range 3-4 45156 &device_write_45156
122077 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
122078 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
122079 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL nohasharray
122080 +sctp_pack_cookie_45190 sctp_pack_cookie 6 45190 &snd_sb_csp_load_user_45190
122081 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
122082 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
122083 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
122084 +event_enable_write_45238 event_enable_write 3 45238 NULL
122085 +prism2_pda_proc_read_45246 prism2_pda_proc_read 3 45246 NULL
122086 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
122087 +gfs2_fiemap_45282 gfs2_fiemap 4 45282 NULL
122088 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
122089 +e1000_tx_map_45309 e1000_tx_map 5 45309 NULL
122090 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
122091 +brcmf_sdio_died_dump_45359 brcmf_sdio_died_dump 3 45359 NULL
122092 +null_alloc_repbuf_45375 null_alloc_repbuf 3 45375 NULL
122093 +count_skb_frag_slots_45395 count_skb_frag_slots 0 45395 NULL
122094 +sock_recv_errqueue_45412 sock_recv_errqueue 3 45412 NULL
122095 +ieee80211_if_fmt_dot11MeshHWMProotInterval_45421 ieee80211_if_fmt_dot11MeshHWMProotInterval 3 45421 NULL
122096 +ll_iocontrol_register_45430 ll_iocontrol_register 2 45430 NULL
122097 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
122098 +blkdev_direct_IO_45440 blkdev_direct_IO 4 45440 NULL
122099 +__node_remap_45458 __node_remap 4 45458 NULL
122100 +rds_ib_set_wr_signal_state_45463 rds_ib_set_wr_signal_state 0 45463 NULL
122101 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
122102 +__calc_request_pg_45470 __calc_request_pg 0 45470 NULL
122103 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
122104 +copy_macs_45534 copy_macs 4 45534 NULL
122105 +nla_attr_size_45545 nla_attr_size 0-1 45545 NULL
122106 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
122107 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
122108 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
122109 +_regmap_bus_raw_write_45559 _regmap_bus_raw_write 2 45559 NULL
122110 +posix_acl_xattr_size_45561 posix_acl_xattr_size 0-1 45561 NULL
122111 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
122112 +ath6kl_keepalive_write_45600 ath6kl_keepalive_write 3 45600 NULL
122113 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
122114 +ip_dst_mtu_maybe_forward_45627 ip_dst_mtu_maybe_forward 0 45627 NULL
122115 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
122116 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
122117 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
122118 +bscnl_emit_45699 bscnl_emit 2-5-0 45699 NULL nohasharray
122119 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 &bscnl_emit_45699
122120 +sg_proc_write_adio_45704 sg_proc_write_adio 3 45704 NULL
122121 +wlcore_smart_config_decode_event_45714 wlcore_smart_config_decode_event 2-4 45714 NULL
122122 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
122123 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3-0 45748 NULL nohasharray
122124 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
122125 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
122126 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
122127 +osc_checksum_type_seq_write_45785 osc_checksum_type_seq_write 3 45785 NULL
122128 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
122129 +rds_tcp_inc_copy_to_user_45804 rds_tcp_inc_copy_to_user 3 45804 NULL
122130 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
122131 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
122132 +ll_max_readahead_mb_seq_write_45815 ll_max_readahead_mb_seq_write 3 45815 NULL
122133 +memcg_update_cache_size_45828 memcg_update_cache_size 2 45828 NULL
122134 +ipv6_recv_rxpmtu_45830 ipv6_recv_rxpmtu 3 45830 NULL
122135 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
122136 +efx_tx_queue_insert_45859 efx_tx_queue_insert 2 45859 NULL
122137 +isdn_write_45863 isdn_write 3 45863 NULL
122138 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
122139 +ocfs2_xattr_block_find_45891 ocfs2_xattr_block_find 0 45891 NULL
122140 +cfs_cpt_weight_45903 cfs_cpt_weight 0 45903 NULL
122141 +wm_adsp_region_to_reg_45915 wm_adsp_region_to_reg 0-2 45915 NULL
122142 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
122143 +btree_keys_cachelines_45928 btree_keys_cachelines 0 45928 NULL
122144 +alloc_mr_45935 alloc_mr 1 45935 NULL
122145 +copy_to_45969 copy_to 3 45969 NULL
122146 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
122147 +ioat2_dca_count_dca_slots_45984 ioat2_dca_count_dca_slots 0 45984 NULL
122148 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
122149 +fnic_reset_stats_read_46030 fnic_reset_stats_read 3 46030 NULL nohasharray
122150 +get_free_entries_46030 get_free_entries 1 46030 &fnic_reset_stats_read_46030
122151 +__access_remote_vm_46031 __access_remote_vm 0 46031 NULL
122152 +snd_emu10k1x_ptr_read_46049 snd_emu10k1x_ptr_read 0 46049 NULL
122153 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 NULL nohasharray
122154 +__ocfs2_move_extent_46060 __ocfs2_move_extent 3-4 46060 &dma_tx_errors_read_46060
122155 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
122156 +memcg_update_array_size_46111 memcg_update_array_size 1 46111 NULL nohasharray
122157 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 &memcg_update_array_size_46111
122158 +C_SYSC_writev_46113 C_SYSC_writev 3 46113 NULL
122159 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
122160 +rtw_buf_update_46138 rtw_buf_update 4 46138 NULL
122161 +vb2_dma_sg_get_userptr_46146 vb2_dma_sg_get_userptr 3-2 46146 NULL
122162 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
122163 +twl_direction_out_46182 twl_direction_out 2 46182 NULL
122164 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
122165 +fq_resize_46195 fq_resize 2 46195 NULL
122166 +add_conn_list_46197 add_conn_list 3-0 46197 NULL
122167 +i2400m_op_msg_from_user_46213 i2400m_op_msg_from_user 4 46213 NULL
122168 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
122169 +dsp_write_46218 dsp_write 2 46218 NULL
122170 +hash_netiface4_expire_46226 hash_netiface4_expire 4 46226 NULL
122171 +xen_setup_msi_irqs_46245 xen_setup_msi_irqs 2 46245 NULL
122172 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
122173 +sg_proc_write_dressz_46316 sg_proc_write_dressz 3 46316 NULL
122174 +C_SYSC_ppoll_46319 C_SYSC_ppoll 2 46319 NULL
122175 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL nohasharray
122176 +compat_SyS_readv_46328 compat_SyS_readv 3 46328 &__hwahc_dev_set_key_46328
122177 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
122178 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
122179 +crypto_ablkcipher_reqsize_46411 crypto_ablkcipher_reqsize 0 46411 NULL
122180 +ttm_page_pool_get_pages_46431 ttm_page_pool_get_pages 0-5 46431 NULL
122181 +cfs_power2_roundup_46433 cfs_power2_roundup 0-1 46433 NULL
122182 +wdata_alloc_and_fillpages_46437 wdata_alloc_and_fillpages 1 46437 NULL
122183 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
122184 +parport_pc_fifo_write_block_46455 parport_pc_fifo_write_block 3 46455 NULL
122185 +il_dbgfs_clear_traffic_stats_write_46458 il_dbgfs_clear_traffic_stats_write 3 46458 NULL
122186 +filldir64_46469 filldir64 3 46469 NULL
122187 +fill_in_write_vector_46498 fill_in_write_vector 0 46498 NULL
122188 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
122189 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
122190 +kmsg_read_46514 kmsg_read 3 46514 NULL nohasharray
122191 +nouveau_drm_ioctl_46514 nouveau_drm_ioctl 2 46514 &kmsg_read_46514
122192 +nl80211_send_rx_assoc_46538 nl80211_send_rx_assoc 4 46538 NULL
122193 +__btrfs_free_extent_46573 __btrfs_free_extent 7 46573 NULL
122194 +dn_current_mss_46574 dn_current_mss 0 46574 NULL
122195 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
122196 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
122197 +il3945_stats_flag_46606 il3945_stats_flag 0-3 46606 NULL
122198 +vscnprintf_46617 vscnprintf 0-2 46617 NULL
122199 +__kfifo_out_r_46623 __kfifo_out_r 0-3 46623 NULL
122200 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
122201 +pci_enable_device_46642 pci_enable_device 0 46642 NULL
122202 +vfs_getxattr_alloc_46649 vfs_getxattr_alloc 0 46649 NULL
122203 +e1000_tx_map_46672 e1000_tx_map 4 46672 NULL
122204 +l2cap_create_le_flowctl_pdu_46682 l2cap_create_le_flowctl_pdu 3 46682 NULL
122205 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
122206 +__ilog2_u32_46706 __ilog2_u32 0 46706 NULL
122207 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
122208 +wl1271_rx_filter_alloc_field_46721 wl1271_rx_filter_alloc_field 5 46721 NULL
122209 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
122210 +read_file_tx99_46741 read_file_tx99 3 46741 NULL
122211 +ext4_count_free_46754 ext4_count_free 2 46754 NULL
122212 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
122213 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
122214 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
122215 +shmem_pwrite_fast_46842 shmem_pwrite_fast 3 46842 NULL
122216 +readreg_46845 readreg 0 46845 NULL
122217 +spi_async_46857 spi_async 0 46857 NULL
122218 +vsnprintf_46863 vsnprintf 0 46863 NULL
122219 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
122220 +qp_memcpy_from_queue_iov_46874 qp_memcpy_from_queue_iov 5-4 46874 NULL
122221 +lov_iocontrol_46876 lov_iocontrol 3 46876 NULL
122222 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
122223 +sk_mem_pages_46896 sk_mem_pages 0-1 46896 NULL
122224 +ieee80211_if_fmt_power_mode_46906 ieee80211_if_fmt_power_mode 3 46906 NULL
122225 +wlcore_alloc_hw_46917 wlcore_alloc_hw 1-3 46917 NULL
122226 +fb_write_46924 fb_write 3 46924 NULL
122227 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
122228 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
122229 +SYSC_poll_46965 SYSC_poll 2 46965 NULL
122230 +crypto_tfm_alg_alignmask_46971 crypto_tfm_alg_alignmask 0 46971 NULL
122231 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
122232 +strlcat_46985 strlcat 3 46985 NULL
122233 +bitmap_file_clear_bit_46990 bitmap_file_clear_bit 2 46990 NULL
122234 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
122235 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
122236 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2-4 47024 NULL
122237 +fs_path_len_47060 fs_path_len 0 47060 NULL
122238 +event_trigger_regex_write_47067 event_trigger_regex_write 3 47067 NULL
122239 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
122240 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
122241 +iwl_dump_nic_event_log_47089 iwl_dump_nic_event_log 0 47089 NULL
122242 +ptlrpc_lprocfs_threads_max_seq_write_47104 ptlrpc_lprocfs_threads_max_seq_write 3 47104 NULL
122243 +mousedev_read_47123 mousedev_read 3 47123 NULL
122244 +upcall_msg_size_47141 upcall_msg_size 2 47141 NULL
122245 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 NULL nohasharray
122246 +ses_recv_diag_47143 ses_recv_diag 4 47143 &acpi_ut_initialize_buffer_47143
122247 +mxms_headerlen_47161 mxms_headerlen 0 47161 NULL
122248 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
122249 +options_write_47243 options_write 3 47243 NULL
122250 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
122251 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
122252 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
122253 +vsnprintf_47291 vsnprintf 0 47291 NULL
122254 +SYSC_semop_47292 SYSC_semop 3 47292 NULL
122255 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
122256 +nouveau_fb_create__47316 nouveau_fb_create_ 4 47316 NULL
122257 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
122258 +avc_get_hash_stats_47359 avc_get_hash_stats 0 47359 NULL
122259 +kvm_arch_create_memslot_47364 kvm_arch_create_memslot 3 47364 NULL nohasharray
122260 +__output_copy_user_47364 __output_copy_user 3 47364 &kvm_arch_create_memslot_47364
122261 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
122262 +nv_rd32_47390 nv_rd32 0 47390 NULL nohasharray
122263 +trace_options_core_read_47390 trace_options_core_read 3 47390 &nv_rd32_47390
122264 +nametbl_list_47391 nametbl_list 2 47391 NULL
122265 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
122266 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
122267 +lbs_wrmac_write_47400 lbs_wrmac_write 3 47400 NULL
122268 +sta_vht_capa_read_47409 sta_vht_capa_read 3 47409 NULL
122269 +crypto_ablkcipher_alignmask_47410 crypto_ablkcipher_alignmask 0 47410 NULL
122270 +lbs_wrrf_write_47418 lbs_wrrf_write 3 47418 NULL
122271 +C_SYSC_set_mempolicy_47466 C_SYSC_set_mempolicy 3 47466 NULL
122272 +lprocfs_fid_write_common_47471 lprocfs_fid_write_common 2 47471 NULL
122273 +nvme_trans_send_fw_cmd_47479 nvme_trans_send_fw_cmd 4 47479 NULL
122274 +newpart_47485 newpart 6-4 47485 NULL
122275 +mcp23s17_read_regs_47491 mcp23s17_read_regs 4 47491 NULL
122276 +core_sys_select_47494 core_sys_select 1 47494 NULL
122277 +as3722_block_write_47503 as3722_block_write 2-3 47503 NULL
122278 +alloc_arraycache_47505 alloc_arraycache 2 47505 NULL
122279 +unlink_simple_47506 unlink_simple 3 47506 NULL
122280 +pstore_decompress_47510 pstore_decompress 0 47510 NULL
122281 +ec_i2c_count_response_47518 ec_i2c_count_response 0 47518 NULL
122282 +__proc_lnet_portal_rotor_47529 __proc_lnet_portal_rotor 5 47529 NULL
122283 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL nohasharray
122284 +vscnprintf_47533 vscnprintf 0-2 47533 &process_vm_rw_47533
122285 +ieee80211_if_fmt_min_discovery_timeout_47539 ieee80211_if_fmt_min_discovery_timeout 3 47539 NULL
122286 +drbg_statelen_47551 drbg_statelen 0 47551 NULL
122287 +read_ldt_47570 read_ldt 2 47570 NULL
122288 +isku_sysfs_read_last_set_47572 isku_sysfs_read_last_set 6 47572 NULL
122289 +btrfs_stack_header_bytenr_47589 btrfs_stack_header_bytenr 0 47589 NULL
122290 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
122291 +sctp_ssnmap_new_47608 sctp_ssnmap_new 2-1 47608 NULL
122292 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
122293 +twl4030_clear_set_47624 twl4030_clear_set 4 47624 NULL
122294 +ccp_sha_setkey_47633 ccp_sha_setkey 3 47633 NULL
122295 +get_size_47644 get_size 1-2 47644 NULL
122296 +osc_brw_prep_request_47680 osc_brw_prep_request 5 47680 NULL
122297 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL nohasharray
122298 +ipath_format_hwmsg_47700 ipath_format_hwmsg 2 47700 &packet_recvmsg_47700
122299 +save_microcode_47717 save_microcode 3 47717 NULL
122300 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
122301 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
122302 +ir_prepare_write_buffer_47747 ir_prepare_write_buffer 3 47747 NULL
122303 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
122304 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
122305 +uwb_ie_dump_hex_47774 uwb_ie_dump_hex 4 47774 NULL
122306 +SyS_setgroups16_47780 SyS_setgroups16 1 47780 NULL
122307 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
122308 +ptlrpc_prep_req_47792 ptlrpc_prep_req 4 47792 NULL
122309 +posix_acl_fix_xattr_from_user_47793 posix_acl_fix_xattr_from_user 2 47793 NULL
122310 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
122311 +lov_packmd_47810 lov_packmd 0 47810 NULL
122312 +tree_mod_log_insert_move_47823 tree_mod_log_insert_move 5 47823 NULL
122313 +pinconf_dbg_config_write_47835 pinconf_dbg_config_write 3 47835 NULL
122314 +KEY_SIZE_47855 KEY_SIZE 0 47855 NULL
122315 +vhci_read_47878 vhci_read 3 47878 NULL
122316 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
122317 +cfs_percpt_alloc_47918 cfs_percpt_alloc 2 47918 NULL
122318 +comedi_write_47926 comedi_write 3 47926 NULL
122319 +nvme_trans_get_blk_desc_len_47946 nvme_trans_get_blk_desc_len 0-2 47946 NULL
122320 +gether_get_ifname_47972 gether_get_ifname 3 47972 NULL
122321 +mempool_resize_47983 mempool_resize 2 47983 NULL nohasharray
122322 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 &mempool_resize_47983
122323 +dbg_port_buf_47990 dbg_port_buf 2 47990 NULL
122324 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
122325 +lustre_cfg_len_48002 lustre_cfg_len 0-1 48002 NULL
122326 +gdm_tty_recv_complete_48011 gdm_tty_recv_complete 2 48011 NULL
122327 +bio_integrity_set_tag_48035 bio_integrity_set_tag 3 48035 NULL
122328 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
122329 +SYSC_writev_48040 SYSC_writev 3 48040 NULL
122330 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
122331 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
122332 +palmas_bulk_write_48068 palmas_bulk_write 2-3-5 48068 NULL
122333 +disc_write_48070 disc_write 3 48070 NULL
122334 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
122335 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
122336 +wm_latency_write_48125 wm_latency_write 3 48125 NULL
122337 +load_firmware_48128 load_firmware 2 48128 NULL
122338 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
122339 +set_discoverable_48141 set_discoverable 4 48141 NULL
122340 +dn_fib_count_nhs_48145 dn_fib_count_nhs 0 48145 NULL
122341 +SyS_vmsplice_48150 SyS_vmsplice 3 48150 NULL
122342 +_add_to_r4w_48152 _add_to_r4w 4 48152 NULL
122343 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
122344 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
122345 +rbd_obj_method_sync_48170 rbd_obj_method_sync 8 48170 NULL
122346 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
122347 +cfg80211_process_deauth_48200 cfg80211_process_deauth 3 48200 NULL
122348 +ext4_index_trans_blocks_48205 ext4_index_trans_blocks 0-2 48205 NULL
122349 +snd_seq_dump_var_event_48209 snd_seq_dump_var_event 0 48209 NULL
122350 +uv_blade_nr_possible_cpus_48226 uv_blade_nr_possible_cpus 0 48226 NULL
122351 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
122352 +read_file_recv_48232 read_file_recv 3 48232 NULL
122353 +unaccount_shadowed_48233 unaccount_shadowed 2 48233 NULL
122354 +nouveau_i2c_port_create__48240 nouveau_i2c_port_create_ 7 48240 NULL
122355 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
122356 +batadv_socket_read_48257 batadv_socket_read 3 48257 NULL
122357 +__videobuf_free_48260 __videobuf_free 0 48260 NULL
122358 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
122359 +trace_options_write_48275 trace_options_write 3 48275 NULL
122360 +send_set_info_48288 send_set_info 7 48288 NULL
122361 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
122362 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
122363 +hash_setkey_48310 hash_setkey 3 48310 NULL
122364 +kvm_mmu_pte_write_48340 kvm_mmu_pte_write 2 48340 NULL
122365 +skb_add_data_48363 skb_add_data 3 48363 NULL
122366 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
122367 +ath10k_read_htt_max_amsdu_ampdu_48401 ath10k_read_htt_max_amsdu_ampdu 3 48401 NULL
122368 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
122369 +uhid_event_from_user_48417 uhid_event_from_user 2 48417 NULL
122370 +div64_u64_rem_48418 div64_u64_rem 0-1-2 48418 NULL
122371 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
122372 +print_filtered_48442 print_filtered 2-0 48442 NULL
122373 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
122374 +copy_page_from_iter_iovec_48466 copy_page_from_iter_iovec 3-0 48466 NULL
122375 +compat_SyS_preadv64_48469 compat_SyS_preadv64 3 48469 NULL
122376 +_iwl_dbgfs_bt_tx_prio_write_48473 _iwl_dbgfs_bt_tx_prio_write 3 48473 NULL
122377 +ipath_format_hwerrors_48487 ipath_format_hwerrors 5 48487 NULL
122378 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
122379 +ocfs2_refcount_cow_48495 ocfs2_refcount_cow 3 48495 NULL
122380 +send_control_msg_48498 send_control_msg 6 48498 NULL
122381 +count_masked_bytes_48507 count_masked_bytes 0-1 48507 NULL
122382 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
122383 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
122384 +phantom_get_free_48514 phantom_get_free 0 48514 NULL
122385 +drbd_bm_capacity_48530 drbd_bm_capacity 0 48530 NULL
122386 +raid10_size_48571 raid10_size 0-2-3 48571 NULL
122387 +nvif_notify_init_48578 nvif_notify_init 7 48578 NULL
122388 +llog_data_len_48607 llog_data_len 1 48607 NULL
122389 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
122390 +kernel_sock_ioctl_48644 kernel_sock_ioctl 0 48644 NULL
122391 +ll_rw_extents_stats_pp_seq_write_48651 ll_rw_extents_stats_pp_seq_write 3 48651 NULL
122392 +mtd_read_48655 mtd_read 0 48655 NULL
122393 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
122394 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL
122395 +hysdn_log_write_48694 hysdn_log_write 3 48694 NULL
122396 +altera_drscan_48698 altera_drscan 2 48698 NULL
122397 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
122398 +lpfc_idiag_drbacc_write_48712 lpfc_idiag_drbacc_write 3 48712 NULL
122399 +SyS_lgetxattr_48719 SyS_lgetxattr 4 48719 NULL
122400 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
122401 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
122402 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
122403 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
122404 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
122405 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
122406 +azx_get_position_48841 azx_get_position 0 48841 NULL
122407 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
122408 +comedi_buf_write_alloc_48846 comedi_buf_write_alloc 0-2 48846 NULL
122409 +suspend_dtim_interval_write_48854 suspend_dtim_interval_write 3 48854 NULL
122410 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 NULL nohasharray
122411 +C_SYSC_pwritev64_48864 C_SYSC_pwritev64 3 48864 &viafb_dvp1_proc_write_48864
122412 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
122413 +crypto_cipher_ctxsize_48890 crypto_cipher_ctxsize 0 48890 NULL
122414 +joydev_handle_JSIOCSAXMAP_48898 joydev_handle_JSIOCSAXMAP 3 48898 NULL
122415 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
122416 +msg_hdr_sz_48908 msg_hdr_sz 0 48908 NULL
122417 +sep_crypto_dma_48937 sep_crypto_dma 0 48937 NULL
122418 +si5351_write_parameters_48940 si5351_write_parameters 2 48940 NULL
122419 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
122420 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
122421 +vmci_handle_arr_create_48971 vmci_handle_arr_create 1 48971 NULL
122422 +nilfs_direct_IO_48981 nilfs_direct_IO 4 48981 NULL
122423 +rds_rm_size_48996 rds_rm_size 0-2 48996 NULL
122424 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
122425 +null_alloc_rs_49019 null_alloc_rs 2 49019 NULL
122426 +filemap_check_errors_49022 filemap_check_errors 0 49022 NULL
122427 +transient_status_49027 transient_status 4 49027 NULL
122428 +ll_xattr_cache_add_49032 ll_xattr_cache_add 4-0 49032 NULL
122429 +scsi_register_49094 scsi_register 2 49094 NULL
122430 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
122431 +xfrm_replay_state_esn_len_49119 xfrm_replay_state_esn_len 0 49119 NULL
122432 +ll_max_cached_mb_seq_write_49122 ll_max_cached_mb_seq_write 3 49122 NULL
122433 +pt_read_49136 pt_read 3 49136 NULL
122434 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
122435 +f2fs_acl_count_49155 f2fs_acl_count 0-1 49155 NULL
122436 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
122437 +__jfs_setxattr_49175 __jfs_setxattr 5 49175 NULL
122438 +ath6kl_bgscan_int_write_49178 ath6kl_bgscan_int_write 3 49178 NULL
122439 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
122440 +print_queue_49191 print_queue 0-4 49191 NULL
122441 +root_nfs_cat_49192 root_nfs_cat 3 49192 NULL
122442 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
122443 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
122444 +do_jffs2_getxattr_49210 do_jffs2_getxattr 0 49210 NULL
122445 +nouveau_therm_create__49228 nouveau_therm_create_ 4 49228 NULL
122446 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
122447 +isku_sysfs_read_keys_media_49268 isku_sysfs_read_keys_media 6 49268 NULL
122448 +ptlrpc_check_set_49277 ptlrpc_check_set 0 49277 NULL
122449 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
122450 +viafb_dfph_proc_write_49288 viafb_dfph_proc_write 3 49288 NULL
122451 +uio_read_49300 uio_read 3 49300 NULL
122452 +isku_sysfs_read_keys_macro_49312 isku_sysfs_read_keys_macro 6 49312 NULL
122453 +SYSC_mincore_49319 SYSC_mincore 2-1 49319 NULL
122454 +fwtty_port_handler_49327 fwtty_port_handler 9 49327 NULL
122455 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-4-3 49330 NULL
122456 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
122457 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
122458 +ext4_ext_index_trans_blocks_49396 ext4_ext_index_trans_blocks 0 49396 NULL
122459 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
122460 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
122461 +samples_to_bytes_49426 samples_to_bytes 0-2 49426 NULL
122462 +compat_do_msg_fill_49440 compat_do_msg_fill 3 49440 NULL
122463 +__hfsplus_getxattr_49460 __hfsplus_getxattr 0 49460 NULL
122464 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
122465 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
122466 +tipc_bclink_get_mtu_49483 tipc_bclink_get_mtu 0 49483 NULL
122467 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
122468 +iwl_dbgfs_disable_power_off_read_49517 iwl_dbgfs_disable_power_off_read 3 49517 NULL
122469 +SyS_listxattr_49519 SyS_listxattr 3 49519 NULL
122470 +emulator_write_phys_49520 emulator_write_phys 2-4 49520 NULL
122471 +smk_write_access_49561 smk_write_access 3 49561 NULL
122472 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
122473 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
122474 +readfifo_49583 readfifo 1 49583 NULL
122475 +tap_write_49595 tap_write 3 49595 NULL
122476 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
122477 +btrfs_mksubvol_49616 btrfs_mksubvol 3 49616 NULL
122478 +heap_init_49617 heap_init 2 49617 NULL
122479 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
122480 +port_fops_read_49626 port_fops_read 3 49626 NULL
122481 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
122482 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 3-4 49683 NULL
122483 +SyS_pwritev_49688 SyS_pwritev 3 49688 NULL
122484 +__copy_from_user_nocheck_49699 __copy_from_user_nocheck 0-3 49699 NULL
122485 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
122486 +write_pool_49718 write_pool 3 49718 NULL
122487 +kvm_mmu_notifier_invalidate_page_49723 kvm_mmu_notifier_invalidate_page 3 49723 NULL nohasharray
122488 +sfw_create_test_rpc_49723 sfw_create_test_rpc 4 49723 &kvm_mmu_notifier_invalidate_page_49723
122489 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
122490 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
122491 +btrfs_chunk_num_stripes_49751 btrfs_chunk_num_stripes 0 49751 NULL
122492 +fuse_wr_pages_49753 fuse_wr_pages 0-1-2 49753 NULL
122493 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
122494 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
122495 +w83977af_fir_interrupt_49775 w83977af_fir_interrupt 0 49775 NULL
122496 +ceph_osdc_readpages_49789 ceph_osdc_readpages 0 49789 NULL
122497 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
122498 +__of_parse_phandle_with_args_49807 __of_parse_phandle_with_args 0 49807 NULL
122499 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6-0 49829 NULL
122500 +add_uuid_49831 add_uuid 4 49831 NULL
122501 +iraw_loop_49842 iraw_loop 0-1 49842 NULL
122502 +twl4030_write_49846 twl4030_write 2 49846 NULL
122503 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
122504 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
122505 +fiemap_count_to_size_49869 fiemap_count_to_size 0-1 49869 NULL
122506 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
122507 +osc_brw_49896 osc_brw 4 49896 NULL
122508 +fuse_send_write_49915 fuse_send_write 4-0 49915 NULL
122509 +ieee80211_if_fmt_dtim_count_49987 ieee80211_if_fmt_dtim_count 3 49987 NULL
122510 +drm_buffer_copy_from_user_49990 drm_buffer_copy_from_user 3 49990 NULL
122511 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
122512 +dn_mss_from_pmtu_50011 dn_mss_from_pmtu 0-2 50011 NULL
122513 +security_context_to_sid_50019 security_context_to_sid 2 50019 NULL
122514 +isdn_read_50021 isdn_read 3 50021 NULL
122515 +mdc_rename_pack_50023 mdc_rename_pack 4-6 50023 NULL
122516 +brcmf_debugfs_chipinfo_read_50033 brcmf_debugfs_chipinfo_read 3 50033 NULL
122517 +ioread8_50049 ioread8 0 50049 NULL
122518 +fuse_conn_max_background_write_50061 fuse_conn_max_background_write 3 50061 NULL
122519 +__kfifo_dma_in_prepare_50081 __kfifo_dma_in_prepare 4 50081 NULL
122520 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
122521 +libcfs_ioctl_popdata_50087 libcfs_ioctl_popdata 3 50087 NULL
122522 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
122523 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
122524 +android_set_cntry_50100 android_set_cntry 0 50100 NULL
122525 +read_file_slot_50111 read_file_slot 3 50111 NULL
122526 +rx_streaming_interval_write_50120 rx_streaming_interval_write 3 50120 NULL
122527 +SYSC_preadv_50134 SYSC_preadv 3 50134 NULL
122528 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
122529 +kmalloc_node_50163 kmalloc_node 1 50163 NULL
122530 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
122531 +ahd_probe_stack_size_50168 ahd_probe_stack_size 0 50168 NULL
122532 +odev_update_50169 odev_update 2 50169 NULL
122533 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL nohasharray
122534 +ieee80211_if_fmt_dot11MeshHWMPRannInterval_50172 ieee80211_if_fmt_dot11MeshHWMPRannInterval 3 50172 &ubi_resize_volume_50172
122535 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
122536 +cyttsp4_probe_50201 cyttsp4_probe 4 50201 NULL
122537 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
122538 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
122539 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
122540 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
122541 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
122542 +soc_codec_reg_show_50302 soc_codec_reg_show 0-3 50302 NULL
122543 +SYSC_flistxattr_50307 SYSC_flistxattr 3 50307 NULL
122544 +SYSC_sched_setaffinity_50310 SYSC_sched_setaffinity 2 50310 NULL
122545 +soc_camera_read_50319 soc_camera_read 3 50319 NULL
122546 +do_launder_page_50329 do_launder_page 0 50329 NULL
122547 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
122548 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
122549 +snd_pcm_lib_writev_50337 snd_pcm_lib_writev 0-3 50337 NULL
122550 +tpm_read_50344 tpm_read 3 50344 NULL
122551 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
122552 +iwl_dbgfs_echo_test_write_50362 iwl_dbgfs_echo_test_write 3 50362 NULL
122553 +xfrm_send_migrate_50365 xfrm_send_migrate 5 50365 NULL
122554 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
122555 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
122556 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
122557 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
122558 +validate_acl_mac_addrs_50429 validate_acl_mac_addrs 0 50429 NULL
122559 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
122560 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
122561 +device_create_sys_dev_entry_50458 device_create_sys_dev_entry 0 50458 NULL
122562 +cfs_size_round_50472 cfs_size_round 0-1 50472 NULL
122563 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
122564 +mei_io_cb_alloc_req_buf_50493 mei_io_cb_alloc_req_buf 2 50493 NULL
122565 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
122566 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
122567 +trigger_request_store_50548 trigger_request_store 4 50548 NULL
122568 +usbat_flash_write_data_50553 usbat_flash_write_data 4 50553 NULL
122569 +fat_readpages_50582 fat_readpages 4 50582 NULL
122570 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
122571 +xillybus_write_50605 xillybus_write 3 50605 NULL
122572 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
122573 +sparse_early_usemaps_alloc_node_50623 sparse_early_usemaps_alloc_node 4 50623 NULL
122574 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
122575 +ath6kl_tm_rx_event_50664 ath6kl_tm_rx_event 3 50664 NULL
122576 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
122577 +prism2_read_fid_reg_50689 prism2_read_fid_reg 0 50689 NULL
122578 +xfs_growfs_get_hdr_buf_50697 xfs_growfs_get_hdr_buf 3 50697 NULL
122579 +dev_mem_read_50706 dev_mem_read 3 50706 NULL
122580 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
122581 +__ext3_get_inode_loc_50744 __ext3_get_inode_loc 0 50744 NULL
122582 +ocfs2_xattr_block_get_50773 ocfs2_xattr_block_get 0 50773 NULL
122583 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL
122584 +tpm_write_50798 tpm_write 3 50798 NULL
122585 +tun_do_read_50800 tun_do_read 4 50800 NULL
122586 +write_flush_50803 write_flush 3 50803 NULL
122587 +dvb_play_50814 dvb_play 3 50814 NULL
122588 +btrfs_stack_file_extent_disk_num_bytes_50825 btrfs_stack_file_extent_disk_num_bytes 0 50825 NULL
122589 +dpcm_show_state_50827 dpcm_show_state 0 50827 NULL
122590 +SetArea_50835 SetArea 4 50835 NULL
122591 +nft_trans_alloc_50836 nft_trans_alloc 3 50836 NULL
122592 +videobuf_dma_init_user_50839 videobuf_dma_init_user 4-3 50839 NULL
122593 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
122594 +SyS_lgetxattr_50889 SyS_lgetxattr 4 50889 NULL
122595 +netlbl_secattr_catmap_walk_rng_50894 netlbl_secattr_catmap_walk_rng 0-2 50894 NULL
122596 +__bdev_writeseg_50903 __bdev_writeseg 4 50903 NULL
122597 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
122598 +blk_rq_cur_sectors_50910 blk_rq_cur_sectors 0 50910 NULL
122599 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
122600 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
122601 +show_device_status_50947 show_device_status 0 50947 NULL
122602 +irq_timeout_write_50950 irq_timeout_write 3 50950 NULL
122603 +virtio_cread16_50951 virtio_cread16 0 50951 NULL
122604 +sdio_uart_write_50954 sdio_uart_write 3 50954 NULL
122605 +SyS_setxattr_50957 SyS_setxattr 4 50957 NULL
122606 +of_modalias_node_50975 of_modalias_node 3 50975 NULL
122607 +iwl_statistics_flag_50981 iwl_statistics_flag 0-3 50981 NULL
122608 +timeout_write_50991 timeout_write 3 50991 NULL
122609 +proc_write_51003 proc_write 3 51003 NULL
122610 +jbd2_journal_extend_51012 jbd2_journal_extend 2 51012 NULL
122611 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
122612 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
122613 +BcmGetSectionValEndOffset_51039 BcmGetSectionValEndOffset 0 51039 NULL
122614 +dump_midi_51040 dump_midi 3 51040 NULL
122615 +usb_get_descriptor_51041 usb_get_descriptor 0 51041 NULL
122616 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
122617 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
122618 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
122619 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
122620 +__ocfs2_find_path_51096 __ocfs2_find_path 0 51096 NULL
122621 +ti_recv_51110 ti_recv 3 51110 NULL
122622 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
122623 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
122624 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
122625 +iwl_dbgfs_bcast_filters_macs_read_51231 iwl_dbgfs_bcast_filters_macs_read 3 51231 NULL
122626 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
122627 +snd_pcm_write_51235 snd_pcm_write 3 51235 NULL
122628 +drm_property_create_51239 drm_property_create 4 51239 NULL
122629 +st_read_51251 st_read 3 51251 NULL
122630 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
122631 +target_alloc_sgl_51264 target_alloc_sgl 3 51264 NULL
122632 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
122633 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
122634 +pvr2_std_id_to_str_51288 pvr2_std_id_to_str 2 51288 NULL
122635 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
122636 +init_map_ipmac_51317 init_map_ipmac 5 51317 NULL
122637 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
122638 +ext2_xattr_get_51327 ext2_xattr_get 0 51327 NULL
122639 +smk_write_ptrace_51333 smk_write_ptrace 3 51333 NULL
122640 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
122641 +ipw_get_event_log_len_51341 ipw_get_event_log_len 0 51341 NULL
122642 +ieee80211_if_fmt_estab_plinks_51370 ieee80211_if_fmt_estab_plinks 3 51370 NULL
122643 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
122644 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
122645 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
122646 +hfsplus_brec_read_51436 hfsplus_brec_read 0 51436 NULL
122647 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
122648 +print_devstats_dot11ACKFailureCount_51443 print_devstats_dot11ACKFailureCount 3 51443 NULL
122649 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
122650 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
122651 +osc_brw_internal_51489 osc_brw_internal 5 51489 NULL
122652 +kvm_fetch_guest_virt_51493 kvm_fetch_guest_virt 4-2 51493 NULL
122653 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
122654 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
122655 +batadv_tt_prepare_tvlv_local_data_51568 batadv_tt_prepare_tvlv_local_data 0 51568 NULL
122656 +ixgb_get_eeprom_len_51586 ixgb_get_eeprom_len 0 51586 NULL
122657 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
122658 +table_size_to_number_of_entries_51613 table_size_to_number_of_entries 0-1 51613 NULL
122659 +extent_fiemap_51621 extent_fiemap 3 51621 NULL
122660 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
122661 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
122662 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
122663 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
122664 +rtw_os_xmit_resource_alloc23a_51693 rtw_os_xmit_resource_alloc23a 3 51693 NULL
122665 +host_mapping_level_51696 host_mapping_level 0 51696 NULL
122666 +sel_write_access_51704 sel_write_access 3 51704 NULL
122667 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
122668 +v9fs_alloc_rdir_buf_51716 v9fs_alloc_rdir_buf 2 51716 NULL
122669 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
122670 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
122671 +str_read_51731 str_read 4 51731 NULL
122672 +cm4040_read_51732 cm4040_read 3 51732 NULL
122673 +get_user_pages_fast_51751 get_user_pages_fast 0 51751 NULL
122674 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
122675 +if_write_51756 if_write 3 51756 NULL
122676 +ssd1307fb_alloc_array_51788 ssd1307fb_alloc_array 1 51788 NULL
122677 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
122678 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
122679 +ioread32_51847 ioread32 0 51847 NULL nohasharray
122680 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 &ioread32_51847
122681 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
122682 +SYSC_sendto_51852 SYSC_sendto 6 51852 NULL
122683 +bm_page_io_async_51858 bm_page_io_async 2 51858 NULL
122684 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
122685 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
122686 +user_read_51881 user_read 3 51881 NULL
122687 +dbAdjCtl_51888 dbAdjCtl 0 51888 NULL
122688 +SyS_mq_timedsend_51896 SyS_mq_timedsend 3 51896 NULL
122689 +wmi_set_ie_51919 wmi_set_ie 3 51919 NULL
122690 +dbg_status_buf_51930 dbg_status_buf 2 51930 NULL
122691 +__tcp_mtu_to_mss_51938 __tcp_mtu_to_mss 0-2 51938 NULL
122692 +xfrm_alg_len_51940 xfrm_alg_len 0 51940 NULL
122693 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
122694 +get_clock_info_51952 get_clock_info 4 51952 NULL
122695 +snd_mask_min_51969 snd_mask_min 0 51969 NULL
122696 +get_zone_51981 get_zone 0-1 51981 NULL
122697 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
122698 +_c4iw_write_mem_dma_51991 _c4iw_write_mem_dma 3 51991 NULL
122699 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
122700 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
122701 +rdmalt_52022 rdmalt 0 52022 NULL
122702 +override_release_52032 override_release 2 52032 NULL
122703 +end_port_52042 end_port 0 52042 NULL
122704 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
122705 +msnd_fifo_write_52052 msnd_fifo_write 0-3 52052 NULL
122706 +dvb_ringbuffer_avail_52057 dvb_ringbuffer_avail 0 52057 NULL
122707 +__fuse_request_alloc_52060 __fuse_request_alloc 1 52060 NULL
122708 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
122709 +mxuport_process_read_urb_data_52072 mxuport_process_read_urb_data 3 52072 NULL
122710 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
122711 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
122712 +smsdvb_stats_read_52114 smsdvb_stats_read 3 52114 NULL
122713 +split_scan_timeout_write_52128 split_scan_timeout_write 3 52128 NULL
122714 +retry_count_read_52129 retry_count_read 3 52129 NULL
122715 +gdm_usb_hci_send_52138 gdm_usb_hci_send 3 52138 NULL
122716 +sub_alloc_52140 sub_alloc 0 52140 NULL
122717 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
122718 +htable_size_52148 htable_size 0-1 52148 NULL
122719 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
122720 +tipc_node_get_mtu_52157 tipc_node_get_mtu 0 52157 NULL
122721 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
122722 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
122723 +print_prefix_52176 print_prefix 0 52176 NULL
122724 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
122725 +reiserfs_posix_acl_from_disk_52191 reiserfs_posix_acl_from_disk 2 52191 NULL
122726 +f2fs_seek_block_52194 f2fs_seek_block 2 52194 NULL
122727 +vmci_qp_broker_alloc_52216 vmci_qp_broker_alloc 6-5 52216 NULL
122728 +fuse_request_alloc_52243 fuse_request_alloc 1 52243 NULL
122729 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
122730 +shrink_slab_52261 shrink_slab 2 52261 NULL
122731 +ext2_direct_IO_52270 ext2_direct_IO 4 52270 NULL
122732 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
122733 +handle_supp_msgs_52284 handle_supp_msgs 4 52284 NULL
122734 +kobject_set_name_vargs_52309 kobject_set_name_vargs 0 52309 NULL
122735 +read_file_reset_52310 read_file_reset 3 52310 NULL
122736 +ssd1307fb_write_52315 ssd1307fb_write 3 52315 NULL
122737 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
122738 +hwflags_read_52318 hwflags_read 3 52318 NULL
122739 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
122740 +hur_len_52339 hur_len 0 52339 NULL
122741 +bytes_to_frames_52362 bytes_to_frames 0-2 52362 NULL
122742 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
122743 +iwl_dump_fh_52371 iwl_dump_fh 0 52371 NULL
122744 +hfsplus_find_attr_52374 hfsplus_find_attr 0 52374 NULL
122745 +mq_emit_config_values_52378 mq_emit_config_values 3 52378 NULL
122746 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
122747 +jfs_setxattr_52389 jfs_setxattr 4 52389 NULL
122748 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
122749 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
122750 +hso_serial_common_create_52428 hso_serial_common_create 4 52428 NULL
122751 +delay_status_52431 delay_status 5 52431 NULL
122752 +ath6kl_delete_qos_write_52435 ath6kl_delete_qos_write 3 52435 NULL
122753 +ieee80211_if_fmt_num_sta_ps_52438 ieee80211_if_fmt_num_sta_ps 3 52438 NULL
122754 +alauda_read_data_52452 alauda_read_data 3 52452 NULL
122755 +bt_alloc_52457 bt_alloc 2 52457 NULL
122756 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1 52477 NULL
122757 +usb_tranzport_write_52479 usb_tranzport_write 3 52479 NULL
122758 +ocfs2_extend_no_holes_52483 ocfs2_extend_no_holes 3-4 52483 NULL
122759 +fd_do_rw_52495 fd_do_rw 3 52495 NULL
122760 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
122761 +lmv_get_easize_52504 lmv_get_easize 0 52504 NULL
122762 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
122763 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
122764 +dup_variable_bug_52525 dup_variable_bug 3 52525 NULL
122765 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
122766 +SyS_vmsplice_52540 SyS_vmsplice 3 52540 NULL
122767 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
122768 +debug_level_proc_write_52572 debug_level_proc_write 3 52572 NULL
122769 +isku_sysfs_read_macro_52587 isku_sysfs_read_macro 6 52587 NULL
122770 +SyS_setsockopt_52610 SyS_setsockopt 5 52610 NULL
122771 +ll_sa_entry_alloc_52611 ll_sa_entry_alloc 4 52611 NULL
122772 +tps80031_writes_52638 tps80031_writes 3-4 52638 NULL
122773 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
122774 +nvme_queue_extra_52661 nvme_queue_extra 0-1 52661 NULL
122775 +SYSC_gethostname_52677 SYSC_gethostname 2 52677 NULL
122776 +nvd0_disp_pioc_create__52693 nvd0_disp_pioc_create_ 5 52693 NULL
122777 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
122778 +__dm_stat_bio_52722 __dm_stat_bio 3 52722 NULL
122779 +cx25840_ir_rx_read_52724 cx25840_ir_rx_read 3 52724 NULL
122780 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
122781 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
122782 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
122783 +carl9170_debugfs_vif_dump_read_52755 carl9170_debugfs_vif_dump_read 3 52755 NULL
122784 +ieee80211_if_read_beacon_timeout_52756 ieee80211_if_read_beacon_timeout 3 52756 NULL
122785 +nvme_trans_ext_inq_page_52776 nvme_trans_ext_inq_page 3 52776 NULL
122786 +xenvif_write_io_ring_52802 xenvif_write_io_ring 3 52802 NULL
122787 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
122788 +lb_alloc_ep_req_52837 lb_alloc_ep_req 2 52837 NULL
122789 +mon_bin_get_event_52863 mon_bin_get_event 4-6 52863 NULL
122790 +twl6030_gpadc_write_52867 twl6030_gpadc_write 1 52867 NULL
122791 +qib_decode_6120_err_52876 qib_decode_6120_err 3 52876 NULL
122792 +twlreg_write_52880 twlreg_write 3 52880 NULL
122793 +pvr2_ctrl_value_to_sym_internal_52881 pvr2_ctrl_value_to_sym_internal 5 52881 NULL
122794 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
122795 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
122796 +dio_bio_reap_52913 dio_bio_reap 0 52913 NULL
122797 +__kfifo_out_peek_r_52919 __kfifo_out_peek_r 3 52919 NULL
122798 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
122799 +__nodes_remap_52951 __nodes_remap 5 52951 NULL
122800 +ieee80211_if_fmt_fwded_mcast_52961 ieee80211_if_fmt_fwded_mcast 3 52961 NULL
122801 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
122802 +num_node_state_52989 num_node_state 0 52989 NULL
122803 +efivarfs_file_write_53000 efivarfs_file_write 3 53000 NULL
122804 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
122805 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
122806 +bio_cur_bytes_53037 bio_cur_bytes 0 53037 NULL
122807 +nv50_chan_create_53039 nv50_chan_create 5 53039 NULL
122808 +regcache_lzo_block_count_53056 regcache_lzo_block_count 0 53056 NULL
122809 +cfi_read_query_53066 cfi_read_query 0 53066 NULL
122810 +iwl_dbgfs_interrupt_write_53069 iwl_dbgfs_interrupt_write 3 53069 NULL
122811 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
122812 +mic_virtio_copy_from_user_53107 mic_virtio_copy_from_user 3 53107 NULL
122813 +verity_status_53120 verity_status 5 53120 NULL
122814 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
122815 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL
122816 +copy_user_segment_list_53150 copy_user_segment_list 2 53150 NULL
122817 +ieee80211_bss_info_update_53170 ieee80211_bss_info_update 4 53170 NULL
122818 +btrfs_io_bio_alloc_53179 btrfs_io_bio_alloc 2 53179 NULL
122819 +clear_capture_buf_53192 clear_capture_buf 2 53192 NULL
122820 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
122821 +ptlrpc_lprocfs_req_history_max_seq_write_53243 ptlrpc_lprocfs_req_history_max_seq_write 3 53243 NULL
122822 +xfs_trans_read_buf_map_53258 xfs_trans_read_buf_map 5 53258 NULL
122823 +wil_write_file_ssid_53266 wil_write_file_ssid 3 53266 NULL
122824 +btrfs_file_extent_num_bytes_53269 btrfs_file_extent_num_bytes 0 53269 NULL
122825 +f2fs_fiemap_53310 f2fs_fiemap 4 53310 NULL
122826 +ftrace_profile_write_53327 ftrace_profile_write 3 53327 NULL
122827 +find_nr_power_limit_53330 find_nr_power_limit 0 53330 NULL
122828 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
122829 +btree_keys_bytes_53348 btree_keys_bytes 0 53348 NULL
122830 +sock_setbindtodevice_53369 sock_setbindtodevice 3 53369 NULL
122831 +get_random_bytes_arch_53370 get_random_bytes_arch 2 53370 NULL
122832 +test_fw_misc_read_53384 test_fw_misc_read 3 53384 NULL
122833 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
122834 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
122835 +apei_exec_run_optional_53452 apei_exec_run_optional 0 53452 NULL
122836 +paging64_prefetch_gpte_53468 paging64_prefetch_gpte 4 53468 NULL
122837 +ima_write_template_field_data_53475 ima_write_template_field_data 2 53475 NULL nohasharray
122838 +create_trace_kprobe_53475 create_trace_kprobe 1 53475 &ima_write_template_field_data_53475
122839 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
122840 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
122841 +do_verify_xattr_datum_53499 do_verify_xattr_datum 0 53499 NULL
122842 +snd_pcm_format_physical_width_53505 snd_pcm_format_physical_width 0 53505 NULL
122843 +dbAllocNext_53506 dbAllocNext 0 53506 NULL
122844 +check_acl_53512 check_acl 0 53512 NULL nohasharray
122845 +force_sc_support_write_53512 force_sc_support_write 3 53512 &check_acl_53512
122846 +nft_data_dump_53549 nft_data_dump 5 53549 NULL
122847 +SYSC_bind_53582 SYSC_bind 3 53582 NULL
122848 +cifs_utf16_bytes_53593 cifs_utf16_bytes 0 53593 NULL
122849 +proc_uid_map_write_53596 proc_uid_map_write 3 53596 NULL
122850 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
122851 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL nohasharray
122852 +wil_write_file_txmgmt_53626 wil_write_file_txmgmt 3 53626 &___alloc_bootmem_nopanic_53626
122853 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
122854 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
122855 +fuse_fill_write_pages_53682 fuse_fill_write_pages 0-4 53682 NULL
122856 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
122857 +bdev_logical_block_size_53690 bdev_logical_block_size 0 53690 NULL nohasharray
122858 +igb_alloc_q_vector_53690 igb_alloc_q_vector 4-6 53690 &bdev_logical_block_size_53690
122859 +find_overflow_devnum_53711 find_overflow_devnum 0 53711 NULL
122860 +__proc_debug_mb_53732 __proc_debug_mb 5 53732 NULL
122861 +wdm_write_53735 wdm_write 3 53735 NULL
122862 +lpfc_idiag_queacc_read_qe_53755 lpfc_idiag_queacc_read_qe 0-2 53755 NULL
122863 +wa_populate_buf_in_urb_53758 wa_populate_buf_in_urb 3-4 53758 NULL
122864 +ext2_acl_count_53773 ext2_acl_count 0-1 53773 NULL
122865 +__kfifo_dma_in_prepare_r_53792 __kfifo_dma_in_prepare_r 4-5 53792 NULL
122866 +qp_alloc_host_work_53798 qp_alloc_host_work 5-3 53798 NULL
122867 +regmap_raw_write_53803 regmap_raw_write 2-4 53803 NULL
122868 +lpfc_idiag_ctlacc_read_reg_53809 lpfc_idiag_ctlacc_read_reg 0-3 53809 NULL
122869 +nls_nullsize_53815 nls_nullsize 0 53815 NULL
122870 +setup_data_read_53822 setup_data_read 3 53822 NULL
122871 +btrfs_free_reserved_extent_53873 btrfs_free_reserved_extent 2 53873 NULL nohasharray
122872 +pms_read_53873 pms_read 3 53873 &btrfs_free_reserved_extent_53873
122873 +ieee80211_if_fmt_dropped_frames_congestion_53883 ieee80211_if_fmt_dropped_frames_congestion 3 53883 NULL
122874 +SyS_setgroups_53900 SyS_setgroups 1 53900 NULL
122875 +batadv_tt_tvlv_ogm_handler_v1_53909 batadv_tt_tvlv_ogm_handler_v1 5 53909 NULL
122876 +azx_via_get_position_53916 azx_via_get_position 0 53916 NULL
122877 +usb_serial_generic_write_53927 usb_serial_generic_write 4 53927 NULL
122878 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
122879 +__ocfs2_xattr_set_value_outside_53981 __ocfs2_xattr_set_value_outside 5 53981 NULL
122880 +ieee80211_if_fmt_dot11MeshHWMPperrMinInterval_53998 ieee80211_if_fmt_dot11MeshHWMPperrMinInterval 3 53998 NULL
122881 +hfsplus_attr_build_key_54013 hfsplus_attr_build_key 0 54013 NULL
122882 +snd_pcm_lib_write_transfer_54018 snd_pcm_lib_write_transfer 5-2-4 54018 NULL
122883 +mdc_kuc_write_54019 mdc_kuc_write 3 54019 NULL
122884 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
122885 +batadv_tt_update_orig_54049 batadv_tt_update_orig 6-4 54049 NULL
122886 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
122887 +nl80211_send_disconnected_54056 nl80211_send_disconnected 5 54056 NULL
122888 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
122889 +bitmap_bitremap_54096 bitmap_bitremap 4 54096 NULL
122890 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL nohasharray
122891 +lustre_posix_acl_xattr_filter_54103 lustre_posix_acl_xattr_filter 2 54103 &altera_set_ir_pre_54103
122892 +__comedi_buf_write_alloc_54112 __comedi_buf_write_alloc 0-2 54112 NULL
122893 +strn_len_54122 strn_len 0 54122 NULL
122894 +isku_receive_54130 isku_receive 4 54130 NULL
122895 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
122896 +irq_blk_threshold_write_54138 irq_blk_threshold_write 3 54138 NULL
122897 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 NULL
122898 +nouveau_falcon_create__54169 nouveau_falcon_create_ 8 54169 NULL
122899 +p9_client_prepare_req_54175 p9_client_prepare_req 3 54175 NULL
122900 +do_sys_poll_54221 do_sys_poll 2 54221 NULL
122901 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
122902 +pi_read_regr_54231 pi_read_regr 0 54231 NULL
122903 +mcp23s08_read_regs_54246 mcp23s08_read_regs 4 54246 NULL
122904 +reada_add_block_54247 reada_add_block 2 54247 NULL
122905 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
122906 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
122907 +audio_write_54261 audio_write 4 54261 NULL nohasharray
122908 +wusb_prf_54261 wusb_prf 7 54261 &audio_write_54261
122909 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
122910 +kstrtou16_from_user_54274 kstrtou16_from_user 2 54274 NULL
122911 +sizeof_long_54276 sizeof_long 0 54276 NULL
122912 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
122913 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
122914 +reclaim_pages_54301 reclaim_pages 3 54301 NULL
122915 +sprintf_54306 sprintf 0 54306 NULL
122916 +bio_add_pc_page_54319 bio_add_pc_page 4 54319 NULL
122917 +br_fdb_fillbuf_54339 br_fdb_fillbuf 0 54339 NULL
122918 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
122919 +__get_free_pages_54352 __get_free_pages 0 54352 NULL
122920 +readlink_copy_54366 readlink_copy 2 54366 NULL
122921 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
122922 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 NULL nohasharray
122923 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 &intel_sdvo_write_cmd_54377
122924 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
122925 +snd_pcm_oss_read2_54387 snd_pcm_oss_read2 0-3 54387 NULL
122926 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
122927 +ll_ra_count_get_54410 ll_ra_count_get 3 54410 NULL
122928 +copy_gadget_strings_54417 copy_gadget_strings 2-3 54417 NULL
122929 +sparse_early_mem_maps_alloc_node_54485 sparse_early_mem_maps_alloc_node 4 54485 NULL
122930 +simple_strtoull_54493 simple_strtoull 0 54493 NULL
122931 +l2cap_create_basic_pdu_54508 l2cap_create_basic_pdu 3 54508 NULL
122932 +btrfs_ordered_sum_size_54509 btrfs_ordered_sum_size 0-2 54509 NULL
122933 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
122934 +vmci_transport_dgram_enqueue_54525 vmci_transport_dgram_enqueue 4 54525 NULL
122935 +viacam_read_54526 viacam_read 3 54526 NULL
122936 +unix_dgram_connect_54535 unix_dgram_connect 3 54535 NULL
122937 +setsockopt_54539 setsockopt 5 54539 NULL
122938 +lbs_lowsnr_write_54549 lbs_lowsnr_write 3 54549 NULL
122939 +SYSC_setsockopt_54561 SYSC_setsockopt 5 54561 NULL
122940 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
122941 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
122942 +nvme_npages_54601 nvme_npages 0-1 54601 NULL
122943 +irq_pkt_threshold_write_54605 irq_pkt_threshold_write 3 54605 NULL
122944 +port_fops_write_54627 port_fops_write 3 54627 NULL
122945 +tipc_send_stream_54648 tipc_send_stream 4 54648 NULL
122946 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
122947 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
122948 +twl6030_interrupt_mask_54659 twl6030_interrupt_mask 2 54659 NULL
122949 +tdp_page_fault_54663 tdp_page_fault 2 54663 NULL
122950 +bus_add_device_54665 bus_add_device 0 54665 NULL
122951 +cw1200_queue_stats_init_54670 cw1200_queue_stats_init 2 54670 NULL
122952 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
122953 +evm_read_key_54674 evm_read_key 3 54674 NULL
122954 +jfs_direct_IO_54687 jfs_direct_IO 4 54687 NULL
122955 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
122956 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
122957 +kzalloc_54740 kzalloc 1 54740 NULL
122958 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
122959 +lpfc_idiag_pcicfg_write_54749 lpfc_idiag_pcicfg_write 3 54749 NULL
122960 +crystalhd_user_data_54754 crystalhd_user_data 3 54754 NULL
122961 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
122962 +adis16480_show_firmware_date_54762 adis16480_show_firmware_date 3 54762 NULL
122963 +ldsem_atomic_update_54774 ldsem_atomic_update 1 54774 NULL
122964 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
122965 +nfsd_write_54809 nfsd_write 6 54809 NULL
122966 +ar9287_dump_modal_eeprom_54814 ar9287_dump_modal_eeprom 3-2 54814 NULL
122967 +kvzalloc_54815 kvzalloc 1 54815 NULL nohasharray
122968 +crypto_tfm_ctx_alignment_54815 crypto_tfm_ctx_alignment 0 54815 &kvzalloc_54815 nohasharray
122969 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 &crypto_tfm_ctx_alignment_54815
122970 +generic_perform_write_54832 generic_perform_write 3 54832 NULL
122971 +write_rio_54837 write_rio 3 54837 NULL
122972 +ext3_acl_from_disk_54839 ext3_acl_from_disk 2 54839 NULL nohasharray
122973 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 &ext3_acl_from_disk_54839
122974 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
122975 +printer_read_54851 printer_read 3 54851 NULL
122976 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
122977 +prism_build_supp_rates_54865 prism_build_supp_rates 0 54865 NULL
122978 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL nohasharray
122979 +kobject_set_name_vargs_54913 kobject_set_name_vargs 0 54913 &iscsi_pool_init_54913
122980 +btrfs_stack_chunk_num_stripes_54923 btrfs_stack_chunk_num_stripes 0 54923 NULL
122981 +bio_add_page_54933 bio_add_page 0-3 54933 NULL
122982 +mxms_structlen_54939 mxms_structlen 0 54939 NULL
122983 +add_port_54941 add_port 2 54941 NULL
122984 +tipc_send2name_54946 tipc_send2name 5 54946 NULL
122985 +ath9k_dump_btcoex_54949 ath9k_dump_btcoex 0-3 54949 NULL
122986 +alauda_write_data_54967 alauda_write_data 3 54967 NULL
122987 +c4_add_card_54968 c4_add_card 3 54968 NULL
122988 +ext3_xattr_get_54989 ext3_xattr_get 0 54989 NULL
122989 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
122990 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
122991 +efw_transaction_55052 efw_transaction 5-7 55052 NULL
122992 +apei_exec_run_55075 apei_exec_run 0 55075 NULL
122993 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
122994 +read_dma_55086 read_dma 3 55086 NULL
122995 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
122996 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
122997 +filldir_55137 filldir 3 55137 NULL
122998 +ocfs2_truncate_file_55148 ocfs2_truncate_file 3 55148 NULL
122999 +npages_to_npools_55149 npages_to_npools 0-1 55149 NULL
123000 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
123001 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
123002 +compat_SyS_ppoll_55196 compat_SyS_ppoll 2 55196 NULL
123003 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
123004 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL
123005 +__kfifo_dma_out_prepare_r_55211 __kfifo_dma_out_prepare_r 4-5 55211 NULL
123006 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
123007 +qxl_alloc_client_monitors_config_55216 qxl_alloc_client_monitors_config 2 55216 NULL
123008 +nouveau_mc_create__55217 nouveau_mc_create_ 4 55217 NULL
123009 +dbAllocDmap_55227 dbAllocDmap 0 55227 NULL
123010 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
123011 +lbs_failcount_write_55276 lbs_failcount_write 3 55276 NULL
123012 +persistent_ram_new_55286 persistent_ram_new 1-2 55286 NULL
123013 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
123014 +lov_get_stripecnt_55297 lov_get_stripecnt 0-3 55297 NULL
123015 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
123016 +wimax_msg_len_55304 wimax_msg_len 0 55304 NULL
123017 +qp_alloc_guest_work_55305 qp_alloc_guest_work 5-3 55305 NULL nohasharray
123018 +compat_SyS_process_vm_readv_55305 compat_SyS_process_vm_readv 3-5 55305 &qp_alloc_guest_work_55305
123019 +compat_SyS_mbind_55329 compat_SyS_mbind 5 55329 NULL
123020 +vme_user_read_55338 vme_user_read 3 55338 NULL
123021 +__wa_xfer_setup_sizes_55342 __wa_xfer_setup_sizes 0 55342 NULL nohasharray
123022 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 &__wa_xfer_setup_sizes_55342
123023 +cw1200_sdio_align_size_55391 cw1200_sdio_align_size 2 55391 NULL
123024 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
123025 +nouveau_cli_create_55425 nouveau_cli_create 3 55425 NULL
123026 +si476x_radio_read_rds_blckcnt_blob_55427 si476x_radio_read_rds_blckcnt_blob 3 55427 NULL
123027 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
123028 +cx23888_ir_rx_read_55473 cx23888_ir_rx_read 3 55473 NULL
123029 +ufshcd_exec_dev_cmd_55479 ufshcd_exec_dev_cmd 0 55479 NULL
123030 +snd_pcm_lib_write_55483 snd_pcm_lib_write 0-3 55483 NULL
123031 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
123032 +batadv_tt_entries_55487 batadv_tt_entries 0-1 55487 NULL
123033 +ras_stride_increase_window_55501 ras_stride_increase_window 3 55501 NULL
123034 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 NULL
123035 +ea_get_55522 ea_get 3-0 55522 NULL
123036 +buffer_size_55534 buffer_size 0 55534 NULL
123037 +set_msr_interception_55538 set_msr_interception 2 55538 NULL
123038 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
123039 +hash_ipport6_expire_55549 hash_ipport6_expire 4 55549 NULL
123040 +dm_stats_list_55551 dm_stats_list 4 55551 NULL
123041 +compat_SyS_setsockopt_55581 compat_SyS_setsockopt 5 55581 NULL
123042 +add_partition_55588 add_partition 2 55588 NULL
123043 +kstrtou8_from_user_55599 kstrtou8_from_user 2 55599 NULL
123044 +SyS_keyctl_55602 SyS_keyctl 4 55602 NULL
123045 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
123046 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
123047 +edge_tty_recv_55622 edge_tty_recv 3 55622 NULL
123048 +reiserfs_xattr_get_55628 reiserfs_xattr_get 0 55628 NULL nohasharray
123049 +pktgen_if_write_55628 pktgen_if_write 3 55628 &reiserfs_xattr_get_55628
123050 +osc_obd_max_pages_per_rpc_seq_write_55636 osc_obd_max_pages_per_rpc_seq_write 3 55636 NULL
123051 +xfs_bmbt_maxrecs_55649 xfs_bmbt_maxrecs 0-2 55649 NULL
123052 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
123053 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
123054 +get_info_55681 get_info 3 55681 NULL
123055 +iwl_dbgfs_plcp_delta_write_55682 iwl_dbgfs_plcp_delta_write 3 55682 NULL
123056 +ext4_alloc_file_blocks_55689 ext4_alloc_file_blocks 3 55689 NULL
123057 +genl_allocate_reserve_groups_55705 genl_allocate_reserve_groups 1 55705 NULL
123058 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
123059 +tap_pwup_write_55723 tap_pwup_write 3 55723 NULL
123060 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 2 55738 NULL
123061 +set_local_name_55757 set_local_name 4 55757 NULL
123062 +ethtool_copy_validate_indir_55769 ethtool_copy_validate_indir 4 55769 NULL
123063 +strlen_55778 strlen 0 55778 NULL
123064 +set_spte_55783 set_spte 4-5 55783 NULL
123065 +conf_read_55786 conf_read 3 55786 NULL nohasharray
123066 +req_bio_endio_55786 req_bio_endio 3 55786 &conf_read_55786
123067 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
123068 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
123069 +ip_hdrlen_55849 ip_hdrlen 0 55849 NULL
123070 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
123071 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
123072 +hsc_write_55875 hsc_write 3 55875 NULL
123073 +ramdisk_store_55885 ramdisk_store 4 55885 NULL
123074 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
123075 +hash_ip4_expire_55911 hash_ip4_expire 4 55911 NULL
123076 +snd_pcm_hw_param_value_min_55917 snd_pcm_hw_param_value_min 0 55917 NULL
123077 +kvm_write_guest_virt_system_55944 kvm_write_guest_virt_system 4-2 55944 NULL
123078 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
123079 +ceph_get_direct_page_vector_55956 ceph_get_direct_page_vector 2 55956 NULL
123080 +simple_read_from_buffer_55957 simple_read_from_buffer 5-2-0 55957 NULL
123081 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
123082 +btrfs_clone_55977 btrfs_clone 5-3-6 55977 NULL
123083 +wa_xfer_create_subset_sg_55992 wa_xfer_create_subset_sg 3-2 55992 NULL
123084 +nvme_alloc_iod_56027 nvme_alloc_iod 1-2 56027 NULL
123085 +iwl_trans_read_prph_56052 iwl_trans_read_prph 0 56052 NULL
123086 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
123087 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
123088 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
123089 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
123090 +write_file_frameerrors_56145 write_file_frameerrors 3 56145 NULL
123091 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
123092 +ath9k_dump_legacy_btcoex_56194 ath9k_dump_legacy_btcoex 0-3 56194 NULL
123093 +vring_add_indirect_56222 vring_add_indirect 4 56222 NULL
123094 +ocfs2_find_xe_in_bucket_56224 ocfs2_find_xe_in_bucket 0 56224 NULL
123095 +ufshcd_query_descriptor_56236 ufshcd_query_descriptor 0 56236 NULL
123096 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
123097 +fd_copyin_56247 fd_copyin 3 56247 NULL
123098 +sk_rmem_schedule_56255 sk_rmem_schedule 3 56255 NULL
123099 +acpi_ex_get_serial_access_length_56275 acpi_ex_get_serial_access_length 0-2 56275 NULL
123100 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
123101 +ieee80211_if_fmt_user_power_level_56283 ieee80211_if_fmt_user_power_level 3 56283 NULL
123102 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
123103 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
123104 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
123105 +speakup_file_write_56310 speakup_file_write 3 56310 NULL
123106 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
123107 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
123108 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
123109 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
123110 +mite_device_bytes_transferred_56355 mite_device_bytes_transferred 0 56355 NULL
123111 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 0-4 56368 NULL
123112 +dev_read_56369 dev_read 3 56369 NULL
123113 +ath10k_read_simulate_fw_crash_56371 ath10k_read_simulate_fw_crash 3 56371 NULL
123114 +lnet_ping_56378 lnet_ping 4 56378 NULL
123115 +write_gssp_56404 write_gssp 3 56404 NULL
123116 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
123117 +store_msg_56417 store_msg 3 56417 NULL
123118 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
123119 +l2cap_segment_le_sdu_56426 l2cap_segment_le_sdu 4 56426 NULL
123120 +lprocfs_fid_space_seq_write_56431 lprocfs_fid_space_seq_write 3 56431 NULL nohasharray
123121 +ec_dbgfs_cmd_read_56431 ec_dbgfs_cmd_read 3 56431 &lprocfs_fid_space_seq_write_56431
123122 +fl_create_56435 fl_create 5 56435 NULL
123123 +gnttab_map_56439 gnttab_map 2 56439 NULL
123124 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2-4 56453 NULL
123125 +set_connectable_56458 set_connectable 4 56458 NULL
123126 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
123127 +putused_user_56467 putused_user 3 56467 NULL
123128 +ocfs2_zero_extend_range_56468 ocfs2_zero_extend_range 3-2 56468 NULL
123129 +lbs_rdmac_write_56471 lbs_rdmac_write 3 56471 NULL
123130 +crypto_shash_alignmask_56486 crypto_shash_alignmask 0 56486 NULL
123131 +ieee80211_rx_mgmt_probe_beacon_56491 ieee80211_rx_mgmt_probe_beacon 3 56491 NULL
123132 +memblock_virt_alloc_56501 memblock_virt_alloc 1 56501 NULL
123133 +init_map_ip_56508 init_map_ip 5 56508 NULL
123134 +lustre_posix_acl_xattr_reduce_space_56512 lustre_posix_acl_xattr_reduce_space 3 56512 NULL
123135 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
123136 +ip_options_get_56538 ip_options_get 4 56538 NULL
123137 +ll_wr_track_id_56544 ll_wr_track_id 2 56544 NULL
123138 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
123139 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
123140 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
123141 +gro_pull_from_frag0_56593 gro_pull_from_frag0 2 56593 NULL
123142 +event_filter_write_56609 event_filter_write 3 56609 NULL
123143 +nvme_trans_log_temperature_56613 nvme_trans_log_temperature 3 56613 NULL
123144 +gather_array_56641 gather_array 3 56641 NULL
123145 +lookup_extent_backref_56644 lookup_extent_backref 9 56644 NULL
123146 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
123147 +nv50_gpio_intr_mask_56665 nv50_gpio_intr_mask 4-3 56665 NULL
123148 +tg3_nvram_write_block_56666 tg3_nvram_write_block 3 56666 NULL
123149 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
123150 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3-0 56702 NULL
123151 +sfw_alloc_pages_56709 sfw_alloc_pages 3 56709 NULL
123152 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
123153 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
123154 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
123155 +__copy_from_user_ll_56738 __copy_from_user_ll 0-3 56738 NULL
123156 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
123157 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
123158 +ttm_alloc_new_pages_56792 ttm_alloc_new_pages 5 56792 NULL
123159 +ion_ioctl_56806 ion_ioctl 2 56806 NULL
123160 +do_syslog_56807 do_syslog 3 56807 NULL
123161 +mtdchar_write_56831 mtdchar_write 3 56831 NULL
123162 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4-0 56847 NULL
123163 +si476x_radio_read_agc_blob_56849 si476x_radio_read_agc_blob 3 56849 NULL
123164 +gk20a_ram_get_56863 gk20a_ram_get 2 56863 NULL
123165 +ext3_xattr_ibody_get_56880 ext3_xattr_ibody_get 0 56880 NULL
123166 +pvr2_debugifc_print_status_56890 pvr2_debugifc_print_status 3 56890 NULL
123167 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
123168 +le_auto_conn_write_56895 le_auto_conn_write 3 56895 NULL nohasharray
123169 +batadv_tt_update_changes_56895 batadv_tt_update_changes 3 56895 &le_auto_conn_write_56895
123170 +hfsplus_find_cat_56899 hfsplus_find_cat 0 56899 NULL
123171 +strcspn_56913 strcspn 0 56913 NULL
123172 +__kfifo_out_56927 __kfifo_out 0-3 56927 NULL
123173 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
123174 +nouveau_xtensa_create__56952 nouveau_xtensa_create_ 8 56952 NULL
123175 +diva_get_driver_info_56967 diva_get_driver_info 0 56967 NULL
123176 +sptlrpc_secflags2str_56995 sptlrpc_secflags2str 3 56995 NULL
123177 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
123178 +btrfs_super_csum_size_57004 btrfs_super_csum_size 0 57004 NULL
123179 +aircable_process_packet_57027 aircable_process_packet 4 57027 NULL
123180 +ieee80211_if_fmt_state_57043 ieee80211_if_fmt_state 3 57043 NULL nohasharray
123181 +skb_network_offset_57043 skb_network_offset 0 57043 &ieee80211_if_fmt_state_57043
123182 +bytes_to_samples_57049 bytes_to_samples 0-2 57049 NULL
123183 +xfs_buf_read_map_57053 xfs_buf_read_map 3 57053 NULL
123184 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
123185 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
123186 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
123187 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
123188 +altera_get_note_57099 altera_get_note 6 57099 NULL
123189 +hpfs_readpages_57106 hpfs_readpages 4 57106 NULL
123190 +crypto_compress_ctxsize_57109 crypto_compress_ctxsize 0 57109 NULL
123191 +cipso_v4_gentag_loc_57119 cipso_v4_gentag_loc 0 57119 NULL
123192 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 NULL nohasharray
123193 +rds_ib_sub_signaled_57136 rds_ib_sub_signaled 2 57136 &ima_show_htable_value_57136 nohasharray
123194 +nl80211_send_deauth_57136 nl80211_send_deauth 4 57136 &rds_ib_sub_signaled_57136
123195 +snd_sonicvibes_getdmac_57140 snd_sonicvibes_getdmac 0 57140 NULL
123196 +_iwl_dbgfs_bf_params_write_57141 _iwl_dbgfs_bf_params_write 3 57141 NULL
123197 +acpi_gsb_i2c_read_bytes_57145 acpi_gsb_i2c_read_bytes 4 57145 NULL
123198 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
123199 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
123200 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
123201 +hash_netnet6_expire_57191 hash_netnet6_expire 4 57191 NULL
123202 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
123203 +dma_fifo_alloc_57236 dma_fifo_alloc 2-3-5 57236 NULL
123204 +drbg_blocklen_57239 drbg_blocklen 0 57239 NULL
123205 +rsxx_cram_write_57244 rsxx_cram_write 3 57244 NULL
123206 +ieee80211_if_fmt_tsf_57249 ieee80211_if_fmt_tsf 3 57249 NULL
123207 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
123208 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
123209 +lbs_sleepparams_write_57283 lbs_sleepparams_write 3 57283 NULL
123210 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
123211 +snd_pcm_read_57289 snd_pcm_read 3 57289 NULL
123212 +string_length_no_trail_57290 string_length_no_trail 0-2 57290 NULL
123213 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
123214 +write_file_regval_57313 write_file_regval 3 57313 NULL
123215 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
123216 +usblp_read_57342 usblp_read 3 57342 NULL
123217 +print_devstats_dot11RTSFailureCount_57347 print_devstats_dot11RTSFailureCount 3 57347 NULL
123218 +dio_send_cur_page_57348 dio_send_cur_page 0 57348 NULL
123219 +tipc_bclink_stats_57372 tipc_bclink_stats 2 57372 NULL
123220 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
123221 +bzImage64_load_57388 bzImage64_load 7 57388 NULL
123222 +read_file_blob_57406 read_file_blob 3 57406 NULL
123223 +enclosure_register_57412 enclosure_register 3 57412 NULL
123224 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL
123225 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
123226 +__roundup_pow_of_two_57461 __roundup_pow_of_two 0 57461 NULL
123227 +sisusb_clear_vram_57466 sisusb_clear_vram 2-3 57466 NULL
123228 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL
123229 +read_file_skb_rx_57490 read_file_skb_rx 3 57490 NULL
123230 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
123231 +skb_headlen_57501 skb_headlen 0 57501 NULL
123232 +copy_in_user_57502 copy_in_user 3 57502 NULL
123233 +ckhdid_printf_57505 ckhdid_printf 2 57505 NULL
123234 +init_tag_map_57515 init_tag_map 3 57515 NULL
123235 +wil_read_file_ssid_57517 wil_read_file_ssid 3 57517 NULL nohasharray
123236 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 &wil_read_file_ssid_57517
123237 +cmm_read_57520 cmm_read 3 57520 NULL
123238 +inode_permission_57531 inode_permission 0 57531 NULL
123239 +acpi_dev_get_resources_57534 acpi_dev_get_resources 0 57534 NULL
123240 +ptlrpc_lprocfs_hp_ratio_seq_write_57537 ptlrpc_lprocfs_hp_ratio_seq_write 3 57537 NULL
123241 +compat_SyS_process_vm_writev_57542 compat_SyS_process_vm_writev 3-5 57542 NULL
123242 +ReadHDLCPnP_57559 ReadHDLCPnP 0 57559 NULL
123243 +snd_pcm_playback_ioctl1_57569 snd_pcm_playback_ioctl1 0 57569 NULL
123244 +get_bridge_ifindices_57579 get_bridge_ifindices 0 57579 NULL
123245 +ldlm_cli_enqueue_local_57582 ldlm_cli_enqueue_local 11 57582 NULL
123246 +il_dbgfs_interrupt_write_57591 il_dbgfs_interrupt_write 3 57591 NULL
123247 +read_file_spectral_fft_period_57593 read_file_spectral_fft_period 3 57593 NULL
123248 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
123249 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 NULL
123250 +mem_read_57631 mem_read 3 57631 NULL
123251 +r3964_write_57662 r3964_write 4 57662 NULL
123252 +proc_ns_readlink_57664 proc_ns_readlink 3 57664 NULL
123253 +__lgwrite_57669 __lgwrite 4 57669 NULL
123254 +f1x_match_to_this_node_57695 f1x_match_to_this_node 3 57695 NULL
123255 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
123256 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
123257 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 NULL
123258 +ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval_57762 ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval 3 57762 NULL
123259 +SYSC_process_vm_writev_57776 SYSC_process_vm_writev 3-5 57776 NULL
123260 +ld2_57794 ld2 0 57794 NULL
123261 +ivtv_read_57796 ivtv_read 3 57796 NULL
123262 +ion_test_ioctl_57799 ion_test_ioctl 2 57799 NULL
123263 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
123264 +copy_to_user_57835 copy_to_user 3-0 57835 NULL
123265 +flash_read_57843 flash_read 3 57843 NULL
123266 +kiblnd_create_tx_pool_57846 kiblnd_create_tx_pool 2 57846 NULL
123267 +radeon_ttm_gtt_read_57879 radeon_ttm_gtt_read 3 57879 NULL
123268 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
123269 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
123270 +ll_xattr_find_get_lock_57912 ll_xattr_find_get_lock 0 57912 NULL
123271 +memcg_caches_array_size_57918 memcg_caches_array_size 0-1 57918 NULL
123272 +mwifiex_hscfg_read_57920 mwifiex_hscfg_read 3 57920 NULL
123273 +twl_i2c_write_57923 twl_i2c_write 3-4 57923 NULL
123274 +__snd_gf1_look16_57925 __snd_gf1_look16 0 57925 NULL
123275 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
123276 +xfs_mru_cache_create_57943 xfs_mru_cache_create 3 57943 NULL
123277 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
123278 +arch_gnttab_init_57948 arch_gnttab_init 2-1 57948 NULL
123279 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL nohasharray
123280 +ioat3_dca_count_dca_slots_57953 ioat3_dca_count_dca_slots 0 57953 &ip_set_alloc_57953
123281 +iov_iter_npages_57979 iov_iter_npages 0-2 57979 NULL
123282 +do_rx_dma_57996 do_rx_dma 5 57996 NULL
123283 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
123284 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
123285 +io_playback_transfer_58030 io_playback_transfer 4 58030 NULL
123286 +mce_async_out_58056 mce_async_out 3 58056 NULL
123287 +ocfs2_find_leaf_58065 ocfs2_find_leaf 0 58065 NULL
123288 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
123289 +cm4040_write_58079 cm4040_write 3 58079 NULL
123290 +savemem_58129 savemem 3 58129 NULL
123291 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
123292 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
123293 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
123294 +ieee80211_if_fmt_flags_58205 ieee80211_if_fmt_flags 3 58205 NULL
123295 +i40evf_allocate_virt_mem_d_58210 i40evf_allocate_virt_mem_d 3 58210 NULL
123296 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
123297 +read_file_debug_58256 read_file_debug 3 58256 NULL
123298 +osc_max_dirty_mb_seq_write_58263 osc_max_dirty_mb_seq_write 3 58263 NULL
123299 +cfg80211_mgmt_tx_status_58266 cfg80211_mgmt_tx_status 4 58266 NULL
123300 +profile_load_58267 profile_load 3 58267 NULL
123301 +kstrtos8_from_user_58268 kstrtos8_from_user 2 58268 NULL
123302 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
123303 +r100_mm_rreg_58276 r100_mm_rreg 0 58276 NULL
123304 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
123305 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
123306 +mic_virtio_copy_from_user_58323 mic_virtio_copy_from_user 3 58323 NULL
123307 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
123308 +lstcon_rpc_prep_58325 lstcon_rpc_prep 4 58325 NULL
123309 +ext4_ext_truncate_extend_restart_58331 ext4_ext_truncate_extend_restart 3 58331 NULL
123310 +__copy_from_user_swizzled_58337 __copy_from_user_swizzled 2-4 58337 NULL
123311 +ec_i2c_parse_response_58347 ec_i2c_parse_response 0 58347 NULL
123312 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
123313 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
123314 +_drbd_md_sync_page_io_58403 _drbd_md_sync_page_io 6 58403 NULL
123315 +kvm_mmu_write_protect_pt_masked_58406 kvm_mmu_write_protect_pt_masked 3 58406 NULL nohasharray
123316 +idetape_pad_zeros_58406 idetape_pad_zeros 2 58406 &kvm_mmu_write_protect_pt_masked_58406
123317 +i2400m_pld_size_58415 i2400m_pld_size 0 58415 NULL
123318 +capabilities_read_58457 capabilities_read 3 58457 NULL
123319 +usnic_vnic_get_resources_58462 usnic_vnic_get_resources 3 58462 NULL
123320 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 NULL nohasharray
123321 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 &compat_do_ipt_set_ctl_58466
123322 +nv_rd08_58472 nv_rd08 0 58472 NULL
123323 +snd_gf1_read_addr_58483 snd_gf1_read_addr 0 58483 NULL
123324 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
123325 +btrfs_cont_expand_58498 btrfs_cont_expand 2-3 58498 NULL
123326 +tcf_hash_create_58507 tcf_hash_create 4 58507 NULL
123327 +cifs_write_from_iter_58526 cifs_write_from_iter 2 58526 NULL
123328 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
123329 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
123330 +scnprint_mac_oui_58578 scnprint_mac_oui 3-0 58578 NULL
123331 +cur_wm_latency_write_58581 cur_wm_latency_write 3 58581 NULL
123332 +get_rhf_errstring_58582 get_rhf_errstring 3 58582 NULL
123333 +ea_read_inline_58589 ea_read_inline 0 58589 NULL
123334 +isku_sysfs_read_keys_thumbster_58590 isku_sysfs_read_keys_thumbster 6 58590 NULL
123335 +xip_file_read_58592 xip_file_read 3 58592 NULL
123336 +ecryptfs_write_end_58594 ecryptfs_write_end 5-3 58594 NULL
123337 +radeon_bo_size_58606 radeon_bo_size 0 58606 NULL
123338 +btrfs_direct_IO_58608 btrfs_direct_IO 4 58608 NULL
123339 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
123340 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
123341 +iwl_dbgfs_rx_handlers_write_58655 iwl_dbgfs_rx_handlers_write 3 58655 NULL
123342 +find_zero_58685 find_zero 0-1 58685 NULL
123343 +uwb_bce_print_IEs_58686 uwb_bce_print_IEs 4 58686 NULL
123344 +tps6586x_writes_58689 tps6586x_writes 2-3 58689 NULL
123345 +visor_charqueue_create_58703 visor_charqueue_create 1 58703 NULL
123346 +vx_send_msg_58711 vx_send_msg 0 58711 NULL
123347 +csum_exist_in_range_58730 csum_exist_in_range 2-3 58730 NULL
123348 +frames_to_bytes_58741 frames_to_bytes 0-2 58741 NULL
123349 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
123350 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
123351 +regmap_calc_reg_len_58795 regmap_calc_reg_len 0 58795 NULL
123352 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
123353 +isku_sysfs_read_58806 isku_sysfs_read 5 58806 NULL
123354 +ep_read_58813 ep_read 3 58813 NULL
123355 +command_write_58841 command_write 3 58841 NULL
123356 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
123357 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
123358 +esas2r_change_queue_depth_58886 esas2r_change_queue_depth 2 58886 NULL
123359 +lprocfs_wr_pinger_recov_58914 lprocfs_wr_pinger_recov 3 58914 NULL
123360 +print_devstats_dot11FCSErrorCount_58919 print_devstats_dot11FCSErrorCount 3 58919 NULL
123361 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
123362 +wait_table_hash_nr_entries_58962 wait_table_hash_nr_entries 0 58962 NULL
123363 +ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout_58965 ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout 3 58965 NULL
123364 +crypto_aead_ivsize_58970 crypto_aead_ivsize 0 58970 NULL
123365 +init_list_set_59005 init_list_set 3 59005 NULL
123366 +ep_write_59008 ep_write 3 59008 NULL
123367 +lpfc_idiag_baracc_write_59014 lpfc_idiag_baracc_write 3 59014 NULL
123368 +SyS_preadv_59029 SyS_preadv 3 59029 NULL
123369 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
123370 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
123371 +crypto_aead_reqsize_59039 crypto_aead_reqsize 0 59039 NULL
123372 +regmap_bulk_write_59049 regmap_bulk_write 2-4 59049 NULL
123373 +mmc_sd_num_wr_blocks_59112 mmc_sd_num_wr_blocks 0 59112 NULL
123374 +sta_tx_latency_stat_table_59122 sta_tx_latency_stat_table 0-4-5 59122 NULL nohasharray
123375 +scsi_io_completion_59122 scsi_io_completion 2 59122 &sta_tx_latency_stat_table_59122
123376 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
123377 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 NULL nohasharray
123378 +print_devstats_dot11RTSSuccessCount_59145 print_devstats_dot11RTSSuccessCount 3 59145 &framebuffer_alloc_59145
123379 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
123380 +pvr2_hdw_report_clients_59152 pvr2_hdw_report_clients 3 59152 NULL
123381 +ksize_59176 ksize 0 59176 NULL
123382 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
123383 +ocfs2_move_extent_59187 ocfs2_move_extent 2-5 59187 NULL
123384 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
123385 +check_mapped_selector_name_59216 check_mapped_selector_name 5 59216 NULL
123386 +dt3155_read_59226 dt3155_read 3 59226 NULL
123387 +paging64_gpte_to_gfn_lvl_59229 paging64_gpte_to_gfn_lvl 0-1-2 59229 NULL
123388 +nla_len_59258 nla_len 0 59258 NULL
123389 +drbd_bm_write_page_59290 drbd_bm_write_page 2 59290 NULL
123390 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
123391 +fd_copyout_59323 fd_copyout 3 59323 NULL
123392 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
123393 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
123394 +__map_request_59350 __map_request 0 59350 NULL
123395 +SyS_getrandom_59366 SyS_getrandom 2 59366 NULL
123396 +f2fs_fallocate_59377 f2fs_fallocate 4-3 59377 NULL
123397 +pvr2_debugifc_print_info_59380 pvr2_debugifc_print_info 3 59380 NULL
123398 +journal_init_dev_59384 journal_init_dev 5 59384 NULL
123399 +__net_get_random_once_59389 __net_get_random_once 2 59389 NULL
123400 +isku_sysfs_read_keys_function_59412 isku_sysfs_read_keys_function 6 59412 NULL
123401 +vxge_hw_ring_rxds_per_block_get_59425 vxge_hw_ring_rxds_per_block_get 0 59425 NULL
123402 +SyS_sched_setaffinity_59442 SyS_sched_setaffinity 2 59442 NULL
123403 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
123404 +tipc_recv_stream_59456 tipc_recv_stream 4 59456 NULL
123405 +_iwl_dbgfs_bcast_filters_write_59491 _iwl_dbgfs_bcast_filters_write 3 59491 NULL
123406 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
123407 +C_SYSC_get_mempolicy_59516 C_SYSC_get_mempolicy 3 59516 NULL
123408 +mic_vringh_copy_59523 mic_vringh_copy 4 59523 NULL
123409 +mpi_get_nbits_59551 mpi_get_nbits 0 59551 NULL
123410 +tunables_write_59563 tunables_write 3 59563 NULL
123411 +bio_split_59564 bio_split 2 59564 NULL
123412 +__copy_from_user_ll_nozero_59571 __copy_from_user_ll_nozero 0-3 59571 NULL
123413 +write_pbl_59583 write_pbl 4 59583 NULL
123414 +memdup_user_59590 memdup_user 2 59590 NULL
123415 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 NULL nohasharray
123416 +xrcdn_free_res_59616 xrcdn_free_res 5 59616 &mem_fwlog_free_mem_blks_read_59616
123417 +ath6kl_endpoint_stats_write_59621 ath6kl_endpoint_stats_write 3 59621 NULL
123418 +mtrr_write_59622 mtrr_write 3 59622 NULL
123419 +find_first_zero_bit_59636 find_first_zero_bit 0 59636 NULL
123420 +SyS_setdomainname_59646 SyS_setdomainname 2 59646 NULL
123421 +hidraw_read_59650 hidraw_read 3 59650 NULL
123422 +v9fs_xattr_set_acl_59651 v9fs_xattr_set_acl 4 59651 NULL
123423 +__devcgroup_check_permission_59665 __devcgroup_check_permission 0 59665 NULL
123424 +iwl_dbgfs_mac_params_read_59666 iwl_dbgfs_mac_params_read 3 59666 NULL
123425 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
123426 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
123427 +ioperm_get_59701 ioperm_get 4-3 59701 NULL
123428 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
123429 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 NULL nohasharray
123430 +nv94_aux_mask_59740 nv94_aux_mask 2 59740 &ieee80211_if_read_fwded_unicast_59740
123431 +qib_decode_7220_sdma_errs_59745 qib_decode_7220_sdma_errs 4 59745 NULL
123432 +strnlen_59746 strnlen 0 59746 NULL
123433 +ext3_acl_count_59754 ext3_acl_count 0-1 59754 NULL
123434 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL
123435 +venus_remove_59781 venus_remove 4 59781 NULL
123436 +mei_nfc_recv_59784 mei_nfc_recv 3 59784 NULL
123437 +C_SYSC_preadv_59801 C_SYSC_preadv 3 59801 NULL
123438 +ipw_write_59807 ipw_write 3 59807 NULL
123439 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
123440 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
123441 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
123442 +regmap_raw_write_async_59849 regmap_raw_write_async 2-4 59849 NULL
123443 +biovec_create_pool_59878 biovec_create_pool 1 59878 NULL
123444 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
123445 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
123446 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
123447 +kvm_mmu_notifier_invalidate_range_start_59944 kvm_mmu_notifier_invalidate_range_start 3-4 59944 NULL
123448 +ath10k_read_dfs_stats_59949 ath10k_read_dfs_stats 3 59949 NULL
123449 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 NULL nohasharray
123450 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 &dapm_widget_power_read_file_59950
123451 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
123452 +__arch_hweight16_59975 __arch_hweight16 0 59975 NULL
123453 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
123454 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
123455 +ieee80211_if_fmt_dot11MeshAwakeWindowDuration_60006 ieee80211_if_fmt_dot11MeshAwakeWindowDuration 3 60006 NULL
123456 +copy_items_60009 copy_items 7 60009 NULL
123457 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
123458 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
123459 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
123460 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
123461 +bio_integrity_hw_sectors_60039 bio_integrity_hw_sectors 0-2 60039 NULL
123462 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
123463 +vcs_size_60050 vcs_size 0 60050 NULL
123464 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 NULL
123465 +compat_writev_60063 compat_writev 3 60063 NULL
123466 +ath6kl_listen_int_write_60066 ath6kl_listen_int_write 3 60066 NULL
123467 +c4iw_num_stags_60073 c4iw_num_stags 0 60073 NULL
123468 +usb_os_desc_prepare_interf_dir_60075 usb_os_desc_prepare_interf_dir 2 60075 NULL
123469 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
123470 +ieee80211_if_fmt_fwded_frames_60103 ieee80211_if_fmt_fwded_frames 3 60103 NULL
123471 +SYSC_msgsnd_60113 SYSC_msgsnd 3 60113 NULL
123472 +nfs_idmap_request_key_60124 nfs_idmap_request_key 2 60124 NULL
123473 +__mutex_lock_common_60134 __mutex_lock_common 0 60134 NULL
123474 +ld_usb_read_60156 ld_usb_read 3 60156 NULL
123475 +jmb38x_ms_count_slots_60164 jmb38x_ms_count_slots 0 60164 NULL
123476 +init_state_60165 init_state 2 60165 NULL
123477 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 NULL nohasharray
123478 +sg_build_sgat_60179 sg_build_sgat 3 60179 &jffs2_alloc_full_dirent_60179
123479 +fuse_async_req_send_60183 fuse_async_req_send 0-3 60183 NULL
123480 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL
123481 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 NULL
123482 +btrfs_get_token_16_60220 btrfs_get_token_16 0 60220 NULL
123483 +irq_alloc_domain_generic_chips_60264 irq_alloc_domain_generic_chips 2-3 60264 NULL
123484 +display_crc_ctl_write_60273 display_crc_ctl_write 3 60273 NULL
123485 +printer_write_60276 printer_write 3 60276 NULL
123486 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
123487 +getDataLength_60301 getDataLength 0 60301 NULL
123488 +bch_subtract_dirty_60306 bch_subtract_dirty 3-4 60306 NULL
123489 +usb_alphatrack_write_60341 usb_alphatrack_write 3 60341 NULL
123490 +__kfifo_from_user_r_60345 __kfifo_from_user_r 5-3 60345 NULL
123491 +max_unfragmented_pages_60362 max_unfragmented_pages 0 60362 NULL
123492 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
123493 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
123494 +ocfs2_zero_extend_60396 ocfs2_zero_extend 3 60396 NULL
123495 +driver_names_read_60399 driver_names_read 3 60399 NULL
123496 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
123497 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
123498 +kmalloc_60432 kmalloc 1 60432 NULL nohasharray
123499 +tstats_write_60432 tstats_write 3 60432 &kmalloc_60432
123500 +snd_hda_get_num_raw_conns_60462 snd_hda_get_num_raw_conns 0 60462 NULL
123501 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
123502 +lustre_msg_early_size_60496 lustre_msg_early_size 0 60496 NULL
123503 +compat_SyS_get_mempolicy_60527 compat_SyS_get_mempolicy 3 60527 NULL
123504 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
123505 +nonpaging_map_60551 nonpaging_map 4 60551 NULL
123506 +osc_lockless_truncate_seq_write_60553 osc_lockless_truncate_seq_write 3 60553 NULL
123507 +xfs_vm_direct_IO_60557 xfs_vm_direct_IO 4 60557 NULL
123508 +tracing_entries_write_60563 tracing_entries_write 3 60563 NULL
123509 +memblock_virt_alloc_try_nid_nopanic_60604 memblock_virt_alloc_try_nid_nopanic 1 60604 NULL
123510 +skb_transport_offset_60619 skb_transport_offset 0 60619 NULL
123511 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
123512 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
123513 +__proc_lnet_stats_60647 __proc_lnet_stats 5 60647 NULL
123514 +if_sdio_host_to_card_60666 if_sdio_host_to_card 4 60666 NULL
123515 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
123516 +snd_ice1712_ds_read_60754 snd_ice1712_ds_read 0 60754 NULL
123517 +raid_status_60755 raid_status 5 60755 NULL
123518 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
123519 +opticon_write_60775 opticon_write 4 60775 NULL
123520 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
123521 +snd_pcm_oss_readv3_60792 snd_pcm_oss_readv3 3 60792 NULL
123522 +nvif_object_init_60848 nvif_object_init 6 60848 NULL
123523 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
123524 +alloc_buf_60864 alloc_buf 3-2 60864 NULL
123525 +generic_writepages_60871 generic_writepages 0 60871 NULL
123526 +ext4_update_inline_data_60888 ext4_update_inline_data 3 60888 NULL
123527 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
123528 +libcfs_sock_ioctl_60915 libcfs_sock_ioctl 0 60915 NULL
123529 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
123530 +submit_extent_page_60928 submit_extent_page 5 60928 NULL
123531 +pti_char_write_60960 pti_char_write 3 60960 NULL
123532 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
123533 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
123534 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
123535 +generic_file_direct_write_60995 generic_file_direct_write 0 60995 NULL
123536 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
123537 +graph_depth_write_61024 graph_depth_write 3 61024 NULL
123538 +sdhci_pltfm_register_61031 sdhci_pltfm_register 3 61031 NULL
123539 +lpfc_idiag_queacc_write_61043 lpfc_idiag_queacc_write 3 61043 NULL
123540 +symtab_init_61050 symtab_init 2 61050 NULL
123541 +fuse_send_write_61053 fuse_send_write 0-4 61053 NULL
123542 +bitmap_scnlistprintf_61062 bitmap_scnlistprintf 0-2 61062 NULL
123543 +ahash_align_buffer_size_61070 ahash_align_buffer_size 0-1-2 61070 NULL
123544 +get_derived_key_61100 get_derived_key 4 61100 NULL
123545 +i40e_calculate_l2fpm_size_61104 i40e_calculate_l2fpm_size 0-4-3-2-1 61104 NULL
123546 +alloc_chrdev_region_61112 alloc_chrdev_region 0 61112 NULL
123547 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
123548 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
123549 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
123550 +pair_device_61175 pair_device 4 61175 NULL nohasharray
123551 +event_oom_late_read_61175 event_oom_late_read 3 61175 &pair_device_61175
123552 +dio_bio_add_page_61178 dio_bio_add_page 0 61178 NULL
123553 +SyS_prctl_61202 SyS_prctl 4 61202 NULL
123554 +srp_create_fr_pool_61207 srp_create_fr_pool 3 61207 NULL
123555 +arch_hibernation_header_save_61212 arch_hibernation_header_save 0 61212 NULL
123556 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
123557 +v9fs_mmap_file_read_61262 v9fs_mmap_file_read 3 61262 NULL
123558 +find_get_pages_tag_61270 find_get_pages_tag 0 61270 NULL nohasharray
123559 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 &find_get_pages_tag_61270 nohasharray
123560 +ifalias_store_61270 ifalias_store 4 61270 &btrfs_bio_alloc_61270
123561 +hfsplus_getxattr_finder_info_61283 hfsplus_getxattr_finder_info 0 61283 NULL nohasharray
123562 +vortex_adbdma_getlinearpos_61283 vortex_adbdma_getlinearpos 0 61283 &hfsplus_getxattr_finder_info_61283
123563 +nvme_trans_copy_to_user_61288 nvme_trans_copy_to_user 3 61288 NULL
123564 +xfer_from_user_61307 xfer_from_user 3 61307 NULL
123565 +xfrm_user_sec_ctx_size_61320 xfrm_user_sec_ctx_size 0 61320 NULL
123566 +C_SYSC_msgsnd_61330 C_SYSC_msgsnd 3 61330 NULL
123567 +write_file_spectral_short_repeat_61335 write_file_spectral_short_repeat 3 61335 NULL
123568 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
123569 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
123570 +__dm_get_reserved_ios_61342 __dm_get_reserved_ios 0-3-2 61342 NULL
123571 +f1x_map_sysaddr_to_csrow_61344 f1x_map_sysaddr_to_csrow 2 61344 NULL
123572 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
123573 +system_enable_write_61396 system_enable_write 3 61396 NULL
123574 +xfs_zero_remaining_bytes_61423 xfs_zero_remaining_bytes 3 61423 NULL
123575 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
123576 +snd_pcm_lib_writev_transfer_61483 snd_pcm_lib_writev_transfer 5-4-2 61483 NULL
123577 +btrfs_item_size_61485 btrfs_item_size 0 61485 NULL
123578 +erst_errno_61526 erst_errno 0 61526 NULL
123579 +proc_write_device_61541 proc_write_device 3 61541 NULL
123580 +compat_SyS_select_61542 compat_SyS_select 1 61542 NULL
123581 +trace_options_core_write_61551 trace_options_core_write 3 61551 NULL
123582 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
123583 +parport_pc_fifo_write_block_dma_61568 parport_pc_fifo_write_block_dma 3 61568 NULL
123584 +fan_proc_write_61569 fan_proc_write 3 61569 NULL
123585 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
123586 +ldlm_pool_rw_atomic_seq_write_61572 ldlm_pool_rw_atomic_seq_write 3 61572 NULL
123587 +seq_open_private_61589 seq_open_private 3 61589 NULL
123588 +ept_gpte_to_gfn_lvl_61591 ept_gpte_to_gfn_lvl 0-1-2 61591 NULL
123589 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
123590 +nfs4_init_uniform_client_string_61601 nfs4_init_uniform_client_string 3 61601 NULL
123591 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
123592 +ieee80211_if_fmt_hw_queues_61629 ieee80211_if_fmt_hw_queues 3 61629 NULL
123593 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
123594 +snd_pcm_oss_read3_61643 snd_pcm_oss_read3 0-3 61643 NULL nohasharray
123595 +tcf_hashinfo_init_61643 tcf_hashinfo_init 2 61643 &snd_pcm_oss_read3_61643
123596 +resize_stripes_61650 resize_stripes 2 61650 NULL
123597 +ttm_page_pool_free_61661 ttm_page_pool_free 2-0 61661 NULL
123598 +insert_one_name_61668 insert_one_name 7 61668 NULL
123599 +qib_format_hwmsg_61679 qib_format_hwmsg 2 61679 NULL
123600 +lock_loop_61681 lock_loop 1 61681 NULL
123601 +__do_tune_cpucache_61684 __do_tune_cpucache 2 61684 NULL
123602 +filter_read_61692 filter_read 3 61692 NULL
123603 +SyS_kexec_file_load_61715 SyS_kexec_file_load 3 61715 NULL
123604 +iov_length_61716 iov_length 0 61716 NULL
123605 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
123606 +null_alloc_reqbuf_61719 null_alloc_reqbuf 3 61719 NULL
123607 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
123608 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
123609 +SyS_sendto_61763 SyS_sendto 6 61763 NULL
123610 +mls_compute_context_len_61812 mls_compute_context_len 0 61812 NULL
123611 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
123612 +regcache_sync_block_61846 regcache_sync_block 5-4 61846 NULL
123613 +ath9k_hw_def_dump_eeprom_61853 ath9k_hw_def_dump_eeprom 5-4 61853 NULL
123614 +evdev_compute_buffer_size_61863 evdev_compute_buffer_size 0 61863 NULL
123615 +SYSC_lsetxattr_61869 SYSC_lsetxattr 4 61869 NULL
123616 +get_fw_name_61874 get_fw_name 3 61874 NULL
123617 +btrfs_ioctl_clone_61886 btrfs_ioctl_clone 3-4-5 61886 NULL
123618 +lprocfs_write_frac_u64_helper_61897 lprocfs_write_frac_u64_helper 2 61897 NULL
123619 +clear_refs_write_61904 clear_refs_write 3 61904 NULL
123620 +kernfs_name_61910 kernfs_name 3 61910 NULL
123621 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
123622 +au0828_init_isoc_61917 au0828_init_isoc 3-2-4 61917 NULL
123623 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
123624 +efi_get_runtime_map_size_61927 efi_get_runtime_map_size 0 61927 NULL
123625 +SyS_kexec_load_61946 SyS_kexec_load 2 61946 NULL
123626 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
123627 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
123628 +fix_read_error_61965 fix_read_error 4 61965 NULL
123629 +ocfs2_quota_write_61972 ocfs2_quota_write 4-5 61972 NULL
123630 +fd_locked_ioctl_61978 fd_locked_ioctl 3 61978 NULL
123631 +cow_file_range_61979 cow_file_range 3 61979 NULL
123632 +dequeue_event_62000 dequeue_event 3 62000 NULL
123633 +xt_compat_match_offset_62011 xt_compat_match_offset 0 62011 NULL
123634 +SyS_setxattr_62019 SyS_setxattr 4 62019 NULL
123635 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
123636 +SYSC_select_62024 SYSC_select 1 62024 NULL
123637 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
123638 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
123639 +do_pselect_62061 do_pselect 1 62061 NULL
123640 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
123641 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
123642 +ip_recv_error_62117 ip_recv_error 3 62117 NULL
123643 +generic_block_fiemap_62122 generic_block_fiemap 4 62122 NULL
123644 +llc_ui_header_len_62131 llc_ui_header_len 0 62131 NULL
123645 +qib_diag_write_62133 qib_diag_write 3 62133 NULL nohasharray
123646 +kobject_add_varg_62133 kobject_add_varg 0 62133 &qib_diag_write_62133
123647 +ql_status_62135 ql_status 5 62135 NULL nohasharray
123648 +device_add_attrs_62135 device_add_attrs 0 62135 &ql_status_62135
123649 +video_usercopy_62151 video_usercopy 2 62151 NULL
123650 +SyS_getxattr_62166 SyS_getxattr 4 62166 NULL
123651 +prism54_wpa_bss_ie_get_62173 prism54_wpa_bss_ie_get 0 62173 NULL
123652 +write_file_dfs_62180 write_file_dfs 3 62180 NULL
123653 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
123654 +rounded_hashtable_size_62198 rounded_hashtable_size 0 62198 NULL
123655 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
123656 +smk_read_syslog_62227 smk_read_syslog 3 62227 NULL
123657 +SYSC_setgroups16_62232 SYSC_setgroups16 1 62232 NULL
123658 +ion_handle_test_dma_62262 ion_handle_test_dma 4-5 62262 NULL
123659 +get_random_int_62279 get_random_int 0 62279 NULL
123660 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
123661 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
123662 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
123663 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
123664 +subseq_list_62332 subseq_list 3-0 62332 NULL
123665 +ll_statahead_max_seq_write_62333 ll_statahead_max_seq_write 3 62333 NULL
123666 +flash_write_62354 flash_write 3 62354 NULL
123667 +xfpregs_set_62363 xfpregs_set 4 62363 NULL
123668 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
123669 +altera_irscan_62396 altera_irscan 2 62396 NULL
123670 +set_ssp_62411 set_ssp 4 62411 NULL
123671 +tracing_saved_cmdlines_size_read_62491 tracing_saved_cmdlines_size_read 3 62491 NULL
123672 +srpc_alloc_bulk_62522 srpc_alloc_bulk 2 62522 NULL
123673 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
123674 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
123675 +debugfs_read_62535 debugfs_read 3 62535 NULL
123676 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
123677 +qib_refresh_qsfp_cache_62547 qib_refresh_qsfp_cache 0 62547 NULL
123678 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
123679 +compat_SyS_rt_sigpending_62580 compat_SyS_rt_sigpending 2 62580 NULL
123680 +get_subdir_62581 get_subdir 3 62581 NULL
123681 +dut_mode_write_62630 dut_mode_write 3 62630 NULL
123682 +vfs_fsync_range_62635 vfs_fsync_range 0 62635 NULL
123683 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
123684 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
123685 +ieee80211_set_probe_resp_62700 ieee80211_set_probe_resp 3 62700 NULL
123686 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
123687 +gfs2_log_write_62717 gfs2_log_write 3 62717 NULL
123688 +rdm_62719 rdm 0 62719 NULL
123689 +obd_ioctl_popdata_62741 obd_ioctl_popdata 3 62741 NULL
123690 +key_replays_read_62746 key_replays_read 3 62746 NULL
123691 +lov_verify_lmm_62747 lov_verify_lmm 2 62747 NULL
123692 +mwifiex_rdeeprom_write_62754 mwifiex_rdeeprom_write 3 62754 NULL
123693 +mxt_obj_instances_62764 mxt_obj_instances 0 62764 NULL
123694 +copy_page_to_iter_iovec_62770 copy_page_to_iter_iovec 0-3 62770 NULL nohasharray
123695 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 &copy_page_to_iter_iovec_62770
123696 +C_SYSC_ipc_62776 C_SYSC_ipc 3 62776 NULL
123697 +ptlrpc_req_set_repsize_62784 ptlrpc_req_set_repsize 2 62784 NULL
123698 +SyS_sched_getaffinity_62786 SyS_sched_getaffinity 2 62786 NULL
123699 +dm_stats_account_io_62787 dm_stats_account_io 3 62787 NULL
123700 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
123701 +__rounddown_pow_of_two_62836 __rounddown_pow_of_two 0 62836 NULL
123702 +bio_get_nr_vecs_62838 bio_get_nr_vecs 0 62838 NULL
123703 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
123704 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
123705 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
123706 +aoechr_write_62883 aoechr_write 3 62883 NULL
123707 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
123708 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
123709 +getdqbuf_62908 getdqbuf 1 62908 NULL
123710 +ll_statahead_agl_seq_write_62928 ll_statahead_agl_seq_write 3 62928 NULL
123711 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
123712 +nvif_object_mthd_62960 nvif_object_mthd 4 62960 NULL
123713 +hwdep_read_62992 hwdep_read 3 62992 NULL
123714 +kstrtoull_from_user_63026 kstrtoull_from_user 2 63026 NULL
123715 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
123716 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
123717 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
123718 +unlink1_63059 unlink1 3 63059 NULL
123719 +xen_set_nslabs_63066 xen_set_nslabs 0 63066 NULL
123720 +iwl_dbgfs_fw_rx_stats_read_63070 iwl_dbgfs_fw_rx_stats_read 3 63070 NULL
123721 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5 63087 NULL
123722 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
123723 +ext4_chunk_trans_blocks_63123 ext4_chunk_trans_blocks 0-2 63123 NULL
123724 +iwl_mvm_coex_dump_mbox_63153 iwl_mvm_coex_dump_mbox 4-3-0 63153 NULL
123725 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
123726 +SyS_syslog_63178 SyS_syslog 3 63178 NULL
123727 +vme_master_read_63221 vme_master_read 0 63221 NULL
123728 +SyS_gethostname_63227 SyS_gethostname 2 63227 NULL
123729 +ptp_read_63251 ptp_read 4 63251 NULL
123730 +xfs_dir2_leaf_getdents_63262 xfs_dir2_leaf_getdents 3 63262 NULL
123731 +iwl_dbgfs_fw_error_dump_read_63263 iwl_dbgfs_fw_error_dump_read 3 63263 NULL
123732 +raid5_resize_63306 raid5_resize 2 63306 NULL
123733 +nfsd_vfs_read_63307 nfsd_vfs_read 5 63307 NULL
123734 +ath10k_read_fw_dbglog_63323 ath10k_read_fw_dbglog 3 63323 NULL
123735 +proc_info_read_63344 proc_info_read 3 63344 NULL
123736 +nvif_device_new_63358 nvif_device_new 5 63358 NULL
123737 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
123738 +idmouse_read_63374 idmouse_read 3 63374 NULL
123739 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 NULL nohasharray
123740 +usbnet_read_cmd_nopm_63388 usbnet_read_cmd_nopm 7 63388 &edac_pci_alloc_ctl_info_63388
123741 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
123742 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
123743 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
123744 +si5351_bulk_write_63468 si5351_bulk_write 2-3 63468 NULL
123745 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
123746 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
123747 +read_kcore_63488 read_kcore 3 63488 NULL
123748 +iwl_dbgfs_bcast_filters_read_63489 iwl_dbgfs_bcast_filters_read 3 63489 NULL
123749 +snd_pcm_plug_write_transfer_63503 snd_pcm_plug_write_transfer 0-3 63503 NULL
123750 +efx_mcdi_rpc_async_63529 efx_mcdi_rpc_async 4-5 63529 NULL
123751 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL
123752 +write_file_spectral_period_63536 write_file_spectral_period 3 63536 NULL
123753 +if_sdio_read_scratch_63540 if_sdio_read_scratch 0 63540 NULL
123754 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
123755 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 NULL
123756 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
123757 +write_debug_level_63613 write_debug_level 3 63613 NULL
123758 +__spi_validate_63618 __spi_validate 0 63618 NULL
123759 +symbol_build_supp_rates_63634 symbol_build_supp_rates 0 63634 NULL
123760 +hid_report_len_63637 hid_report_len 0 63637 NULL
123761 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
123762 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
123763 +ldlm_cli_enqueue_63657 ldlm_cli_enqueue 8 63657 NULL
123764 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
123765 +vbi_read_63673 vbi_read 3 63673 NULL
123766 +write_file_spectral_fft_period_63696 write_file_spectral_fft_period 3 63696 NULL
123767 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
123768 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
123769 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
123770 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
123771 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
123772 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
123773 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
123774 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
123775 +C_SYSC_process_vm_readv_63811 C_SYSC_process_vm_readv 3-5 63811 NULL
123776 +regmap_multi_reg_write_63826 regmap_multi_reg_write 3 63826 NULL nohasharray
123777 +prepare_copy_63826 prepare_copy 2 63826 &regmap_multi_reg_write_63826
123778 +sel_write_load_63830 sel_write_load 3 63830 NULL
123779 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
123780 +nv10_gpio_intr_mask_63862 nv10_gpio_intr_mask 4-3 63862 NULL
123781 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
123782 +uvc_alloc_urb_buffers_63922 uvc_alloc_urb_buffers 0-2-3 63922 NULL
123783 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
123784 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
123785 +__team_options_register_63941 __team_options_register 3 63941 NULL
123786 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
123787 +set_bredr_63975 set_bredr 4 63975 NULL
123788 +construct_key_and_link_63985 construct_key_and_link 3 63985 NULL
123789 +rs_extent_to_bm_page_63996 rs_extent_to_bm_page 0-1 63996 NULL
123790 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
123791 +SyS_rt_sigpending_64018 SyS_rt_sigpending 2 64018 NULL
123792 +dbAllocDmapLev_64030 dbAllocDmapLev 0 64030 NULL
123793 +SyS_fsetxattr_64039 SyS_fsetxattr 4 64039 NULL
123794 +__sock_create_64069 __sock_create 0 64069 NULL
123795 +get_u8_64076 get_u8 0 64076 NULL
123796 +xilly_malloc_64077 xilly_malloc 2 64077 NULL
123797 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
123798 +vmci_handle_arr_get_size_64088 vmci_handle_arr_get_size 0 64088 NULL
123799 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
123800 +SyS_set_mempolicy_64096 SyS_set_mempolicy 3 64096 NULL
123801 +to_bytes_64103 to_bytes 0-1 64103 NULL
123802 +SyS_mq_timedsend_64107 SyS_mq_timedsend 3 64107 NULL
123803 +rdma_addr_size_64116 rdma_addr_size 0 64116 NULL
123804 +do_load_xattr_datum_64118 do_load_xattr_datum 0 64118 NULL
123805 +bypass_wd_write_64120 bypass_wd_write 3 64120 NULL
123806 +ext4_prepare_inline_data_64124 ext4_prepare_inline_data 3 64124 NULL
123807 +init_bch_64130 init_bch 1-2 64130 NULL
123808 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
123809 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
123810 +number_of_tds_64156 number_of_tds 0 64156 NULL
123811 +bnx2x_vf_mcast_64166 bnx2x_vf_mcast 4 64166 NULL
123812 +cpumask_scnprintf_64170 cpumask_scnprintf 0-2 64170 NULL
123813 +kernfs_iop_setxattr_64220 kernfs_iop_setxattr 4 64220 NULL
123814 +read_pulse_64227 read_pulse 0-3 64227 NULL
123815 +ea_len_64229 ea_len 0 64229 NULL
123816 +io_capture_transfer_64276 io_capture_transfer 4 64276 NULL
123817 +btrfs_file_extent_offset_64278 btrfs_file_extent_offset 0 64278 NULL nohasharray
123818 +bpf_check_classic_64278 bpf_check_classic 2 64278 &btrfs_file_extent_offset_64278
123819 +sta_current_tx_rate_read_64286 sta_current_tx_rate_read 3 64286 NULL
123820 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 NULL nohasharray
123821 +event_id_read_64288 event_id_read 3 64288 &xfs_dir_cilookup_result_64288
123822 +info_debugfs_read_64291 info_debugfs_read 3 64291 NULL
123823 +ocfs2_block_check_validate_bhs_64302 ocfs2_block_check_validate_bhs 0 64302 NULL
123824 +snd_hda_get_sub_nodes_64304 snd_hda_get_sub_nodes 0 64304 NULL
123825 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
123826 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
123827 +ts_write_64336 ts_write 3 64336 NULL
123828 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
123829 +user_regset_copyin_64360 user_regset_copyin 7 64360 NULL
123830 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
123831 +reg_create_64372 reg_create 5 64372 NULL
123832 +ilo_write_64378 ilo_write 3 64378 NULL
123833 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
123834 +vmcs_readl_64381 vmcs_readl 0 64381 NULL
123835 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
123836 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
123837 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
123838 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
123839 +keyctl_get_security_64418 keyctl_get_security 3 64418 NULL
123840 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
123841 +read_file_spectral_short_repeat_64431 read_file_spectral_short_repeat 3 64431 NULL
123842 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
123843 +single_open_size_64483 single_open_size 4 64483 NULL
123844 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
123845 +msg_data_sz_64503 msg_data_sz 0 64503 NULL
123846 +remove_uuid_64505 remove_uuid 4 64505 NULL
123847 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
123848 +iwl_dbgfs_ucode_tracing_write_64524 iwl_dbgfs_ucode_tracing_write 3 64524 NULL
123849 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
123850 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
123851 +SyS_bind_64544 SyS_bind 3 64544 NULL
123852 +rbd_obj_read_sync_64554 rbd_obj_read_sync 3-4 64554 NULL
123853 +__btrfs_prealloc_file_range_64557 __btrfs_prealloc_file_range 3 64557 NULL
123854 +ll_max_rw_chunk_seq_write_64561 ll_max_rw_chunk_seq_write 3 64561 NULL nohasharray
123855 +__spi_sync_64561 __spi_sync 0 64561 &ll_max_rw_chunk_seq_write_64561
123856 +__apei_exec_run_64563 __apei_exec_run 0 64563 NULL
123857 +kstrtoul_from_user_64569 kstrtoul_from_user 2 64569 NULL
123858 +do_erase_64574 do_erase 4 64574 NULL
123859 +fanotify_write_64623 fanotify_write 3 64623 NULL
123860 +_iwl_dbgfs_d0i3_refs_write_64642 _iwl_dbgfs_d0i3_refs_write 3 64642 NULL
123861 +regmap_read_debugfs_64658 regmap_read_debugfs 5 64658 NULL
123862 +ocfs2_read_xattr_block_64661 ocfs2_read_xattr_block 0 64661 NULL nohasharray
123863 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 &ocfs2_read_xattr_block_64661
123864 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
123865 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
123866 +nr_free_zone_pages_64680 nr_free_zone_pages 0 64680 NULL
123867 +snd_pcm_oss_capture_position_fixup_64713 snd_pcm_oss_capture_position_fixup 0 64713 NULL
123868 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
123869 +atomic_add_return_64720 atomic_add_return 0-1 64720 NULL
123870 +i2400m_msg_to_dev_64722 i2400m_msg_to_dev 3 64722 NULL
123871 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
123872 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
123873 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
123874 +hwdep_write_64776 hwdep_write 3 64776 NULL
123875 +message_for_md_64777 message_for_md 5 64777 NULL
123876 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
123877 +regmap_reg_ranges_read_file_64798 regmap_reg_ranges_read_file 3 64798 NULL
123878 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
123879 +rfkill_fop_write_64808 rfkill_fop_write 3 64808 NULL nohasharray
123880 +nv_mask_64808 nv_mask 0 64808 &rfkill_fop_write_64808
123881 +proc_projid_map_write_64810 proc_projid_map_write 3 64810 NULL
123882 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
123883 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
123884 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
123885 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
123886 +pci_vc_do_save_buffer_64876 pci_vc_do_save_buffer 0 64876 NULL
123887 +lprocfs_write_u64_helper_64880 lprocfs_write_u64_helper 2 64880 NULL
123888 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
123889 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL nohasharray
123890 +tipc_port_iovec_reject_64958 tipc_port_iovec_reject 4 64958 &ip_options_get_from_user_64958
123891 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
123892 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
123893 +crypto_ahash_digestsize_65014 crypto_ahash_digestsize 0 65014 NULL
123894 +insert_dent_65034 insert_dent 7 65034 NULL
123895 +snd_hda_get_pin_label_65035 snd_hda_get_pin_label 5 65035 NULL
123896 +ext4_ind_trans_blocks_65053 ext4_ind_trans_blocks 0-2 65053 NULL
123897 +pcibios_enable_device_65059 pcibios_enable_device 0 65059 NULL
123898 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
123899 +batadv_socket_write_65083 batadv_socket_write 3 65083 NULL
123900 +ocfs2_truncate_cluster_pages_65086 ocfs2_truncate_cluster_pages 2 65086 NULL
123901 +ath9k_dump_mci_btcoex_65090 ath9k_dump_mci_btcoex 0-3 65090 NULL
123902 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
123903 +nouveau_event_create_65229 nouveau_event_create 2-1 65229 NULL
123904 +print_endpoint_stat_65232 print_endpoint_stat 0-4-3 65232 NULL
123905 +whci_n_caps_65247 whci_n_caps 0 65247 NULL
123906 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
123907 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
123908 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
123909 +fat_direct_IO_65295 fat_direct_IO 4 65295 NULL
123910 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
123911 +get_var_len_65304 get_var_len 0 65304 NULL
123912 +unpack_array_65318 unpack_array 0 65318 NULL
123913 +pci_vpd_find_tag_65325 pci_vpd_find_tag 0-2 65325 NULL
123914 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
123915 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
123916 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
123917 +SyS_writev_65372 SyS_writev 3 65372 NULL
123918 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
123919 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
123920 +__read_vmcore_65402 __read_vmcore 2 65402 NULL
123921 +ocfs2_write_begin_nolock_65410 ocfs2_write_begin_nolock 3-4 65410 NULL
123922 +device_add_groups_65423 device_add_groups 0 65423 NULL
123923 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
123924 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
123925 +il_dbgfs_wd_timeout_write_65464 il_dbgfs_wd_timeout_write 3 65464 NULL
123926 +clear_user_65470 clear_user 2 65470 NULL
123927 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
123928 +lookup_inline_extent_backref_65493 lookup_inline_extent_backref 9 65493 NULL
123929 +nvme_trans_standard_inquiry_page_65526 nvme_trans_standard_inquiry_page 4 65526 NULL
123930 +tree_mod_log_eb_copy_65535 tree_mod_log_eb_copy 6 65535 NULL
123931 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
123932 new file mode 100644
123933 index 0000000..560cd7b
123934 --- /dev/null
123935 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
123936 @@ -0,0 +1,92 @@
123937 +spa_set_aux_vdevs_746 spa_set_aux_vdevs 3 746 NULL
123938 +zfs_lookup_2144 zfs_lookup 0 2144 NULL
123939 +mappedread_2627 mappedread 2 2627 NULL
123940 +vdev_disk_dio_alloc_2957 vdev_disk_dio_alloc 1 2957 NULL
123941 +nv_alloc_pushpage_spl_4286 nv_alloc_pushpage_spl 2 4286 NULL
123942 +zpl_xattr_get_4574 zpl_xattr_get 0 4574 NULL
123943 +sa_replace_all_by_template_5699 sa_replace_all_by_template 3 5699 NULL
123944 +dmu_write_6048 dmu_write 4-3 6048 NULL
123945 +dmu_buf_hold_array_6095 dmu_buf_hold_array 4-3 6095 NULL
123946 +update_pages_6225 update_pages 2-3 6225 NULL
123947 +bio_nr_pages_7117 bio_nr_pages 0-2 7117 NULL
123948 +dmu_buf_hold_array_by_bonus_8562 dmu_buf_hold_array_by_bonus 3-2 8562 NULL
123949 +zpios_dmu_write_8858 zpios_dmu_write 4-5 8858 NULL
123950 +ddi_copyout_9401 ddi_copyout 3 9401 NULL
123951 +avl_numnodes_12384 avl_numnodes 0 12384 NULL
123952 +dmu_write_uio_dnode_12473 dmu_write_uio_dnode 3 12473 NULL
123953 +dmu_xuio_init_12866 dmu_xuio_init 2 12866 NULL
123954 +zpl_read_common_14389 zpl_read_common 0 14389 NULL
123955 +dmu_snapshot_realname_14632 dmu_snapshot_realname 4 14632 NULL
123956 +kmem_alloc_debug_14852 kmem_alloc_debug 1 14852 NULL
123957 +kmalloc_node_nofail_15151 kmalloc_node_nofail 1 15151 NULL
123958 +dmu_write_uio_16351 dmu_write_uio 4 16351 NULL
123959 +zfs_log_write_16524 zfs_log_write 6-5 16524 NULL
123960 +sa_build_layouts_16910 sa_build_layouts 3 16910 NULL
123961 +dsl_dir_namelen_17053 dsl_dir_namelen 0 17053 NULL
123962 +kcopy_copy_to_user_17336 kcopy_copy_to_user 5 17336 NULL
123963 +sa_add_layout_entry_17507 sa_add_layout_entry 3 17507 NULL
123964 +sa_attr_table_setup_18029 sa_attr_table_setup 3 18029 NULL
123965 +uiocopy_18680 uiocopy 2 18680 NULL
123966 +dmu_buf_hold_array_by_dnode_19125 dmu_buf_hold_array_by_dnode 2-3 19125 NULL
123967 +zpl_acl_from_xattr_21141 zpl_acl_from_xattr 2 21141 NULL
123968 +dsl_pool_tx_assign_init_22518 dsl_pool_tx_assign_init 2 22518 NULL
123969 +nvlist_lookup_byte_array_22527 nvlist_lookup_byte_array 0 22527 NULL
123970 +sa_replace_all_by_template_locked_22533 sa_replace_all_by_template_locked 3 22533 NULL
123971 +tsd_hash_table_init_22559 tsd_hash_table_init 1 22559 NULL
123972 +spa_vdev_remove_aux_23966 spa_vdev_remove_aux 4 23966 NULL
123973 +zpl_xattr_acl_set_access_24129 zpl_xattr_acl_set_access 4 24129 NULL
123974 +dmu_assign_arcbuf_24622 dmu_assign_arcbuf 2 24622 NULL
123975 +zap_lookup_norm_25166 zap_lookup_norm 9 25166 NULL
123976 +dmu_prealloc_25456 dmu_prealloc 4-3 25456 NULL
123977 +kmalloc_nofail_26347 kmalloc_nofail 1 26347 NULL
123978 +zfsctl_snapshot_zpath_27578 zfsctl_snapshot_zpath 2 27578 NULL
123979 +zpios_dmu_read_30015 zpios_dmu_read 4-5 30015 NULL
123980 +splat_write_30943 splat_write 3 30943 NULL
123981 +zpl_xattr_get_sa_31183 zpl_xattr_get_sa 0 31183 NULL
123982 +dmu_read_uio_31467 dmu_read_uio 4 31467 NULL
123983 +zfs_replay_fuids_31479 zfs_replay_fuids 4 31479 NULL
123984 +spa_history_log_to_phys_31632 spa_history_log_to_phys 0-1 31632 NULL
123985 +__zpl_xattr_get_32601 __zpl_xattr_get 0 32601 NULL
123986 +proc_copyout_string_34049 proc_copyout_string 2 34049 NULL
123987 +nv_alloc_sleep_spl_34544 nv_alloc_sleep_spl 2 34544 NULL
123988 +nv_alloc_nosleep_spl_34761 nv_alloc_nosleep_spl 2 34761 NULL
123989 +zap_leaf_array_match_36922 zap_leaf_array_match 4 36922 NULL
123990 +copyinstr_36980 copyinstr 3 36980 NULL
123991 +zpl_xattr_acl_set_default_37864 zpl_xattr_acl_set_default 4 37864 NULL
123992 +splat_read_38116 splat_read 3 38116 NULL
123993 +sa_setup_38756 sa_setup 4 38756 NULL
123994 +vdev_disk_physio_39898 vdev_disk_physio 3 39898 NULL
123995 +arc_buf_size_39982 arc_buf_size 0 39982 NULL
123996 +kzalloc_nofail_40719 kzalloc_nofail 1 40719 NULL
123997 +fuidstr_to_sid_40777 fuidstr_to_sid 4 40777 NULL
123998 +vdev_raidz_matrix_reconstruct_40852 vdev_raidz_matrix_reconstruct 2-3 40852 NULL
123999 +sa_find_layout_40892 sa_find_layout 4 40892 NULL
124000 +zpl_xattr_get_dir_41918 zpl_xattr_get_dir 0 41918 NULL
124001 +zfs_sa_get_xattr_42600 zfs_sa_get_xattr 0 42600 NULL
124002 +zpl_xattr_acl_set_42808 zpl_xattr_acl_set 4 42808 NULL
124003 +xdr_dec_array_43091 xdr_dec_array 5 43091 NULL
124004 +dsl_dataset_namelen_43136 dsl_dataset_namelen 0 43136 NULL
124005 +kcopy_write_43683 kcopy_write 3 43683 NULL
124006 +uiomove_44355 uiomove 2 44355 NULL
124007 +dmu_read_44418 dmu_read 4-3 44418 NULL
124008 +ddi_copyin_44846 ddi_copyin 3 44846 NULL
124009 +kcopy_do_get_45061 kcopy_do_get 5 45061 NULL
124010 +copyin_45945 copyin 3 45945 NULL
124011 +zil_itx_create_46555 zil_itx_create 2 46555 NULL
124012 +dmu_write_uio_dbuf_48064 dmu_write_uio_dbuf 3 48064 NULL
124013 +blk_rq_pos_48233 blk_rq_pos 0 48233 NULL
124014 +spa_history_write_49650 spa_history_write 3 49650 NULL
124015 +kcopy_copy_pages_to_user_49823 kcopy_copy_pages_to_user 3-4 49823 NULL
124016 +zfs_log_write_50162 zfs_log_write 6-5 50162 NULL
124017 +i_fm_alloc_51038 i_fm_alloc 2 51038 NULL
124018 +copyout_51409 copyout 3 51409 NULL
124019 +zvol_log_write_54898 zvol_log_write 4-3 54898 NULL
124020 +zfs_acl_node_alloc_55641 zfs_acl_node_alloc 1 55641 NULL
124021 +get_nvlist_56685 get_nvlist 2 56685 NULL
124022 +zprop_get_numprops_56820 zprop_get_numprops 0 56820 NULL
124023 +splat_taskq_test4_common_59829 splat_taskq_test4_common 5 59829 NULL
124024 +zfs_replay_domain_cnt_61399 zfs_replay_domain_cnt 0 61399 NULL
124025 +zpios_write_61823 zpios_write 3 61823 NULL
124026 +proc_copyin_string_62019 proc_copyin_string 4 62019 NULL
124027 +random_get_pseudo_bytes_64611 random_get_pseudo_bytes 2 64611 NULL
124028 +zpios_read_64734 zpios_read 3 64734 NULL
124029 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
124030 new file mode 100644
124031 index 0000000..95f7abd
124032 --- /dev/null
124033 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
124034 @@ -0,0 +1,259 @@
124035 +/*
124036 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
124037 + * Licensed under the GPL v2, or (at your option) v3
124038 + *
124039 + * Homepage:
124040 + * http://www.grsecurity.net/~ephox/overflow_plugin/
124041 + *
124042 + * Documentation:
124043 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
124044 + *
124045 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
124046 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
124047 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
124048 + *
124049 + * Usage:
124050 + * $ make
124051 + * $ make run
124052 + */
124053 +
124054 +#include "gcc-common.h"
124055 +#include "size_overflow.h"
124056 +
124057 +int plugin_is_GPL_compatible;
124058 +
124059 +tree report_size_overflow_decl;
124060 +
124061 +tree size_overflow_type_HI;
124062 +tree size_overflow_type_SI;
124063 +tree size_overflow_type_DI;
124064 +tree size_overflow_type_TI;
124065 +
124066 +static struct plugin_info size_overflow_plugin_info = {
124067 + .version = "20140725",
124068 + .help = "no-size-overflow\tturn off size overflow checking\n",
124069 +};
124070 +
124071 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
124072 +{
124073 + unsigned int arg_count;
124074 + enum tree_code code = TREE_CODE(*node);
124075 +
124076 + switch (code) {
124077 + case FUNCTION_DECL:
124078 + arg_count = type_num_arguments(TREE_TYPE(*node));
124079 + break;
124080 + case FUNCTION_TYPE:
124081 + case METHOD_TYPE:
124082 + arg_count = type_num_arguments(*node);
124083 + break;
124084 + default:
124085 + *no_add_attrs = true;
124086 + error("%s: %qE attribute only applies to functions", __func__, name);
124087 + return NULL_TREE;
124088 + }
124089 +
124090 + for (; args; args = TREE_CHAIN(args)) {
124091 + tree position = TREE_VALUE(args);
124092 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
124093 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
124094 + *no_add_attrs = true;
124095 + }
124096 + }
124097 + return NULL_TREE;
124098 +}
124099 +
124100 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
124101 +{
124102 + unsigned int arg_count;
124103 + enum tree_code code = TREE_CODE(*node);
124104 +
124105 + switch (code) {
124106 + case FUNCTION_DECL:
124107 + arg_count = type_num_arguments(TREE_TYPE(*node));
124108 + break;
124109 + case FUNCTION_TYPE:
124110 + case METHOD_TYPE:
124111 + arg_count = type_num_arguments(*node);
124112 + break;
124113 + case FIELD_DECL:
124114 + return NULL_TREE;
124115 + default:
124116 + *no_add_attrs = true;
124117 + error("%qE attribute only applies to functions", name);
124118 + return NULL_TREE;
124119 + }
124120 +
124121 + if (TREE_INT_CST_HIGH(TREE_VALUE(args)) != 0)
124122 + return NULL_TREE;
124123 +
124124 + for (; args; args = TREE_CHAIN(args)) {
124125 + tree position = TREE_VALUE(args);
124126 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
124127 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
124128 + *no_add_attrs = true;
124129 + }
124130 + }
124131 + return NULL_TREE;
124132 +}
124133 +
124134 +static struct attribute_spec size_overflow_attr = {
124135 + .name = "size_overflow",
124136 + .min_length = 1,
124137 + .max_length = -1,
124138 + .decl_required = true,
124139 + .type_required = false,
124140 + .function_type_required = false,
124141 + .handler = handle_size_overflow_attribute,
124142 +#if BUILDING_GCC_VERSION >= 4007
124143 + .affects_type_identity = false
124144 +#endif
124145 +};
124146 +
124147 +static struct attribute_spec intentional_overflow_attr = {
124148 + .name = "intentional_overflow",
124149 + .min_length = 1,
124150 + .max_length = -1,
124151 + .decl_required = true,
124152 + .type_required = false,
124153 + .function_type_required = false,
124154 + .handler = handle_intentional_overflow_attribute,
124155 +#if BUILDING_GCC_VERSION >= 4007
124156 + .affects_type_identity = false
124157 +#endif
124158 +};
124159 +
124160 +static void register_attributes(void __unused *event_data, void __unused *data)
124161 +{
124162 + register_attribute(&size_overflow_attr);
124163 + register_attribute(&intentional_overflow_attr);
124164 +}
124165 +
124166 +static tree create_typedef(tree type, const char* ident)
124167 +{
124168 + tree new_type, decl;
124169 +
124170 + new_type = build_variant_type_copy(type);
124171 + decl = build_decl(BUILTINS_LOCATION, TYPE_DECL, get_identifier(ident), new_type);
124172 + DECL_ORIGINAL_TYPE(decl) = type;
124173 + TYPE_NAME(new_type) = decl;
124174 + return new_type;
124175 +}
124176 +
124177 +// Create the noreturn report_size_overflow() function decl.
124178 +static void size_overflow_start_unit(void __unused *gcc_data, void __unused *user_data)
124179 +{
124180 + tree const_char_ptr_type_node;
124181 + tree fntype;
124182 +
124183 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
124184 +
124185 + size_overflow_type_HI = create_typedef(intHI_type_node, "size_overflow_type_HI");
124186 + size_overflow_type_SI = create_typedef(intSI_type_node, "size_overflow_type_SI");
124187 + size_overflow_type_DI = create_typedef(intDI_type_node, "size_overflow_type_DI");
124188 + size_overflow_type_TI = create_typedef(intTI_type_node, "size_overflow_type_TI");
124189 +
124190 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
124191 + fntype = build_function_type_list(void_type_node,
124192 + const_char_ptr_type_node,
124193 + unsigned_type_node,
124194 + const_char_ptr_type_node,
124195 + const_char_ptr_type_node,
124196 + NULL_TREE);
124197 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
124198 +
124199 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
124200 + TREE_PUBLIC(report_size_overflow_decl) = 1;
124201 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
124202 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
124203 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
124204 +}
124205 +
124206 +
124207 +extern struct gimple_opt_pass pass_dce;
124208 +
124209 +static struct opt_pass *make_dce_pass(void)
124210 +{
124211 +#if BUILDING_GCC_VERSION >= 4009
124212 + return make_pass_dce(g);
124213 +#else
124214 + return &pass_dce.pass;
124215 +#endif
124216 +}
124217 +
124218 +
124219 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
124220 +{
124221 + int i;
124222 + const char * const plugin_name = plugin_info->base_name;
124223 + const int argc = plugin_info->argc;
124224 + const struct plugin_argument * const argv = plugin_info->argv;
124225 + bool enable = true;
124226 + struct register_pass_info insert_size_overflow_asm_pass_info;
124227 + struct register_pass_info __unused dump_before_pass_info;
124228 + struct register_pass_info __unused dump_after_pass_info;
124229 + struct register_pass_info insert_size_overflow_check_info;
124230 + struct register_pass_info dce_pass_info;
124231 + static const struct ggc_root_tab gt_ggc_r_gt_size_overflow[] = {
124232 + {
124233 + .base = &report_size_overflow_decl,
124234 + .nelt = 1,
124235 + .stride = sizeof(report_size_overflow_decl),
124236 + .cb = &gt_ggc_mx_tree_node,
124237 + .pchw = &gt_pch_nx_tree_node
124238 + },
124239 + LAST_GGC_ROOT_TAB
124240 + };
124241 +
124242 + insert_size_overflow_asm_pass_info.pass = make_insert_size_overflow_asm_pass();
124243 + insert_size_overflow_asm_pass_info.reference_pass_name = "ssa";
124244 + insert_size_overflow_asm_pass_info.ref_pass_instance_number = 1;
124245 + insert_size_overflow_asm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
124246 +
124247 + dump_before_pass_info.pass = make_dump_pass();
124248 + dump_before_pass_info.reference_pass_name = "increase_alignment";
124249 + dump_before_pass_info.ref_pass_instance_number = 1;
124250 + dump_before_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
124251 +
124252 + insert_size_overflow_check_info.pass = make_insert_size_overflow_check();
124253 + insert_size_overflow_check_info.reference_pass_name = "increase_alignment";
124254 + insert_size_overflow_check_info.ref_pass_instance_number = 1;
124255 + insert_size_overflow_check_info.pos_op = PASS_POS_INSERT_BEFORE;
124256 +
124257 + dump_after_pass_info.pass = make_dump_pass();
124258 + dump_after_pass_info.reference_pass_name = "increase_alignment";
124259 + dump_after_pass_info.ref_pass_instance_number = 1;
124260 + dump_after_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
124261 +
124262 + dce_pass_info.pass = make_dce_pass();
124263 + dce_pass_info.reference_pass_name = "vrp";
124264 + dce_pass_info.ref_pass_instance_number = 1;
124265 + dce_pass_info.pos_op = PASS_POS_INSERT_AFTER;
124266 +
124267 + if (!plugin_default_version_check(version, &gcc_version)) {
124268 + error(G_("incompatible gcc/plugin versions"));
124269 + return 1;
124270 + }
124271 +
124272 + for (i = 0; i < argc; ++i) {
124273 + if (!strcmp(argv[i].key, "no-size-overflow")) {
124274 + enable = false;
124275 + continue;
124276 + }
124277 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
124278 + }
124279 +
124280 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
124281 + if (enable) {
124282 + register_callback(plugin_name, PLUGIN_START_UNIT, &size_overflow_start_unit, NULL);
124283 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_size_overflow);
124284 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_asm_pass_info);
124285 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_before_pass_info);
124286 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_check_info);
124287 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_after_pass_info);
124288 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dce_pass_info);
124289 + }
124290 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
124291 +
124292 + return 0;
124293 +}
124294 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
124295 new file mode 100644
124296 index 0000000..0888f6c
124297 --- /dev/null
124298 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
124299 @@ -0,0 +1,364 @@
124300 +/*
124301 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
124302 + * Licensed under the GPL v2, or (at your option) v3
124303 + *
124304 + * Homepage:
124305 + * http://www.grsecurity.net/~ephox/overflow_plugin/
124306 + *
124307 + * Documentation:
124308 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
124309 + *
124310 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
124311 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
124312 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
124313 + *
124314 + * Usage:
124315 + * $ make
124316 + * $ make run
124317 + */
124318 +
124319 +#include "gcc-common.h"
124320 +#include "size_overflow.h"
124321 +
124322 +#include "size_overflow_hash.h"
124323 +#include "size_overflow_hash_aux.h"
124324 +
124325 +#define CODES_LIMIT 32
124326 +
124327 +static unsigned char get_tree_code(const_tree type)
124328 +{
124329 + switch (TREE_CODE(type)) {
124330 + case ARRAY_TYPE:
124331 + return 0;
124332 + case BOOLEAN_TYPE:
124333 + return 1;
124334 + case ENUMERAL_TYPE:
124335 + return 2;
124336 + case FUNCTION_TYPE:
124337 + return 3;
124338 + case INTEGER_TYPE:
124339 + return 4;
124340 + case POINTER_TYPE:
124341 + return 5;
124342 + case RECORD_TYPE:
124343 + return 6;
124344 + case UNION_TYPE:
124345 + return 7;
124346 + case VOID_TYPE:
124347 + return 8;
124348 + case REAL_TYPE:
124349 + return 9;
124350 + case VECTOR_TYPE:
124351 + return 10;
124352 + case REFERENCE_TYPE:
124353 + return 11;
124354 + case OFFSET_TYPE:
124355 + return 12;
124356 + case COMPLEX_TYPE:
124357 + return 13;
124358 + default:
124359 + debug_tree((tree)type);
124360 + gcc_unreachable();
124361 + }
124362 +}
124363 +
124364 +struct function_hash {
124365 + size_t tree_codes_len;
124366 + unsigned char tree_codes[CODES_LIMIT];
124367 + const_tree fndecl;
124368 + unsigned int hash;
124369 +};
124370 +
124371 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
124372 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
124373 +{
124374 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
124375 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
124376 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
124377 +
124378 + unsigned int m = 0x57559429;
124379 + unsigned int n = 0x5052acdb;
124380 + const unsigned int *key4 = (const unsigned int *)key;
124381 + unsigned int h = len;
124382 + unsigned int k = len + seed + n;
124383 + unsigned long long p;
124384 +
124385 + while (len >= 8) {
124386 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
124387 + len -= 8;
124388 + }
124389 + if (len >= 4) {
124390 + cwmixb(key4[0]) key4 += 1;
124391 + len -= 4;
124392 + }
124393 + if (len)
124394 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
124395 + cwmixb(h ^ (k + n));
124396 + return k ^ h;
124397 +
124398 +#undef cwfold
124399 +#undef cwmixa
124400 +#undef cwmixb
124401 +}
124402 +
124403 +static void set_hash(const char *fn_name, struct function_hash *fn_hash_data)
124404 +{
124405 + unsigned int fn, codes, seed = 0;
124406 +
124407 + fn = CrapWow(fn_name, strlen(fn_name), seed) & 0xffff;
124408 + codes = CrapWow((const char*)fn_hash_data->tree_codes, fn_hash_data->tree_codes_len, seed) & 0xffff;
124409 +
124410 + fn_hash_data->hash = fn ^ codes;
124411 +}
124412 +
124413 +static void set_node_codes(const_tree type, struct function_hash *fn_hash_data)
124414 +{
124415 + gcc_assert(type != NULL_TREE);
124416 + gcc_assert(TREE_CODE_CLASS(TREE_CODE(type)) == tcc_type);
124417 +
124418 + while (type && fn_hash_data->tree_codes_len < CODES_LIMIT) {
124419 + fn_hash_data->tree_codes[fn_hash_data->tree_codes_len] = get_tree_code(type);
124420 + fn_hash_data->tree_codes_len++;
124421 + type = TREE_TYPE(type);
124422 + }
124423 +}
124424 +
124425 +static void set_result_codes(const_tree node, struct function_hash *fn_hash_data)
124426 +{
124427 + const_tree result;
124428 +
124429 + gcc_assert(node != NULL_TREE);
124430 +
124431 + if (DECL_P(node)) {
124432 + result = DECL_RESULT(node);
124433 + if (result != NULL_TREE)
124434 + return set_node_codes(TREE_TYPE(result), fn_hash_data);
124435 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
124436 + }
124437 +
124438 + gcc_assert(TYPE_P(node));
124439 +
124440 + if (TREE_CODE(node) == FUNCTION_TYPE)
124441 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
124442 +
124443 + return set_node_codes(node, fn_hash_data);
124444 +}
124445 +
124446 +static void set_function_codes(struct function_hash *fn_hash_data)
124447 +{
124448 + const_tree arg, type = TREE_TYPE(fn_hash_data->fndecl);
124449 + enum tree_code code = TREE_CODE(type);
124450 +
124451 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
124452 +
124453 + set_result_codes(fn_hash_data->fndecl, fn_hash_data);
124454 +
124455 + for (arg = TYPE_ARG_TYPES(type); arg != NULL_TREE && fn_hash_data->tree_codes_len < CODES_LIMIT; arg = TREE_CHAIN(arg))
124456 + set_node_codes(TREE_VALUE(arg), fn_hash_data);
124457 +}
124458 +
124459 +static const struct size_overflow_hash *get_proper_hash_chain(const struct size_overflow_hash *entry, const char *func_name)
124460 +{
124461 + while (entry) {
124462 + if (!strcmp(entry->name, func_name))
124463 + return entry;
124464 + entry = entry->next;
124465 + }
124466 + return NULL;
124467 +}
124468 +
124469 +const struct size_overflow_hash *get_function_hash(const_tree fndecl)
124470 +{
124471 + const struct size_overflow_hash *entry;
124472 + struct function_hash fn_hash_data;
124473 + const char *func_name;
124474 +
124475 + // skip builtins __builtin_constant_p
124476 + if (DECL_BUILT_IN(fndecl))
124477 + return NULL;
124478 +
124479 + fn_hash_data.fndecl = fndecl;
124480 + fn_hash_data.tree_codes_len = 0;
124481 +
124482 + set_function_codes(&fn_hash_data);
124483 + gcc_assert(fn_hash_data.tree_codes_len != 0);
124484 +
124485 + func_name = DECL_NAME_POINTER(fn_hash_data.fndecl);
124486 + set_hash(func_name, &fn_hash_data);
124487 +
124488 + entry = size_overflow_hash[fn_hash_data.hash];
124489 + entry = get_proper_hash_chain(entry, func_name);
124490 + if (entry)
124491 + return entry;
124492 + entry = size_overflow_hash_aux[fn_hash_data.hash];
124493 + return get_proper_hash_chain(entry, func_name);
124494 +}
124495 +
124496 +static void print_missing_msg(const_tree func, unsigned int argnum)
124497 +{
124498 + location_t loc;
124499 + const char *curfunc;
124500 + struct function_hash fn_hash_data;
124501 +
124502 + fn_hash_data.fndecl = DECL_ORIGIN(func);
124503 + fn_hash_data.tree_codes_len = 0;
124504 +
124505 + loc = DECL_SOURCE_LOCATION(fn_hash_data.fndecl);
124506 + curfunc = DECL_NAME_POINTER(fn_hash_data.fndecl);
124507 +
124508 + set_function_codes(&fn_hash_data);
124509 + set_hash(curfunc, &fn_hash_data);
124510 +
124511 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, fn_hash_data.hash);
124512 +}
124513 +
124514 +unsigned int find_arg_number_tree(const_tree arg, const_tree func)
124515 +{
124516 + tree var;
124517 + unsigned int argnum = 1;
124518 +
124519 + if (TREE_CODE(arg) == SSA_NAME)
124520 + arg = SSA_NAME_VAR(arg);
124521 +
124522 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var), argnum++) {
124523 + if (!operand_equal_p(arg, var, 0) && strcmp(DECL_NAME_POINTER(var), DECL_NAME_POINTER(arg)))
124524 + continue;
124525 + if (!skip_types(var))
124526 + return argnum;
124527 + }
124528 +
124529 + return CANNOT_FIND_ARG;
124530 +}
124531 +
124532 +static const char *get_asm_string(const_gimple stmt)
124533 +{
124534 + if (!stmt)
124535 + return NULL;
124536 + if (gimple_code(stmt) != GIMPLE_ASM)
124537 + return NULL;
124538 +
124539 + return gimple_asm_string(stmt);
124540 +}
124541 +
124542 +bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt)
124543 +{
124544 + const char *str;
124545 +
124546 + str = get_asm_string(stmt);
124547 + if (!str)
124548 + return false;
124549 + return !strncmp(str, TURN_OFF_ASM_STR, sizeof(TURN_OFF_ASM_STR) - 1);
124550 +}
124551 +
124552 +bool is_size_overflow_intentional_asm_yes(const_gimple stmt)
124553 +{
124554 + const char *str;
124555 +
124556 + str = get_asm_string(stmt);
124557 + if (!str)
124558 + return false;
124559 + return !strncmp(str, YES_ASM_STR, sizeof(YES_ASM_STR) - 1);
124560 +}
124561 +
124562 +bool is_size_overflow_asm(const_gimple stmt)
124563 +{
124564 + const char *str;
124565 +
124566 + str = get_asm_string(stmt);
124567 + if (!str)
124568 + return false;
124569 + return !strncmp(str, OK_ASM_STR, sizeof(OK_ASM_STR) - 1);
124570 +}
124571 +
124572 +bool is_a_return_check(const_tree node)
124573 +{
124574 + if (TREE_CODE(node) == FUNCTION_DECL)
124575 + return true;
124576 +
124577 + gcc_assert(TREE_CODE(node) == PARM_DECL);
124578 + return false;
124579 +}
124580 +
124581 +// Get the argnum of a function decl, if node is a return then the argnum is 0
124582 +unsigned int get_function_num(const_tree node, const_tree orig_fndecl)
124583 +{
124584 + if (is_a_return_check(node))
124585 + return 0;
124586 + else
124587 + return find_arg_number_tree(node, orig_fndecl);
124588 +}
124589 +
124590 +unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl)
124591 +{
124592 + const struct size_overflow_hash *hash;
124593 + unsigned int new_argnum;
124594 + tree arg;
124595 + const_tree origarg;
124596 +
124597 + if (argnum == 0)
124598 + return argnum;
124599 +
124600 + hash = get_function_hash(fndecl);
124601 + if (hash && hash->param & (1U << argnum))
124602 + return argnum;
124603 +
124604 + if (DECL_EXTERNAL(fndecl))
124605 + return argnum;
124606 +
124607 + origarg = DECL_ARGUMENTS(DECL_ORIGIN(fndecl));
124608 + argnum--;
124609 + while (origarg && argnum) {
124610 + origarg = TREE_CHAIN(origarg);
124611 + argnum--;
124612 + }
124613 + gcc_assert(argnum == 0);
124614 + gcc_assert(origarg != NULL_TREE);
124615 +
124616 + for (arg = DECL_ARGUMENTS(fndecl), new_argnum = 1; arg; arg = TREE_CHAIN(arg), new_argnum++)
124617 + if (operand_equal_p(origarg, arg, 0) || !strcmp(DECL_NAME_POINTER(origarg), DECL_NAME_POINTER(arg)))
124618 + return new_argnum;
124619 +
124620 + return CANNOT_FIND_ARG;
124621 +}
124622 +
124623 +static bool is_in_hash_table(const_tree fndecl, unsigned int num)
124624 +{
124625 + const struct size_overflow_hash *hash;
124626 +
124627 + hash = get_function_hash(fndecl);
124628 + if (hash && (hash->param & (1U << num)))
124629 + return true;
124630 + return false;
124631 +}
124632 +
124633 +/* Check if the function has a size_overflow attribute or it is in the size_overflow hash table.
124634 + * If the function is missing everywhere then print the missing message into stderr.
124635 + */
124636 +bool is_missing_function(const_tree orig_fndecl, unsigned int num)
124637 +{
124638 + switch (DECL_FUNCTION_CODE(orig_fndecl)) {
124639 +#if BUILDING_GCC_VERSION >= 4008
124640 + case BUILT_IN_BSWAP16:
124641 +#endif
124642 + case BUILT_IN_BSWAP32:
124643 + case BUILT_IN_BSWAP64:
124644 + case BUILT_IN_EXPECT:
124645 + case BUILT_IN_MEMCMP:
124646 + return false;
124647 + default:
124648 + break;
124649 + }
124650 +
124651 + // skip test.c
124652 + if (strcmp(DECL_NAME_POINTER(current_function_decl), "coolmalloc")) {
124653 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(orig_fndecl)))
124654 + warning(0, "unnecessary size_overflow attribute on: %s\n", DECL_NAME_POINTER(orig_fndecl));
124655 + }
124656 +
124657 + if (is_in_hash_table(orig_fndecl, num))
124658 + return false;
124659 +
124660 + print_missing_msg(orig_fndecl, num);
124661 + return true;
124662 +}
124663 +
124664 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
124665 new file mode 100644
124666 index 0000000..924652b
124667 --- /dev/null
124668 +++ b/tools/gcc/stackleak_plugin.c
124669 @@ -0,0 +1,395 @@
124670 +/*
124671 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
124672 + * Licensed under the GPL v2
124673 + *
124674 + * Note: the choice of the license means that the compilation process is
124675 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
124676 + * but for the kernel it doesn't matter since it doesn't link against
124677 + * any of the gcc libraries
124678 + *
124679 + * gcc plugin to help implement various PaX features
124680 + *
124681 + * - track lowest stack pointer
124682 + *
124683 + * TODO:
124684 + * - initialize all local variables
124685 + *
124686 + * BUGS:
124687 + * - none known
124688 + */
124689 +
124690 +#include "gcc-common.h"
124691 +
124692 +int plugin_is_GPL_compatible;
124693 +
124694 +static int track_frame_size = -1;
124695 +static const char track_function[] = "pax_track_stack";
124696 +static const char check_function[] = "pax_check_alloca";
124697 +static tree track_function_decl, check_function_decl;
124698 +static bool init_locals;
124699 +
124700 +static struct plugin_info stackleak_plugin_info = {
124701 + .version = "201408011900",
124702 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
124703 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
124704 +};
124705 +
124706 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
124707 +{
124708 + gimple check_alloca;
124709 + tree alloca_size;
124710 +
124711 + // insert call to void pax_check_alloca(unsigned long size)
124712 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
124713 + check_alloca = gimple_build_call(check_function_decl, 1, alloca_size);
124714 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
124715 +}
124716 +
124717 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
124718 +{
124719 + gimple track_stack;
124720 +
124721 + // insert call to void pax_track_stack(void)
124722 + track_stack = gimple_build_call(track_function_decl, 0);
124723 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
124724 +}
124725 +
124726 +static bool is_alloca(gimple stmt)
124727 +{
124728 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
124729 + return true;
124730 +
124731 +#if BUILDING_GCC_VERSION >= 4007
124732 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
124733 + return true;
124734 +#endif
124735 +
124736 + return false;
124737 +}
124738 +
124739 +static unsigned int execute_stackleak_tree_instrument(void)
124740 +{
124741 + basic_block bb, entry_bb;
124742 + bool prologue_instrumented = false, is_leaf = true;
124743 +
124744 + entry_bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb;
124745 +
124746 + // 1. loop through BBs and GIMPLE statements
124747 + FOR_EACH_BB_FN(bb, cfun) {
124748 + gimple_stmt_iterator gsi;
124749 +
124750 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
124751 + gimple stmt;
124752 +
124753 + stmt = gsi_stmt(gsi);
124754 +
124755 + if (is_gimple_call(stmt))
124756 + is_leaf = false;
124757 +
124758 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
124759 + if (!is_alloca(stmt))
124760 + continue;
124761 +
124762 + // 2. insert stack overflow check before each __builtin_alloca call
124763 + stackleak_check_alloca(&gsi);
124764 +
124765 + // 3. insert track call after each __builtin_alloca call
124766 + stackleak_add_instrumentation(&gsi);
124767 + if (bb == entry_bb)
124768 + prologue_instrumented = true;
124769 + }
124770 + }
124771 +
124772 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
124773 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
124774 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
124775 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
124776 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
124777 + return 0;
124778 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
124779 + return 0;
124780 +
124781 + // 4. insert track call at the beginning
124782 + if (!prologue_instrumented) {
124783 + gimple_stmt_iterator gsi;
124784 +
124785 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
124786 + if (dom_info_available_p(CDI_DOMINATORS))
124787 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
124788 + gsi = gsi_start_bb(bb);
124789 + stackleak_add_instrumentation(&gsi);
124790 + }
124791 +
124792 + return 0;
124793 +}
124794 +
124795 +static unsigned int execute_stackleak_final(void)
124796 +{
124797 + rtx insn, next;
124798 +
124799 + if (cfun->calls_alloca)
124800 + return 0;
124801 +
124802 + // keep calls only if function frame is big enough
124803 + if (get_frame_size() >= track_frame_size)
124804 + return 0;
124805 +
124806 + // 1. find pax_track_stack calls
124807 + for (insn = get_insns(); insn; insn = next) {
124808 + // 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))
124809 + rtx body;
124810 +
124811 + next = NEXT_INSN(insn);
124812 + if (!CALL_P(insn))
124813 + continue;
124814 + body = PATTERN(insn);
124815 + if (GET_CODE(body) != CALL)
124816 + continue;
124817 + body = XEXP(body, 0);
124818 + if (GET_CODE(body) != MEM)
124819 + continue;
124820 + body = XEXP(body, 0);
124821 + if (GET_CODE(body) != SYMBOL_REF)
124822 + continue;
124823 +// if (strcmp(XSTR(body, 0), track_function))
124824 + if (SYMBOL_REF_DECL(body) != track_function_decl)
124825 + continue;
124826 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
124827 + // 2. delete call
124828 + delete_insn_and_edges(insn);
124829 +#if BUILDING_GCC_VERSION >= 4007
124830 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
124831 + insn = next;
124832 + next = NEXT_INSN(insn);
124833 + delete_insn_and_edges(insn);
124834 + }
124835 +#endif
124836 + }
124837 +
124838 +// print_simple_rtl(stderr, get_insns());
124839 +// print_rtl(stderr, get_insns());
124840 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
124841 +
124842 + return 0;
124843 +}
124844 +
124845 +static bool gate_stackleak_track_stack(void)
124846 +{
124847 + tree section;
124848 +
124849 + if (ix86_cmodel != CM_KERNEL)
124850 + return false;
124851 +
124852 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
124853 + if (section && TREE_VALUE(section)) {
124854 + section = TREE_VALUE(TREE_VALUE(section));
124855 +
124856 + if (!strncmp(TREE_STRING_POINTER(section), ".init.text", 10))
124857 + return false;
124858 + if (!strncmp(TREE_STRING_POINTER(section), ".devinit.text", 13))
124859 + return false;
124860 + if (!strncmp(TREE_STRING_POINTER(section), ".cpuinit.text", 13))
124861 + return false;
124862 + if (!strncmp(TREE_STRING_POINTER(section), ".meminit.text", 13))
124863 + return false;
124864 + }
124865 +
124866 + return track_frame_size >= 0;
124867 +}
124868 +
124869 +static void stackleak_start_unit(void *gcc_data, void *user_data)
124870 +{
124871 + tree fntype;
124872 +
124873 + // void pax_track_stack(void)
124874 + fntype = build_function_type_list(void_type_node, NULL_TREE);
124875 + track_function_decl = build_fn_decl(track_function, fntype);
124876 + DECL_ASSEMBLER_NAME(track_function_decl); // for LTO
124877 + TREE_PUBLIC(track_function_decl) = 1;
124878 + DECL_EXTERNAL(track_function_decl) = 1;
124879 + DECL_ARTIFICIAL(track_function_decl) = 1;
124880 +
124881 + // void pax_check_alloca(unsigned long)
124882 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
124883 + check_function_decl = build_fn_decl(check_function, fntype);
124884 + DECL_ASSEMBLER_NAME(check_function_decl); // for LTO
124885 + TREE_PUBLIC(check_function_decl) = 1;
124886 + DECL_EXTERNAL(check_function_decl) = 1;
124887 + DECL_ARTIFICIAL(check_function_decl) = 1;
124888 +}
124889 +
124890 +#if BUILDING_GCC_VERSION >= 4009
124891 +static const struct pass_data stackleak_tree_instrument_pass_data = {
124892 +#else
124893 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
124894 + .pass = {
124895 +#endif
124896 + .type = GIMPLE_PASS,
124897 + .name = "stackleak_tree_instrument",
124898 +#if BUILDING_GCC_VERSION >= 4008
124899 + .optinfo_flags = OPTGROUP_NONE,
124900 +#endif
124901 +#if BUILDING_GCC_VERSION >= 4009
124902 + .has_gate = true,
124903 + .has_execute = true,
124904 +#else
124905 + .gate = gate_stackleak_track_stack,
124906 + .execute = execute_stackleak_tree_instrument,
124907 + .sub = NULL,
124908 + .next = NULL,
124909 + .static_pass_number = 0,
124910 +#endif
124911 + .tv_id = TV_NONE,
124912 + .properties_required = PROP_gimple_leh | PROP_cfg,
124913 + .properties_provided = 0,
124914 + .properties_destroyed = 0,
124915 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
124916 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa | TODO_rebuild_cgraph_edges
124917 +#if BUILDING_GCC_VERSION < 4009
124918 + }
124919 +#endif
124920 +};
124921 +
124922 +#if BUILDING_GCC_VERSION >= 4009
124923 +static const struct pass_data stackleak_final_rtl_opt_pass_data = {
124924 +#else
124925 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
124926 + .pass = {
124927 +#endif
124928 + .type = RTL_PASS,
124929 + .name = "stackleak_final",
124930 +#if BUILDING_GCC_VERSION >= 4008
124931 + .optinfo_flags = OPTGROUP_NONE,
124932 +#endif
124933 +#if BUILDING_GCC_VERSION >= 4009
124934 + .has_gate = true,
124935 + .has_execute = true,
124936 +#else
124937 + .gate = gate_stackleak_track_stack,
124938 + .execute = execute_stackleak_final,
124939 + .sub = NULL,
124940 + .next = NULL,
124941 + .static_pass_number = 0,
124942 +#endif
124943 + .tv_id = TV_NONE,
124944 + .properties_required = 0,
124945 + .properties_provided = 0,
124946 + .properties_destroyed = 0,
124947 + .todo_flags_start = 0,
124948 + .todo_flags_finish = TODO_dump_func
124949 +#if BUILDING_GCC_VERSION < 4009
124950 + }
124951 +#endif
124952 +};
124953 +
124954 +#if BUILDING_GCC_VERSION >= 4009
124955 +namespace {
124956 +class stackleak_tree_instrument_pass : public gimple_opt_pass {
124957 +public:
124958 + stackleak_tree_instrument_pass() : gimple_opt_pass(stackleak_tree_instrument_pass_data, g) {}
124959 + bool gate() { return gate_stackleak_track_stack(); }
124960 + unsigned int execute() { return execute_stackleak_tree_instrument(); }
124961 +};
124962 +
124963 +class stackleak_final_rtl_opt_pass : public rtl_opt_pass {
124964 +public:
124965 + stackleak_final_rtl_opt_pass() : rtl_opt_pass(stackleak_final_rtl_opt_pass_data, g) {}
124966 + bool gate() { return gate_stackleak_track_stack(); }
124967 + unsigned int execute() { return execute_stackleak_final(); }
124968 +};
124969 +}
124970 +
124971 +static opt_pass *make_stackleak_tree_instrument_pass(void)
124972 +{
124973 + return new stackleak_tree_instrument_pass();
124974 +}
124975 +
124976 +static opt_pass *make_stackleak_final_rtl_opt_pass(void)
124977 +{
124978 + return new stackleak_final_rtl_opt_pass();
124979 +}
124980 +#else
124981 +static struct opt_pass *make_stackleak_tree_instrument_pass(void)
124982 +{
124983 + return &stackleak_tree_instrument_pass.pass;
124984 +}
124985 +
124986 +static struct opt_pass *make_stackleak_final_rtl_opt_pass(void)
124987 +{
124988 + return &stackleak_final_rtl_opt_pass.pass;
124989 +}
124990 +#endif
124991 +
124992 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
124993 +{
124994 + const char * const plugin_name = plugin_info->base_name;
124995 + const int argc = plugin_info->argc;
124996 + const struct plugin_argument * const argv = plugin_info->argv;
124997 + int i;
124998 + struct register_pass_info stackleak_tree_instrument_pass_info;
124999 + struct register_pass_info stackleak_final_pass_info;
125000 + static const struct ggc_root_tab gt_ggc_r_gt_stackleak[] = {
125001 + {
125002 + .base = &track_function_decl,
125003 + .nelt = 1,
125004 + .stride = sizeof(track_function_decl),
125005 + .cb = &gt_ggc_mx_tree_node,
125006 + .pchw = &gt_pch_nx_tree_node
125007 + },
125008 + {
125009 + .base = &check_function_decl,
125010 + .nelt = 1,
125011 + .stride = sizeof(check_function_decl),
125012 + .cb = &gt_ggc_mx_tree_node,
125013 + .pchw = &gt_pch_nx_tree_node
125014 + },
125015 + LAST_GGC_ROOT_TAB
125016 + };
125017 +
125018 + stackleak_tree_instrument_pass_info.pass = make_stackleak_tree_instrument_pass();
125019 +// stackleak_tree_instrument_pass_info.reference_pass_name = "tree_profile";
125020 + stackleak_tree_instrument_pass_info.reference_pass_name = "optimized";
125021 + stackleak_tree_instrument_pass_info.ref_pass_instance_number = 1;
125022 + stackleak_tree_instrument_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
125023 +
125024 + stackleak_final_pass_info.pass = make_stackleak_final_rtl_opt_pass();
125025 + stackleak_final_pass_info.reference_pass_name = "final";
125026 + stackleak_final_pass_info.ref_pass_instance_number = 1;
125027 + stackleak_final_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
125028 +
125029 + if (!plugin_default_version_check(version, &gcc_version)) {
125030 + error(G_("incompatible gcc/plugin versions"));
125031 + return 1;
125032 + }
125033 +
125034 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
125035 +
125036 + for (i = 0; i < argc; ++i) {
125037 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
125038 + if (!argv[i].value) {
125039 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
125040 + continue;
125041 + }
125042 + track_frame_size = atoi(argv[i].value);
125043 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
125044 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
125045 + continue;
125046 + }
125047 + if (!strcmp(argv[i].key, "initialize-locals")) {
125048 + if (argv[i].value) {
125049 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
125050 + continue;
125051 + }
125052 + init_locals = true;
125053 + continue;
125054 + }
125055 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
125056 + }
125057 +
125058 + register_callback(plugin_name, PLUGIN_START_UNIT, &stackleak_start_unit, NULL);
125059 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_stackleak);
125060 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
125061 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
125062 +
125063 + return 0;
125064 +}
125065 diff --git a/tools/gcc/structleak_plugin.c b/tools/gcc/structleak_plugin.c
125066 new file mode 100644
125067 index 0000000..4ee2231
125068 --- /dev/null
125069 +++ b/tools/gcc/structleak_plugin.c
125070 @@ -0,0 +1,274 @@
125071 +/*
125072 + * Copyright 2013-2014 by PaX Team <pageexec@freemail.hu>
125073 + * Licensed under the GPL v2
125074 + *
125075 + * Note: the choice of the license means that the compilation process is
125076 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
125077 + * but for the kernel it doesn't matter since it doesn't link against
125078 + * any of the gcc libraries
125079 + *
125080 + * gcc plugin to forcibly initialize certain local variables that could
125081 + * otherwise leak kernel stack to userland if they aren't properly initialized
125082 + * by later code
125083 + *
125084 + * Homepage: http://pax.grsecurity.net/
125085 + *
125086 + * Usage:
125087 + * $ # for 4.5/4.6/C based 4.7
125088 + * $ 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
125089 + * $ # for C++ based 4.7/4.8+
125090 + * $ 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
125091 + * $ gcc -fplugin=./structleak_plugin.so test.c -O2
125092 + *
125093 + * TODO: eliminate redundant initializers
125094 + * increase type coverage
125095 + */
125096 +
125097 +#include "gcc-common.h"
125098 +
125099 +// unused C type flag in all versions 4.5-4.9
125100 +#define TYPE_USERSPACE(TYPE) TYPE_LANG_FLAG_3(TYPE)
125101 +
125102 +int plugin_is_GPL_compatible;
125103 +
125104 +static struct plugin_info structleak_plugin_info = {
125105 + .version = "201401260140",
125106 + .help = "disable\tdo not activate plugin\n",
125107 +};
125108 +
125109 +static tree handle_user_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
125110 +{
125111 + *no_add_attrs = true;
125112 +
125113 + // check for types? for now accept everything linux has to offer
125114 + if (TREE_CODE(*node) != FIELD_DECL)
125115 + return NULL_TREE;
125116 +
125117 + *no_add_attrs = false;
125118 + return NULL_TREE;
125119 +}
125120 +
125121 +static struct attribute_spec user_attr = {
125122 + .name = "user",
125123 + .min_length = 0,
125124 + .max_length = 0,
125125 + .decl_required = false,
125126 + .type_required = false,
125127 + .function_type_required = false,
125128 + .handler = handle_user_attribute,
125129 +#if BUILDING_GCC_VERSION >= 4007
125130 + .affects_type_identity = true
125131 +#endif
125132 +};
125133 +
125134 +static void register_attributes(void *event_data, void *data)
125135 +{
125136 + register_attribute(&user_attr);
125137 +// register_attribute(&force_attr);
125138 +}
125139 +
125140 +static tree get_field_type(tree field)
125141 +{
125142 + return strip_array_types(TREE_TYPE(field));
125143 +}
125144 +
125145 +static bool is_userspace_type(tree type)
125146 +{
125147 + tree field;
125148 +
125149 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
125150 + tree fieldtype = get_field_type(field);
125151 + enum tree_code code = TREE_CODE(fieldtype);
125152 +
125153 + if (code == RECORD_TYPE || code == UNION_TYPE)
125154 + if (is_userspace_type(fieldtype))
125155 + return true;
125156 +
125157 + if (lookup_attribute("user", DECL_ATTRIBUTES(field)))
125158 + return true;
125159 + }
125160 + return false;
125161 +}
125162 +
125163 +static void finish_type(void *event_data, void *data)
125164 +{
125165 + tree type = (tree)event_data;
125166 +
125167 + if (TYPE_USERSPACE(type))
125168 + return;
125169 +
125170 + if (is_userspace_type(type))
125171 + TYPE_USERSPACE(type) = 1;
125172 +}
125173 +
125174 +static void initialize(tree var)
125175 +{
125176 + basic_block bb;
125177 + gimple_stmt_iterator gsi;
125178 + tree initializer;
125179 + gimple init_stmt;
125180 +
125181 + // this is the original entry bb before the forced split
125182 + // TODO: check further BBs in case more splits occured before us
125183 + bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb->next_bb;
125184 +
125185 + // first check if the variable is already initialized, warn otherwise
125186 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
125187 + gimple stmt = gsi_stmt(gsi);
125188 + tree rhs1;
125189 +
125190 + // we're looking for an assignment of a single rhs...
125191 + if (!gimple_assign_single_p(stmt))
125192 + continue;
125193 + rhs1 = gimple_assign_rhs1(stmt);
125194 +#if BUILDING_GCC_VERSION >= 4007
125195 + // ... of a non-clobbering expression...
125196 + if (TREE_CLOBBER_P(rhs1))
125197 + continue;
125198 +#endif
125199 + // ... to our variable...
125200 + if (gimple_get_lhs(stmt) != var)
125201 + continue;
125202 + // if it's an initializer then we're good
125203 + if (TREE_CODE(rhs1) == CONSTRUCTOR)
125204 + return;
125205 + }
125206 +
125207 + // these aren't the 0days you're looking for
125208 +// inform(DECL_SOURCE_LOCATION(var), "userspace variable will be forcibly initialized");
125209 +
125210 + // build the initializer expression
125211 + initializer = build_constructor(TREE_TYPE(var), NULL);
125212 +
125213 + // build the initializer stmt
125214 + init_stmt = gimple_build_assign(var, initializer);
125215 + gsi = gsi_start_bb(ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb);
125216 + gsi_insert_before(&gsi, init_stmt, GSI_NEW_STMT);
125217 + update_stmt(init_stmt);
125218 +}
125219 +
125220 +static unsigned int handle_function(void)
125221 +{
125222 + basic_block bb;
125223 + unsigned int ret = 0;
125224 + tree var;
125225 + unsigned int i;
125226 +
125227 + // split the first bb where we can put the forced initializers
125228 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
125229 + if (dom_info_available_p(CDI_DOMINATORS))
125230 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
125231 +
125232 + // enumarate all local variables and forcibly initialize our targets
125233 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
125234 + tree type = TREE_TYPE(var);
125235 +
125236 + gcc_assert(DECL_P(var));
125237 + if (!auto_var_in_fn_p(var, current_function_decl))
125238 + continue;
125239 +
125240 + // only care about structure types
125241 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
125242 + continue;
125243 +
125244 + // if the type is of interest, examine the variable
125245 + if (TYPE_USERSPACE(type))
125246 + initialize(var);
125247 + }
125248 +
125249 + return ret;
125250 +}
125251 +
125252 +#if BUILDING_GCC_VERSION >= 4009
125253 +static const struct pass_data structleak_pass_data = {
125254 +#else
125255 +static struct gimple_opt_pass structleak_pass = {
125256 + .pass = {
125257 +#endif
125258 + .type = GIMPLE_PASS,
125259 + .name = "structleak",
125260 +#if BUILDING_GCC_VERSION >= 4008
125261 + .optinfo_flags = OPTGROUP_NONE,
125262 +#endif
125263 +#if BUILDING_GCC_VERSION >= 4009
125264 + .has_gate = false,
125265 + .has_execute = true,
125266 +#else
125267 + .gate = NULL,
125268 + .execute = handle_function,
125269 + .sub = NULL,
125270 + .next = NULL,
125271 + .static_pass_number = 0,
125272 +#endif
125273 + .tv_id = TV_NONE,
125274 + .properties_required = PROP_cfg,
125275 + .properties_provided = 0,
125276 + .properties_destroyed = 0,
125277 + .todo_flags_start = 0,
125278 + .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
125279 +#if BUILDING_GCC_VERSION < 4009
125280 + }
125281 +#endif
125282 +};
125283 +
125284 +#if BUILDING_GCC_VERSION >= 4009
125285 +namespace {
125286 +class structleak_pass : public gimple_opt_pass {
125287 +public:
125288 + structleak_pass() : gimple_opt_pass(structleak_pass_data, g) {}
125289 + unsigned int execute() { return handle_function(); }
125290 +};
125291 +}
125292 +
125293 +static opt_pass *make_structleak_pass(void)
125294 +{
125295 + return new structleak_pass();
125296 +}
125297 +#else
125298 +static struct opt_pass *make_structleak_pass(void)
125299 +{
125300 + return &structleak_pass.pass;
125301 +}
125302 +#endif
125303 +
125304 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
125305 +{
125306 + int i;
125307 + const char * const plugin_name = plugin_info->base_name;
125308 + const int argc = plugin_info->argc;
125309 + const struct plugin_argument * const argv = plugin_info->argv;
125310 + bool enable = true;
125311 + struct register_pass_info structleak_pass_info;
125312 +
125313 + structleak_pass_info.pass = make_structleak_pass();
125314 + structleak_pass_info.reference_pass_name = "ssa";
125315 + structleak_pass_info.ref_pass_instance_number = 1;
125316 + structleak_pass_info.pos_op = PASS_POS_INSERT_AFTER;
125317 +
125318 + if (!plugin_default_version_check(version, &gcc_version)) {
125319 + error(G_("incompatible gcc/plugin versions"));
125320 + return 1;
125321 + }
125322 +
125323 + if (strcmp(lang_hooks.name, "GNU C")) {
125324 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
125325 + enable = false;
125326 + }
125327 +
125328 + for (i = 0; i < argc; ++i) {
125329 + if (!strcmp(argv[i].key, "disable")) {
125330 + enable = false;
125331 + continue;
125332 + }
125333 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
125334 + }
125335 +
125336 + register_callback(plugin_name, PLUGIN_INFO, NULL, &structleak_plugin_info);
125337 + if (enable) {
125338 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &structleak_pass_info);
125339 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
125340 + }
125341 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
125342 +
125343 + return 0;
125344 +}
125345 diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h
125346 index 88461f0..6fb70a0 100644
125347 --- a/tools/include/linux/compiler.h
125348 +++ b/tools/include/linux/compiler.h
125349 @@ -35,6 +35,14 @@
125350 # define unlikely(x) __builtin_expect(!!(x), 0)
125351 #endif
125352
125353 +#ifndef __size_overflow
125354 +# define __size_overflow(...)
125355 +#endif
125356 +
125357 +#ifndef __intentional_overflow
125358 +# define __intentional_overflow(...)
125359 +#endif
125360 +
125361 #define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
125362
125363 #endif /* _TOOLS_LINUX_COMPILER_H */
125364 diff --git a/tools/lib/api/Makefile b/tools/lib/api/Makefile
125365 index ce00f7e..0aca5e4 100644
125366 --- a/tools/lib/api/Makefile
125367 +++ b/tools/lib/api/Makefile
125368 @@ -16,7 +16,7 @@ LIB_OBJS += $(OUTPUT)fs/fs.o
125369
125370 LIBFILE = libapikfs.a
125371
125372 -CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
125373 +CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
125374 EXTLIBS = -lelf -lpthread -lrt -lm
125375 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
125376 ALL_LDFLAGS = $(LDFLAGS)
125377 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
125378 index 6789d788..4afd019e 100644
125379 --- a/tools/perf/util/include/asm/alternative-asm.h
125380 +++ b/tools/perf/util/include/asm/alternative-asm.h
125381 @@ -5,4 +5,7 @@
125382
125383 #define altinstruction_entry #
125384
125385 + .macro pax_force_retaddr rip=0, reload=0
125386 + .endm
125387 +
125388 #endif
125389 diff --git a/tools/virtio/linux/uaccess.h b/tools/virtio/linux/uaccess.h
125390 index 0a578fe..b81f62d 100644
125391 --- a/tools/virtio/linux/uaccess.h
125392 +++ b/tools/virtio/linux/uaccess.h
125393 @@ -13,7 +13,7 @@ static inline void __chk_user_ptr(const volatile void *p, size_t size)
125394 ({ \
125395 typeof(ptr) __pu_ptr = (ptr); \
125396 __chk_user_ptr(__pu_ptr, sizeof(*__pu_ptr)); \
125397 - ACCESS_ONCE(*(__pu_ptr)) = x; \
125398 + ACCESS_ONCE_RW(*(__pu_ptr)) = x; \
125399 0; \
125400 })
125401
125402 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
125403 index 6a3f29b..a1d2e93 100644
125404 --- a/virt/kvm/kvm_main.c
125405 +++ b/virt/kvm/kvm_main.c
125406 @@ -77,12 +77,17 @@ LIST_HEAD(vm_list);
125407
125408 static cpumask_var_t cpus_hardware_enabled;
125409 static int kvm_usage_count = 0;
125410 -static atomic_t hardware_enable_failed;
125411 +static atomic_unchecked_t hardware_enable_failed;
125412
125413 struct kmem_cache *kvm_vcpu_cache;
125414 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
125415
125416 -static __read_mostly struct preempt_ops kvm_preempt_ops;
125417 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
125418 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
125419 +static struct preempt_ops kvm_preempt_ops = {
125420 + .sched_in = kvm_sched_in,
125421 + .sched_out = kvm_sched_out,
125422 +};
125423
125424 struct dentry *kvm_debugfs_dir;
125425
125426 @@ -780,7 +785,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
125427 /* We can read the guest memory with __xxx_user() later on. */
125428 if ((mem->slot < KVM_USER_MEM_SLOTS) &&
125429 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
125430 - !access_ok(VERIFY_WRITE,
125431 + !access_ok_noprefault(VERIFY_WRITE,
125432 (void __user *)(unsigned long)mem->userspace_addr,
125433 mem->memory_size)))
125434 goto out;
125435 @@ -1637,9 +1642,17 @@ EXPORT_SYMBOL_GPL(kvm_read_guest_cached);
125436
125437 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len)
125438 {
125439 - const void *zero_page = (const void *) __va(page_to_phys(ZERO_PAGE(0)));
125440 + int r;
125441 + unsigned long addr;
125442
125443 - return kvm_write_guest_page(kvm, gfn, zero_page, offset, len);
125444 + addr = gfn_to_hva(kvm, gfn);
125445 + if (kvm_is_error_hva(addr))
125446 + return -EFAULT;
125447 + r = __clear_user((void __user *)addr + offset, len);
125448 + if (r)
125449 + return -EFAULT;
125450 + mark_page_dirty(kvm, gfn);
125451 + return 0;
125452 }
125453 EXPORT_SYMBOL_GPL(kvm_clear_guest_page);
125454
125455 @@ -1889,7 +1902,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
125456 return 0;
125457 }
125458
125459 -static struct file_operations kvm_vcpu_fops = {
125460 +static file_operations_no_const kvm_vcpu_fops __read_only = {
125461 .release = kvm_vcpu_release,
125462 .unlocked_ioctl = kvm_vcpu_ioctl,
125463 #ifdef CONFIG_COMPAT
125464 @@ -2593,7 +2606,7 @@ out:
125465 }
125466 #endif
125467
125468 -static struct file_operations kvm_vm_fops = {
125469 +static file_operations_no_const kvm_vm_fops __read_only = {
125470 .release = kvm_vm_release,
125471 .unlocked_ioctl = kvm_vm_ioctl,
125472 #ifdef CONFIG_COMPAT
125473 @@ -2666,7 +2679,7 @@ out:
125474 return r;
125475 }
125476
125477 -static struct file_operations kvm_chardev_ops = {
125478 +static file_operations_no_const kvm_chardev_ops __read_only = {
125479 .unlocked_ioctl = kvm_dev_ioctl,
125480 .compat_ioctl = kvm_dev_ioctl,
125481 .llseek = noop_llseek,
125482 @@ -2692,7 +2705,7 @@ static void hardware_enable_nolock(void *junk)
125483
125484 if (r) {
125485 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
125486 - atomic_inc(&hardware_enable_failed);
125487 + atomic_inc_unchecked(&hardware_enable_failed);
125488 printk(KERN_INFO "kvm: enabling virtualization on "
125489 "CPU%d failed\n", cpu);
125490 }
125491 @@ -2748,10 +2761,10 @@ static int hardware_enable_all(void)
125492
125493 kvm_usage_count++;
125494 if (kvm_usage_count == 1) {
125495 - atomic_set(&hardware_enable_failed, 0);
125496 + atomic_set_unchecked(&hardware_enable_failed, 0);
125497 on_each_cpu(hardware_enable_nolock, NULL, 1);
125498
125499 - if (atomic_read(&hardware_enable_failed)) {
125500 + if (atomic_read_unchecked(&hardware_enable_failed)) {
125501 hardware_disable_all_nolock();
125502 r = -EBUSY;
125503 }
125504 @@ -3156,7 +3169,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
125505 kvm_arch_vcpu_put(vcpu);
125506 }
125507
125508 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
125509 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
125510 struct module *module)
125511 {
125512 int r;
125513 @@ -3203,7 +3216,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
125514 if (!vcpu_align)
125515 vcpu_align = __alignof__(struct kvm_vcpu);
125516 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
125517 - 0, NULL);
125518 + SLAB_USERCOPY, NULL);
125519 if (!kvm_vcpu_cache) {
125520 r = -ENOMEM;
125521 goto out_free_3;
125522 @@ -3213,9 +3226,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
125523 if (r)
125524 goto out_free;
125525
125526 + pax_open_kernel();
125527 kvm_chardev_ops.owner = module;
125528 kvm_vm_fops.owner = module;
125529 kvm_vcpu_fops.owner = module;
125530 + pax_close_kernel();
125531
125532 r = misc_register(&kvm_dev);
125533 if (r) {
125534 @@ -3225,9 +3240,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
125535
125536 register_syscore_ops(&kvm_syscore_ops);
125537
125538 - kvm_preempt_ops.sched_in = kvm_sched_in;
125539 - kvm_preempt_ops.sched_out = kvm_sched_out;
125540 -
125541 r = kvm_init_debug();
125542 if (r) {
125543 printk(KERN_ERR "kvm: create debugfs files failed\n");